%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jexl.parser.TokenMgrError |
|
|
1 | /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 2.1 */ |
|
2 | package org.apache.commons.jexl.parser; |
|
3 | ||
4 | public class TokenMgrError extends Error |
|
5 | { |
|
6 | /* |
|
7 | * Ordinals for various reasons why an Error of this type can be thrown. |
|
8 | */ |
|
9 | ||
10 | /** |
|
11 | * Lexical error occured. |
|
12 | */ |
|
13 | static final int LEXICAL_ERROR = 0; |
|
14 | ||
15 | /** |
|
16 | * An attempt wass made to create a second instance of a static token manager. |
|
17 | */ |
|
18 | static final int STATIC_LEXER_ERROR = 1; |
|
19 | ||
20 | /** |
|
21 | * Tried to change to an invalid lexical state. |
|
22 | */ |
|
23 | static final int INVALID_LEXICAL_STATE = 2; |
|
24 | ||
25 | /** |
|
26 | * Detected (and bailed out of) an infinite loop in the token manager. |
|
27 | */ |
|
28 | static final int LOOP_DETECTED = 3; |
|
29 | ||
30 | /** |
|
31 | * Indicates the reason why the exception is thrown. It will have |
|
32 | * one of the above 4 values. |
|
33 | */ |
|
34 | int errorCode; |
|
35 | ||
36 | /** |
|
37 | * Replaces unprintable characters by their espaced (or unicode escaped) |
|
38 | * equivalents in the given string |
|
39 | */ |
|
40 | protected static final String addEscapes(String str) { |
|
41 | 0 | StringBuffer retval = new StringBuffer(); |
42 | char ch; |
|
43 | 0 | for (int i = 0; i < str.length(); i++) { |
44 | 0 | switch (str.charAt(i)) |
45 | { |
|
46 | case 0 : |
|
47 | 0 | continue; |
48 | case '\b': |
|
49 | 0 | retval.append("\\b"); |
50 | 0 | continue; |
51 | case '\t': |
|
52 | 0 | retval.append("\\t"); |
53 | 0 | continue; |
54 | case '\n': |
|
55 | 0 | retval.append("\\n"); |
56 | 0 | continue; |
57 | case '\f': |
|
58 | 0 | retval.append("\\f"); |
59 | 0 | continue; |
60 | case '\r': |
|
61 | 0 | retval.append("\\r"); |
62 | 0 | continue; |
63 | case '\"': |
|
64 | 0 | retval.append("\\\""); |
65 | 0 | continue; |
66 | case '\'': |
|
67 | 0 | retval.append("\\\'"); |
68 | 0 | continue; |
69 | case '\\': |
|
70 | 0 | retval.append("\\\\"); |
71 | 0 | continue; |
72 | default: |
|
73 | 0 | if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { |
74 | 0 | String s = "0000" + Integer.toString(ch, 16); |
75 | 0 | retval.append("\\u" + s.substring(s.length() - 4, s.length())); |
76 | } else { |
|
77 | 0 | retval.append(ch); |
78 | } |
|
79 | continue; |
|
80 | } |
|
81 | } |
|
82 | 0 | return retval.toString(); |
83 | } |
|
84 | ||
85 | /** |
|
86 | * Returns a detailed message for the Error when it is thrown by the |
|
87 | * token manager to indicate a lexical error. |
|
88 | * Parameters : |
|
89 | * EOFSeen : indicates if EOF caused the lexicl error |
|
90 | * curLexState : lexical state in which this error occured |
|
91 | * errorLine : line number when the error occured |
|
92 | * errorColumn : column number when the error occured |
|
93 | * errorAfter : prefix that was seen before this error occured |
|
94 | * curchar : the offending character |
|
95 | * Note: You can customize the lexical error message by modifying this method. |
|
96 | */ |
|
97 | private static final String LexicalError(boolean EOFSeen, int lexState, class="keyword">int errorLine, class="keyword">int errorColumn, String errorAfter, char curChar) { |
|
98 | 0 | return("Lexical error at line " + |
99 | errorLine + ", column " + |
|
100 | errorColumn + ". Encountered: " + |
|
101 | (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + |
|
102 | "after : \"" + addEscapes(errorAfter) + "\""); |
|
103 | } |
|
104 | ||
105 | /** |
|
106 | * You can also modify the body of this method to customize your error messages. |
|
107 | * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not |
|
108 | * of end-users concern, so you can return something like : |
|
109 | * |
|
110 | * "Internal Error : Please file a bug report .... " |
|
111 | * |
|
112 | * from this method for such cases in the release version of your parser. |
|
113 | */ |
|
114 | public String getMessage() { |
|
115 | 0 | return super.getMessage(); |
116 | } |
|
117 | ||
118 | /* |
|
119 | * Constructors of various flavors follow. |
|
120 | */ |
|
121 | ||
122 | 0 | public TokenMgrError() { |
123 | 0 | } |
124 | ||
125 | public TokenMgrError(String message, int reason) { |
|
126 | 0 | super(message); |
127 | 0 | errorCode = reason; |
128 | 0 | } |
129 | ||
130 | public TokenMgrError(boolean EOFSeen, int lexState, class="keyword">int errorLine, class="keyword">int errorColumn, String errorAfter, char curChar, class="keyword">int reason) { |
|
131 | 0 | this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); |
132 | 0 | } |
133 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |