KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > jsp > ast > TokenMgrError


1 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
2 /**
3  * JSP Parser for PMD.
4  * @author Pieter � Application Engineers NV/SA � http://www.ae.be
5  */

6
7 package net.sourceforge.pmd.jsp.ast;
8
9 public class TokenMgrError extends RuntimeException JavaDoc {
10     /*
11      * Ordinals for various reasons why an Error of this type can be thrown.
12      */

13
14     /**
15      * Lexical error occured.
16      */

17     static final int LEXICAL_ERROR = 0;
18
19     /**
20      * An attempt wass made to create a second instance of a static token manager.
21      */

22     static final int STATIC_LEXER_ERROR = 1;
23
24     /**
25      * Tried to change to an invalid lexical state.
26      */

27     static final int INVALID_LEXICAL_STATE = 2;
28
29     /**
30      * Detected (and bailed out of) an infinite loop in the token manager.
31      */

32     static final int LOOP_DETECTED = 3;
33
34     /**
35      * Indicates the reason why the exception is thrown. It will have
36      * one of the above 4 values.
37      */

38     int errorCode;
39
40     /**
41      * Replaces unprintable characters by their espaced (or unicode escaped)
42      * equivalents in the given string
43      */

44     protected static final String JavaDoc addEscapes(String JavaDoc str) {
45         StringBuffer JavaDoc retval = new StringBuffer JavaDoc();
46         char ch;
47         for (int i = 0; i < str.length(); i++) {
48             switch (str.charAt(i)) {
49                 case 0:
50                     continue;
51                 case '\b':
52                     retval.append("\\b");
53                     continue;
54                 case '\t':
55                     retval.append("\\t");
56                     continue;
57                 case '\n':
58                     retval.append("\\n");
59                     continue;
60                 case '\f':
61                     retval.append("\\f");
62                     continue;
63                 case '\r':
64                     retval.append("\\r");
65                     continue;
66                 case '\"':
67                     retval.append("\\\"");
68                     continue;
69                 case '\'':
70                     retval.append("\\\'");
71                     continue;
72                 case '\\':
73                     retval.append("\\\\");
74                     continue;
75                 default:
76                     if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
77                         String JavaDoc s = "0000" + Integer.toString(ch, 16);
78                         retval.append("\\u" + s.substring(s.length() - 4, s.length()));
79                     } else {
80                         retval.append(ch);
81                     }
82                     continue;
83             }
84         }
85         return retval.toString();
86     }
87
88     /**
89      * Returns a detailed message for the Error when it is thrown by the
90      * token manager to indicate a lexical error.
91      * Parameters :
92      * EOFSeen : indicates if EOF caused the lexicl error
93      * curLexState : lexical state in which this error occured
94      * errorLine : line number when the error occured
95      * errorColumn : column number when the error occured
96      * errorAfter : prefix that was seen before this error occured
97      * curchar : the offending character
98      * Note: You can customize the lexical error message by modifying this method.
99      */

100     protected static String JavaDoc LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String JavaDoc errorAfter, char curChar) {
101         return ("Lexical error at line " +
102                 errorLine + ", column " +
103                 errorColumn + ". Encountered: " +
104                 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") +
105                 "after : \"" + addEscapes(errorAfter) + "\"");
106     }
107
108     /**
109      * You can also modify the body of this method to customize your error messages.
110      * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
111      * of end-users concern, so you can return something like :
112      * <p/>
113      * "Internal Error : Please file a bug report .... "
114      * <p/>
115      * from this method for such cases in the release version of your parser.
116      */

117     public String JavaDoc getMessage() {
118         return super.getMessage();
119     }
120
121     /*
122      * Constructors of various flavors follow.
123      */

124
125     public TokenMgrError() {
126     }
127
128     public TokenMgrError(String JavaDoc message, int reason) {
129         super(message);
130         errorCode = reason;
131     }
132
133     public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String JavaDoc errorAfter, char curChar, int reason) {
134         this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
135     }
136 }
137
Popular Tags