Skip to content

Commit

Permalink
Issue checkstyle#3843: Fix coverage problem for DesignForExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
MEZk committed Feb 19, 2017
1 parent 48d48fd commit 603c43d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Expand Up @@ -24,7 +24,6 @@
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
Expand Down Expand Up @@ -102,8 +101,8 @@ public class DesignForExtensionCheck extends AbstractCheck {
/**
* A set of annotations which allow the check to skip the method from validation.
*/
private Set<String> ignoredAnnotations = Stream.of("Test", "Before", "After", "BeforeClass",
"AfterClass").collect(Collectors.toSet());
private Set<String> ignoredAnnotations = Arrays.stream(new String[] {"Test", "Before", "After",
"BeforeClass", "AfterClass", }).collect(Collectors.toSet());

/**
* Sets annotations which allow the check to skip the method from validation.
Expand Down Expand Up @@ -139,9 +138,9 @@ public boolean isCommentNodesRequired() {
@Override
public void visitToken(DetailAST ast) {
if (!hasJavadocComment(ast)
&& canBeOverridden(ast)
&& (isNativeMethod(ast)
|| !hasEmptyImplementation(ast))
&& canBeOverridden(ast)
&& !hasIgnoredAnnotation(ast, ignoredAnnotations)) {

final DetailAST classDef = getNearestClassOrEnumDefinition(ast);
Expand Down Expand Up @@ -182,19 +181,17 @@ private boolean isNativeMethod(DetailAST ast) {
private static boolean hasEmptyImplementation(DetailAST ast) {
boolean hasEmptyBody = true;
final DetailAST methodImplOpenBrace = ast.findFirstToken(TokenTypes.SLIST);
if (methodImplOpenBrace != null) {
final DetailAST methodImplCloseBrace = methodImplOpenBrace.getLastChild();
final Predicate<DetailAST> predicate = currentNode -> {
return currentNode != null
&& currentNode != methodImplCloseBrace
&& currentNode.getLineNo() <= methodImplCloseBrace.getLineNo()
&& !TokenUtils.isCommentType(currentNode.getType());
};
final Optional<DetailAST> methodBody =
TokenUtils.findFirstTokenByPredicate(methodImplOpenBrace, predicate);
if (methodBody.isPresent()) {
hasEmptyBody = false;
}
final DetailAST methodImplCloseBrace = methodImplOpenBrace.getLastChild();
final Predicate<DetailAST> predicate = currentNode -> {
return currentNode != null
&& currentNode != methodImplCloseBrace
&& currentNode.getLineNo() <= methodImplCloseBrace.getLineNo()
&& !TokenUtils.isCommentType(currentNode.getType());
};
final Optional<DetailAST> methodBody =
TokenUtils.findFirstTokenByPredicate(methodImplOpenBrace, predicate);
if (methodBody.isPresent()) {
hasEmptyBody = false;
}
return hasEmptyBody;
}
Expand Down
Expand Up @@ -218,4 +218,8 @@ public final class B {

protected final int foo4(int a, int b) {return a + b;}
}

public abstract class C {
public abstract void foo1(int a);
}
}

0 comments on commit 603c43d

Please sign in to comment.