Debian Codegraph @

rhino/src/org/mozilla/javascript/ast/ParenthesizedExpression.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 parenthesized expression.
13 * Node type is {@link Token#LP}.<p>
14 */
15 public class ParenthesizedExpression extends AstNode {
16
17 private AstNode expression;
18
19 {
20 type = Token.LP;
21 }
22
23 public ParenthesizedExpression() {
24 }
25
26 public ParenthesizedExpression(int pos) {
27 super(pos);
28 }
29
30 public ParenthesizedExpression(int pos, int len) {
31 super(pos, len);
32 }
33
34 public ParenthesizedExpression(AstNode expr) {
35 this(expr != null ? expr.getPosition() : 0,
36 expr != null ? expr.getLength() : 1,
37 expr);
38 }
39
40 public ParenthesizedExpression(int pos, int len, AstNode expr) {
41 super(pos, len);
42 setExpression(expr);
43 }
44
45 /**
46 * Returns the expression between the parens
47 */
48 public AstNode getExpression() {
49 return expression;
50 }
51
52 /**
53 * Sets the expression between the parens, and sets the parent
54 * to this node.
55 * @param expression the expression between the parens
56 * @throws IllegalArgumentException} if expression is {@code null}
57 */
58 public void setExpression(AstNode expression) {
59 assertNotNull(expression);
60 this.expression = expression;
61 expression.setParent(this);
62 }
63
64 @Override
65 public String toSource(int depth) {
66 return makeIndent(depth) + "(" + expression.toSource(0) + ")";
67 }
68
69 /**
70 * Visits this node, then the child expression.
71 */
72 @Override
73 public void visit(NodeVisitor v) {
74 if (v.visit(this)) {
75 expression.visit(v);
76 }
77 }
78 }