KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > tools > example > debug > expr > TokenMgrError


1 /*
2  * @(#)TokenMgrError.java 1.8 05/11/17
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 0.7pre2 */
9 package com.sun.tools.example.debug.expr;
10
11 public class TokenMgrError extends Error JavaDoc
12 {
13    /*
14     * Ordinals for various reasons why an Error of this type can be thrown.
15     */

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

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

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

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

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

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

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

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

121    public String JavaDoc getMessage() {
122       return super.getMessage();
123    }
124
125    /*
126     * Constructors of various flavors follow.
127     */

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