Debian Codegraph @

rhino/src/org/mozilla/javascript/ast/ArrayComprehensionLoop.java

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 package org.mozilla.javascript.ast;
8
9 import org.mozilla.javascript.Token;
10
11 /**
12 * AST node for a single 'for (foo in bar)' loop construct in a JavaScript 1.7
13 * Array comprehension. This node type is almost equivalent to a
14 * {@link ForInLoop}, except that it has no body statement.
15 * Node type is {@link Token#FOR}.<p>
16 */
17 public class ArrayComprehensionLoop extends ForInLoop {
18
19 public ArrayComprehensionLoop() {
20 }
21
22 public ArrayComprehensionLoop(int pos) {
23 super(pos);
24 }
25
26 public ArrayComprehensionLoop(int pos, int len) {
27 super(pos, len);
28 }
29
30 /**
31 * Returns {@code null} for loop body
32 * @return loop body (always {@code null} for this node type)
33 */
34 @Override
35 public AstNode getBody() {
36 return null;
37 }
38
39 /**
40 * Throws an exception on attempts to set the loop body.
41 * @param body loop body
42 * @throws UnsupportedOperationException
43 */
44 @Override
45 public void setBody(AstNode body) {
46 throw new UnsupportedOperationException("this node type has no body");
47 }
48
49 @Override
50 public String toSource(int depth) {
51 return makeIndent(depth)
52 + " for "
53 + (isForEach()?"each ":"")
54 + "("
55 + iterator.toSource(0)
56 + (isForOf()?" of ":" in ")
57 + iteratedObject.toSource(0)
58 + ")";
59 }
60
61 /**
62 * Visits the iterator expression and the iterated object expression.
63 * There is no body-expression for this loop type.
64 */
65 @Override
66 public void visit(NodeVisitor v) {
67 if (v.visit(this)) {
68 iterator.visit(v);
69 iteratedObject.visit(v);
70 }
71 }
72 }