Class 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.

    • Constructor Detail

    • 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:
        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.
        Specified by:
        visitMethodInvocation in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitMethodInvocation in class BaseTypeVisitor<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: BaseTypeVisitor
        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.
        Overrides:
        commonAssignmentCheck in class BaseTypeVisitor<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 fails
        extraArgs - 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: BaseTypeVisitor
        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.
        Overrides:
        commonAssignmentCheck in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>
        Parameters:
        varType - the annotated type of the variable
        valueType - the annotated type of the value
        valueTree - the location to use when reporting the error message
        errorKey - the error message key to use if the check fails
        extraArgs - 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: BaseTypeVisitor
        Checks 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:
        visitThrow in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitThrow in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>
      • visitVariable

        public java.lang.Void visitVariable​(com.sun.source.tree.VariableTree tree,
                                            java.lang.Void p)
        Specified by:
        visitVariable in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitVariable in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>
      • visitNewArray

        public java.lang.Void visitNewArray​(com.sun.source.tree.NewArrayTree tree,
                                            java.lang.Void p)
        Specified by:
        visitNewArray in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitNewArray in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>
      • checkThisOrSuperConstructorCall

        protected void checkThisOrSuperConstructorCall​(com.sun.source.tree.MethodInvocationTree superCall,
                                                       @CompilerMessageKey java.lang.String errorKey)
        Description copied from class: BaseTypeVisitor
        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.
        Overrides:
        checkThisOrSuperConstructorCall in class BaseTypeVisitor<AliasingAnnotatedTypeFactory>
        Parameters:
        superCall - the AST node for the constructor call
        errorKey - the error message key to use if the check fails