Class GenericAnnotatedTypeFactory<Value extends CFAbstractValue<Value>,Store extends CFAbstractStore<Value,Store>,TransferFunction extends CFAbstractTransfer<Value,Store,TransferFunction>,FlowAnalysis extends CFAbstractAnalysis<Value,Store,TransferFunction>>

java.lang.Object
org.checkerframework.framework.type.AnnotatedTypeFactory
org.checkerframework.framework.type.GenericAnnotatedTypeFactory<Value,Store,TransferFunction,FlowAnalysis>
Type Parameters:
Value - the value type
Store - the store type
TransferFunction - the transfer function type
FlowAnalysis - the flow analysis type
All Implemented Interfaces:
AnnotationProvider
Direct Known Subclasses:
AccumulationAnnotatedTypeFactory, BaseAnnotatedTypeFactory, InitializationParentAnnotatedTypeFactory, KeyForAnnotatedTypeFactory, LockAnnotatedTypeFactory, NullnessNoInitAnnotatedTypeFactory

@AnnotatedFor("nullness") public abstract class GenericAnnotatedTypeFactory<Value extends CFAbstractValue<Value>,Store extends CFAbstractStore<Value,Store>,TransferFunction extends CFAbstractTransfer<Value,Store,TransferFunction>,FlowAnalysis extends CFAbstractAnalysis<Value,Store,TransferFunction>> extends AnnotatedTypeFactory
A factory that extends AnnotatedTypeFactory to optionally use flow-sensitive qualifier inference.

It also adds other features: qualifier polymorphism, default annotations via DefaultFor, user-specified defaults via DefaultQualifier, standardization via DependentTypesHelper, etc. Those features, and addComputedTypeAnnotations(com.sun.source.tree.Tree, org.checkerframework.framework.type.AnnotatedTypeMirror) (other than the part related to flow-sensitivity), could and should be in the superclass AnnotatedTypeFactory; it is not clear why they are defined in this class.

  • Field Details

  • Constructor Details

    • GenericAnnotatedTypeFactory

      protected GenericAnnotatedTypeFactory(BaseTypeChecker checker, boolean useFlow)
      Creates a type factory. Its compilation unit is not yet set.
      Parameters:
      checker - the checker to which this type factory belongs
      useFlow - true if flow analysis should be performed
    • GenericAnnotatedTypeFactory

      protected GenericAnnotatedTypeFactory(BaseTypeChecker checker)
      Creates a type factory. Its compilation unit is not yet set. This constructor might get reflectively called by BaseTypeVisitor.createTypeFactory and uses flowByDefault to determine whether flow refinement should be enabled. Subclasses should instead use the two-parameter constructor and explicitly set whether to use flow refinement.
      Parameters:
      checker - the checker to which this type factory belongs
  • Method Details

    • getUseFlow

      protected boolean getUseFlow()
      Determines whether flow-sensitive type refinement should be used or not.
      Returns:
      whether flow-sensitive type refinement should be used or not
      See Also:
      • useFlow
    • postInit

      protected void postInit(@UnderInitialization(GenericAnnotatedTypeFactory.class) GenericAnnotatedTypeFactory<Value extends CFAbstractValue<Value>,Store extends CFAbstractStore<Value,Store>,TransferFunction extends CFAbstractTransfer<Value,Store,TransferFunction>,FlowAnalysis extends CFAbstractAnalysis<Value,Store,TransferFunction>> this)
      Description copied from class: AnnotatedTypeFactory
      Actions that logically belong in the constructor, but need to run after the subclass constructor has completed. In particular, AnnotationFileElementTypes.parseStubFiles() may try to do type resolution with this AnnotatedTypeFactory.
      Overrides:
      postInit in class AnnotatedTypeFactory
    • getQualifierDefaults

      public QualifierDefaults getQualifierDefaults()
      Description copied from class: AnnotatedTypeFactory
      Returns the QualifierDefaults this factory applies, or null if it applies no defaults.
      Overrides:
      getQualifierDefaults in class AnnotatedTypeFactory
      Returns:
      the QualifierDefaults this factory applies, or null
    • preProcessClassTree

      public void preProcessClassTree(ClassTree classTree)
      Performs flow-sensitive type refinement on classTree if this type factory is configured to do so.
      Overrides:
      preProcessClassTree in class AnnotatedTypeFactory
      Parameters:
      classTree - tree on which to perform flow-sensitive type refinement
    • setRoot

      public void setRoot(@Nullable CompilationUnitTree root)
      Description copied from class: AnnotatedTypeFactory
      Set the CompilationUnitTree that should be used.
      Overrides:
      setRoot in class AnnotatedTypeFactory
      Parameters:
      root - the new compilation unit to use
    • getSupportedMonotonicTypeQualifiers

      public final Set<Class<? extends Annotation>> getSupportedMonotonicTypeQualifiers()
      Returns an immutable set of the monotonic type qualifiers supported by this checker.
      Returns:
      the monotonic type qualifiers supported this processor, or an empty set if none
      See Also:
    • createTreeAnnotator

      protected TreeAnnotator createTreeAnnotator()
      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));
       
      Returns:
      a tree annotator
    • createTypeAnnotator

      protected TypeAnnotator createTypeAnnotator()
      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.
      Returns:
      a type annotator
    • annotationsForIrrelevantJavaType

      public AnnotationMirrorSet annotationsForIrrelevantJavaType(TypeMirror tm)
      Returns the annotations that should appear on the given irrelevant Java type. If the type is relevant, this method's behavior is undefined.
      Parameters:
      tm - an irrelevant Java type
      Returns:
      the annotations that should appear on the given irrelevant Java type
    • createDefaultForUseTypeAnnotator

      protected DefaultQualifierForUseTypeAnnotator createDefaultForUseTypeAnnotator()
      Returns:
      a new DefaultQualifierForUseTypeAnnotator
    • getDefaultAnnosForUses

      protected AnnotationMirrorSet getDefaultAnnosForUses(Element element)
      Description copied from class: AnnotatedTypeFactory
      Returns the set of qualifiers that should be applied to unannotated uses of the given element, as specified by DefaultQualifierForUse.

      This implementation always returns an empty set, because @DefaultQualifierForUse is implemented by DefaultQualifierForUseTypeAnnotator, which only a GenericAnnotatedTypeFactory creates. GenericAnnotatedTypeFactory overrides this to consult that annotator.

      Overrides:
      getDefaultAnnosForUses in class AnnotatedTypeFactory
      Parameters:
      element - the element
      Returns:
      the set of default-for-use qualifiers; empty in this implementation
    • createDefaultForTypeAnnotator

      protected DefaultForTypeAnnotator createDefaultForTypeAnnotator()
      Returns:
      a new DefaultForTypeAnnotator
    • getDefaultForTypeAnnotator

      public DefaultForTypeAnnotator getDefaultForTypeAnnotator()
      Returns:
      the DefaultForTypeAnnotator
    • createFlowAnalysis

      protected FlowAnalysis createFlowAnalysis()
      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.

      Returns:
      the appropriate flow analysis class that is used for the org.checkerframework.dataflow analysis
    • createFlowTransferFunction

      public TransferFunction createFlowTransferFunction(CFAbstractAnalysis<Value,Store,TransferFunction> analysis)
      Returns the appropriate transfer function that is used for the given org.checkerframework.dataflow analysis.

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

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

      Parameters:
      analysis - a dataflow analysis
      Returns:
      a new transfer function
    • createDependentTypesHelper

      protected DependentTypesHelper createDependentTypesHelper()
      Creates a DependentTypesHelper and returns it. Use getDependentTypesHelper() to access the value.
      Returns:
      a new DependentTypesHelper
    • getDependentTypesHelper

      public DependentTypesHelper getDependentTypesHelper()
      Returns the DependentTypesHelper.
      Returns:
      the DependentTypesHelper
    • createContractsFromMethod

      protected ContractsFromMethod createContractsFromMethod()
      Creates an DefaultContractsFromMethod and returns it. If contract annotations are not used for a type system, override this method and return a NoContractsFromMethod.
      Returns:
      a new ContractsFromMethod
    • getContractsFromMethod

      public ContractsFromMethod getContractsFromMethod()
      Returns the helper for method pre- and postconditions.
      Returns:
      the helper for method pre- and postconditions
    • getExplicitNewClassClassTypeArgs

      protected List<AnnotatedTypeMirror> getExplicitNewClassClassTypeArgs(NewClassTree newClassTree)
      Description copied from class: AnnotatedTypeFactory
      Returns the partially-annotated explicit class type arguments of the new class tree. The AnnotatedTypeMirror only include the annotations explicitly written on the explict type arguments. (If newClass use a diamond operator, this method returns the empty list.) For example, when called with new MyClass<@HERE String>() this method would return a list containing @HERE String.
      Overrides:
      getExplicitNewClassClassTypeArgs in class AnnotatedTypeFactory
      Parameters:
      newClassTree - a new class tree
      Returns:
      the partially annotated AnnotatedTypeMirrors for the (explicit) class type arguments of the new class tree
    • getExplicitNewClassAnnos

      public AnnotationMirrorSet getExplicitNewClassAnnos(NewClassTree newClassTree)
      Description copied from class: AnnotatedTypeFactory
      Returns the annotations explicitly written on a NewClassTree.

      new @HERE Class()

      Overrides:
      getExplicitNewClassAnnos in class AnnotatedTypeFactory
      Parameters:
      newClassTree - a constructor invocation
      Returns:
      the annotations explicitly written on a NewClassTree
    • createAndInitQualifierDefaults

      protected final QualifierDefaults createAndInitQualifierDefaults()
      Create QualifierDefaults which handles checker specified defaults, and initialize the created QualifierDefaults. Subclasses should override addCheckedCodeDefaults(QualifierDefaults defs) to add more defaults or use different defaults.
      Returns:
      the QualifierDefaults object
    • createQualifierDefaults

      protected QualifierDefaults createQualifierDefaults()
      Create QualifierDefaults which handles checker specified defaults. Sub-classes override this method to provide a different QualifierDefault implementation.
    • getSortedQualifierNames

      protected final String getSortedQualifierNames()
      Creates and returns a string containing the number of qualifiers and the canonical class names of each qualifier that has been added to this checker's supported qualifier set. The names are alphabetically sorted.
      Returns:
      a string containing the number of qualifiers and canonical names of each qualifier
    • addCheckedCodeDefaults

      protected void addCheckedCodeDefaults(QualifierDefaults defs)
      Adds default qualifiers for type-checked code by reading DefaultFor and DefaultQualifierInHierarchy meta-annotations. Subclasses may override this method to add defaults that cannot be specified with a DefaultFor or DefaultQualifierInHierarchy meta-annotations.
      Parameters:
      defs - the QualifierDefault object to which defaults are added
    • addCheckedStandardDefaults

      protected void addCheckedStandardDefaults(QualifierDefaults defs)
      Adds the standard CLIMB defaults that do not conflict with previously added defaults.
      Parameters:
      defs - QualifierDefaults object to which defaults are added
    • addUncheckedStandardDefaults

      protected void addUncheckedStandardDefaults(QualifierDefaults defs)
      Adds the defaults for unchecked code of each mode the command-line options enable. Subclasses may override this method to customize unchecked-code defaults.
      Parameters:
      defs - QualifierDefaults object to which defaults are added
    • checkForDefaultQualifierInHierarchy

      protected void checkForDefaultQualifierInHierarchy(QualifierDefaults defs)
      Check that a default qualifier (in at least one hierarchy) has been set and issue an error if not.
      Parameters:
      defs - QualifierDefaults object to which defaults are added
    • createQualifierPolymorphism

      protected QualifierPolymorphism createQualifierPolymorphism()
      Creates the QualifierPolymorphism instance which supports the QualifierPolymorphism mechanism.
      Returns:
      the QualifierPolymorphism instance to use
    • getQualifierPolymorphism

      public QualifierPolymorphism getQualifierPolymorphism()
      Gives the current QualifierPolymorphism instance which supports the QualifierPolymorphism mechanism.
      Returns:
      the QualifierPolymorphism instance to use
    • getAnnotationFromJavaExpressionString

      public @Nullable AnnotationMirror getAnnotationFromJavaExpressionString(String expression, Tree tree, TreePath path, Class<? extends Annotation> clazz) throws JavaExpressionParseException
      Returns the primary annotation with clazz on expression's type, at a particular location. The returned annotation may be null even if the expression should have a primary annotation of clazz. This is because JavaExpressions do not always have enough information to get an annotated type.

      This method should only be used if a tree, element, or node is not available for expression. Use AnnotatedTypeFactory.getAnnotatedType(Tree) or AnnotatedTypeFactory.getAnnotatedType(Element) instead.

      Parameters:
      expression - the expression for which the annotation is returned
      tree - current tree
      path - location at which expression is evaluated
      clazz - the annotation class for which to look
      Returns:
      the annotation of clazz on expression's type, or null if one does not exist or if expression does not have enough information to get the annotated type
      Throws:
      JavaExpressionParseException - thrown if the expression cannot be parsed
    • getAnnotationFromJavaExpression

      public @Nullable AnnotationMirror getAnnotationFromJavaExpression(JavaExpression expr, Tree tree, Class<? extends Annotation> clazz)
      Returns the primary annotation with clazz on expr's type, at a particular location. The returned annotation may be null even if the expression should have a primary annotation of clazz. This is because JavaExpressions do not always have enough information to get an annotated type.

      This method should only be used if a tree, element, or node is not available for expr. Use AnnotatedTypeFactory.getAnnotatedType(Tree) or AnnotatedTypeFactory.getAnnotatedType(Element) instead.

      Parameters:
      expr - the expression for which the annotation is returned
      tree - current tree
      clazz - the annotation class for which to look
      Returns:
      the annotation of clazz on expr's type, or null if one does not exist or if expr does not have enough information to get the annotated type
    • getAnnotationsFromJavaExpression

      public AnnotationMirrorSet getAnnotationsFromJavaExpression(JavaExpression expr, Tree tree)
      Returns the primary annotations on an expression, at a particular location. The returned set of annotations may be empty even if the expression should have primary annotations. This is because JavaExpression do not always have enough information to get an annotated type.

      This method should only be used if a tree, element, or node is not available for expr. Use AnnotatedTypeFactory.getAnnotatedType(Tree) or AnnotatedTypeFactory.getAnnotatedType(Element) instead.

      Parameters:
      expr - the expression for which the annotation is returned
      tree - current tree
      Returns:
      the annotations on the expression. May be empty if expr does not have enough information to get the annotated type.
    • parseJavaExpressionString

      public JavaExpression parseJavaExpressionString(String expression, TreePath currentPath) throws JavaExpressionParseException
      Produces the JavaExpression as if expression were written at currentPath.
      Parameters:
      expression - a Java expression
      currentPath - the current path
      Returns:
      the JavaExpression associated with expression on currentPath
      Throws:
      JavaExpressionParseException - thrown if the expression cannot be parsed
    • getExpressionAndOffsetFromJavaExpressionString

      public Pair<JavaExpression,String> getExpressionAndOffsetFromJavaExpressionString(String expression, TreePath currentPath) throws JavaExpressionParseException
      Produces the JavaExpression and offset associated with an expression. For instance, "n+1" has no associated JavaExpression, but this method produces a pair of a JavaExpression (for "n") and an offset ("1").
      Parameters:
      expression - a Java expression, possibly with a constant offset
      currentPath - location at which expression is evaluated
      Returns:
      the JavaExpression and offset for the given expression
      Throws:
      JavaExpressionParseException - thrown if the expression cannot be parsed
    • getAnnotationMirrorFromJavaExpressionString

      public @Nullable AnnotationMirror getAnnotationMirrorFromJavaExpressionString(String expression, Tree tree, TreePath currentPath) throws JavaExpressionParseException
      Returns the annotation mirror from dataflow for expression.

      This will output a different annotation than getAnnotationFromJavaExpressionString(String, Tree, TreePath, Class), because if the specified annotation isn't found in the store, the type from the factory is used.

      Parameters:
      expression - a Java expression
      tree - the tree at the location to parse the expression
      currentPath - location at which expression is evaluated
      Returns:
      an AnnotationMirror representing the type in the store at the given location from this type factory's type system, or null if one is not available
      Throws:
      JavaExpressionParseException - thrown if the expression cannot be parsed
    • isUnreachable

      public boolean isUnreachable(ExpressionTree exprTree)
      Returns true if the exprTree is unreachable. This is a conservative estimate and may return false even though the exprTree is unreachable. Only meaningful when "-AignoreDeadCode" was passed on the command line; otherwise always returns false.
      Parameters:
      exprTree - an expression tree
      Returns:
      true if the exprTree is unreachable
    • isAnonymousDiamondSupertypeFinal

      public boolean isAnonymousDiamondSupertypeFinal(NewClassTree creation)
      Description copied from class: AnnotatedTypeFactory
      Returns true if the supertype inferred for the anonymous class created by creation, a diamond such as new C<>(args) {...}, can no longer change. It is inferred from the types of the arguments and of the context, which change during dataflow analysis of the enclosing method.

      This implementation, which performs no dataflow analysis, returns true, like AnnotatedTypeFactory.canUseCachedFlowDependentType(ExpressionTree). GenericAnnotatedTypeFactory returns true once dataflow analysis of the anonymous class has started, which is after that of the enclosing method. A factory that does not keep track of the analyzed classes itself must forward to the factory that does.

      Overrides:
      isAnonymousDiamondSupertypeFinal in class AnnotatedTypeFactory
      Parameters:
      creation - an anonymous class creation with a diamond
      Returns:
      true if the inferred supertype of the anonymous class can no longer change
    • getRegularExitStore

      public @Nullable Store getRegularExitStore(Tree tree)
      Returns the regular exit store for a method or another code block (such as static initializers). Returns null if there is no such store. This can happen because the method cannot exit through the regular exit block, or it is abstract or in an interface.
      Parameters:
      tree - a MethodTree or other code block, such as a static initializer
      Returns:
      the regular exit store, or null
    • getExceptionalExitStore

      public @Nullable Store getExceptionalExitStore(Tree tree)
      Returns the exceptional exit store for a method or another code block (such as static initializers).
      Parameters:
      tree - a MethodTree or other code block, such as a static initializer
      Returns:
      the exceptional exit store, or null, if there is no such store
    • getReturnStatementStores

      public List<Pair<ReturnNode,TransferResult<Value,Store>>> getReturnStatementStores(MethodTree methodTree)
      Returns a list of all return statements of method paired with their corresponding TransferResult. If method has no return statement, then the empty list is returned.
      Parameters:
      methodTree - method whose return statements should be returned
      Returns:
      a list of all return statements of method paired with their corresponding TransferResult or an empty list if method has no return statements
    • getStoreBefore

      public @Nullable Store getStoreBefore(Tree tree)
      Returns the store immediately before a given Tree.
      Parameters:
      tree - the tree
      Returns:
      the store immediately before a given Tree
    • getStoreBefore

      public @Nullable Store getStoreBefore(Node node)
      Returns the store immediately before a given node.
      Parameters:
      node - a node whose pre-store to return
      Returns:
      the store immediately before node
    • getStoreAfter

      public @Nullable Store getStoreAfter(Tree tree)
      Returns the store immediately after a given tree.

      May return null; for example, after a return statement.

      Parameters:
      tree - the tree whose post-store to return
      Returns:
      the store immediately after a given tree
    • getStoreAfter

      public Store getStoreAfter(Node node)
      Returns the store immediately after a given Node.
      Parameters:
      node - node after which the store is returned
      Returns:
      the store immediately after a given Node
    • getNodesForTree

      public @Nullable Set<Node> getNodesForTree(Tree tree)
      Parameters:
      tree - a tree
      Returns:
      the Nodes for a given Tree
      See Also:
    • getFirstNodeOfKindForTree

      public <T extends Node> @Nullable T getFirstNodeOfKindForTree(Tree tree, Class<T> kind)
      Returns the first Node for a given Tree that has class kind.

      You probably don't want to use this function: iterate over the result of getNodesForTree(Tree) yourself or ask for a conservative approximation of the store using getStoreBefore(Tree) or getStoreAfter(Tree). This method is for code that uses a Node in a rather unusual way. Callers should probably be rewritten to not use a Node at all.

      Type Parameters:
      T - the class of the node to return
      Parameters:
      tree - a tree in which to search for a node of class kind
      kind - the class of the node to return
      Returns:
      the first Node for a given Tree that has class kind
      See Also:
    • getFinalLocalValues

      public Map<VariableElement,Value> getFinalLocalValues()
      Returns the value of effectively final local variables.
      Returns:
      the value of effectively final local variables
    • getFinalLocalValues

      public Map<VariableElement,Value> getFinalLocalValues(Element declarer)
      Returns the values of the effectively-final local variables whose declaration is directly enclosed by the given element.
      Parameters:
      declarer - an element, typically a method, lambda, or initializer
      Returns:
      the values of the effectively-final local variables declared directly in declarer; the empty map if there are none
    • isNotFullyInitializedReceiver

      @Pure public boolean isNotFullyInitializedReceiver(MethodTree methodDeclTree)
      Returns true if the receiver of a method or constructor might not be fully initialized.
      Parameters:
      methodDeclTree - the declaration of the method or constructor
      Returns:
      true if the receiver of a method or constructor might not be fully initialized
    • performFlowAnalysisForClass

      protected final void performFlowAnalysisForClass(ClassTree classTree)
      Perform a org.checkerframework.dataflow analysis over a single class tree and its nested classes.

      This method does the bookkeeping that canUseCachedFlowDependentType(ExpressionTree) relies on: it counts the active analyses and discards the cached types of expressions that the analysis may refine. It is final so that no subclass can skip it; a subclass customizes the analysis by overriding performFlowAnalysisForClassImpl(ClassTree).

      Parameters:
      classTree - the class to analyze
    • canUseCachedFlowDependentType

      protected boolean canUseCachedFlowDependentType(ExpressionTree tree)
      Returns true if a cached type of the flow-dependent expression tree (see AnnotatedTypeFactory.isFlowDependent(ExpressionTree)) is still correct, i.e., the refined types of the expressions it was computed from have not changed since it was cached. This implementation, which performs no dataflow analysis, returns true.

      A factory that computes the types of expressions from another factory's dataflow results, such as the Initialization Checker's from the InitializationFieldAccessSubchecker's, relies on the order of the checkers: the subchecker finishes the compilation unit before the parent checker's visitor runs. It may keep this default only as long as it is not queried earlier. A factory that can be queried earlier must override this method and AnnotatedTypeFactory.canCacheFlowDependentType(ExpressionTree).

      AnnotatedTypeFactory.isAnonymousDiamondSupertypeFinal(com.sun.source.tree.NewClassTree) has the same default for the same reason.

      When no dataflow analysis is running, the refined types of the trees of all classes that have been analyzed are final, and a class is analyzed before any of its trees are type-checked; the cached types of the trees of a class that has not been analyzed yet are discarded when its analysis starts.

      While a class is analyzed, a cached type is used only for a tree that is evaluated before the tree whose node the analysis is computing: a proper subexpression of that tree, or part of the receiver or of an earlier argument of an enclosing invocation. The node of such a tree was visited before the current node in the current pass, so its cached type was computed in the current pass and not in an earlier one (see canCacheFlowDependentType(ExpressionTree)). The cached type of any other tree may be from an earlier pass over a loop: for example, inferring the type arguments of bar() in foo(bar(), id(x)) also types the later argument id(x), whose node has not been visited yet. A backward analysis would need another rule.

      Overrides:
      canUseCachedFlowDependentType in class AnnotatedTypeFactory
      Parameters:
      tree - a flow-dependent expression
      Returns:
      true if a cached type of tree can be used
    • canCacheFlowDependentType

      protected boolean canCacheFlowDependentType(ExpressionTree tree)
      Returns true if the type of the flow-dependent expression tree (see AnnotatedTypeFactory.isFlowDependent(ExpressionTree)) can be cached, i.e., it is computed from refined types that remain correct as long as AnnotatedTypeFactory.canUseCachedFlowDependentType(ExpressionTree) holds. The type of a poly expression whose type arguments are inferred together with an enclosing invocation also depends on the other arguments of that invocation, not only on its own subexpressions. This implementation, which performs no dataflow analysis, returns true.

      While a class is analyzed, the type of a tree is cached only when the analysis computes the value of the tree's own node and the tree is its own type argument inference problem, that is, not a poly expression whose type arguments are inferred together with an enclosing invocation. Then its type depends only on its subexpressions, whose nodes have been visited in the current pass, and the tree's own node recomputes its type at each visit. The type of bar() in foo(bar(), id(x)) depends on the type of id(x), whose node is visited after that of bar().

      Overrides:
      canCacheFlowDependentType in class AnnotatedTypeFactory
      Parameters:
      tree - a flow-dependent expression
      Returns:
      true if the type of tree can be cached
    • isComputingNodeValue

      protected boolean isComputingNodeValue()
      Returns true if a dataflow analysis is computing the value of a node, which it does from the type of the node's tree. The analysis state that the types of expressions depend on does not change during that computation, so the results of type argument inference during it are reused within it (see AnnotatedTypeFactory.nodeValueInferenceResultCache). This implementation, which performs no dataflow analysis, returns false.

      The analysis computes the value of a node in CFAbstractTransfer.getValueFromFactory(com.sun.source.tree.Tree, org.checkerframework.dataflow.cfg.node.Node), which sets the analysis's current tree for the duration of the computation and clears the reused results before and after it.

      Overrides:
      isComputingNodeValue in class AnnotatedTypeFactory
      Returns:
      true if a dataflow analysis is computing the value of a node
    • getStandaloneTypeForNodeValue

      public @Nullable AnnotatedTypeMirror getStandaloneTypeForNodeValue(Tree tree)
      Returns the type of tree for the dataflow value of its node, computed as if tree were not nested in another expression, or null if the value is computed from AnnotatedTypeFactory.getAnnotatedType(Tree) as usual.

      This applies to a diamond that does not create an anonymous class, has no poly expression argument, and is inferred together with an enclosing invocation, such as new Pair<>(a, b) in Arrays.asList(new Pair<>(a, b), ...). Its type arguments come from that invocation, but its primary annotations, which are all that a dataflow value keeps of its type, do not; inferring the enclosing invocation for each such argument would take time quadratic in the number of arguments. The underlying type of the result is not the one javac infers, so the caller uses only its primary annotations.

      The primary annotations of such a diamond are the same with and without the enclosing inference: a test that compared them for every nested diamond in the Checker Framework's tests and in a large project found no difference (see performance-notes.md and framework/tests/standalone-diamond). That is not so for a generic method invocation, whose return type can be a type variable that only the enclosing inference determines, nor for a lambda, which has no type without its target, so neither may be a direct argument.

      Parameters:
      tree - a tree whose node's value is being computed
      Returns:
      the type of tree inferred without its enclosing invocation, or null
    • performFlowAnalysisForClassImpl

      protected void performFlowAnalysisForClassImpl(ClassTree classTree)
      Performs the dataflow analysis for performFlowAnalysisForClass(com.sun.source.tree.ClassTree), which calls this method between its bookkeeping. A subclass that does not run its own analysis, or runs it only under some condition, overrides this method and not performFlowAnalysisForClass, which it cannot override.
      Parameters:
      classTree - the class to analyze
    • analyze

      protected ControlFlowGraph analyze(Queue<Pair<ClassTree,@Nullable Store>> classQueue, Queue<Pair<LambdaExpressionTree,@Nullable Store>> lambdaQueue, UnderlyingAST ast, List<CFAbstractAnalysis.FieldInitialValue<Value>> fieldValues, @Nullable ControlFlowGraph cfg, boolean isInitializationCode, boolean updateInitializationStore, boolean isStatic, @Nullable Store capturedStore)
      Analyze the AST ast and store the result. Additional operations that should be performed after analysis should be implemented in postAnalyze(ControlFlowGraph).
      Parameters:
      classQueue - the queue for encountered class trees and their initial stores
      lambdaQueue - the queue for encountered lambda expression trees and their initial stores
      ast - the AST to analyze
      fieldValues - the abstract values for all fields of the same class
      cfg - control flow graph to use; if null, one will be created and returned
      isInitializationCode - are we analyzing a (static/non-static) initializer block of a class
      updateInitializationStore - should the initialization store be updated
      isStatic - are we analyzing a static construct
      capturedStore - the input Store to use for captured variables, e.g. in a lambda
      Returns:
      the control flow graph for ast, which is cfg if cfg is non-null
      See Also:
    • runWithBodyVisitorPath

      protected final void runWithBodyVisitorPath(ControlFlowGraph cfg, Runnable action)
      Parameters:
      cfg - a CFG that has been analyzed
      action - the action to run
    • isIgnoredExceptionType

      public boolean isIgnoredExceptionType(TypeMirror typeMirror)
      Returns true if typeMirror is an exception type that should be ignored.
      Parameters:
      typeMirror - an exception type
      Returns:
      true if typeMirror is an exception type that should be ignored
    • postAnalyze

      protected void postAnalyze(ControlFlowGraph cfg)
      Perform any additional operations on a CFG. Called once per CFG, after the CFG has been analyzed by analyze(Queue, Queue, UnderlyingAST, List, ControlFlowGraph, boolean, boolean, boolean, CFAbstractStore). If the CFG is analyzed more than once, this method is still only called one time after the last time the CFG is analyzed. This method can be used to initialize additional state or to perform any analyzes that are easier to perform on the CFG instead of the AST.

      This implementation type-checks the method invocations that the CFG synthesized for conversions, see BaseTypeVisitor.checkSyntheticMethodInvocations(org.checkerframework.dataflow.cfg.ControlFlowGraph), and visualizes the CFG if requested.

      Parameters:
      cfg - the CFG
      See Also:
    • handleCFGViz

      protected void handleCFGViz(ControlFlowGraph cfg)
      Handle the visualization of the CFG, if necessary.
      Parameters:
      cfg - the CFG
    • getAnnotatedTypeLhsNoTypeVarDefault

      public AnnotatedTypeMirror getAnnotatedTypeLhsNoTypeVarDefault(Tree lhsTree)
      Returns the type of the left-hand side of an assignment without applying local variable defaults to type variables.

      The type variables that are types of local variables are defaulted to top so that they can be refined by dataflow. When these types are used as context during type argument inference, this default is too conservative. So this method is used instead of getAnnotatedTypeLhs(Tree).

      InferenceFactory.assignedToVariable(AnnotatedTypeFactory, Tree) explains why a different type is used.

      Parameters:
      lhsTree - left-hand side of an assignment
      Returns:
      AnnotatedTypeMirror of lhsTree
    • isComputingAnnotatedTypeMirrorOfLhs

      public boolean isComputingAnnotatedTypeMirrorOfLhs()
      Returns whether getAnnotatedTypeLhs(Tree) is running right now. This controls which hierarchies' qualifiers are changed based on the receiver type and the declared annotations for a field.
      Returns:
      whether getAnnotatedTypeLhs(Tree) is running right now
      See Also:
    • getAnnotatedTypeBefore

      public AnnotatedTypeMirror getAnnotatedTypeBefore(JavaExpression expr, ExpressionTree tree)
      Returns the type of a JavaExpression expr if it were evaluated before a tree tree.

      This is used by BaseTypeVisitor.visitMethodInvocation(MethodInvocationTree, Void) to check the preconditions of method calls.

      Parameters:
      expr - the expression to type
      tree - a tree
      Returns:
      the type of expr if it were evaluated before tree tree
    • getAnnotatedTypeLhs

      public AnnotatedTypeMirror getAnnotatedTypeLhs(Tree lhsTree)
      Returns the type of a left-hand side of an assignment.

      The default implementation returns the type without considering dataflow type refinement. Subclass can override this method and add additional logic for computing the type of a LHS.

      Parameters:
      lhsTree - left-hand side of an assignment
      Returns:
      AnnotatedTypeMirror of lhsTree
    • getAnnotatedTypeVarargsArray

      public @Nullable AnnotatedTypeMirror getAnnotatedTypeVarargsArray(Tree tree)
      Returns the type of a varargs array of a method invocation or a constructor invocation. Returns null only if private field useFlow is false.
      Parameters:
      tree - a method invocation or a constructor invocation
      Returns:
      AnnotatedTypeMirror of varargs array for a method or constructor invocation tree; returns null if private field useFlow is false
    • getAnnotatedTypeRhsUnaryAssign

      public AnnotatedTypeMirror getAnnotatedTypeRhsUnaryAssign(UnaryTree tree)
      Returns the type of v + 1 or v - 1 where v is the expression in the postfixed increment or decrement expression.
      Parameters:
      tree - a postfixed increment or decrement tree
      Returns:
      AnnotatedTypeMirror of a right-hand side of an assignment for unary operation
    • constructorFromUse

      protected AnnotatedTypeFactory.ParameterizedExecutableType constructorFromUse(NewClassTree tree, boolean inferTypeArgs)
      Description copied from class: AnnotatedTypeFactory
      Overrides:
      constructorFromUse in class AnnotatedTypeFactory
      Parameters:
      tree - the constructor invocation tree
      inferTypeArgs - true if the type arguments should be inferred
      Returns:
      the annotated type of the invoked constructor (as an executable type) and the type arguments
    • constructorFromUsePreSubstitution

      protected void constructorFromUsePreSubstitution(NewClassTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type, boolean resolvePolyQuals)
      Description copied from class: AnnotatedTypeFactory
      A callback method for the AnnotatedTypeFactory subtypes to customize the handling of the declared constructor type before type variable substitution.
      Overrides:
      constructorFromUsePreSubstitution in class AnnotatedTypeFactory
      Parameters:
      tree - a NewClassTree from constructorFromUse()
      type - declared method type before type variable substitution
      resolvePolyQuals - if true, resolve polymorphic qualifiers
    • getMethodReturnType

      public AnnotatedTypeMirror getMethodReturnType(MethodTree m)
      Description copied from class: AnnotatedTypeFactory
      Returns the return type of the method m.
      Overrides:
      getMethodReturnType in class AnnotatedTypeFactory
      Parameters:
      m - tree of a method declaration
      Returns:
      the return type of the method
    • addDefaultAnnotations

      public void addDefaultAnnotations(AnnotatedTypeMirror type)
      Description copied from class: AnnotatedTypeFactory
      Adds default annotations to type. This method should only be used in places where the correct annotations cannot be computed because of type argument of raw types. (See AnnotatedTypeMirror.AnnotatedWildcardType.isTypeArgOfRawType().)
      Overrides:
      addDefaultAnnotations in class AnnotatedTypeFactory
      Parameters:
      type - annotated type to which default annotations are added
    • getDefaultAnnotations

      public AnnotatedTypeMirror getDefaultAnnotations(Tree tree, AnnotatedTypeMirror type)
      Removes all primary annotations on a copy of the type and calculates the default annotations that apply to the copied type, without type refinements.
      Parameters:
      tree - tree where the type is used
      type - type to determine the defaulted version for
      Returns:
      the annotated type mirror with default annotations
    • addComputedTypeAnnotationsWithoutFlow

      protected final void addComputedTypeAnnotationsWithoutFlow(Tree tree, AnnotatedTypeMirror type)
      A helper method to add computed type annotations to a type without using flow information.

      This method is final; override addComputedTypeAnnotations(Tree, AnnotatedTypeMirror) instead.

      Parameters:
      tree - an AST node
      type - the type obtained from tree
      See Also:
    • addComputedTypeAnnotations

      protected void addComputedTypeAnnotations(Tree tree, AnnotatedTypeMirror type)
      Changes annotations on a type obtained from a Tree. By default, this method does nothing. GenericAnnotatedTypeFactory uses this method to implement defaulting and inference (flow-sensitive type refinement). Its subclasses usually override it only to customize default annotations.

      Subclasses that override this method should also override AnnotatedTypeFactory.addComputedTypeAnnotations(Element, AnnotatedTypeMirror).

      This method adds defaults and flow-sensitive type refinements.

      Overrides:
      addComputedTypeAnnotations in class AnnotatedTypeFactory
      Parameters:
      tree - an AST node
      type - the type obtained from tree
      See Also:
    • performFlowAnalysisForClassOnce

      protected void performFlowAnalysisForClassOnce(ClassTree classTree)
      Flow analysis will be performed if all of the following are true.
      • tree is a ClassTree
      • Flow analysis has not already been performed on tree
      Parameters:
      classTree - the tree to check and possibly perform flow analysis on
    • getInferredValueFor

      public @Nullable Value getInferredValueFor(Tree tree)
      Returns the inferred value (by the org.checkerframework.dataflow analysis) for a given tree.
      Parameters:
      tree - the tree
      Returns:
      the value for the tree, if one has been computed by dataflow. If no value has been computed, null is returned (this does not mean that no value will ever be computed for the given tree).
    • applyInferredAnnotations

      protected void applyInferredAnnotations(AnnotatedTypeMirror type, Value inferred)
      Applies the annotations inferred by the org.checkerframework.dataflow analysis to the type type.
      Parameters:
      type - the type to modify
      inferred - the inferred annotations to apply
    • applyQualifierParameterDefaults

      protected void applyQualifierParameterDefaults(Tree tree, AnnotatedTypeMirror type)
      Applies defaults for types in a class with an qualifier parameter.

      Within a class with @HasQualifierParameter, types with that class default to the polymorphic qualifier rather than the typical default. Local variables with a type that has a qualifier parameter are initialized to the type of their initializer, rather than the default for local variables.

      Parameters:
      tree - a Tree whose type is type
      type - where the defaults are applied
    • applyQualifierParameterDefaults

      protected void applyQualifierParameterDefaults(@Nullable Element elt, AnnotatedTypeMirror type)
      Applies defaults for types in a class with an qualifier parameter.

      Within a class with @HasQualifierParameter, types with that class default to the polymorphic qualifier rather than the typical default. Local variables with a type that has a qualifier parameter are initialized to the type of their initializer, rather than the default for local variables.

      Parameters:
      elt - an Element whose type is type
      type - where the defaults are applied
    • clearParsePhaseCache

      public void clearParsePhaseCache()
      Description copied from class: AnnotatedTypeFactory
      Clears any caches used exclusively during the parse phase. Subclasses may override this to clear their own caches.
      Overrides:
      clearParsePhaseCache in class AnnotatedTypeFactory
    • addComputedTypeAnnotations

      public void addComputedTypeAnnotations(Element elt, AnnotatedTypeMirror type)
      To add annotations to the type of method or constructor parameters, add a TypeAnnotator using createTypeAnnotator() and see the comment in TypeAnnotator.visitExecutable(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType, Void).
      Overrides:
      addComputedTypeAnnotations in class AnnotatedTypeFactory
      Parameters:
      elt - an element
      type - the type obtained from elt
    • methodFromUse

      protected AnnotatedTypeFactory.ParameterizedExecutableType methodFromUse(MethodInvocationTree tree, boolean inferTypeArg)
      Description copied from class: AnnotatedTypeFactory
      Overrides:
      methodFromUse in class AnnotatedTypeFactory
      Parameters:
      tree - a method invocation tree
      inferTypeArg - true if type arguments should be inferred
      Returns:
      the type of the invoked method, any explicit type arguments, and if inferTypeArgs is true, any inferred type arguments
    • methodFromUsePreSubstitution

      public void methodFromUsePreSubstitution(ExpressionTree tree, AnnotatedTypeMirror.AnnotatedExecutableType type, boolean resolvePolyQuals)
      Description copied from class: AnnotatedTypeFactory
      A callback method for the AnnotatedTypeFactory subtypes to customize the handling of the declared method type before type variable substitution.
      Overrides:
      methodFromUsePreSubstitution in class AnnotatedTypeFactory
      Parameters:
      tree - either a method invocation or a member reference tree
      type - declared method type before type variable substitution
      resolvePolyQuals - if true, resolve polymorphic qualifiers
    • typeVariablesFromUse

      Description copied from class: AnnotatedTypeFactory
      Adapt the upper bounds of the type variables of a class relative to the type instantiation. In some type systems, the upper bounds depend on the instantiation of the class. For example, in the Generic Universe Type system, consider a class declaration
        class C<X extends @Peer Object> 
      then the instantiation
        @Rep C<@Rep Object> 
      is legal. The upper bounds of class C have to be adapted by the main modifier.

      An example of an adaptation follows. Suppose, I have a declaration:

       class MyClass<E extends List<E>>
      And an instantiation:
       new MyClass<@NonNull String>()

      The upper bound of E adapted to the argument String, would be List<@NonNull String> and the lower bound would be an AnnotatedNullType.

      TODO: ensure that this method is consistently used instead of directly querying the type variables.

      Overrides:
      typeVariablesFromUse in class AnnotatedTypeFactory
      Parameters:
      type - the use of the type
      element - the corresponding element
      Returns:
      the adapted bounds of the type parameters
    • getEmptyStore

      public Store getEmptyStore()
      Returns the empty store.
      Returns:
      the empty store
    • getTypeFactoryOfSubchecker

      public final <T extends GenericAnnotatedTypeFactory<?, ?, ?, ?>> T getTypeFactoryOfSubchecker(Class<? extends SourceChecker> subCheckerClass)
      Returns the type factory used by a subchecker. Throws an exception if no matching subchecker was found or if the type factory is null. The caller must know the exact checker class to request.

      Because the visitor path is copied, call this method each time a subfactory is needed rather than store the returned subfactory in a field.

      Type Parameters:
      T - the type of subCheckerClass's AnnotatedTypeFactory
      Parameters:
      subCheckerClass - the exact class of the subchecker
      Returns:
      the AnnotatedTypeFactory of the subchecker; never null
      See Also:
    • getTypeFactoryOfSubcheckerOrNull

      public <T extends GenericAnnotatedTypeFactory<?, ?, ?, ?>> @Nullable T getTypeFactoryOfSubcheckerOrNull(Class<? extends SourceChecker> subCheckerClass)
      Returns the type factory used by a subchecker. Returns null if no matching subchecker was found or if the type factory is null. The caller must know the exact checker class to request.

      Because the visitor path is copied, call this method each time a subfactory is needed rather than store the returned subfactory in a field.

      Type Parameters:
      T - the type of subCheckerClass's AnnotatedTypeFactory
      Parameters:
      subCheckerClass - the exact class of the subchecker
      Returns:
      the AnnotatedTypeFactory of the subchecker or null if no subchecker exists
      See Also:
    • getShouldDefaultTypeVarLocals

      public boolean getShouldDefaultTypeVarLocals()
      Should the local variable default annotation be applied to type variables?

      It is initialized to true if data flow is used by the checker. It is set to false when getting the assignment context for type argument inference.

      Returns:
      shouldDefaultTypeVarLocals
      See Also:
    • createCFGVisualizer

      protected @Nullable CFGVisualizer<Value,Store,TransferFunction> createCFGVisualizer()
      Create a new CFGVisualizer.
      Returns:
      a new CFGVisualizer, or null if none will be used on this run
    • getCFGVisualizer

      public CFGVisualizer<Value,Store,TransferFunction> getCFGVisualizer()
      The CFGVisualizer to be used by all CFAbstractAnalysis instances.
    • postAsMemberOf

      public void postAsMemberOf(AnnotatedTypeMirror type, AnnotatedTypeMirror owner, Element element)
      Description copied from class: AnnotatedTypeFactory
      A callback method for the AnnotatedTypeFactory subtypes to customize AnnotatedTypes.asMemberOf(). Overriding methods should merely change the annotations on the subtypes, without changing the types.
      Overrides:
      postAsMemberOf in class AnnotatedTypeFactory
      Parameters:
      type - the annotated type of the element
      owner - the annotated type of the receiver of the accessing tree
      element - the element of the field or method
    • addAnnotationsFromDefaultForType

      protected void addAnnotationsFromDefaultForType(@Nullable Element element, AnnotatedTypeMirror type)
      Adds default qualifiers based on the underlying type of type to type. If element is a local variable, or if the type already has an annotation from the relevant type hierarchy, then the defaults are not added.

      (This uses both the DefaultQualifierForUseTypeAnnotator and DefaultForTypeAnnotator.)

      Parameters:
      element - possibly null element whose type is type
      type - the type to which defaults are added
    • isRelevant

      public final boolean isRelevant(TypeMirror tm)
      Returns true if users can write type annotations from this type system directly on the given Java type.

      For a compound type, returns true only if a programmer may write a type qualifier on the top level of the compound type. That is, this method may return false, when it is possible to write type qualifiers on elements of the type.

      Subclasses should override #isRelevantImpl instead of this method.

      Parameters:
      tm - a type
      Returns:
      true if users can write type annotations from this type system directly on the given Java type
    • isRelevant

      public final boolean isRelevant(AnnotatedTypeMirror tm)
      Returns true if users can write type annotations from this type system directly on the given Java type.

      For a compound type, returns true only if it a programmer may write a type qualifier on the top level of the compound type. That is, this method may return false, when it is possible to write type qualifiers on elements of the type.

      Subclasses should override #isRelevantImpl instead of this method.

      Parameters:
      tm - a type
      Returns:
      true if users can write type annotations from this type system directly on the given Java type
    • isRelevantImpl

      protected boolean isRelevantImpl(TypeMirror tm)
      Returns true if users can write type annotations from this type system on the given Java type. Does not use a cache.

      Clients should never call this. Call isRelevant(javax.lang.model.type.TypeMirror) instead. This is a helper method for isRelevant(javax.lang.model.type.TypeMirror).

      Parameters:
      tm - a type
      Returns:
      true if users can write type annotations from this type system on the given Java type
    • irrelevantExtraMessage

      public String irrelevantExtraMessage()
      Returns a string that can be passed to the "anno.on.irrelevant" error, giving information about which types are relevant.
      Returns:
      a string that can be passed to the "anno.on.irrelevant" error, possibly the empty string
    • getDefaultValueAnnotatedType

      public AnnotatedTypeMirror getDefaultValueAnnotatedType(TypeMirror typeMirror)
      Returns the type of the default value of the given type. The default value is 0, false, or null.
      Parameters:
      typeMirror - a type
      Returns:
      the annotated type of type's default value
    • createRequiresOrEnsuresQualifier

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

      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 - what 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
    • addSharedCFGForTree

      public boolean addSharedCFGForTree(Tree tree, ControlFlowGraph cfg)
      Add a new entry to the shared CFG. If this is a subchecker, this method delegates to the superchecker's GenericAnnotatedTypeFactory, if it exists. Duplicate keys must map to the same CFG.

      Calls to this method should be guarded by checking hasOrIsSubchecker; it is nonsensical to have a shared CFG when a checker is running alone.

      Parameters:
      tree - the source code corresponding to cfg
      cfg - the control flow graph to use for tree
      Returns:
      true if a shared CFG was found to actually add to (duplicate keys also return true)
    • getSharedCFGForTree

      public @Nullable ControlFlowGraph getSharedCFGForTree(Tree tree)
      Returns the shared control flow graph used for tree by this checker's topmost superchecker. Returns null if no information is available about the given tree, or if this checker has a parent checker that does not have a GenericAnnotatedTypeFactory.

      Calls to this method should be guarded by checking hasOrIsSubchecker; it is nonsensical to have a shared CFG when a checker is running alone.

      Parameters:
      tree - the tree whose CFG should be looked up
      Returns:
      the CFG stored by this checker's uppermost superchecker for tree, or null if it is not available
    • getEnsuresQualifierIfResult

      public @Nullable Boolean getEnsuresQualifierIfResult(Contract.Kind kind, AnnotationMirror contractAnnotation)
      If kind = CONDITIONALPOSTCONDITION, return the result element, e.g. EnsuresQualifierIf.result(). Otherwise, return null.
      Parameters:
      kind - the kind of contractAnnotation
      contractAnnotation - a RequiresQualifier, EnsuresQualifier, or EnsuresQualifierIf
      Returns:
      the result element of contractAnnotation, or null if it doesn't have a result element
    • getContractExpressions

      public @Nullable List<String> getContractExpressions(Contract.Kind kind, AnnotationMirror contractAnnotation)
      If contractAnnotation is a framework annotation, return its expression element. Otherwise, contractAnnotation is defined in a checker. If kind = CONDITIONALPOSTCONDITION, return its expression element, else return its value element.
      Parameters:
      kind - the kind of contractAnnotation
      contractAnnotation - a RequiresQualifier, EnsuresQualifier, or EnsuresQualifierIf
      Returns:
      the result element of contractAnnotation, or null if it doesn't have a result element