Revision 44139 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/spi/AbstractLexicalAnalyzer.java
AbstractLexicalAnalyzer.java | ||
---|---|---|
6 | 6 |
import java.util.HashMap; |
7 | 7 |
import java.util.Locale; |
8 | 8 |
import java.util.Map; |
9 |
import java.util.Objects; |
|
9 | 10 |
import java.util.Stack; |
11 |
import org.apache.commons.lang3.StringUtils; |
|
10 | 12 |
import org.gvsig.expressionevaluator.ExpressionRuntimeException; |
11 | 13 |
import org.gvsig.expressionevaluator.ExpressionSyntaxException; |
12 | 14 |
import org.gvsig.expressionevaluator.I18N; |
... | ... | |
62 | 64 |
this.literal = literal; |
63 | 65 |
} |
64 | 66 |
|
67 |
@Override |
|
68 |
public boolean is(String... values) { |
|
69 |
for (String theValue : values) { |
|
70 |
if( StringUtils.isBlank(literal) ) { |
|
71 |
if( StringUtils.isBlank(theValue) ) { |
|
72 |
return true; |
|
73 |
} |
|
74 |
continue; |
|
75 |
} |
|
76 |
if( StringUtils.isBlank(theValue) ) { |
|
77 |
continue; |
|
78 |
} |
|
79 |
if( theValue.trim().equalsIgnoreCase(this.literal.trim()) ) { |
|
80 |
return true; |
|
81 |
} |
|
82 |
} |
|
83 |
return false; |
|
84 |
} |
|
85 |
|
|
86 |
@Override |
|
87 |
public String toString() { |
|
88 |
return String.format("{%d,%s,%s}", this.type, Objects.toString(this.literal), Objects.toString(value)); |
|
89 |
} |
|
90 |
|
|
65 | 91 |
} |
66 | 92 |
|
67 | 93 |
protected class Buffer implements Cloneable { |
... | ... | |
108 | 134 |
protected Buffer buffer; |
109 | 135 |
protected Token token; |
110 | 136 |
protected Map<String, Integer> tokens; |
111 |
|
|
137 |
protected boolean useBracketsForIdentifiers; |
|
138 |
|
|
112 | 139 |
public AbstractLexicalAnalyzer(String source) { |
140 |
this.useBracketsForIdentifiers = false; |
|
113 | 141 |
this.position = 0; |
114 | 142 |
this.source = source; |
115 | 143 |
this.states = new Stack<>(); |
... | ... | |
251 | 279 |
} |
252 | 280 |
String literal = source.substring(this.position, this.nfPos.getIndex()); |
253 | 281 |
this.position = this.nfPos.getIndex(); |
254 |
if (n instanceof Long || n instanceof Integer) { |
|
282 |
if( n instanceof Long ) { |
|
283 |
long l = ((Long)n); |
|
284 |
if( l>Integer.MIN_VALUE && l<Integer.MAX_VALUE ) { |
|
285 |
token.set(Token.INTEGER_LITERAL, literal, (int)l); |
|
286 |
} else { |
|
287 |
token.set(Token.INTEGER_LITERAL, literal, n); |
|
288 |
} |
|
289 |
} else if( n instanceof Integer) { |
|
255 | 290 |
token.set(Token.INTEGER_LITERAL, literal, n); |
256 | 291 |
} else { |
257 | 292 |
token.set(Token.FLOATING_POINT_LITERAL, literal, n); |
258 | 293 |
} |
259 | 294 |
} |
295 |
|
|
296 |
public void setUseBracketsForIdentifiers(boolean useBracketsForIdentifiers) { |
|
297 |
this.useBracketsForIdentifiers = useBracketsForIdentifiers; |
|
298 |
} |
|
299 |
|
|
300 |
public boolean getUseBracketsForIdentifiers() { |
|
301 |
return this.useBracketsForIdentifiers; |
|
302 |
} |
|
260 | 303 |
} |
Also available in: Unified diff