Debian Codegraph @

rhino/src/org/mozilla/javascript/ast/DoLoop.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 * Do statement. Node type is {@link Token#DO}.<p>
13 *
14 * <pre><i>DoLoop</i>:
15 * <b>do</b> Statement <b>while</b> <b>(</b> Expression <b>)</b> <b>;</b></pre>
16 */
17 public class DoLoop extends Loop {
18
19 private AstNode condition;
20 private int whilePosition = -1;
21
22 {
23 type = Token.DO;
24 }
25
26 public DoLoop() {
27 }
28
29 public DoLoop(int pos) {
30 super(pos);
31 }
32
33 public DoLoop(int pos, int len) {
34 super(pos, len);
35 }
36
37 /**
38 * Returns loop condition
39 */
40 public AstNode getCondition() {
41 return condition;
42 }
43
44 /**
45 * Sets loop condition, and sets its parent to this node.
46 * @throws IllegalArgumentException if condition is null
47 */
48 public void setCondition(AstNode condition) {
49 assertNotNull(condition);
50 this.condition = condition;
51 condition.setParent(this);
52 }
53
54 /**
55 * Returns source position of "while" keyword
56 */
57 public int getWhilePosition() {
58 return whilePosition;
59 }
60
61 /**
62 * Sets source position of "while" keyword
63 */
64 public void setWhilePosition(int whilePosition) {
65 this.whilePosition = whilePosition;
66 }
67
68 @Override
69 public String toSource(int depth) {
70 StringBuilder sb = new StringBuilder();
71 sb.append(makeIndent(depth));
72 sb.append("do ");
73 sb.append(body.toSource(depth).trim());
74 sb.append(" while (");
75 sb.append(condition.toSource(0));
76 sb.append(");\n");
77 return sb.toString();
78 }
79
80 /**
81 * Visits this node, the body, and then the while-expression.
82 */
83 @Override
84 public void visit(NodeVisitor v) {
85 if (v.visit(this)) {
86 body.visit(v);
87 condition.visit(v);
88 }
89 }
90 }