KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > expr > TokenMgrError


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
21 package org.netbeans.modules.debugger.jpda.expr;
22
23 class TokenMgrError extends Error JavaDoc
24 {
25    /*
26     * Ordinals for various reasons why an Error of this type can be thrown.
27     */

28
29    /**
30     * Lexical error occured.
31     */

32    static final int LEXICAL_ERROR = 0;
33
34    /**
35     * An attempt wass made to create a second instance of a static token manager.
36     */

37    static final int STATIC_LEXER_ERROR = 1;
38
39    /**
40     * Tried to change to an invalid lexical state.
41     */

42    static final int INVALID_LEXICAL_STATE = 2;
43
44    /**
45     * Detected (and bailed out of) an infinite loop in the token manager.
46     */

47    static final int LOOP_DETECTED = 3;
48
49    /**
50     * Indicates the reason why the exception is thrown. It will have
51     * one of the above 4 values.
52     */

53    int errorCode;
54
55    /**
56     * Replaces unprintable characters by their espaced (or unicode escaped)
57     * equivalents in the given string
58     */

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

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

133    public String JavaDoc getMessage() {
134       return super.getMessage();
135    }
136
137    /*
138     * Constructors of various flavors follow.
139     */

140
141    public TokenMgrError() {
142    }
143
144    public TokenMgrError(String JavaDoc message, int reason) {
145       super(message);
146       errorCode = reason;
147    }
148
149    public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String JavaDoc errorAfter, char curChar, int reason) {
150       this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
151    }
152 }
153
Popular Tags