diff options
author | rnveach <rveach02@gmail.com> | 2017-12-05 10:51:46 -0500 |
---|---|---|
committer | Roman Ivanov <romani@users.noreply.github.com> | 2017-12-31 07:18:57 -0800 |
commit | 98fd9b84ef6fa5f7bb5d1a6299605c3f6e6e458f (patch) | |
tree | e6a9c1a568235667ddff7cdd0f6a7b40a3b025a7 | |
parent | 0ec49f18bb9e17a988ca0eb169f3cccb461df65c (diff) | |
download | checkstyle-98fd9b84ef6fa5f7bb5d1a6299605c3f6e6e458f.tar.gz |
Issue #3455: removed guava from api code
7 files changed, 22 insertions, 30 deletions
diff --git a/config/import-control.xml b/config/import-control.xml index 88242f9e0..2a9ce1b7f 100644 --- a/config/import-control.xml +++ b/config/import-control.xml @@ -95,11 +95,6 @@ local-only="true"/> <allow pkg="org.antlr.v4.runtime" local-only="true"/> - <!-- allowed till https://github.com/checkstyle/checkstyle/issues/3455 --> - <allow class="com.google.common.io.Closeables" local-only="true"/> - <allow class="com.google.common.collect.ImmutableCollection" local-only="true"/> - <allow class="com.google.common.collect.ImmutableMap" local-only="true"/> - <allow class="com.puppycrawl.tools.checkstyle.Checker" local-only="true"/> <!-- allowed till https://github.com/checkstyle/checkstyle/issues/3817 --> <allow pkg="com.puppycrawl.tools.checkstyle.utils"/> diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/Configuration.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/Configuration.java index e4fc7191b..c50b2d1f0 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/Configuration.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/Configuration.java @@ -20,8 +20,7 @@ package com.puppycrawl.tools.checkstyle.api; import java.io.Serializable; - -import com.google.common.collect.ImmutableMap; +import java.util.Map; /** * A Configuration is used to configure a Configurable component. The general @@ -61,5 +60,5 @@ public interface Configuration extends Serializable { * for this configuration. * @return unmodifiable map containing custom messages */ - ImmutableMap<String, String> getMessages(); + Map<String, String> getMessages(); } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/Context.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/Context.java index 795de7058..e96c66352 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/Context.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/Context.java @@ -19,7 +19,7 @@ package com.puppycrawl.tools.checkstyle.api; -import com.google.common.collect.ImmutableCollection; +import java.util.Collection; /** * A context to be used in subcomponents. The general idea of @@ -40,5 +40,5 @@ public interface Context { * Returns the names of all attributes of this context. * @return the names of all attributes of this context. */ - ImmutableCollection<String> getAttributeNames(); + Collection<String> getAttributeNames(); } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/FileContents.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/FileContents.java index ca9a5b363..6aa0ad823 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/FileContents.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/FileContents.java @@ -23,12 +23,12 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Pattern; -import com.google.common.collect.ImmutableMap; import com.puppycrawl.tools.checkstyle.grammars.CommentListener; import com.puppycrawl.tools.checkstyle.utils.CommonUtils; @@ -165,7 +165,7 @@ public final class FileContents implements CommentListener { * @deprecated Use {@link #getSingleLineComments()} instead. */ @Deprecated - public ImmutableMap<Integer, TextBlock> getCppComments() { + public Map<Integer, TextBlock> getCppComments() { return getSingleLineComments(); } @@ -174,8 +174,8 @@ public final class FileContents implements CommentListener { * the value is the comment {@link TextBlock} at the line. * @return the Map of comments */ - public ImmutableMap<Integer, TextBlock> getSingleLineComments() { - return ImmutableMap.copyOf(cppComments); + public Map<Integer, TextBlock> getSingleLineComments() { + return Collections.unmodifiableMap(cppComments); } /** @@ -202,7 +202,7 @@ public final class FileContents implements CommentListener { */ // -@cs[AbbreviationAsWordInName] Can't change yet since class is API. @Deprecated - public ImmutableMap<Integer, List<TextBlock>> getCComments() { + public Map<Integer, List<TextBlock>> getCComments() { return getBlockComments(); } @@ -212,8 +212,8 @@ public final class FileContents implements CommentListener { * that start at that line. * @return the map of comments */ - public ImmutableMap<Integer, List<TextBlock>> getBlockComments() { - return ImmutableMap.copyOf(clangComments); + public Map<Integer, List<TextBlock>> getBlockComments() { + return Collections.unmodifiableMap(clangComments); } /** diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/FileText.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/FileText.java index 3b12ffe20..64e919541 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/FileText.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/FileText.java @@ -37,7 +37,7 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.google.common.io.Closeables; +import com.puppycrawl.tools.checkstyle.utils.CommonUtils; /** * Represents the text contents of a file of arbitrary plain text type. @@ -139,7 +139,7 @@ public final class FileText { lines = textLines.toArray(new String[textLines.size()]); } finally { - Closeables.closeQuietly(reader); + CommonUtils.close(reader); } } @@ -209,7 +209,7 @@ public final class FileText { } } finally { - Closeables.closeQuietly(reader); + CommonUtils.close(reader); } return buf.toString(); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/api/FileContentsTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/api/FileContentsTest.java index 5bd90a89b..13a874328 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/api/FileContentsTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/api/FileContentsTest.java @@ -34,8 +34,6 @@ import java.util.Map; import org.junit.Test; import org.powermock.reflect.Whitebox; -import com.google.common.collect.ImmutableMap; - public class FileContentsTest { @Test @@ -101,7 +99,7 @@ public class FileContentsTest { final FileContents fileContents = new FileContents( new FileText(new File("filename"), Collections.singletonList(" // "))); fileContents.reportCComment(1, 2, 1, 2); - final ImmutableMap<Integer, List<TextBlock>> comments = fileContents.getCComments(); + final Map<Integer, List<TextBlock>> comments = fileContents.getCComments(); assertEquals("Invalid comment", new Comment(new String[] {"/"}, 2, 1, 2).toString(), @@ -158,7 +156,7 @@ public class FileContentsTest { new FileText(new File("filename"), Arrays.asList(" ", " ", " /* test ", " */ ", " "))); fileContents.reportCComment(3, 2, 4, 2); - final ImmutableMap<Integer, List<TextBlock>> blockComments = + final Map<Integer, List<TextBlock>> blockComments = fileContents.getBlockComments(); final String[] text = blockComments.get(3).get(0).getText(); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/api/FileTextTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/api/FileTextTest.java index af5d93cf8..7918d9683 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/api/FileTextTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/api/FileTextTest.java @@ -38,11 +38,11 @@ import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import com.google.common.io.Closeables; import com.puppycrawl.tools.checkstyle.AbstractPathTestSupport; +import com.puppycrawl.tools.checkstyle.utils.CommonUtils; @RunWith(PowerMockRunner.class) -@PrepareForTest(Closeables.class) +@PrepareForTest(CommonUtils.class) public class FileTextTest extends AbstractPathTestSupport { @Override protected String getPackageLocation() { @@ -67,9 +67,9 @@ public class FileTextTest extends AbstractPathTestSupport { @Test public void testSupportedCharset() throws IOException { //check if reader finally closed - mockStatic(Closeables.class); - doNothing().when(Closeables.class); - Closeables.closeQuietly(any(Reader.class)); + mockStatic(CommonUtils.class); + doNothing().when(CommonUtils.class); + CommonUtils.close(any(Reader.class)); final String charsetName = StandardCharsets.ISO_8859_1.name(); final FileText fileText = new FileText(new File(getPath("InputFileTextImportControl.xml")), @@ -77,7 +77,7 @@ public class FileTextTest extends AbstractPathTestSupport { assertEquals("Invalid charset name", charsetName, fileText.getCharset().name()); verifyStatic(times(2)); - Closeables.closeQuietly(any(Reader.class)); + CommonUtils.close(any(Reader.class)); } @Test |