Class InterningVisitor
java.lang.Object
com.sun.source.util.TreeScanner<Void,Void>
com.sun.source.util.TreePathScanner<Void,Void>
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, slowTypecheckingSeconds, slowTypecheckingTree, TARGET, targetValueElement, typeHierarchy, typeValidator, unusedWhenElement, warnRedundantAnnotationsFields inherited from class org.checkerframework.framework.source.SourceVisitor
elements, root, trees, treesWithSuppressWarnings, types -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, ExecutableElement constructorElement) Issue a warning if the result type of the constructor declaration is not top.static booleanReturns true if a method invocation is an invocation ofObject.equals(java.lang.Object)with one argument.protected booleanisTypeCastSafe(AnnotatedTypeMirror castType, AnnotatedTypeMirror exprType) Returns true if the cast is safe.voidprocessClassTree(ClassTree classTree) Method to implement the @UsesObjectEquals functionality.voidprocessMethodTree(String className, MethodTree tree) Type-check methodTree.booleanvalidateTypeOf(Tree tree) Returns true if 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, warnRedundantAnnotationsMethods inherited from class org.checkerframework.framework.source.SourceVisitor
visitMethods inherited from class com.sun.source.util.TreePathScanner
getCurrentPath, scanMethods inherited from class com.sun.source.util.TreeScanner
reduce, scan, visitAnyPattern, visitArrayAccess, visitArrayType, visitAssert, visitBindingPattern, visitBlock, visitBreak, visitCase, visitConstantCaseLabel, visitContinue, visitDeconstructionPattern, visitDefaultCaseLabel, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExports, visitExpressionStatement, visitForLoop, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitMemberSelect, visitModifiers, visitModule, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitPatternCaseLabel, visitPrimitiveType, visitProvides, visitRequires, visitStringTemplate, 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:
visitBinaryin interfaceTreeVisitor<Void,Void> - Overrides:
visitBinaryin classTreeScanner<Void,Void>
-
visitMethodInvocation
If lint option "dotequals" is specified, warn if the .equals method is used where reference equality is safe.- Specified by:
visitMethodInvocationin interfaceTreeVisitor<Void,Void> - Overrides:
visitMethodInvocationin classBaseTypeVisitor<InterningAnnotatedTypeFactory>
-
processMethodTree
Description copied from class:BaseTypeVisitorType-check methodTree. Subclasses should override this method instead ofBaseTypeVisitor.visitMethod(MethodTree, Void).- Overrides:
processMethodTreein classBaseTypeVisitor<InterningAnnotatedTypeFactory>- Parameters:
className- the class that contains the method, for diagnostics onlytree- 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:
processClassTreein classBaseTypeVisitor<InterningAnnotatedTypeFactory>- Parameters:
classTree- class to check- See Also:
-
checkConstructorResult
protected void checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, ExecutableElement constructorElement) Description copied from class:BaseTypeVisitorIssue 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:
checkConstructorResultin classBaseTypeVisitor<InterningAnnotatedTypeFactory>- Parameters:
constructorType- the AnnotatedExecutableType for the constructorconstructorElement- the element that declares the constructor
-
validateTypeOf
Description copied from class:BaseTypeVisitorReturns true if 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:
validateTypeOfin classBaseTypeVisitor<InterningAnnotatedTypeFactory>- Parameters:
tree- the AST type supplied by the user- Returns:
- true if the tree is a valid type
-
isInvocationOfEquals
Returns true if 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
treeis a invocation ofequals()
-
isTypeCastSafe
Description copied from class:BaseTypeVisitorReturns true if the cast is safe.Only primary qualifiers are checked unless the command line option "checkCastElementType" is supplied.
- Overrides:
isTypeCastSafein 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
-