Revision 44379 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/ExpressionSyntaxException.java
ExpressionSyntaxException.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator; |
2 | 2 |
|
3 |
import org.apache.commons.lang3.StringUtils; |
|
4 |
|
|
3 | 5 |
/** |
4 | 6 |
* |
5 | 7 |
* @author jjdelcerro |
... | ... | |
7 | 9 |
public class ExpressionSyntaxException extends RuntimeException { |
8 | 10 |
|
9 | 11 |
private final int position; |
12 |
private final int line; |
|
13 |
private final int column; |
|
10 | 14 |
private final String phrase; |
11 | 15 |
private final String description; |
12 | 16 |
private String tip; |
... | ... | |
15 | 19 |
super("Syntax error in expression."); |
16 | 20 |
this.phrase = null; |
17 | 21 |
this.position = -1; |
22 |
this.line = -1; |
|
23 |
this.column = -1; |
|
18 | 24 |
this.description = I18N.Syntax_error_in_expression(); |
19 | 25 |
this.tip = null; |
20 | 26 |
} |
21 | 27 |
|
22 | 28 |
public ExpressionSyntaxException(LexicalAnalyzer lexer) { |
23 |
super("Syntax error in '"+lexer.getSource()+"' near character "+ lexer.getPosition()+".");
|
|
29 |
super("Syntax error in '"+getSource(lexer.getSource(), lexer.getPosition())+"' near character "+ lexer.getPosition()+" ("+lexer.getLine()+":"+lexer.getColumn()+").");
|
|
24 | 30 |
this.phrase = lexer.getSource(); |
25 | 31 |
this.position = lexer.getPosition(); |
32 |
this.line = lexer.getLine(); |
|
33 |
this.column = lexer.getColumn(); |
|
26 | 34 |
this.description = I18N.Syntax_error_near_character_XPositionX(position); |
27 | 35 |
} |
28 | 36 |
|
29 | 37 |
public ExpressionSyntaxException(String msg, LexicalAnalyzer lexer) { |
30 |
super("Syntax error in '"+lexer.getSource()+"' near character "+ lexer.getPosition()+". "+msg);
|
|
38 |
super("Syntax error in '"+getSource(lexer.getSource(), lexer.getPosition()) +"' near character "+ lexer.getPosition()+" ("+lexer.getLine()+":"+lexer.getColumn()+"). "+msg);
|
|
31 | 39 |
this.phrase = lexer.getSource(); |
32 | 40 |
this.position = lexer.getPosition(); |
41 |
this.line = lexer.getLine(); |
|
42 |
this.column = lexer.getColumn(); |
|
33 | 43 |
this.description = I18N.Syntax_error_near_character_XPositionX(position)+ " "+msg; |
34 | 44 |
} |
35 | 45 |
|
... | ... | |
39 | 49 |
} |
40 | 50 |
|
41 | 51 |
public ExpressionSyntaxException(String phrase, int position) { |
42 |
super("Syntax error in '"+phrase+"' near character "+ position+".");
|
|
52 |
super("Syntax error in '"+getSource(phrase, position) +"' near character "+ position+".");
|
|
43 | 53 |
this.phrase = phrase; |
44 | 54 |
this.position = position; |
55 |
this.line = -1; |
|
56 |
this.column = -1; |
|
45 | 57 |
this.description = I18N.Syntax_error_near_character_XPositionX(position); |
46 | 58 |
} |
47 | 59 |
|
48 | 60 |
public ExpressionSyntaxException(String msg, String phrase, int position) { |
49 |
super("Syntax error in '"+phrase+"' near character "+ position+". "+msg);
|
|
61 |
super("Syntax error in '"+ getSource(phrase, position) +"' near character "+ position+". "+msg);
|
|
50 | 62 |
this.phrase = phrase; |
51 | 63 |
this.position = position; |
64 |
this.line = -1; |
|
65 |
this.column = -1; |
|
52 | 66 |
this.description = I18N.Syntax_error_near_character_XPositionX(position)+" "+msg; |
53 | 67 |
} |
54 | 68 |
|
69 |
private static String getSource(String source, int position) { |
|
70 |
String s = StringUtils.left(source, position) + "[*]" + StringUtils.mid(source, position, 200); |
|
71 |
if( s.length()>200 ) { |
|
72 |
s = "..."+StringUtils.mid(s, position-100, 200)+"..."; |
|
73 |
} |
|
74 |
return s; |
|
75 |
} |
|
76 |
|
|
55 | 77 |
public String getPhrase() { |
56 | 78 |
return this.phrase; |
57 | 79 |
} |
... | ... | |
60 | 82 |
return this.position; |
61 | 83 |
} |
62 | 84 |
|
85 |
public int getLine() { |
|
86 |
return this.line; |
|
87 |
} |
|
88 |
|
|
89 |
public int getColumn() { |
|
90 |
return this.column; |
|
91 |
} |
|
92 |
|
|
63 | 93 |
public String getDescription() { |
64 | 94 |
return this.description; |
65 | 95 |
} |
Also available in: Unified diff