Debian Codegraph @

rhino/src/org/mozilla/javascript/ast/XmlRef.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 /**
10 * Base class for E4X XML attribute-access or property-get expressions.
11 * Such expressions can take a variety of forms. The general syntax has
12 * three parts:<p>
13 *
14 * <ol>
15 * <li>optional: an {@code @}</li> (specifying an attribute access)</li>
16 * <li>optional: a namespace (a {@code Name}) and double-colon</li>
17 * <li>required: either a {@code Name} or a bracketed [expression]</li>
18 * </ol>
19 *
20 * The property-name expressions (examples: {@code ns::name}, {@code @name})
21 * are represented as {@link XmlPropRef} nodes. The bracketed-expression
22 * versions (examples: {@code ns::[name]}, {@code @[name]}) become
23 * {@link XmlElemRef} nodes.<p>
24 *
25 * This node type (or more specifically, its subclasses) will
26 * sometimes be the right-hand child of a {@link PropertyGet} node or
27 * an {@link XmlMemberGet} node. The {@code XmlRef} node may also
28 * be a standalone primary expression with no explicit target, which
29 * is valid in certain expression contexts such as
30 * {@code company..employee.(@id &lt; 100)} - in this case, the {@code @id}
31 * is an {@code XmlRef} that is part of an infix '&lt;' expression
32 * whose parent is an {@code XmlDotQuery} node.<p>
33 */
34 public abstract class XmlRef extends AstNode {
35
36 protected Name namespace;
37 protected int atPos = -1;
38 protected int colonPos = -1;
39
40 public XmlRef() {
41 }
42
43 public XmlRef(int pos) {
44 super(pos);
45 }
46
47 public XmlRef(int pos, int len) {
48 super(pos, len);
49 }
50
51 /**
52 * Return the namespace. May be {@code @null}.
53 */
54 public Name getNamespace() {
55 return namespace;
56 }
57
58 /**
59 * Sets namespace, and sets its parent to this node.
60 * Can be {@code null}.
61 */
62 public void setNamespace(Name namespace) {
63 this.namespace = namespace;
64 if (namespace != null)
65 namespace.setParent(this);
66 }
67
68 /**
69 * Returns {@code true} if this expression began with an {@code @}-token.
70 */
71 public boolean isAttributeAccess() {
72 return atPos >= 0;
73 }
74
75 /**
76 * Returns position of {@code @}-token, or -1 if this is not
77 * an attribute-access expression.
78 */
79 public int getAtPos() {
80 return atPos;
81 }
82
83 /**
84 * Sets position of {@code @}-token, or -1
85 */
86 public void setAtPos(int atPos) {
87 this.atPos = atPos;
88 }
89
90 /**
91 * Returns position of {@code ::} token, or -1 if not present.
92 * It will only be present if the namespace node is non-{@code null}.
93 */
94 public int getColonPos() {
95 return colonPos;
96 }
97
98 /**
99 * Sets position of {@code ::} token, or -1 if not present
100 */
101 public void setColonPos(int colonPos) {
102 this.colonPos = colonPos;
103 }
104 }