Skip to content

Commit

Permalink
Issue checkstyle#3455: removed guava from api code
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Dec 6, 2017
1 parent 7a30bb9 commit 4d34484
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 30 deletions.
5 changes: 0 additions & 5 deletions config/import-control.xml
Expand Up @@ -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"/>
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Up @@ -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
Expand All @@ -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();
}
Expand Up @@ -23,12 +23,12 @@
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;

Expand Down Expand Up @@ -165,7 +165,7 @@ public void reportCppComment(int startLineNo, int startColNo) {
* @deprecated Use {@link #getSingleLineComments()} instead.
*/
@Deprecated
public ImmutableMap<Integer, TextBlock> getCppComments() {
public Map<Integer, TextBlock> getCppComments() {
return getSingleLineComments();
}

Expand All @@ -174,8 +174,8 @@ public ImmutableMap<Integer, TextBlock> getCppComments() {
* 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);
}

/**
Expand All @@ -202,7 +202,7 @@ public void reportCComment(int startLineNo, int startColNo,
*/
// -@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();
}

Expand All @@ -212,8 +212,8 @@ public ImmutableMap<Integer, List<TextBlock>> getCComments() {
* 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);
}

/**
Expand Down
Expand Up @@ -37,7 +37,7 @@
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.
Expand Down Expand Up @@ -139,7 +139,7 @@ public FileText(File file, String charsetName) throws IOException {
lines = textLines.toArray(new String[textLines.size()]);
}
finally {
Closeables.closeQuietly(reader);
CommonUtils.close(reader);
}
}

Expand Down Expand Up @@ -209,7 +209,7 @@ private static String readFile(final File inputFile, final CharsetDecoder decode
}
}
finally {
Closeables.closeQuietly(reader);
CommonUtils.close(reader);
}
return buf.toString();
}
Expand Down
Expand Up @@ -34,8 +34,6 @@
import org.junit.Test;
import org.powermock.reflect.Whitebox;

import com.google.common.collect.ImmutableMap;

public class FileContentsTest {

@Test
Expand Down Expand Up @@ -101,7 +99,7 @@ public void testReportComment() {
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(),
Expand Down Expand Up @@ -158,7 +156,7 @@ public void testExtractBlockComment() {
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();

Expand Down
Expand Up @@ -38,11 +38,11 @@
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() {
Expand All @@ -67,17 +67,17 @@ public void testUnsupportedCharset() throws IOException {
@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")),
charsetName);
assertEquals("Invalid charset name", charsetName, fileText.getCharset().name());

verifyStatic(times(2));
Closeables.closeQuietly(any(Reader.class));
CommonUtils.close(any(Reader.class));
}

@Test
Expand Down

0 comments on commit 4d34484

Please sign in to comment.