Skip to content

Commit

Permalink
UnusedMethod: pioneer a list of exempting class annotations in orde…
Browse files Browse the repository at this point in the history
…r to exempt methods on `AnnotationsToApply` classes.

PiperOrigin-RevId: 565654920
  • Loading branch information
graememorgan authored and Error Prone Team committed Sep 15, 2023
1 parent 5c391b4 commit 19fefad
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static com.google.errorprone.util.ASTHelpers.canBeRemoved;
import static com.google.errorprone.util.ASTHelpers.getSymbol;
import static com.google.errorprone.util.ASTHelpers.getType;
import static com.google.errorprone.util.ASTHelpers.hasAnnotation;
import static com.google.errorprone.util.ASTHelpers.isGeneratedConstructor;
import static com.google.errorprone.util.ASTHelpers.isSubtype;
import static com.google.errorprone.util.ASTHelpers.scope;
Expand Down Expand Up @@ -150,6 +151,9 @@ public final class UnusedMethod extends BugChecker implements CompilationUnitTre
"org.junit.jupiter.api.Test",
"org.junit.jupiter.params.ParameterizedTest");

/** Class annotations which exempt methods within the annotated class from findings. */
private static final ImmutableSet<String> EXEMPTING_CLASS_ANNOTATIONS = ImmutableSet.of();

/** The set of types exempting a type that is extending or implementing them. */
private static final ImmutableSet<String> EXEMPTING_SUPER_TYPES = ImmutableSet.of();

Expand Down Expand Up @@ -188,7 +192,8 @@ class MethodFinder extends SuppressibleTreePathScanner<Void, Void> {

@Override
public Void visitClass(ClassTree tree, Void unused) {
if (exemptedBySuperType(getType(tree), state)) {
if (exemptedBySuperType(getType(tree), state)
|| EXEMPTING_CLASS_ANNOTATIONS.stream().anyMatch(a -> hasAnnotation(tree, a, state))) {
return null;
}
return super.visitClass(tree, null);
Expand Down

0 comments on commit 19fefad

Please sign in to comment.