Class ForInLoop

All Implemented Interfaces:
Comparable<AstNode>, Iterable<Node>
Direct Known Subclasses:
ArrayComprehensionLoop, GeneratorExpressionLoop

public class ForInLoop extends Loop
For-in or for-each-in or for-of statement. Node type is Token.FOR.
for [each] ( LeftHandSideExpression in Expression ) Statement
 for [each] ( var VariableDeclarationNoIn in Expression ) Statement
 
for ( LeftHandSideExpression of Expression ) Statement
for ( ForDeclaration of Expression ) Statement
  • Field Details

    • iterator

      protected AstNode iterator
    • iteratedObject

      protected AstNode iteratedObject
    • inPosition

      protected int inPosition
    • eachPosition

      protected int eachPosition
    • isForEach

      protected boolean isForEach
    • isForOf

      protected boolean isForOf
  • Constructor Details

    • ForInLoop

      public ForInLoop()
    • ForInLoop

      public ForInLoop(int pos)
    • ForInLoop

      public ForInLoop(int pos, int len)
  • Method Details

    • getIterator

      public AstNode getIterator()
      Returns loop iterator expression
    • setIterator

      public void setIterator(AstNode iterator)
      Sets loop iterator expression: the part before the "in" or "of" keyword. Also sets its parent to this node.
      Throws:
      IllegalArgumentException - if iterator is null
    • getIteratedObject

      public AstNode getIteratedObject()
      Returns object being iterated over
    • setIteratedObject

      public void setIteratedObject(AstNode object)
      Sets object being iterated over, and sets its parent to this node.
      Throws:
      IllegalArgumentException - if object is null
    • isForEach

      public boolean isForEach()
      Returns whether the loop is a for-each loop
    • setIsForEach

      public void setIsForEach(boolean isForEach)
      Sets whether the loop is a for-each loop
    • isForOf

      public boolean isForOf()
      Returns whether the loop is a for-of loop
    • setIsForOf

      public void setIsForOf(boolean isForOf)
      Sets whether the loop is a for-each loop
    • getInPosition

      public int getInPosition()
      Returns position of "in" or "of" keyword
    • setInPosition

      public void setInPosition(int inPosition)
      Sets position of "in" or "of" keyword
      Parameters:
      inPosition - position of "in" or "of" keyword, or -1 if not present (e.g. in presence of a syntax error)
    • getEachPosition

      public int getEachPosition()
      Returns position of "each" keyword
    • setEachPosition

      public void setEachPosition(int eachPosition)
      Sets position of "each" keyword
      Parameters:
      eachPosition - position of "each" keyword, or -1 if not present.
    • toSource

      public String toSource(int depth)
      Description copied from class: AstNode
      Emits source code for this node. Callee is responsible for calling this function recursively on children, incrementing indent as appropriate.

      Note: if the parser was in error-recovery mode, some AST nodes may have null children that are expected to be non-null when no errors are present. In this situation, the behavior of the toSource method is undefined: toSource implementations may assume that the AST node is error-free, since it is intended to be invoked only at runtime after a successful parse.

      Overrides:
      toSource in class Scope
      Parameters:
      depth - the current recursion depth, typically beginning at 0 when called on the root node.
    • visit

      public void visit(NodeVisitor v)
      Visits this node, the iterator, the iterated object, and the body.
      Overrides:
      visit in class Scope
      Parameters:
      v - the object to call with this node and its children