Class InterningVisitor
- java.lang.Object
-
- com.sun.source.util.TreeScanner<R,P>
-
- com.sun.source.util.TreePathScanner<R,P>
-
- org.checkerframework.framework.source.SourceVisitor<java.lang.Void,java.lang.Void>
-
- org.checkerframework.common.basetype.BaseTypeVisitor<InterningAnnotatedTypeFactory>
-
- org.checkerframework.checker.interning.InterningVisitor
-
- All Implemented Interfaces:
com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
public final class InterningVisitor extends BaseTypeVisitor<InterningAnnotatedTypeFactory>
Typechecks source code for interning violations. A type is considered interned if its primary annotation isInterned
orInternedDistinct
. 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:
BaseTypeVisitor
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
BaseTypeVisitor.FoundRequired, BaseTypeVisitor.OverrideChecker
-
-
Field Summary
-
Fields inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
atypeFactory, checker, DETERMINISTIC, ignoreTargetLocations, IMPURE, methodTree, positions, PURE, qualAllowedLocations, qualHierarchy, showchecks, SIDE_EFFECT_FREE, TARGET, targetValueElement, typeHierarchy, typeValidator, unusedWhenElement
-
Fields inherited from class org.checkerframework.framework.source.SourceVisitor
elements, root, trees, treesWithSuppressWarnings, types
-
-
Constructor Summary
Constructors Constructor Description InterningVisitor(BaseTypeChecker checker)
Create an InterningVisitor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, javax.lang.model.element.ExecutableElement constructorElement)
Issue a warning if the result type of the constructor declaration is not top.static boolean
isInvocationOfEquals(com.sun.source.tree.MethodInvocationTree tree)
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(com.sun.source.tree.ClassTree classTree)
Method to implement the @UsesObjectEquals functionality.boolean
validateTypeOf(com.sun.source.tree.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.java.lang.Void
visitBinary(com.sun.source.tree.BinaryTree tree, java.lang.Void p)
Checks comparison operators, == and !=, for INTERNING violations.java.lang.Void
visitMethod(com.sun.source.tree.MethodTree tree, java.lang.Void p)
Checks that the method obeys override and subtype rules to all overridden methods.java.lang.Void
visitMethodInvocation(com.sun.source.tree.MethodInvocationTree tree, java.lang.Void p)
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, checkEnclosingExpr, checkExceptionParameter, checkExplicitAnnotationsOnIntersectionBounds, checkExtendsAndImplements, checkExtendsOrImplements, checkFieldInvariantDeclarations, checkForPolymorphicQualifiers, checkForPolymorphicQualifiers, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkOverride, checkPostcondition, checkPreconditions, checkPurity, checkQualifierParameter, checkSuperConstructorCall, checkThisConstructorCall, checkThisOrSuperConstructorCall, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, createOverrideChecker, createQualAllowedLocations, createTypeFactory, createTypeFactoryPublic, createTypeValidator, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isValidUse, isValidUse, isValidUse, reportCommonAssignmentError, reportMethodInvocabilityError, reportPurityErrors, scan, setRoot, shouldSkipUses, shouldWarnAboutIrrelevantJavaTypes, skipReceiverSubtypeCheck, testAnnotationInsertion, testJointJavacJavaParserVisitor, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateTargetLocation, validateType, validateVariablesTargetLocation, visitAnnotatedType, visitAnnotatedType, visitAnnotation, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitNewArray, visitNewClass, visitReturn, visitSwitchExpression17, visitThrow, visitTypeCast, visitTypeParameter, visitUnary, visitVariable, warnAboutIrrelevantJavaTypes, warnRedundantAnnotations
-
Methods inherited from class org.checkerframework.framework.source.SourceVisitor
visit
-
Methods inherited from class com.sun.source.util.TreeScanner
reduce, scan, visitArrayAccess, visitArrayType, visitAssert, visitBlock, visitBreak, visitCase, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExports, visitExpressionStatement, visitForLoop, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitMemberSelect, visitModifiers, visitModule, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitPrimitiveType, visitProvides, visitRequires, visitSwitch, visitSynchronized, visitTry, visitUnionType, visitUses, visitWhileLoop, visitWildcard
-
-
-
-
Constructor Detail
-
InterningVisitor
public InterningVisitor(BaseTypeChecker checker)
Create an InterningVisitor.
-
-
Method Detail
-
visitBinary
public java.lang.Void visitBinary(com.sun.source.tree.BinaryTree tree, java.lang.Void p)
Checks comparison operators, == and !=, for INTERNING violations.- Specified by:
visitBinary
in interfacecom.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
- Overrides:
visitBinary
in classcom.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
-
visitMethodInvocation
public java.lang.Void visitMethodInvocation(com.sun.source.tree.MethodInvocationTree tree, java.lang.Void p)
If lint option "dotequals" is specified, warn if the .equals method is used where reference equality is safe.- Specified by:
visitMethodInvocation
in interfacecom.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
- Overrides:
visitMethodInvocation
in classBaseTypeVisitor<InterningAnnotatedTypeFactory>
-
visitMethod
public java.lang.Void visitMethod(com.sun.source.tree.MethodTree tree, java.lang.Void p)
Description copied from class:BaseTypeVisitor
Checks that the method obeys override and subtype rules to all overridden methods. (Uses the pseudo-assignment logic to do so.)The override rule specifies that a method, m1, may override a method m2 only if:
- m1 return type is a subtype of m2
- m1 receiver type is a supertype of m2
- m1 parameters are supertypes of corresponding m2 parameters
- Specified by:
visitMethod
in interfacecom.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
- Overrides:
visitMethod
in classBaseTypeVisitor<InterningAnnotatedTypeFactory>
-
processClassTree
public void processClassTree(com.sun.source.tree.ClassTree classTree)
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:
SourceVisitor.visitClass(com.sun.source.tree.ClassTree, java.lang.Object)
-
checkConstructorResult
protected void checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, javax.lang.model.element.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 type.invalid.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
public boolean validateTypeOf(com.sun.source.tree.Tree tree)
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
public static boolean isInvocationOfEquals(com.sun.source.tree.MethodInvocationTree tree)
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
protected boolean isTypeCastSafe(AnnotatedTypeMirror castType, AnnotatedTypeMirror exprType)
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
-
-