Class AliasingVisitor
- 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<AliasingAnnotatedTypeFactory>
 - 
- org.checkerframework.common.aliasing.AliasingVisitor
 
 
 
 
 
 
- 
- All Implemented Interfaces:
 com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
public class AliasingVisitor extends BaseTypeVisitor<AliasingAnnotatedTypeFactory>
This visitor ensures that every constructor whose result is annotated as @Unique does not leak aliases.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.
 
- 
- 
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 AliasingVisitor(BaseTypeChecker checker) 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, javax.lang.model.element.ExecutableElement constructorElement)Issue a warning if the result type of the constructor declaration is not top.protected voidcheckThisOrSuperConstructorCall(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 booleancommonAssignmentCheck(com.sun.source.tree.Tree varTree, com.sun.source.tree.ExpressionTree valueExp, @CompilerMessageKey java.lang.String errorKey, java.lang.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 booleancommonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, com.sun.source.tree.Tree valueTree, @CompilerMessageKey java.lang.String errorKey, java.lang.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.java.lang.VoidvisitMethodInvocation(com.sun.source.tree.MethodInvocationTree tree, 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.VoidvisitNewArray(com.sun.source.tree.NewArrayTree tree, java.lang.Void p)java.lang.VoidvisitThrow(com.sun.source.tree.ThrowTree tree, java.lang.Void p)Checks the type of a thrown exception.java.lang.VoidvisitVariable(com.sun.source.tree.VariableTree tree, java.lang.Void p)- 
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, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, createOverrideChecker, createQualAllowedLocations, createTypeFactory, createTypeFactoryPublic, createTypeValidator, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isTypeCastSafe, isValidUse, isValidUse, isValidUse, processClassTree, reportCommonAssignmentError, reportMethodInvocabilityError, reportPurityErrors, scan, setRoot, shouldSkipUses, shouldWarnAboutIrrelevantJavaTypes, skipReceiverSubtypeCheck, testAnnotationInsertion, testJointJavacJavaParserVisitor, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateTargetLocation, validateType, validateTypeOf, validateVariablesTargetLocation, visitAnnotatedType, visitAnnotatedType, visitAnnotation, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethod, visitNewClass, visitReturn, visitSwitchExpression17, visitTypeCast, visitTypeParameter, visitUnary, 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, 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 
 - 
 
 - 
 
- 
- 
Constructor Detail
- 
AliasingVisitor
public AliasingVisitor(BaseTypeChecker checker)
 
 - 
 
- 
Method Detail
- 
visitMethodInvocation
public java.lang.Void visitMethodInvocation(com.sun.source.tree.MethodInvocationTree tree, 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. There are 3 ways to make sure that this is not happening:thisis not an argument of the method call.thisis an argument of the method call, but the respective parameter is annotated as @NonLeaked.thisis 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).
isUniqueCheckhandles cases 2 and 3.- Specified by:
 visitMethodInvocationin interfacecom.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>- Overrides:
 visitMethodInvocationin classBaseTypeVisitor<AliasingAnnotatedTypeFactory>
 
- 
commonAssignmentCheck
protected boolean commonAssignmentCheck(com.sun.source.tree.Tree varTree, com.sun.source.tree.ExpressionTree valueExp, @CompilerMessageKey java.lang.String errorKey, java.lang.Object... extraArgs)Description copied from class:BaseTypeVisitorChecks 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.- Overrides:
 commonAssignmentCheckin classBaseTypeVisitor<AliasingAnnotatedTypeFactory>- Parameters:
 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" types- Returns:
 - true if the check succeeds, false if an error message was issued
 
 
- 
commonAssignmentCheck
@FormatMethod protected boolean commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, com.sun.source.tree.Tree valueTree, @CompilerMessageKey java.lang.String errorKey, java.lang.Object... extraArgs)
Description copied from class:BaseTypeVisitorChecks 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.- Overrides:
 commonAssignmentCheckin classBaseTypeVisitor<AliasingAnnotatedTypeFactory>- Parameters:
 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" types- Returns:
 - true if the check succeeds, false if an error message was issued
 
 
- 
visitThrow
public java.lang.Void visitThrow(com.sun.source.tree.ThrowTree tree, java.lang.Void p)Description copied from class:BaseTypeVisitorChecks the type of a thrown exception. Subclasses should override checkThrownExpression(ThrowTree tree) rather than this method to change the behavior of this check.- Specified by:
 visitThrowin interfacecom.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>- Overrides:
 visitThrowin classBaseTypeVisitor<AliasingAnnotatedTypeFactory>
 
- 
visitVariable
public java.lang.Void visitVariable(com.sun.source.tree.VariableTree tree, java.lang.Void p)- Specified by:
 visitVariablein interfacecom.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>- Overrides:
 visitVariablein classBaseTypeVisitor<AliasingAnnotatedTypeFactory>
 
- 
visitNewArray
public java.lang.Void visitNewArray(com.sun.source.tree.NewArrayTree tree, java.lang.Void p)- Specified by:
 visitNewArrayin interfacecom.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>- Overrides:
 visitNewArrayin classBaseTypeVisitor<AliasingAnnotatedTypeFactory>
 
- 
checkConstructorResult
protected void checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, javax.lang.model.element.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 type.invalid.conflicting.annos error will also be issued byBaseTypeVisitor.isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType,AnnotatedTypeMirror.AnnotatedDeclaredType,Tree).- Overrides:
 checkConstructorResultin classBaseTypeVisitor<AliasingAnnotatedTypeFactory>- Parameters:
 constructorType- the AnnotatedExecutableType for the constructorconstructorElement- the element that declares the constructor
 
- 
checkThisOrSuperConstructorCall
protected void checkThisOrSuperConstructorCall(com.sun.source.tree.MethodInvocationTree superCall, @CompilerMessageKey java.lang.String errorKey)Description copied from class:BaseTypeVisitorChecks 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.- Overrides:
 checkThisOrSuperConstructorCallin classBaseTypeVisitor<AliasingAnnotatedTypeFactory>- Parameters:
 superCall- the AST node for the constructor callerrorKey- the error message key to use if the check fails
 
 - 
 
 -