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.OverrideCheckeratypeFactory, checker, contractsUtils, positions, TARGET, targetValueElement, typeValidator, visitorStateelements, root, trees, treesWithSuppressWarnings, types| Constructor and Description |
|---|
AliasingVisitor(BaseTypeChecker checker) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType,
javax.lang.model.element.ExecutableElement constructorElement)
Issue a warning if the result type of the constructor is not top.
|
protected void |
checkThisOrSuperConstructorCall(com.sun.source.tree.MethodInvocationTree superCall,
@CompilerMessageKey java.lang.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,
com.sun.source.tree.Tree valueTree,
@CompilerMessageKey java.lang.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(com.sun.source.tree.Tree varTree,
com.sun.source.tree.ExpressionTree valueExp,
@CompilerMessageKey java.lang.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.
|
java.lang.Void |
visitMethodInvocation(com.sun.source.tree.MethodInvocationTree node,
java.lang.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.
|
java.lang.Void |
visitNewArray(com.sun.source.tree.NewArrayTree node,
java.lang.Void p) |
java.lang.Void |
visitThrow(com.sun.source.tree.ThrowTree node,
java.lang.Void p)
Checks the type of a thrown exception.
|
java.lang.Void |
visitVariable(com.sun.source.tree.VariableTree node,
java.lang.Void p) |
checkAccess, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkConstructorInvocation, checkContract, checkDefaultConstructor, checkExceptionParameter, checkExtendsImplements, checkFieldInvariantDeclarations, checkForAnnotatedJdk, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkOverride, checkPostcondition, checkPreconditions, checkSuperConstructorCall, checkThisConstructorCall, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, createOverrideChecker, createTypeFactory, createTypeValidator, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isAccessAllowed, isTypeCastSafe, isValidUse, isValidUse, isValidUse, processClassTree, reportPurityErrors, scan, setRoot, shouldSkipUses, skipReceiverSubtypeCheck, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateType, validateTypeOf, visitAnnotation, visitArrayAccess, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethod, visitNewClass, visitReturn, visitTypeCast, visitTypeParameter, visitUnaryvisitreduce, scan, visitAnnotatedType, 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, visitWildcardpublic AliasingVisitor(BaseTypeChecker checker)
public java.lang.Void visitMethodInvocation(com.sun.source.tree.MethodInvocationTree node,
java.lang.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 com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitMethodInvocation in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>protected void commonAssignmentCheck(com.sun.source.tree.Tree varTree,
com.sun.source.tree.ExpressionTree valueExp,
@CompilerMessageKey java.lang.String errorKey)
BaseTypeVisitorcommonAssignmentCheck 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 to use if the check fails (must be a compiler message key,
see CompilerMessageKey)protected void commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, com.sun.source.tree.Tree valueTree, @CompilerMessageKey java.lang.String errorKey)
BaseTypeVisitorcommonAssignmentCheck 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 java.lang.Void visitThrow(com.sun.source.tree.ThrowTree node,
java.lang.Void p)
BaseTypeVisitorvisitThrow in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitThrow in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>public java.lang.Void visitVariable(com.sun.source.tree.VariableTree node,
java.lang.Void p)
visitVariable in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitVariable in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>public java.lang.Void visitNewArray(com.sun.source.tree.NewArrayTree node,
java.lang.Void p)
visitNewArray in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitNewArray in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>protected void checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, javax.lang.model.element.ExecutableElement constructorElement)
BaseTypeVisitorBaseTypeVisitor.isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType,AnnotatedTypeMirror.AnnotatedDeclaredType,Tree).checkConstructorResult in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>constructorType - AnnotatedExecutableType for the constructorconstructorElement - element that declares the constructorprotected void checkThisOrSuperConstructorCall(com.sun.source.tree.MethodInvocationTree superCall,
@CompilerMessageKey java.lang.String errorKey)
BaseTypeVisitorcheckThisOrSuperConstructorCall in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>