Debian Codegraph @

rhino/src/org/mozilla/javascript/ast/XmlMemberGet.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 E4X ".@" and ".." expressions, such as
13 * {@code foo..bar}, {@code foo..@bar}, {@code @foo.@bar}, and
14 * {@code foo..@ns::*}. The right-hand node is always an
15 * {@link XmlRef}. <p>
16 *
17 * Node type is {@link Token#DOT} or {@link Token#DOTDOT}.
18 */
19 public class XmlMemberGet extends InfixExpression {
20
21 {
22 type = Token.DOTDOT;
23 }
24
25 public XmlMemberGet() {
26 }
27
28 public XmlMemberGet(int pos) {
29 super(pos);
30 }
31
32 public XmlMemberGet(int pos, int len) {
33 super(pos, len);
34 }
35
36 public XmlMemberGet(int pos, int len, AstNode target, XmlRef ref) {
37 super(pos, len, target, ref);
38 }
39
40 /**
41 * Constructs a new {@code XmlMemberGet} node.
42 * Updates bounds to include {@code target} and {@code ref} nodes.
43 */
44 public XmlMemberGet(AstNode target, XmlRef ref) {
45 super(target, ref);
46 }
47
48 public XmlMemberGet(AstNode target, XmlRef ref, int opPos) {
49 super(Token.DOTDOT, target, ref, opPos);
50 }
51
52 /**
53 * Returns the object on which the XML member-ref expression
54 * is being evaluated. Should never be {@code null}.
55 */
56 public AstNode getTarget() {
57 return getLeft();
58 }
59
60 /**
61 * Sets target object, and sets its parent to this node.
62 * @throws IllegalArgumentException if {@code target} is {@code null}
63 */
64 public void setTarget(AstNode target) {
65 setLeft(target);
66 }
67
68 /**
69 * Returns the right-side XML member ref expression.
70 * Should never be {@code null} unless the code is malformed.
71 */
72 public XmlRef getMemberRef() {
73 return (XmlRef)getRight();
74 }
75
76 /**
77 * Sets the XML member-ref expression, and sets its parent
78 * to this node.
79 * @throws IllegalArgumentException if property is {@code null}
80 */
81 public void setProperty(XmlRef ref) {
82 setRight(ref);
83 }
84
85 @Override
86 public String toSource(int depth) {
87 StringBuilder sb = new StringBuilder();
88 sb.append(makeIndent(depth));
89 sb.append(getLeft().toSource(0));
90 sb.append(operatorToString(getType()));
91 sb.append(getRight().toSource(0));
92 return sb.toString();
93 }
94 }