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
23 public class ASTIdentifierAccess extends JexlNode {
24
25
26
27 private static final long serialVersionUID = 1L;
28 private String name = null;
29 private Integer identifier = null;
30
31 ASTIdentifierAccess(final int id) {
32 super(id);
33 }
34
35 ASTIdentifierAccess(final Parser p, final int id) {
36 super(p, id);
37 }
38
39 void setIdentifier(final String id) {
40 name = id;
41 identifier = parseIdentifier(id);
42 }
43
44 @Override
45 public boolean isGlobalVar() {
46 return !isSafe() && !isExpression();
47 }
48
49
50
51
52
53 public boolean isSafe() {
54 return false;
55 }
56
57
58
59
60
61 public boolean isExpression() {
62 return false;
63 }
64
65
66
67
68
69
70
71 public static Integer parseIdentifier(final String id) {
72
73 if (id != null) {
74 final int length = id.length();
75 int val = 0;
76 for (int i = 0; i < length; ++i) {
77 final char c = id.charAt(i);
78
79 if (c == '0') {
80 if (length == 1) {
81 return 0;
82 }
83 if (val == 0) {
84 return null;
85 }
86 }
87 else if (c < '0' || c > '9') {
88 return null;
89 }
90 val *= 10;
91 val += (c - '0');
92 }
93 return val;
94 }
95 return null;
96 }
97
98 public Object getIdentifier() {
99 return identifier != null? identifier : name;
100 }
101
102 public String getName() {
103 return name;
104 }
105
106 @Override
107 public Object jjtAccept(final ParserVisitor visitor, final Object data) {
108 return visitor.visit(this, data);
109 }
110
111 @Override
112 public String toString() {
113 return name;
114 }
115 }