Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
Issue checkstyle#4940: fix twelfth part idea violations
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimfadora committed Aug 17, 2017
1 parent 32cb732 commit c86c08c
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 43 deletions.
23 changes: 11 additions & 12 deletions config/intellij-idea-inspections.xml
Expand Up @@ -44,8 +44,7 @@
<inspection_tool class="AnonymousClassMethodCount" enabled="false" level="WARNING" enabled_by_default="false"/>
<inspection_tool class="AnonymousClassVariableHidesContainingMethodVariable" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AnonymousFunctionJS" enabled="true" level="ERROR" enabled_by_default="true" />
<!-- suppressed till GSoC project completion .... -->
<inspection_tool class="AnonymousHasLambdaAlternative" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="AnonymousHasLambdaAlternative" enabled="true" level="WARNING" enabled_by_default="true" />
<!-- we are ok with anonymous classes -->
<inspection_tool class="AnonymousInnerClass" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="AnonymousInnerClassMayBeStatic" enabled="true" level="WARNING" enabled_by_default="true">
Expand Down Expand Up @@ -455,8 +454,7 @@ isolated classes and we cannot put them to separate package as it will affect us
<inspection_tool class="ControlFlowStatementWithoutBraces" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="Convert2Diamond" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="Convert2Lambda" enabled="true" level="ERROR" enabled_by_default="true" />
<!-- disabled till GSoC project completion-->
<inspection_tool class="Convert2MethodRef" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="Convert2MethodRef" enabled="true" level="ERROR" enabled_by_default="true" />
<!-- on the moment of review we were not a big fans of functional style, none of code coverage tools can
distinguish that body of lambda is executed. When this problem is resolved we could reconsider disablement. -->
<inspection_tool class="Convert2streamapi" enabled="false" level="ERROR" enabled_by_default="false" />
Expand Down Expand Up @@ -1230,8 +1228,7 @@ isolated classes and we cannot put them to separate package as it will affect us
<!-- on the moment of review we were not a big fans of functional style, none of code coverage tools can
distinguish that body of lambda is executed. When this problem is resolved we could reconsider disablement. -->
<inspection_tool class="Java8MapApi" enabled="false" level="WARNING" enabled_by_default="false" />
<!-- Disabled till GSoC completion -->
<inspection_tool class="Java8MapForEach" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="Java8MapForEach" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="JavaDoc" enabled="true" level="ERROR" enabled_by_default="true">
<option name="TOP_LEVEL_CLASS_OPTIONS">
<value>
Expand Down Expand Up @@ -1522,7 +1519,7 @@ isolated classes and we cannot put them to separate package as it will affect us
</inspection_tool>
<!-- we like nested method calls -->
<inspection_tool class="NestedMethodCall" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="NestedSwitchStatement" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="NestedSwitchStatement" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="NestedSwitchStatementJS" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="NestedSynchronizedStatement" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="NestedTryStatement" enabled="true" level="ERROR" enabled_by_default="true" >
Expand Down Expand Up @@ -1905,8 +1902,7 @@ isolated classes and we cannot put them to separate package as it will affect us
<inspection_tool class="SimplifiableIfStatement" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="SimplifiableJUnitAssertion" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="SimplifyNegatedBinaryExpression" enabled="true" level="ERROR" enabled_by_default="true" />
<!-- suppressed till GSoC project completion .... -->
<inspection_tool class="SimplifyStreamApiCallChains" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="SimplifyStreamApiCallChains" enabled="true" level="WARNING" enabled_by_default="true" />
<!-- the only violation found is false-positive at AvoidEscapedUnicodeCharactersCheck -->
<inspection_tool class="SingleCharAlternation" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="SingleCharacterStartsWith" enabled="true" level="ERROR" enabled_by_default="true" />
Expand Down Expand Up @@ -2051,7 +2047,7 @@ isolated classes and we cannot put them to separate package as it will affect us
<inspection_tool class="StringBufferReplaceableByString" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="StringBufferReplaceableByStringBuilder" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="StringBufferToStringInConcatenation" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="StringCompareTo" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="StringCompareTo" enabled="true" level="ERROR" enabled_by_default="true" />
<!-- we like it, it is not performance issue for us -->
<inspection_tool class="StringConcatenation" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="StringConcatenationArgumentToLogCall" enabled="true" level="ERROR" enabled_by_default="true" />
Expand Down Expand Up @@ -2268,8 +2264,11 @@ isolated classes and we cannot put them to separate package as it will affect us
<inspection_tool class="TodoComment" enabled="false" level="ERROR" enabled_by_default="false" />
<!-- show too much false-positives in our code -->
<inspection_tool class="TooBroadCatch" enabled="false" level="ERROR" enabled_by_default="false" />
<!-- Disabled till GSoC completion -->
<inspection_tool class="TooBroadScope" enabled="false" level="ERROR" enabled_by_default="false">
<inspection_tool class="TooBroadScope" enabled="true" level="ERROR" enabled_by_default="false">
<scope name="Production" level="ERROR" enabled="true">
<option name="m_allowConstructorAsInitializer" value="false" />
<option name="m_onlyLookAtBlocks" value="false" />
</scope>
<option name="m_allowConstructorAsInitializer" value="false" />
<option name="m_onlyLookAtBlocks" value="false" />
</inspection_tool>
Expand Down
Expand Up @@ -133,7 +133,6 @@ public Checker createChecker(Configuration moduleConfig)
* @param moduleConfig {@link Configuration} instance.
* @return {@link Checker} instance.
* @throws CheckstyleException if an exception occurs during checker configuration.
* @noinspection BooleanParameter
*/
protected Checker createChecker(Configuration moduleConfig, boolean addTreeWalker)
throws Exception {
Expand Down
Expand Up @@ -42,7 +42,7 @@ protected String getPackageLocation() {
}

private String getPath(String packageName, String fileName) throws IOException {
return super.getPath("rule521" + packageName + File.separator + fileName);
return getPath("rule521" + packageName + File.separator + fileName);
}

@BeforeClass
Expand Down
Expand Up @@ -322,7 +322,7 @@ private static byte[] loadExternalResource(String location) throws CheckstyleExc
* @return true if the contents of external configuration resources were changed.
*/
private boolean areExternalResourcesChanged(Set<ExternalResource> resources) {
return resources.stream().filter(resource -> {
return resources.stream().anyMatch(resource -> {
boolean changed = false;
if (isResourceLocationInCache(resource.location)) {
final String contentHashSum = resource.contentHashSum;
Expand All @@ -335,7 +335,7 @@ private boolean areExternalResourcesChanged(Set<ExternalResource> resources) {
changed = true;
}
return changed;
}).findFirst().isPresent();
});
}

/**
Expand Down
Expand Up @@ -126,9 +126,9 @@ public FileText(File file, String charsetName) throws IOException {
// Use the BufferedReader to break down the lines as this
// is about 30% faster than using the
// LINE_TERMINATOR.split(fullText, -1) method
final ArrayList<String> textLines = new ArrayList<>();
final BufferedReader reader = new BufferedReader(new StringReader(fullText));
try {
final ArrayList<String> textLines = new ArrayList<>();
while (true) {
final String line = reader.readLine();
if (line == null) {
Expand Down
Expand Up @@ -71,12 +71,8 @@ public class SuppressWarningsHolder
* A thread-local holder for the list of suppression entries for the last
* file parsed.
*/
private static final ThreadLocal<List<Entry>> ENTRIES = new ThreadLocal<List<Entry>>() {
@Override
protected List<Entry> initialValue() {
return new LinkedList<>();
}
};
private static final ThreadLocal<List<Entry>> ENTRIES =
ThreadLocal.withInitial(LinkedList::new);

/**
* Returns the default alias for the source name of a check, which is the
Expand Down
Expand Up @@ -164,8 +164,7 @@ public void finishTree(DetailAST rootAST) {
final DetailAST equalsAST = detailASTDetailASTEntry.getValue();
log(equalsAST.getLineNo(), equalsAST.getColumnNo(), MSG_KEY_HASHCODE);
});
objBlockWithHashCode.entrySet().forEach(detailASTDetailASTEntry -> {
final DetailAST equalsAST = detailASTDetailASTEntry.getValue();
objBlockWithHashCode.forEach((key, equalsAST) -> {
log(equalsAST.getLineNo(), equalsAST.getColumnNo(), MSG_KEY_EQUALS);
});

Expand Down
Expand Up @@ -722,11 +722,11 @@ private static List<String> getTypeArgsClassNames(DetailAST typeArgs) {
* @return true if all of generic type arguments are immutable.
*/
private boolean areImmutableTypeArguments(List<String> typeArgsClassNames) {
return !typeArgsClassNames.stream().filter(
return typeArgsClassNames.stream().noneMatch(
typeName -> {
return !immutableClassShortNames.contains(typeName)
&& !immutableClassCanonicalNames.contains(typeName);
}).findFirst().isPresent();
});
}

/**
Expand Down
Expand Up @@ -248,13 +248,15 @@ private void collectReferencesFromJavadoc(DetailAST ast) {
* @return a set of classes referenced in the javadoc block
*/
private static Set<String> collectReferencesFromJavadoc(TextBlock textBlock) {
final Set<String> references = new HashSet<>();
final List<JavadocTag> tags = new ArrayList<>();
// gather all the inline tags, like @link
// INLINE tags inside BLOCKs get hidden when using ALL
tags.addAll(getValidTags(textBlock, JavadocUtils.JavadocTagType.INLINE));
// gather all the block-level tags, like @throws and @see
tags.addAll(getValidTags(textBlock, JavadocUtils.JavadocTagType.BLOCK));

final Set<String> references = new HashSet<>();

tags.stream()
.filter(JavadocTag::canReferenceImports)
.forEach(tag -> references.addAll(processJavadocTag(tag)));
Expand Down
Expand Up @@ -76,12 +76,7 @@ public abstract class AbstractJavadocCheck extends AbstractCheck {
* to guarantee basic thread safety and avoid shared, mutable state when not necessary.
*/
private static final ThreadLocal<Map<String, ParseStatus>> TREE_CACHE =
new ThreadLocal<Map<String, ParseStatus>>() {
@Override
protected Map<String, ParseStatus> initialValue() {
return new HashMap<>();
}
};
ThreadLocal.withInitial(HashMap::new);

/**
* Parses content of Javadoc comment as DetailNode tree.
Expand Down
Expand Up @@ -77,7 +77,7 @@ public static boolean start(RootDoc root)
final List<Tag> tags = Arrays.asList(field.firstSentenceTags());
final String joinedTags = tags
.stream()
.map(tag -> tag.toString())
.map(Tag::toString)
.collect(Collectors.joining("\", \"", "[\"", "\"]"));
final String message = String.format(Locale.ROOT,
"Should be only one tag for %s. Tags %s.",
Expand Down
Expand Up @@ -147,11 +147,11 @@ public void testClearBranchTokenTypes() throws Exception {
parent.setFirstChild(child);

final List<Consumer<DetailAST>> clearBranchTokenTypesMethods = Arrays.asList(
ast -> child.setFirstChild(ast),
ast -> child.setNextSibling(ast),
ast -> child.addPreviousSibling(ast),
ast -> child.addNextSibling(ast),
ast -> child.addChild(ast),
child::setFirstChild,
child::setNextSibling,
child::addPreviousSibling,
child::addNextSibling,
child::addChild,
ast -> {
try {
Whitebox.invokeMethod(child, "setParent", ast);
Expand Down Expand Up @@ -180,9 +180,9 @@ public void testClearChildCountCache() throws Exception {
parent.setFirstChild(child);

final List<Consumer<DetailAST>> clearChildCountCacheMethods = Arrays.asList(
ast -> child.setNextSibling(ast),
ast -> child.addPreviousSibling(ast),
ast -> child.addNextSibling(ast)
child::setNextSibling,
child::addPreviousSibling,
child::addNextSibling
);

for (Consumer<DetailAST> method : clearChildCountCacheMethods) {
Expand Down

0 comments on commit c86c08c

Please sign in to comment.