svn-gvsig-desktop / 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 @ 44421
History | View | Annotate | Download (3.25 KB)
1 | 43983 | jjdelcerro | package org.gvsig.expressionevaluator; |
---|---|---|---|
2 | |||
3 | 44379 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
4 | |||
5 | 43983 | jjdelcerro | /**
|
6 | *
|
||
7 | * @author jjdelcerro
|
||
8 | */
|
||
9 | public class ExpressionSyntaxException extends RuntimeException { |
||
10 | |||
11 | 44098 | jjdelcerro | private final int position; |
12 | 44379 | jjdelcerro | private final int line; |
13 | private final int column; |
||
14 | 44098 | jjdelcerro | private final String phrase; |
15 | private final String description; |
||
16 | 44139 | jjdelcerro | private String tip; |
17 | 43983 | jjdelcerro | |
18 | public ExpressionSyntaxException() {
|
||
19 | super("Syntax error in expression."); |
||
20 | 44098 | jjdelcerro | this.phrase = null; |
21 | this.position = -1; |
||
22 | 44379 | jjdelcerro | this.line = -1; |
23 | this.column = -1; |
||
24 | 44098 | jjdelcerro | this.description = I18N.Syntax_error_in_expression();
|
25 | 44139 | jjdelcerro | this.tip = null; |
26 | 43983 | jjdelcerro | } |
27 | |||
28 | public ExpressionSyntaxException(LexicalAnalyzer lexer) {
|
||
29 | 44379 | jjdelcerro | super("Syntax error in '"+getSource(lexer.getSource(), lexer.getPosition())+"' near character "+ lexer.getPosition()+" ("+lexer.getLine()+":"+lexer.getColumn()+")."); |
30 | 44098 | jjdelcerro | this.phrase = lexer.getSource();
|
31 | this.position = lexer.getPosition();
|
||
32 | 44379 | jjdelcerro | this.line = lexer.getLine();
|
33 | this.column = lexer.getColumn();
|
||
34 | 44098 | jjdelcerro | this.description = I18N.Syntax_error_near_character_XPositionX(position);
|
35 | 43983 | jjdelcerro | } |
36 | |||
37 | public ExpressionSyntaxException(String msg, LexicalAnalyzer lexer) { |
||
38 | 44379 | jjdelcerro | super("Syntax error in '"+getSource(lexer.getSource(), lexer.getPosition()) +"' near character "+ lexer.getPosition()+" ("+lexer.getLine()+":"+lexer.getColumn()+"). "+msg); |
39 | 43983 | jjdelcerro | this.phrase = lexer.getSource();
|
40 | this.position = lexer.getPosition();
|
||
41 | 44379 | jjdelcerro | this.line = lexer.getLine();
|
42 | this.column = lexer.getColumn();
|
||
43 | 44098 | jjdelcerro | this.description = I18N.Syntax_error_near_character_XPositionX(position)+ " "+msg; |
44 | 43983 | jjdelcerro | } |
45 | 44139 | jjdelcerro | |
46 | public ExpressionSyntaxException(String msg, LexicalAnalyzer lexer, String tip) { |
||
47 | this(msg,lexer);
|
||
48 | this.tip = tip;
|
||
49 | } |
||
50 | 43983 | jjdelcerro | |
51 | public ExpressionSyntaxException(String phrase, int position) { |
||
52 | 44379 | jjdelcerro | super("Syntax error in '"+getSource(phrase, position) +"' near character "+ position+"."); |
53 | 43983 | jjdelcerro | this.phrase = phrase;
|
54 | this.position = position;
|
||
55 | 44379 | jjdelcerro | this.line = -1; |
56 | this.column = -1; |
||
57 | 44098 | jjdelcerro | this.description = I18N.Syntax_error_near_character_XPositionX(position);
|
58 | 43983 | jjdelcerro | } |
59 | |||
60 | public ExpressionSyntaxException(String msg, String phrase, int position) { |
||
61 | 44379 | jjdelcerro | super("Syntax error in '"+ getSource(phrase, position) +"' near character "+ position+". "+msg); |
62 | 43983 | jjdelcerro | this.phrase = phrase;
|
63 | this.position = position;
|
||
64 | 44379 | jjdelcerro | this.line = -1; |
65 | this.column = -1; |
||
66 | 44098 | jjdelcerro | this.description = I18N.Syntax_error_near_character_XPositionX(position)+" "+msg; |
67 | 43983 | jjdelcerro | } |
68 | |||
69 | 44379 | jjdelcerro | 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 | |||
77 | 43983 | jjdelcerro | public String getPhrase() { |
78 | return this.phrase; |
||
79 | } |
||
80 | |||
81 | public int getPosition() { |
||
82 | return this.position; |
||
83 | } |
||
84 | 44098 | jjdelcerro | |
85 | 44379 | jjdelcerro | public int getLine() { |
86 | return this.line; |
||
87 | } |
||
88 | |||
89 | public int getColumn() { |
||
90 | return this.column; |
||
91 | } |
||
92 | |||
93 | 44098 | jjdelcerro | public String getDescription() { |
94 | return this.description; |
||
95 | } |
||
96 | 44139 | jjdelcerro | |
97 | public String getTip() { |
||
98 | return this.tip; |
||
99 | } |
||
100 | 43983 | jjdelcerro | } |