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.
atypeFactory, checker, contractsUtils, positions, typeValidator, visitorState
elements, root, trees, types
Constructor and Description |
---|
AliasingVisitor(BaseTypeChecker checker) |
Modifier and Type | Method and Description |
---|---|
protected void |
commonAssignmentCheck(AnnotatedTypeMirror varType,
AnnotatedTypeMirror valueType,
Tree valueTree,
@CompilerMessageKey String errorKey)
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)
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, checkAccess, checkArguments, checkArrayInitialization, checkAssignability, checkConditionalPostconditions, checkConditionalPostconditionsConsistency, checkConstructorInvocation, checkContract, checkDefaultConstructor, checkExceptionParameter, checkFlowExprParameters, checkForAnnotatedJdk, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkPostconditions, checkPostconditionsConsistency, checkPreconditions, checkPreconditions, checkPreconditionsConsistency, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, commonAssignmentCheck, createTypeFactory, createTypeValidator, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isAccessAllowed, isAssignable, isValidUse, isValidUse, isValidUse, isVectorCopyInto, reportPurityErrors, scan, setRoot, shouldSkipUses, skipContractCheck, skipReceiverSubtypeCheck, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateType, validateTypeOf, visitAnnotation, visitArrayAccess, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethod, visitNewClass, visitParameterizedType, visitReturn, visitTypeCast, visitTypeParameter, visitUnary
visit
getCurrentPath, scan
reduce, scan, visitAnnotatedType, visitArrayType, visitAssert, visitBinary, visitBlock, visitBreak, visitCase, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExpressionStatement, visitForLoop, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitMemberSelect, visitModifiers, visitOther, visitParenthesized, visitPrimitiveType, visitSwitch, visitSynchronized, visitTry, visitUnionType, visitWhileLoop, visitWildcard
public AliasingVisitor(BaseTypeChecker checker)
public Void visitMethodInvocation(MethodInvocationTree node, Void p)
1. "this" is not an argument of the method call.
2. "this" is an argument of the method call, but the respective parameter is annotated as @NonLeaked.
3. "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).
The private method 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)
BaseTypeVisitor
commonAssignmentCheck
in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>
varTree
- the AST node for the variablevalueExp
- the AST node for the valueerrorKey
- the error message to use if the check fails (must be a
compiler message key, see CompilerMessageKey
)protected void commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @CompilerMessageKey String errorKey)
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 to use if the check fails (must be a
compiler message key, see CompilerMessageKey
)public 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>