Skip to content

Commit

Permalink
Add notes to UnusedMethod and UnusedVariable to discourage adding mor…
Browse files Browse the repository at this point in the history
…e annotations to the lists of exempting annotations.

PiperOrigin-RevId: 663238173
  • Loading branch information
graememorgan authored and Error Prone Team committed Aug 15, 2024
1 parent 7d4ad63 commit f69e102
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ public final class UnusedMethod extends BugChecker implements CompilationUnitTre
private static final String JUNIT_PARAMS_VALUE = "value";
private static final String JUNIT_PARAMS_ANNOTATION_TYPE = "junitparams.Parameters";

/**
* Annotations that exempt methods from being considered unused.
*
* <p>Try to avoid adding more annotations here. Annotating these annotations with {@code @Keep}
* has the same effect; this list is chiefly for third-party annotations which cannot be
* annotated.
*/
private static final ImmutableSet<String> EXEMPTING_METHOD_ANNOTATIONS =
ImmutableSet.of(
"com.fasterxml.jackson.annotation.JsonCreator",
Expand Down Expand Up @@ -159,10 +166,22 @@ 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. */
/**
* Class annotations which exempt methods within the annotated class from findings.
*
* <p>Try to avoid adding more annotations here. Annotating these annotations with {@code @Keep}
* has the same effect; this list is chiefly for third-party annotations which cannot be
* annotated.
*/
private static final ImmutableSet<String> EXEMPTING_CLASS_ANNOTATIONS = ImmutableSet.of();

/** The set of types exempting a type that is extending or implementing them. */
/**
* The set of types exempting a type that is extending or implementing them.
*
* <p>Try to avoid adding more annotations here. Annotating these annotations with {@code @Keep}
* has the same effect; this list is chiefly for third-party annotations which cannot be
* annotated.
*/
private static final ImmutableSet<String> EXEMPTING_SUPER_TYPES = ImmutableSet.of();

private final ImmutableSet<String> exemptingMethodAnnotations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ public final class UnusedVariable extends BugChecker implements CompilationUnitT

/**
* The set of annotation full names which exempt annotated element from being reported as unused.
*
* <p>Try to avoid adding more annotations here. Annotating these annotations with {@code @Keep}
* has the same effect; this list is chiefly for third-party annotations which cannot be
* annotated.
*/
private static final ImmutableSet<String> EXEMPTING_VARIABLE_ANNOTATIONS =
ImmutableSet.of(
Expand Down

0 comments on commit f69e102

Please sign in to comment.