1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jexl3.parser;
18
19
20
21
22 public class ASTIdentifier extends JexlNode {
23
24
25 private static final long serialVersionUID = 1L;
26
27 private static final int REDEFINED = 0;
28
29 private static final int SHADED = 1;
30
31 private static final int CAPTURED = 2;
32
33
34 private static final int LEXICAL = 3;
35
36 private static final int CONST = 4;
37
38
39
40
41
42
43 private static boolean isSet(final int ordinal, final int mask) {
44 return (mask & 1 << ordinal) != 0;
45 }
46
47
48
49
50
51
52
53 private static int set(final int ordinal, final int mask, final boolean value) {
54 return value? mask | 1 << ordinal : mask & ~(1 << ordinal);
55 }
56 protected String name;
57
58 protected int symbol = -1;
59
60 protected int flags;
61
62 ASTIdentifier(final int id) {
63 super(id);
64 }
65
66 public String getName() {
67 return name;
68 }
69
70 public String getNamespace() {
71 return null;
72 }
73
74 public int getSymbol() {
75 return symbol;
76 }
77
78 public boolean isCaptured() {
79 return isSet(CAPTURED, flags);
80 }
81
82 @Override
83 public boolean isConstant() {
84 return isSet(CONST, flags);
85 }
86
87 public boolean isLexical() {
88 return isSet(LEXICAL, flags);
89 }
90
91 public boolean isRedefined() {
92 return isSet(REDEFINED, flags);
93 }
94
95 public boolean isShaded() {
96 return isSet(SHADED, flags);
97 }
98
99 @Override
100 public Object jjtAccept(final ParserVisitor visitor, final Object data) {
101 return visitor.visit(this, data);
102 }
103
104 public void setCaptured(final boolean f) {
105 flags = set(CAPTURED, flags, f);
106 }
107
108 public void setConstant(final boolean f) {
109 flags = set(CONST, flags, f);
110 }
111
112 public void setLexical(final boolean f) {
113 flags = set(LEXICAL, flags, f);
114 }
115
116 public void setRedefined(final boolean f) {
117 flags = set(REDEFINED, flags, f);
118 }
119
120 public void setShaded(final boolean f) {
121 flags = set(SHADED, flags, f);
122 }
123
124 void setSymbol(final int r, final String identifier) {
125 symbol = r;
126 name = identifier;
127 }
128
129 void setSymbol(final String identifier) {
130 if (identifier.charAt(0) == '#') {
131 symbol = Integer.parseInt(identifier.substring(1));
132 }
133 name = identifier;
134 }
135
136 @Override
137 public String toString() {
138 return name;
139 }
140 }