Class JavacAnnotationEqualityVisitor
- All Implemented Interfaces:
TreeVisitor<Void,Tree>
findMismatch(Tree, Tree) tests if they have the same annotations.
Two annotations are compared as AnnotationMirrors when both ASTs have been attributed
by javac, and as source text otherwise; see sameAnnotation(com.sun.source.tree.AnnotationTree, com.sun.source.tree.AnnotationTree).
Known gap: a receiver parameter is compared only if both ASTs have one, because a
.ajava file may add an explicit receiver parameter that the Java file omits. As a consequence,
if a receiver parameter appears in only one of the two ASTs, its annotations are ignored rather
than reported as a mismatch. See DoubleJavacVisitor.visitMethod(com.sun.source.tree.MethodTree, com.sun.source.tree.Tree).
This is the javac-based replacement for AnnotationEqualityVisitor.
-
Field Summary
Fields inherited from class com.sun.source.util.SimpleTreeVisitor
DEFAULT_VALUE -
Method Summary
Modifier and TypeMethodDescriptionprotected VoiddefaultAction(Tree tree1, Tree tree2) Default action performed on each pair of nodes from matching ASTs.findMismatch(Tree tree1, Tree tree2) Returns null if the two ASTs have matching annotations everywhere, or the first pair of corresponding nodes where annotations differ.protected voidvisitAnnotationList(Tree owner1, Tree owner2, List<? extends AnnotationTree> annotations1, List<? extends AnnotationTree> annotations2) Visits two corresponding annotation lists.Methods inherited from class org.checkerframework.framework.ajava.DoubleJavacVisitor
assertSameKind, assertSameLength, scan, scanList, scanModifiers, visitAnnotatedType, visitAnnotation, visitArrayAccess, visitArrayType, visitAssert, visitAssignment, visitBinary, visitBindingPattern, visitBlock, visitBreak, visitCase, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitEnhancedForLoop, visitErroneous, visitExports, visitExpressionStatement, visitForLoop, visitIdentifier, visitIf, visitImport, visitInstanceOf, visitIntersectionType, visitLabeledStatement, visitLambdaExpression, visitLiteral, visitMemberReference, visitMemberSelect, visitMethod, visitMethodInvocation, visitModifiers, visitModule, visitNewArray, visitNewClass, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitPrimitiveType, visitProvides, visitRequires, visitReturn, visitSwitch, visitSwitchExpression, visitSynchronized, visitThrow, visitTry, visitTypeCast, visitTypeParameter, visitUnary, visitUnionType, visitUses, visitVariable, visitWhileLoop, visitWildcard, visitYieldMethods inherited from class com.sun.source.util.SimpleTreeVisitor
visit, visit, visitAnyPattern, visitConstantCaseLabel, visitDeconstructionPattern, visitDefaultCaseLabel, visitPatternCaseLabel, visitStringTemplate
-
Method Details
-
findMismatch
Returns null if the two ASTs have matching annotations everywhere, or the first pair of corresponding nodes where annotations differ. The comparison is order-sensitive: nodes with the same annotations in a different order are considered to differ. Only the first mismatch is returned even if multiple mismatches exist.- Parameters:
tree1- root of the first ASTtree2- root of the second AST- Returns:
- null if annotations match everywhere, or a pair of corresponding nodes from
tree1andtree2where annotations differ - Throws:
UserError- if the two ASTs differ other than in annotations; for example, if one declares a member that the other does not
-
defaultAction
Description copied from class:DoubleJavacVisitorDefault action performed on each pair of nodes from matching ASTs.This method is called by each
visitXyzmethod in this class before scanning child trees. It does not itself recurse; recursion is driven by thevisitXyzmethods.- Specified by:
defaultActionin classDoubleJavacVisitor- Parameters:
tree1- the first tree in the matched pairtree2- the second tree in the matched pair- Returns:
- null
-
visitAnnotationList
protected void visitAnnotationList(Tree owner1, Tree owner2, List<? extends AnnotationTree> annotations1, List<? extends AnnotationTree> annotations2) Description copied from class:DoubleJavacVisitorVisits two corresponding annotation lists. This base implementation does nothing because annotations may legitimately differ between a Java file and its corresponding.ajavafile. Subclasses may override this method to process annotations.- Overrides:
visitAnnotationListin classDoubleJavacVisitor- Parameters:
owner1- the tree from the first AST that the annotations are attached toowner2- the tree from the second AST that the annotations are attached toannotations1- annotation list from the first ASTannotations2- annotation list from the second AST
-