Class AnnotationFieldReferenceFinder
java.lang.Object
org.sonar.plugins.java.api.tree.BaseTreeVisitor
org.sonar.java.checks.unused.utils.AnnotationFieldReferenceFinder
- All Implemented Interfaces:
TreeVisitor
Finds usages of fields inside annotations.
I.e. currently it is used in
UnusedPrivateFieldCheck to determine whether a field that is not used anywhere in the traditional
sense may actually be used inside a testing annotation.
E.g.
invalid input: '{@code
// This field is used in the @FieldSource annotation below.
private static final List<Integer> field = List.of(1, 2, 3);
@ParameterizedTest
@FieldSource("field")
void test(int input) {
// ...
}
</pre>'-
Method Summary
Modifier and TypeMethodDescriptionReturns the variable trees of all fields that have not been referenced by an annotation.findReferencesTo(Collection<VariableTree> fields) Constructs an instance of this visitor that looks for references of the given fields inside annotations.voidvisitAnnotation(AnnotationTree annotationTree) voidvisitClass(ClassTree tree) Methods inherited from class BaseTreeVisitor
scan, scan, scan, visitArrayAccessExpression, visitArrayDimension, visitArrayType, visitAssertStatement, visitAssignmentExpression, visitBinaryExpression, visitBlock, visitBreakStatement, visitCaseGroup, visitCaseLabel, visitCatch, visitCompilationUnit, visitConditionalExpression, visitContinueStatement, visitDefaultPattern, visitDoWhileStatement, visitEmptyStatement, visitEnumConstant, visitExportsDirectiveTree, visitExpressionStatement, visitForEachStatement, visitForStatement, visitGuardedPattern, visitIdentifier, visitIfStatement, visitImport, visitInstanceOf, visitLabeledStatement, visitLambdaExpression, visitLiteral, visitMemberSelectExpression, visitMethod, visitMethodInvocation, visitMethodReference, visitModifier, visitModule, visitNewArray, visitNewClass, visitNullPattern, visitOpensDirective, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitPatternInstanceOf, visitPrimitiveType, visitProvidesDirective, visitRecordPattern, visitRequiresDirectiveTree, visitReturnStatement, visitSwitchExpression, visitSwitchStatement, visitSynchronizedStatement, visitThrowStatement, visitTryStatement, visitTypeArguments, visitTypeCast, visitTypeParameter, visitTypeParameters, visitTypePattern, visitUnaryExpression, visitUnionType, visitUsesDirective, visitVariable, visitVarType, visitWhileStatement, visitWildcard, visitYieldStatement
-
Method Details
-
findReferencesTo
Constructs an instance of this visitor that looks for references of the given fields inside annotations. -
fieldsNotReferencedInAnnotation
Returns the variable trees of all fields that have not been referenced by an annotation. This method must be called after visiting the class tree of the fields given tofindReferencesTo(Collection). -
visitAnnotation
- Specified by:
visitAnnotationin interfaceTreeVisitor- Overrides:
visitAnnotationin classBaseTreeVisitor
-
visitClass
- Specified by:
visitClassin interfaceTreeVisitor- Overrides:
visitClassin classBaseTreeVisitor
-