Debian Codegraph @

rhino/src/org/mozilla/javascript/ast/ContinueStatement.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 * A continue statement.
13 * Node type is {@link Token#CONTINUE}.<p>
14 *
15 * <pre><i>ContinueStatement</i> :
16 * <b>continue</b> [<i>no LineTerminator here</i>] [Identifier] ;</pre>
17 */
18 public class ContinueStatement extends Jump {
19
20 private Name label;
21 private Loop target;
22
23 {
24 type = Token.CONTINUE;
25 }
26
27 public ContinueStatement() {
28 }
29
30 public ContinueStatement(int pos) {
31 this(pos, -1);
32 }
33
34 public ContinueStatement(int pos, int len) {
35 // can't call super (Jump) for historical reasons
36 position = pos;
37 length = len;
38 }
39
40 public ContinueStatement(Name label) {
41 setLabel(label);
42 }
43
44 public ContinueStatement(int pos, Name label) {
45 this(pos);
46 setLabel(label);
47 }
48
49 public ContinueStatement(int pos, int len, Name label) {
50 this(pos, len);
51 setLabel(label);
52 }
53
54 /**
55 * Returns continue target
56 */
57 public Loop getTarget() {
58 return target;
59 }
60
61 /**
62 * Sets continue target. Does NOT set the parent of the target node:
63 * the target node is an ancestor of this node.
64 * @param target continue target
65 * @throws IllegalArgumentException if target is {@code null}
66 */
67 public void setTarget(Loop target) {
68 assertNotNull(target);
69 this.target = target;
70 setJumpStatement(target);
71 }
72
73 /**
74 * Returns the intended label of this continue statement
75 * @return the continue label. Will be {@code null} if the statement
76 * consisted only of the keyword "continue".
77 */
78 public Name getLabel() {
79 return label;
80 }
81
82 /**
83 * Sets the intended label of this continue statement.
84 * Only applies if the statement was of the form "continue &lt;label&gt;".
85 * @param label the continue label, or {@code null} if not present.
86 */
87 public void setLabel(Name label) {
88 this.label = label;
89 if (label != null)
90 label.setParent(this);
91 }
92
93 @Override
94 public String toSource(int depth) {
95 StringBuilder sb = new StringBuilder();
96 sb.append(makeIndent(depth));
97 sb.append("continue");
98 if (label != null) {
99 sb.append(" ");
100 sb.append(label.toSource(0));
101 }
102 sb.append(";\n");
103 return sb.toString();
104 }
105
106 /**
107 * Visits this node, then visits the label if non-{@code null}.
108 */
109 @Override
110 public void visit(NodeVisitor v) {
111 if (v.visit(this) && label != null) {
112 label.visit(v);
113 }
114 }
115 }