Debian Codegraph @

rhino/src/org/mozilla/javascript/ast/XmlExpression.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 an embedded JavaScript expression within an E4X XML literal.
13 * Node type, like {@link XmlLiteral}, is {@link Token#XML}. The node length
14 * includes the curly braces.
15 */
16 public class XmlExpression extends XmlFragment {
17
18 private AstNode expression;
19 private boolean isXmlAttribute;
20
21 public XmlExpression() {
22 }
23
24 public XmlExpression(int pos) {
25 super(pos);
26 }
27
28 public XmlExpression(int pos, int len) {
29 super(pos, len);
30 }
31
32 public XmlExpression(int pos, AstNode expr) {
33 super(pos);
34 setExpression(expr);
35 }
36
37 /**
38 * Returns the expression embedded in {}
39 */
40 public AstNode getExpression() {
41 return expression;
42 }
43
44 /**
45 * Sets the expression embedded in {}, and sets its parent to this node.
46 * @throws IllegalArgumentException if {@code expression} is {@code null}
47 */
48 public void setExpression(AstNode expression) {
49 assertNotNull(expression);
50 this.expression = expression;
51 expression.setParent(this);
52 }
53
54 /**
55 * Returns whether this is part of an xml attribute value
56 */
57 public boolean isXmlAttribute() {
58 return isXmlAttribute;
59 }
60
61 /**
62 * Sets whether this is part of an xml attribute value
63 */
64 public void setIsXmlAttribute(boolean isXmlAttribute) {
65 this.isXmlAttribute = isXmlAttribute;
66 }
67
68 @Override
69 public String toSource(int depth) {
70 return makeIndent(depth) + "{" + expression.toSource(depth) + "}";
71 }
72
73 /**
74 * Visits this node, then the child expression.
75 */
76 @Override
77 public void visit(NodeVisitor v) {
78 if (v.visit(this)) {
79 expression.visit(v);
80 }
81 }
82 }