Class CalledMethodsAnnotatedTypeFactory

    • Constructor Detail

      • CalledMethodsAnnotatedTypeFactory

        public CalledMethodsAnnotatedTypeFactory​(BaseTypeChecker checker)
        Create a new CalledMethodsAnnotatedTypeFactory.
        Parameters:
        checker - the checker
    • Method Detail

      • returnsThis

        public boolean returnsThis​(com.sun.source.tree.MethodInvocationTree tree)
        Description copied from class: AccumulationAnnotatedTypeFactory
        Returns true if the return type of the given method invocation tree has an @This annotation from the Returns Receiver Checker.
        Overrides:
        returnsThis in class AccumulationAnnotatedTypeFactory
        Parameters:
        tree - a method invocation tree
        Returns:
        true if the method being invoked returns its receiver
      • adjustMethodNameUsingValueChecker

        public java.lang.String adjustMethodNameUsingValueChecker​(java.lang.String methodName,
                                                                  com.sun.source.tree.MethodInvocationTree tree)
        Given a tree, returns the name of the method that the tree should be considered as calling. Returns "withOwners" if the call sets an "owner", "owner-alias", or "owner-id" filter. Returns "withImageIds" if the call sets an "image-ids" filter.

        Package-private to permit calls from CalledMethodsTransfer.

        Parameters:
        methodName - the name of the method being explicitly called
        tree - the invocation of the method
        Returns:
        "withOwners" or "withImageIds" if the tree is an equivalent filter addition. Otherwise, return the first argument.
      • getDummyAssignedTo

        public @Nullable AnnotatedTypeMirror getDummyAssignedTo​(com.sun.source.tree.ExpressionTree expressionTree)
        Returns the annotation type mirror for the type of expressionTree with default annotations applied. As types relevant to Called Methods checking are rarely used inside generics, this is typically the best choice for type inference.
        Overrides:
        getDummyAssignedTo in class AnnotatedTypeFactory
        Parameters:
        expressionTree - an expression which has no assignment context and for which type arguments need to be inferred
        Returns:
        null or an annotated type mirror that inferrence should pretend expressionTree is assigned to
      • createRequiresOrEnsuresQualifier

        protected @Nullable javax.lang.model.element.AnnotationMirror createRequiresOrEnsuresQualifier​(java.lang.String expression,
                                                                                                       javax.lang.model.element.AnnotationMirror qualifier,
                                                                                                       AnnotatedTypeMirror declaredType,
                                                                                                       Analysis.BeforeOrAfter preOrPost,
                                                                                                       @Nullable java.util.List<javax.lang.model.element.AnnotationMirror> preconds)
        Description copied from class: GenericAnnotatedTypeFactory
        Creates a RequiresQualifier("...") or EnsuresQualifier("...") annotation for the given expression.

        This is of the form @RequiresQualifier(expression="expression", qualifier=MyQual.class) or @EnsuresQualifier(expression="expression", qualifier=MyQual.class), where "expression" is exactly the string expression and MyQual is the annotation represented by qualifier.

        Returns null if the expression is invalid when combined with the kind of annotation: for example, precondition annotations on "this" and parameters ("#1", etc.) are not supported, because receiver/parameter annotations should be inferred instead.

        This implementation returns null if no annotation can be created, because the qualifier has elements/arguments, which @RequiresQualifier and @EnsuresQualifier do not support. Subclasses may override this method to return qualifiers that do have arguments instead of returning null.

        Overrides:
        createRequiresOrEnsuresQualifier in class GenericAnnotatedTypeFactory<AccumulationValue,​AccumulationStore,​AccumulationTransfer,​AccumulationAnalysis>
        Parameters:
        expression - the expression to which the qualifier applies
        qualifier - the qualifier that must be present
        declaredType - the declared type of the expression, which is used to avoid inferring redundant pre- or postcondition annotations
        preOrPost - whether to return a precondition or postcondition annotation
        preconds - the list of precondition annotations; used to suppress redundant postconditions; non-null exactly when preOrPost is BeforeOrAfter.BEFORE
        Returns:
        a RequiresQualifier("...") or EnsuresQualifier("...") annotation for the given expression, or null