KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cobertura > javancss > TokenMgrError


1 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 0.7pre2 */
2
3 /*
4  * Cobertura - http://cobertura.sourceforge.net/
5  *
6  * This file was taken from JavaNCSS
7  * http://www.kclee.com/clemens/java/javancss/
8  * Copyright (C) 2000 Chr. Clemens Lee <clemens a.t kclee d.o.t com>
9  *
10  * Cobertura is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published
12  * by the Free Software Foundation; either version 2 of the License,
13  * or (at your option) any later version.
14  *
15  * Cobertura is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Cobertura; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA
24  */

25
26 package net.sourceforge.cobertura.javancss;
27
28 class TokenMgrError extends Error JavaDoc
29 {
30
31     private static final long serialVersionUID = 0L;
32
33     /*
34      * Ordinals for various reasons why an Error of this type can be thrown.
35      */

36
37     /**
38      * Lexical error occured.
39      */

40     static final int LEXICAL_ERROR = 0;
41
42     /**
43      * An attempt wass made to create a second instance of a static token manager.
44      */

45     static final int STATIC_LEXER_ERROR = 1;
46
47     /**
48      * Tried to change to an invalid lexical state.
49      */

50     static final int INVALID_LEXICAL_STATE = 2;
51
52     /**
53      * Detected (and bailed out of) an infinite loop in the token manager.
54      */

55     static final int LOOP_DETECTED = 3;
56
57     /**
58      * Indicates the reason why the exception is thrown. It will have
59      * one of the above 4 values.
60      */

61     int errorCode;
62
63     /**
64      * Replaces unprintable characters by their espaced (or unicode escaped)
65      * equivalents in the given string
66      */

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

129     private static final String JavaDoc LexicalError(boolean EOFSeen, int errorLine, int errorColumn,
130             String JavaDoc errorAfter, char curChar)
131     {
132         return ("Lexical error at line "
133                 + errorLine
134                 + ", column "
135                 + errorColumn
136                 + ". Encountered: "
137                 + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " ("
138                         + (int)curChar + "), ") + "after : \"" + addEscapes(errorAfter) + "\"");
139     }
140
141     /**
142      * You can also modify the body of this method to customize your error messages.
143      * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
144      * of end-users concern, so you can return something like :
145      *
146      * "Internal Error : Please file a bug report .... "
147      *
148      * from this method for such cases in the release version of your parser.
149      */

150     public String JavaDoc getMessage()
151     {
152         return super.getMessage();
153     }
154
155     /*
156      * Constructors of various flavors follow.
157      */

158
159     TokenMgrError()
160     {
161     }
162
163     TokenMgrError(String JavaDoc message, int reason)
164     {
165         super(message);
166         errorCode = reason;
167     }
168
169     TokenMgrError(boolean EOFSeen, int errorLine, int errorColumn, String JavaDoc errorAfter, char curChar,
170             int reason)
171     {
172         this(LexicalError(EOFSeen, errorLine, errorColumn, errorAfter, curChar), reason);
173     }
174 }
175
Popular Tags