KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > annotation > expression > ast > TokenMgrError


1 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
2
3 /***********************************************************************************************************************
4  * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved. * http://aspectwerkz.codehaus.org *
5  * ---------------------------------------------------------------------------------- * The software in this package is
6  * published under the terms of the LGPL license * a copy of which has been included with this distribution in the
7  * license.txt file. *
8  **********************************************************************************************************************/

9 package org.codehaus.aspectwerkz.annotation.expression.ast;
10
11 public class TokenMgrError extends Error JavaDoc {
12     /*
13      * Ordinals for various reasons why an Error of this type can be thrown.
14      */

15
16     /**
17      * Lexical error occured.
18      */

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

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

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

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

39     int errorCode;
40
41     /*
42      * Constructors of various flavors follow.
43      */

44     public TokenMgrError() {
45     }
46
47     public TokenMgrError(String JavaDoc message, int reason) {
48         super(message);
49         errorCode = reason;
50     }
51
52     public TokenMgrError(boolean EOFSeen,
53                          int lexState,
54                          int errorLine,
55                          int errorColumn,
56                          String JavaDoc errorAfter,
57                          char curChar,
58                          int reason) {
59         this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
60     }
61
62     /**
63      * Replaces unprintable characters by their espaced (or unicode escaped) equivalents in the given string
64      */

65     protected static final String JavaDoc addEscapes(String JavaDoc str) {
66         StringBuffer JavaDoc retval = new StringBuffer JavaDoc();
67         char ch;
68         for (int i = 0; i < str.length(); i++) {
69             switch (str.charAt(i)) {
70                 case 0:
71                     continue;
72                 case '\b':
73                     retval.append("\\b");
74                     continue;
75                 case '\t':
76                     retval.append("\\t");
77                     continue;
78                 case '\n':
79                     retval.append("\\n");
80                     continue;
81                 case '\f':
82                     retval.append("\\f");
83                     continue;
84                 case '\r':
85                     retval.append("\\r");
86                     continue;
87                 case '\"':
88                     retval.append("\\\"");
89                     continue;
90                 case '\'':
91                     retval.append("\\\'");
92                     continue;
93                 case '\\':
94                     retval.append("\\\\");
95                     continue;
96                 default:
97                     if (((ch = str.charAt(i)) < 0x20) || (ch > 0x7e)) {
98                         String JavaDoc s = "0000" + Integer.toString(ch, 16);
99                         retval.append("\\u" + s.substring(s.length() - 4, s.length()));
100                     } else {
101                         retval.append(ch);
102                     }
103                     continue;
104             }
105         }
106         return retval.toString();
107     }
108
109     /**
110      * Returns a detailed message for the Error when it is thrown by the token manager to indicate a lexical error.
111      * Parameters : EOFSeen : indicates if EOF caused the lexicl error curLexState : lexical state in which this error
112      * occured errorLine : line number when the error occured errorColumn : column number when the error occured
113      * errorAfter : prefix that was seen before this error occured curchar : the offending character Note: You can
114      * customize the lexical error message by modifying this method.
115      */

116     protected static String JavaDoc LexicalError(boolean EOFSeen,
117                                          int lexState,
118                                          int errorLine,
119                                          int errorColumn,
120                                          String JavaDoc errorAfter,
121                                          char curChar) {
122         return ("Lexical error at line "
123                 + errorLine
124                 + ", column "
125                 + errorColumn
126                 + ". Encountered: "
127                 + (EOFSeen
128                    ? "<EOF> "
129                    : (("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), "))
130                 + "after : \""
131                 + addEscapes(errorAfter) + "\"");
132     }
133
134     /**
135      * You can also modify the body of this method to customize your error messages. For example, cases like
136      * LOOP_DETECTED and INVALID_LEXICAL_STATE are not of end-users concern, so you can return something like :
137      * <p/>"Internal Error : Please file a bug report .... " <p/>from this method for such cases in the release version
138      * of your parser.
139      */

140     public String JavaDoc getMessage() {
141         return super.getMessage();
142     }
143 }
Popular Tags