Class CalledMethodsAnnotatedTypeFactory

All Implemented Interfaces:
Direct Known Subclasses:

public class CalledMethodsAnnotatedTypeFactory extends AccumulationAnnotatedTypeFactory
The annotated type factory for the Called Methods Checker.
  • Constructor Details

    • CalledMethodsAnnotatedTypeFactory

      public CalledMethodsAnnotatedTypeFactory(BaseTypeChecker checker)
      Create a new CalledMethodsAnnotatedTypeFactory.
      checker - the checker
  • Method Details

    • createTreeAnnotator

      protected TreeAnnotator createTreeAnnotator()
      Description copied from class: GenericAnnotatedTypeFactory
      Returns a TreeAnnotator that adds annotations to a type based on the contents of a tree.

      The default tree annotator is a ListTreeAnnotator of the following:

      1. PropagationTreeAnnotator: Propagates annotations from subtrees
      2. LiteralTreeAnnotator: Adds annotations based on QualifierForLiterals meta-annotations
      3. DependentTypesTreeAnnotator: Adapts dependent annotations based on context

      Subclasses may override this method to specify additional tree annotators, for example:

       new ListTreeAnnotator(super.createTreeAnnotator(), new KeyLookupTreeAnnotator(this));
      createTreeAnnotator in class AccumulationAnnotatedTypeFactory
      a tree annotator
    • createTypeAnnotator

      protected TypeAnnotator createTypeAnnotator()
      Description copied from class: GenericAnnotatedTypeFactory
      Returns a DefaultForTypeAnnotator that adds annotations to a type based on the content of the type itself.

      Subclass may override this method. The default type annotator is a ListTypeAnnotator of the following:

      1. IrrelevantTypeAnnotator: Adds top to types not listed in the @RelevantJavaTypes annotation on the checker.
      2. PropagationTypeAnnotator: Propagates annotation onto wildcards.
      createTypeAnnotator in class GenericAnnotatedTypeFactory<AccumulationValue,AccumulationStore,AccumulationTransfer,AccumulationAnalysis>
      a type annotator
    • returnsThis

      public boolean returnsThis(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.
      returnsThis in class AccumulationAnnotatedTypeFactory
      tree - a method invocation tree
      true if the method being invoked returns its receiver
    • adjustMethodNameUsingValueChecker

      public String adjustMethodNameUsingValueChecker(String methodName, 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.

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

      protected CalledMethodsAnalysis createFlowAnalysis()
      Description copied from class: GenericAnnotatedTypeFactory
      Returns the appropriate flow analysis class that is used for the org.checkerframework.dataflow analysis.

      This implementation uses the checker naming convention to create the appropriate analysis. If no transfer function is found, it returns an instance of CFAnalysis.

      Subclasses have to override this method to create the appropriate analysis if they do not follow the checker naming convention.

      createFlowAnalysis in class GenericAnnotatedTypeFactory<AccumulationValue,AccumulationStore,AccumulationTransfer,AccumulationAnalysis>
      the appropriate flow analysis class that is used for the org.checkerframework.dataflow analysis
    • getDummyAssignedTo

      public @Nullable AnnotatedTypeMirror getDummyAssignedTo(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.
      getDummyAssignedTo in class AnnotatedTypeFactory
      expressionTree - an expression which has no assignment context and for which type arguments need to be inferred
      null or an annotated type mirror that inferrence should pretend expressionTree is assigned to
    • createRequiresOrEnsuresQualifier

      protected @Nullable AnnotationMirror createRequiresOrEnsuresQualifier(String expression, AnnotationMirror qualifier, AnnotatedTypeMirror declaredType, Analysis.BeforeOrAfter preOrPost, @Nullable List<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.

      createRequiresOrEnsuresQualifier in class GenericAnnotatedTypeFactory<AccumulationValue,AccumulationStore,AccumulationTransfer,AccumulationAnalysis>
      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
      a RequiresQualifier("...") or EnsuresQualifier("...") annotation for the given expression, or null