Debian Codegraph @

rhino/src/org/mozilla/javascript/ast/Yield.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 JavaScript 1.7 {@code yield} expression or statement.
13 * Node type is {@link Token#YIELD}.<p>
14 *
15 * <pre><i>Yield</i> :
16 * <b>yield</b> [<i>no LineTerminator here</i>] [non-paren Expression] ;</pre>
17 */
18 public class Yield extends AstNode {
19
20 private AstNode value;
21
22 {
23 type = Token.YIELD;
24 }
25
26 public Yield() {
27 }
28
29 public Yield(int pos) {
30 super(pos);
31 }
32
33 public Yield(int pos, int len) {
34 super(pos, len);
35 }
36
37 public Yield(int pos, int len, AstNode value) {
38 super(pos, len);
39 setValue(value);
40 }
41
42 /**
43 * Returns yielded expression, {@code null} if none
44 */
45 public AstNode getValue() {
46 return value;
47 }
48
49 /**
50 * Sets yielded expression, and sets its parent to this node.
51 * @param expr the value to yield. Can be {@code null}.
52 */
53 public void setValue(AstNode expr) {
54 this.value = expr;
55 if (expr != null)
56 expr.setParent(this);
57 }
58
59 @Override
60 public String toSource(int depth) {
61 return value == null
62 ? "yield"
63 : "yield " + value.toSource(0);
64 }
65
66 /**
67 * Visits this node, and if present, the yielded value.
68 */
69 @Override
70 public void visit(NodeVisitor v) {
71 if (v.visit(this) && value != null) {
72 value.visit(v);
73 }
74 }
75 }