Statistics
| Revision:

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 @ 44379

History | View | Annotate | Download (3.25 KB)

1
package org.gvsig.expressionevaluator;
2

    
3
import org.apache.commons.lang3.StringUtils;
4

    
5
/**
6
 *
7
 * @author jjdelcerro
8
 */
9
public class ExpressionSyntaxException extends RuntimeException {
10

    
11
    private final int position;
12
    private final int line;
13
    private final int column;
14
    private final String phrase;
15
    private final String description;
16
    private String tip;
17
    
18
    public ExpressionSyntaxException() {
19
        super("Syntax error in expression.");
20
        this.phrase = null;
21
        this.position = -1;
22
        this.line = -1;
23
        this.column = -1;
24
        this.description = I18N.Syntax_error_in_expression();
25
        this.tip = null;
26
    }
27
    
28
    public ExpressionSyntaxException(LexicalAnalyzer lexer) {
29
        super("Syntax error in '"+getSource(lexer.getSource(), lexer.getPosition())+"' near character "+ lexer.getPosition()+" ("+lexer.getLine()+":"+lexer.getColumn()+").");
30
        this.phrase = lexer.getSource();
31
        this.position = lexer.getPosition();
32
        this.line = lexer.getLine();
33
        this.column = lexer.getColumn();
34
        this.description = I18N.Syntax_error_near_character_XPositionX(position);
35
    }
36
    
37
    public ExpressionSyntaxException(String msg, LexicalAnalyzer lexer) {
38
        super("Syntax error in '"+getSource(lexer.getSource(), lexer.getPosition()) +"' near character "+ lexer.getPosition()+" ("+lexer.getLine()+":"+lexer.getColumn()+"). "+msg);
39
        this.phrase = lexer.getSource();
40
        this.position = lexer.getPosition();
41
        this.line = lexer.getLine();
42
        this.column = lexer.getColumn();
43
        this.description = I18N.Syntax_error_near_character_XPositionX(position)+ " "+msg;
44
    }
45

    
46
    public ExpressionSyntaxException(String msg, LexicalAnalyzer lexer, String tip) {
47
        this(msg,lexer);
48
        this.tip = tip;
49
    }
50
    
51
    public ExpressionSyntaxException(String phrase, int position) {
52
        super("Syntax error in '"+getSource(phrase, position) +"' near character "+ position+".");
53
        this.phrase = phrase;
54
        this.position = position;
55
        this.line = -1;
56
        this.column = -1;
57
        this.description = I18N.Syntax_error_near_character_XPositionX(position);
58
    }
59
    
60
    public ExpressionSyntaxException(String msg, String phrase, int position) {
61
        super("Syntax error in '"+ getSource(phrase, position) +"' near character "+ position+". "+msg);
62
        this.phrase = phrase;
63
        this.position = position;
64
        this.line = -1;
65
        this.column = -1;
66
        this.description = I18N.Syntax_error_near_character_XPositionX(position)+" "+msg;
67
    }
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
    
77
    public String getPhrase() {
78
        return this.phrase;
79
    }
80
    
81
    public int getPosition() {
82
        return this.position;
83
    }
84
    
85
    public int getLine() {
86
        return this.line;
87
    }
88
    
89
    public int getColumn() {
90
        return this.column;
91
    }
92
    
93
    public String getDescription() {
94
        return this.description;
95
    }
96
    
97
    public String getTip() {
98
        return this.tip;
99
    }
100
}