diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitClassModifiers.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitClassModifiers.java index 585a20d23d..c3d6789d1d 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitClassModifiers.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitClassModifiers.java @@ -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; @@ -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; /** @@ -45,12 +40,7 @@ tags = SIMPLIFICATION) public final class JUnitClassModifiers extends BugChecker implements ClassTreeMatcher { private static final long serialVersionUID = 1L; - private static final MultiMatcher TEST_METHOD = - annotations( - AT_LEAST_ONE, - anyOf( - isType("org.junit.jupiter.api.Test"), - hasMetaAnnotation("org.junit.jupiter.api.TestTemplate"))); + private static final Matcher NON_FINAL_TEST_CLASS = allOf( not( @@ -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 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); - } }