Class InterningVisitor
java.lang.Object
com.sun.source.util.TreeScanner<R,P>
com.sun.source.util.TreePathScanner<R,P>
org.checkerframework.framework.source.SourceVisitor<Void,Void>
org.checkerframework.common.basetype.BaseTypeVisitor<InterningAnnotatedTypeFactory>
org.checkerframework.checker.interning.InterningVisitor
- All Implemented Interfaces:
TreeVisitor<Void,
Void>
Typechecks source code for interning violations. A type is considered interned if its primary
annotation is
Interned
or InternedDistinct
. This visitor reports errors or
warnings for violations for the following cases:
- either argument to a "==" or "!=" comparison is not Interned (error "not.interned"). As a special case, the comparison is permitted if either argument is InternedDistinct.
- the receiver and argument for a call to an equals method are both Interned (optional warning "unnecessary.equals")
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
BaseTypeVisitor.OverrideChecker
-
Field Summary
Fields inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
assumePureGetters, atypeFactory, checker, DETERMINISTIC, IMPURE, methodTree, positions, PURE, qualHierarchy, showchecks, SIDE_EFFECT_FREE, TARGET, targetValueElement, typeHierarchy, typeValidator, unusedWhenElement, warnRedundantAnnotations
Fields inherited from class org.checkerframework.framework.source.SourceVisitor
elements, root, trees, treesWithSuppressWarnings, types
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkConstructorResult
(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, ExecutableElement constructorElement) Issue a warning if the result type of the constructor declaration is not top.static boolean
Tests whether a method invocation is an invocation ofObject.equals(java.lang.Object)
with one argument.protected boolean
isTypeCastSafe
(AnnotatedTypeMirror castType, AnnotatedTypeMirror exprType) Returns true if the cast is safe.void
processClassTree
(ClassTree classTree) Method to implement the @UsesObjectEquals functionality.void
processMethodTree
(MethodTree tree) Type-check methodTree.boolean
validateTypeOf
(Tree tree) Tests whether the tree expressed by the passed type tree is a valid type, and emits an error if that is not the case (e.g.visitBinary
(BinaryTree tree, Void p) Checks comparison operators, == and !=, for INTERNING violations.If lint option "dotequals" is specified, warn if the .equals method is used where reference equality is safe.Methods inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
checkAccess, checkAccessAllowed, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkConstructorInvocation, checkContract, checkDefaultConstructor, checkExceptionParameter, checkExplicitAnnotationsOnIntersectionBounds, checkExtendsAndImplements, checkExtendsOrImplements, checkFieldInvariantDeclarations, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkOverride, checkPostcondition, checkPreconditions, checkPurityAnnotations, checkQualifierParameter, checkSuperConstructorCall, checkThisConstructorCall, checkThisOrSuperConstructorCall, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, contractExpressionAndType, createOverrideChecker, createTypeFactory, createTypeFactoryPublic, createTypeValidator, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isValidUse, isValidUse, isValidUse, reportMethodInvocabilityError, reportPurityErrors, scan, setRoot, shouldPerformContractInference, shouldSkipUses, shouldWarnAboutIrrelevantJavaTypes, skipReceiverSubtypeCheck, testAnnotationInsertion, testJointJavacJavaParserVisitor, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateType, visitAnnotatedType, visitAnnotatedType, visitAnnotation, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethod, visitNewArray, visitNewClass, visitReturn, visitSwitchExpression17, visitThrow, visitTypeCast, visitTypeParameter, visitUnary, visitVariable, warnAboutIrrelevantJavaTypes, warnInvalidPolymorphicQualifier, warnInvalidPolymorphicQualifier, warnRedundantAnnotations
Methods inherited from class org.checkerframework.framework.source.SourceVisitor
visit
Methods inherited from class com.sun.source.util.TreePathScanner
getCurrentPath, scan
Methods inherited from class com.sun.source.util.TreeScanner
reduce, scan, visitArrayAccess, visitArrayType, visitAssert, visitBindingPattern, visitBlock, visitBreak, visitCase, visitContinue, visitDefaultCaseLabel, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExports, visitExpressionStatement, visitForLoop, visitGuardedPattern, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitMemberSelect, visitModifiers, visitModule, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitParenthesizedPattern, visitPrimitiveType, visitProvides, visitRequires, visitSwitch, visitSwitchExpression, visitSynchronized, visitTry, visitUnionType, visitUses, visitWhileLoop, visitWildcard, visitYield
-
Constructor Details
-
InterningVisitor
Create an InterningVisitor.
-
-
Method Details
-
visitBinary
Checks comparison operators, == and !=, for INTERNING violations.- Specified by:
visitBinary
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitBinary
in classTreeScanner<Void,
Void>
-
visitMethodInvocation
If lint option "dotequals" is specified, warn if the .equals method is used where reference equality is safe.- Specified by:
visitMethodInvocation
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitMethodInvocation
in classBaseTypeVisitor<InterningAnnotatedTypeFactory>
-
processMethodTree
Description copied from class:BaseTypeVisitor
Type-check methodTree. Subclasses should override this method instead ofBaseTypeVisitor.visitMethod(MethodTree, Void)
.- Overrides:
processMethodTree
in classBaseTypeVisitor<InterningAnnotatedTypeFactory>
- Parameters:
tree
- the method to type-check
-
processClassTree
Method to implement the @UsesObjectEquals functionality. If a class is annotated with @UsesObjectEquals, it must:- not override .equals(Object) and be a subclass of a class annotated with @UsesObjectEquals, or
- override equals(Object) with body "this == arg"
- not have a superclass annotated with @UsesObjectEquals
- Overrides:
processClassTree
in classBaseTypeVisitor<InterningAnnotatedTypeFactory>
- Parameters:
classTree
- class to check- See Also:
-
checkConstructorResult
protected void checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, ExecutableElement constructorElement) Description copied from class:BaseTypeVisitor
Issue a warning if the result type of the constructor declaration is not top. If it is a supertype of the class, then a conflicting.annos error will also be issued byBaseTypeVisitor.isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType,AnnotatedTypeMirror.AnnotatedDeclaredType,Tree)
.- Overrides:
checkConstructorResult
in classBaseTypeVisitor<InterningAnnotatedTypeFactory>
- Parameters:
constructorType
- the AnnotatedExecutableType for the constructorconstructorElement
- the element that declares the constructor
-
validateTypeOf
Description copied from class:BaseTypeVisitor
Tests whether the tree expressed by the passed type tree is a valid type, and emits an error if that is not the case (e.g. '@Mutable String'). If the tree is a method or constructor, check the return type.- Overrides:
validateTypeOf
in classBaseTypeVisitor<InterningAnnotatedTypeFactory>
- Parameters:
tree
- the AST type supplied by the user- Returns:
- true if the tree is a valid type
-
isInvocationOfEquals
Tests whether a method invocation is an invocation ofObject.equals(java.lang.Object)
with one argument.Returns true even if a method overloads
Object.equals(Object)
, because of the common idiom of writing an equals method with a non-Object parameter, in addition to the equals method that overridesObject.equals(Object)
.- Parameters:
tree
- a method invocation tree- Returns:
- true iff
tree
is a invocation ofequals()
-
isTypeCastSafe
Description copied from class:BaseTypeVisitor
Returns true if the cast is safe.Only primary qualifiers are checked unless the command line option "checkCastElementType" is supplied.
- Overrides:
isTypeCastSafe
in classBaseTypeVisitor<InterningAnnotatedTypeFactory>
- Parameters:
castType
- annotated type of the castexprType
- annotated type of the casted expression- Returns:
- true if the type cast is safe, false otherwise
-