Skip to content

Commit

Permalink
Use utilities introduced in #335
Browse files Browse the repository at this point in the history
  • Loading branch information
oxkitsune authored and Stephan202 committed Nov 27, 2022
1 parent f1348e7 commit 5fa10c9
Showing 1 changed file with 3 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import static com.google.errorprone.matchers.Matchers.isType;
import static com.google.errorprone.matchers.Matchers.not;
import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL;
import static tech.picnic.errorprone.bugpatterns.util.MoreJUnitMatchers.TEST_METHOD;
import static tech.picnic.errorprone.bugpatterns.util.MoreMatchers.hasMetaAnnotation;

import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableSet;
Expand All @@ -23,14 +25,7 @@
import com.google.errorprone.fixes.SuggestedFixes;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.matchers.Matcher;
import com.google.errorprone.matchers.MultiMatcher;
import com.google.errorprone.predicates.TypePredicate;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.AnnotationTree;
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.Tree;
import com.sun.tools.javac.code.Symbol;
import javax.lang.model.element.Modifier;

/**
Expand All @@ -45,12 +40,7 @@
tags = SIMPLIFICATION)
public final class JUnitClassModifiers extends BugChecker implements ClassTreeMatcher {
private static final long serialVersionUID = 1L;
private static final MultiMatcher<MethodTree, AnnotationTree> TEST_METHOD =
annotations(
AT_LEAST_ONE,
anyOf(
isType("org.junit.jupiter.api.Test"),
hasMetaAnnotation("org.junit.jupiter.api.TestTemplate")));

private static final Matcher<ClassTree> NON_FINAL_TEST_CLASS =
allOf(
not(
Expand Down Expand Up @@ -86,18 +76,4 @@ public Description matchClass(ClassTree tree, VisitorState state) {

return describeMatch(tree, fixBuilder.build());
}

// XXX: Move to a `MoreMatchers` utility class.
private static Matcher<Tree> hasMetaAnnotation(String annotationClassName) {
TypePredicate typePredicate = hasAnnotation(annotationClassName);
return (tree, state) -> {
Symbol sym = ASTHelpers.getSymbol(tree);
return sym != null && typePredicate.apply(sym.type, state);
};
}

// XXX: Move to a `MoreTypePredicates` utility class.
private static TypePredicate hasAnnotation(String annotationClassName) {
return (type, state) -> ASTHelpers.hasAnnotation(type.tsym, annotationClassName, state);
}
}

0 comments on commit 5fa10c9

Please sign in to comment.