Skip to content

Commit

Permalink
Issue checkstyle#3848: Increase code coverage of RequireThisCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
MEZk committed Feb 27, 2017
1 parent ee700b7 commit 242cfe3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Expand Up @@ -1437,12 +1437,6 @@
<branchRate>79</branchRate>
<lineRate>97</lineRate>
</regex>
<!--Until https://github.com/checkstyle/checkstyle/issues/3848-->
<regex>
<pattern>com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck</pattern>
<branchRate>99</branchRate>
<lineRate>100</lineRate>
</regex>
</regexes>
</check>
<instrumentation>
Expand Down
Expand Up @@ -428,7 +428,8 @@ private void endCollectingDeclarations(Queue<AbstractFrame> frameStack, DetailAS
*/
private static boolean isAnonymousClassDef(DetailAST ast) {
final DetailAST lastChild = ast.getLastChild();
return lastChild != null && lastChild.getType() == TokenTypes.OBJBLOCK;
return lastChild != null
&& lastChild.getType() == TokenTypes.OBJBLOCK;
}

/**
Expand Down Expand Up @@ -800,8 +801,7 @@ private static Set<DetailAST> getAllTokensWhichAreEqualToCurrent(DetailAST ast,
private AbstractFrame getMethodWithoutThis(DetailAST ast) {
AbstractFrame result = null;
final AbstractFrame frame = findFrame(ast, true);
if (frame != null
&& !validateOnlyOverlapping
if (!validateOnlyOverlapping
&& ((ClassFrame) frame).hasInstanceMethod(ast)
&& !((ClassFrame) frame).hasStaticMethod(ast)) {
result = frame;
Expand Down
Expand Up @@ -252,4 +252,13 @@ public void testStatic() throws Exception {
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputRequireThisStatic.java"), expected);
}

@Test
public void testMethodReferencess() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(RequireThisCheck.class);
final String[] expected = {
"15:9: " + getCheckMessage(MSG_VARIABLE, "tags", ""),
};
verify(checkConfig, getPath("InputRequireThisMetodReferences.java"), expected);
}
}
@@ -0,0 +1,23 @@
package com.puppycrawl.tools.checkstyle.checks.coding;

import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

public class InputRequireThisMetodReferences {
private Set<String> tags = Collections.unmodifiableSortedSet(
Arrays.stream(new String[] {"br", "li", "dt", "dd", "hr", "img", "p", "td", "tr", "th",})
.collect(Collectors.toCollection(TreeSet::new)));

public InputRequireThisMetodReferences(Set<String> tags) {
tags = tags; // violation
}

public InputRequireThisMetodReferences() {
this.tags = Arrays.stream(
new String[] {"br", "li", "dt", "dd", "hr", "img", "p", "td", "tr", "th",})
.collect(Collectors.toCollection(TreeSet::new));
}
}

0 comments on commit 242cfe3

Please sign in to comment.