Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
   *
   * This Source Code Form is subject to the terms of the Mozilla Public
   * License, v. 2.0. If a copy of the MPL was not distributed with this
   * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  
  package org.mozilla.javascript.ast;
  
For-in or for-each-in statement. Node type is org.mozilla.javascript.Token.FOR.

for [each] ( LeftHandSideExpression in Expression ) Statement
for [each] ( var VariableDeclarationNoIn in Expression ) Statement
 
 public class ForInLoop extends Loop {
 
     protected AstNode iterator;
     protected AstNode iteratedObject;
     protected int inPosition = -1;
     protected int eachPosition = -1;
     protected boolean isForEach;
 
     {
          = .;
     }
 
     public ForInLoop() {
     }
 
     public ForInLoop(int pos) {
         super(pos);
     }
 
     public ForInLoop(int posint len) {
         super(poslen);
     }

    
Returns loop iterator expression
 
     public AstNode getIterator() {
         return ;
     }

    
Sets loop iterator expression: the part before the "in" keyword. Also sets its parent to this node.

Throws:
java.lang.IllegalArgumentException if iterator is null
 
     public void setIterator(AstNode iterator) {
         assertNotNull(iterator);
         this. = iterator;
         iterator.setParent(this);
     }

    
Returns object being iterated over
 
     public AstNode getIteratedObject() {
         return ;
     }

    
Sets object being iterated over, and sets its parent to this node.

Throws:
java.lang.IllegalArgumentException if object is null
 
     public void setIteratedObject(AstNode object) {
         assertNotNull(object);
         this. = object;
         object.setParent(this);
     }

    
Returns whether the loop is a for-each loop
 
     public boolean isForEach() {
         return ;
     }

    
Sets whether the loop is a for-each loop
 
     public void setIsForEach(boolean isForEach) {
         this. = isForEach;
     }

    
Returns position of "in" keyword
 
     public int getInPosition() {
         return ;
     }

    
Sets position of "in" keyword

Parameters:
inPosition position of "in" keyword, or -1 if not present (e.g. in presence of a syntax error)
    public void setInPosition(int inPosition) {
        this. = inPosition;
    }

    
Returns position of "each" keyword
    public int getEachPosition() {
        return ;
    }

    
Sets position of "each" keyword

Parameters:
eachPosition position of "each" keyword, or -1 if not present.
    public void setEachPosition(int eachPosition) {
        this. = eachPosition;
    }
    @Override
    public String toSource(int depth) {
        StringBuilder sb = new StringBuilder();
        sb.append(makeIndent(depth));
        sb.append("for ");
        if (isForEach()) {
            sb.append("each ");
        }
        sb.append("(");
        sb.append(.toSource(0));
        sb.append(" in ");
        sb.append(.toSource(0));
        sb.append(") ");
        if (.getType() == .) {
            sb.append(.toSource(depth).trim()).append("\n");
        } else {
            sb.append("\n").append(.toSource(depth+1));
        }
        return sb.toString();
    }

    
Visits this node, the iterator, the iterated object, and the body.
    @Override
    public void visit(NodeVisitor v) {
        if (v.visit(this)) {
            .visit(v);
            .visit(v);
            .visit(v);
        }
    }
New to GrepCode? Check out our FAQ X