Class IteratedCollectionElement

java.lang.Object
org.checkerframework.dataflow.expression.JavaExpression
org.checkerframework.dataflow.expression.IteratedCollectionElement

public class IteratedCollectionElement extends JavaExpression
Represents a collection element that is iterated over in a potentially collection-obligation-fulfilling loop, for example o in for (Object o: list) { }.

An IteratedCollectionElement is identified by its tree, compared by reference. Each loop has its own tree, so two loops have different elements even if their code is identical.

  • Field Details

    • node

      public final Node node
      The CFG node for this collection element, such as the LocalVariableNode for o in for (Object o : list), or the MethodInvocationNode for list.get(i) in for (int i = 0; i < list.size(); i++) { list.get(i).close(); }.
    • tree

      public final Tree tree
      The AST tree for this collection element: the tree of node, such as the declaration Object o in for (Object o : list), or the invocation list.get(i) in an indexed loop.
    • reference

      public final JavaExpression reference
      The expression that refers to this collection element in the loop body, such as the local variable o or the method call list.get(i).
  • Constructor Details

    • IteratedCollectionElement

      public IteratedCollectionElement(Node node, Tree tree)
      Creates a new IteratedCollectionElement.
      Parameters:
      node - the CFG node for a collection element, such as the LocalVariableNode for o in for (Object o : list)
      tree - the tree of node, such as the declaration Object o
  • Method Details

    • isDenotedBy

      public boolean isDenotedBy(Node n)
      Returns true if the given node denotes this collection element: its tree is this element's tree, or its expression equals this element's reference. That reference is the local variable that this element's tree declares, such as o in o.close() in the body of for (Object o : list), or a method call such as list.get(i) in list.get(i).close() in the body of for (int i = 0; i < list.size(); i++).

      This method is unsound for a reference that is a nondeterministic method call, such as it.next() in a while loop over an iterator it. It returns true for every call it.next() in the loop body, but each such call yields a different collection element.

      Parameters:
      n - a CFG node
      Returns:
      true if n denotes this collection element
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • containedOfClass

      public <T extends JavaExpression> @Nullable T containedOfClass(Class<T> clazz)
      Description copied from class: JavaExpression
      Returns the first subexpression whose class is the given class, or null.

      This is intended as a diagnostic aid; most clients will use JavaExpression.containsOfClass(java.lang.Class<? extends org.checkerframework.dataflow.expression.JavaExpression>).

      Specified by:
      containedOfClass in class JavaExpression
      Type Parameters:
      T - the type corresponding to clazz
      Parameters:
      clazz - the JavaExpression subclass to search for
      Returns:
      the first subexpression whose class is the given class, or null
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isDeterministic

      public boolean isDeterministic(AnnotationProvider provider)
      Description copied from class: JavaExpression
      Returns true if the expression is deterministic.
      Specified by:
      isDeterministic in class JavaExpression
      Parameters:
      provider - an annotation provider (a type factory)
      Returns:
      true if this expression is deterministic
    • syntacticEquals

      public boolean syntacticEquals(JavaExpression je)
      Description copied from class: JavaExpression
      Returns true if and only if the two Java expressions are syntactically identical.

      This is a stricter test than Object.equals(java.lang.Object), which accommodates commutativity of operations.

      Specified by:
      syntacticEquals in class JavaExpression
      Parameters:
      je - the other Java expression to compare to this one
      Returns:
      true if and only if the two Java expressions are syntactically identical
    • containsSyntacticEqualJavaExpression

      public boolean containsSyntacticEqualJavaExpression(JavaExpression other)
      Description copied from class: JavaExpression
      Returns true if and only if this contains a JavaExpression that is syntactically equal to other.
      Specified by:
      containsSyntacticEqualJavaExpression in class JavaExpression
      Parameters:
      other - the JavaExpression to search for
      Returns:
      true if and only if this contains a JavaExpression that is syntactically equal to other
    • isAssignableByOtherCode

      public boolean isAssignableByOtherCode()
      Description copied from class: JavaExpression
      Returns true if some subexpression of this can be assigned to from outside the current method body.

      This is false for local variables, the self reference, final field accesses whose receiver is not JavaExpression.isAssignableByOtherCode(), and operations whose operands are all not JavaExpression.isModifiableByOtherCode().

      Specified by:
      isAssignableByOtherCode in class JavaExpression
      Returns:
      true if some subexpression of this can be assigned to from outside the current method body
      See Also:
    • isModifiableByOtherCode

      public boolean isModifiableByOtherCode()
      Description copied from class: JavaExpression
      Returns true if the abstract value of this expression can be changed by a method call; equivalently, if the abstract value can be changed by a side effect from outside the containing method.

      Approximately, this returns true if the expression is JavaExpression.isAssignableByOtherCode() or its type is mutable. (String is an immutable type.)

      Specified by:
      isModifiableByOtherCode in class JavaExpression
      Returns:
      true if the value of this expression can be changed from outside the current method body
      See Also:
    • accept

      public <R, P> R accept(JavaExpressionVisitor<R,P> visitor, P p)
      Description copied from class: JavaExpression
      Accept method of the visitor pattern.
      Specified by:
      accept in class JavaExpression
      Type Parameters:
      R - result type of the operation
      P - parameter type
      Parameters:
      visitor - the visitor to be applied to this JavaExpression
      p - the parameter for this operation
      Returns:
      the result of visiting this