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