public class AliasingVisitor extends BaseTypeVisitor<AliasingAnnotatedTypeFactory>
TODO: Implement @NonLeaked and @LeakedToResult verifications:
@NonLeaked: When a method declaration has a parameter annotated as @NonLeaked, the method body must not leak a reference to that parameter.
@LeakedToResult: When a method declaration has a parameter annotated as @LeakedToResult, the method body must not leak a reference to that parameter, except at the method return statements.
Both of the checks above are similar to the @Unique check that is implemented in this visitor.
BaseTypeVisitor.OverrideChecker
atypeFactory, checker, positions, TARGET, targetValueElement, typeValidator, visitorState
elements, root, trees, treesWithSuppressWarnings, types
Constructor and Description |
---|
AliasingVisitor(BaseTypeChecker checker) |
Modifier and Type | Method and Description |
---|---|
protected void |
checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType,
ExecutableElement constructorElement)
Issue a warning if the result type of the constructor is not top.
|
protected void |
checkThisOrSuperConstructorCall(MethodInvocationTree superCall,
@CompilerMessageKey String errorKey)
Checks that the following rule is satisfied: The type on a constructor declaration must be a
supertype of the return type of "this()" or "super()" invocation within that constructor.
|
protected void |
commonAssignmentCheck(AnnotatedTypeMirror varType,
AnnotatedTypeMirror valueType,
Tree valueTree,
@CompilerMessageKey String errorKey,
Object... extraArgs)
Checks the validity of an assignment (or pseudo-assignment) from a value to a variable and
emits an error message (through the compiler's messaging interface) if it is not valid.
|
protected void |
commonAssignmentCheck(Tree varTree,
ExpressionTree valueExp,
@CompilerMessageKey String errorKey,
Object... extraArgs)
Checks the validity of an assignment (or pseudo-assignment) from a value to a variable and
emits an error message (through the compiler's messaging interface) if it is not valid.
|
Void |
visitMethodInvocation(MethodInvocationTree node,
Void p)
Checks that if a method call is being invoked inside a constructor with result type
@Unique, it must not leak the "this" reference.
|
Void |
visitNewArray(NewArrayTree node,
Void p) |
Void |
visitThrow(ThrowTree node,
Void p)
Checks the type of a thrown exception.
|
Void |
visitVariable(VariableTree node,
Void p) |
checkAccess, checkAccessAllowed, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkConstructorInvocation, checkContract, checkDefaultConstructor, checkExceptionParameter, checkExplicitAnnotationsOnIntersectionBounds, checkExtendsImplements, checkFieldInvariantDeclarations, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkOverride, checkPostcondition, checkPreconditions, checkPurity, checkQualifierParameter, checkSuperConstructorCall, checkThisConstructorCall, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, createOverrideChecker, createTypeFactory, createTypeFactoryPublic, createTypeValidator, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isTypeCastSafe, isValidUse, isValidUse, isValidUse, processClassTree, reportMethodInvocabilityError, reportPurityErrors, scan, setRoot, shouldSkipUses, skipReceiverSubtypeCheck, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateType, validateTypeOf, visitAnnotatedType, visitAnnotatedType, visitAnnotation, visitArrayAccess, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethod, visitNewClass, visitReturn, visitTypeCast, visitTypeParameter, visitUnary, warnAboutIrrelevantJavaTypes
visit
getCurrentPath, scan
reduce, scan, visitArrayType, visitAssert, visitBinary, 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
public AliasingVisitor(BaseTypeChecker checker)
public Void visitMethodInvocation(MethodInvocationTree node, Void p)
this
is not an argument of the method call.
this
is an argument of the method call, but the respective parameter is
annotated as @NonLeaked.
this
is an argument of the method call, but the respective parameter is
annotated as @LeakedToResult AND the result of the method call is not being
stored (the method call is a statement).
isUniqueCheck
handles cases 2 and 3.visitMethodInvocation
in interface TreeVisitor<Void,Void>
visitMethodInvocation
in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>
protected void commonAssignmentCheck(Tree varTree, ExpressionTree valueExp, @CompilerMessageKey String errorKey, Object... extraArgs)
BaseTypeVisitor
commonAssignmentCheck
in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>
varTree
- the AST node for the lvalue (usually a variable)valueExp
- the AST node for the rvalue (the new value)errorKey
- the error message key to use if the check failsextraArgs
- arguments to the error message key, before "found" and "expected" typesprotected void commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @CompilerMessageKey String errorKey, Object... extraArgs)
BaseTypeVisitor
commonAssignmentCheck
in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>
varType
- the annotated type of the variablevalueType
- the annotated type of the valuevalueTree
- the location to use when reporting the error messageerrorKey
- the error message key to use if the check failsextraArgs
- arguments to the error message key, before "found" and "expected" typespublic Void visitThrow(ThrowTree node, Void p)
BaseTypeVisitor
visitThrow
in interface TreeVisitor<Void,Void>
visitThrow
in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>
public Void visitVariable(VariableTree node, Void p)
visitVariable
in interface TreeVisitor<Void,Void>
visitVariable
in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>
public Void visitNewArray(NewArrayTree node, Void p)
visitNewArray
in interface TreeVisitor<Void,Void>
visitNewArray
in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>
protected void checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, ExecutableElement constructorElement)
BaseTypeVisitor
BaseTypeVisitor.isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType,AnnotatedTypeMirror.AnnotatedDeclaredType,Tree)
.checkConstructorResult
in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>
constructorType
- AnnotatedExecutableType for the constructorconstructorElement
- element that declares the constructorprotected void checkThisOrSuperConstructorCall(MethodInvocationTree superCall, @CompilerMessageKey String errorKey)
BaseTypeVisitor
checkThisOrSuperConstructorCall
in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>
superCall
- the AST node for the constructor callerrorKey
- the error message key to use if the check fails