1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.jexl3;
19
20 import org.apache.commons.jexl3.internal.Script;
21
22
23
24
25
26 public class JexlInfo {
27
28
29
30
31 public interface Detail {
32
33
34
35 int end();
36
37
38
39
40 int start();
41
42
43
44
45
46 @Override
47 String toString();
48 }
49
50
51
52
53
54
55 public static JexlInfo from(final JexlScript script) {
56 return script instanceof Script? ((Script) script).getInfo() : null;
57 }
58
59
60 private final int line;
61
62
63 private final int column;
64
65
66 private final String name;
67
68
69
70
71
72
73 public JexlInfo() {
74 final StackTraceElement[] stack = new Throwable().getStackTrace();
75 String cname = getClass().getName();
76 final String pkgname = getClass().getPackage().getName();
77 StackTraceElement se = null;
78 for (int s = 1; s < stack.length; ++s) {
79 se = stack[s];
80 final String className = se.getClassName();
81 if (!className.equals(cname)) {
82
83 if (!className.startsWith(pkgname + ".internal.") && !className.startsWith(pkgname + ".Jexl")
84 && !className.startsWith(pkgname + ".parser")) {
85 break;
86 }
87 cname = className;
88 }
89 }
90 this.name = se != null ? se.getClassName() + "." + se.getMethodName() + ":" + se.getLineNumber() : "?";
91 this.line = 1;
92 this.column = 1;
93 }
94
95
96
97
98
99
100 protected JexlInfo(final JexlInfo copy) {
101 this(copy.getName(), copy.getLine(), copy.getColumn());
102 }
103
104
105
106
107
108
109
110
111 public JexlInfo(final String source, final int l, final int c) {
112 name = source;
113 line = l <= 0? 1: l;
114 column = c <= 0? 1 : c;
115 }
116
117
118
119
120
121
122
123
124 public JexlInfo at(final int l, final int c) {
125 return new JexlInfo(name, l, c);
126 }
127
128
129
130
131 public JexlInfo detach() {
132 return this;
133 }
134
135
136
137
138
139
140 public final int getColumn() {
141 return column;
142 }
143
144
145
146
147 public Detail getDetail() {
148 return null;
149 }
150
151
152
153
154
155
156 public final int getLine() {
157 return line;
158 }
159
160
161
162
163
164
165 public final String getName() {
166 return name;
167 }
168
169
170
171
172
173
174 @Override
175 public String toString() {
176 final StringBuilder sb = new StringBuilder(name != null ? name : "");
177 sb.append("@");
178 sb.append(line);
179 sb.append(":");
180 sb.append(column);
181 final JexlInfo.Detail dbg = getDetail();
182 if (dbg!= null) {
183 sb.append("![");
184 sb.append(dbg.start());
185 sb.append(",");
186 sb.append(dbg.end());
187 sb.append("]: '");
188 sb.append(dbg.toString());
189 sb.append("'");
190 }
191 return sb.toString();
192 }
193 }
194