001:/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
002:
003:/***********************************************************************************************************************
004: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. * http://aspectwerkz.codehaus.org *
005: * ---------------------------------------------------------------------------------- * The software in this package is
006: * published under the terms of the LGPL license * a copy of which has been included with this distribution in the
007: * license.txt file. *
008: **********************************************************************************************************************/package org.codehaus.aspectwerkz.annotation.expression.ast;
009:
010:public class TokenMgrError extends Error {
011: /*
012: * Ordinals for various reasons why an Error of this type can be thrown.
013: */
014:
015: /**
016: * Lexical error occured.
017: */
018: static final int LEXICAL_ERROR = 0;
019:
020: /**
021: * An attempt wass made to create a second instance of a static token manager.
022: */
023: static final int STATIC_LEXER_ERROR = 1;
024:
025: /**
026: * Tried to change to an invalid lexical state.
027: */
028: static final int INVALID_LEXICAL_STATE = 2;
029:
030: /**
031: * Detected (and bailed out of) an infinite loop in the token manager.
032: */
033: static final int LOOP_DETECTED = 3;
034:
035: /**
036: * Indicates the reason why the exception is thrown. It will have one of the above 4 values.
037: */
038: int errorCode;
039:
040: /*
041: * Constructors of various flavors follow.
042: */
043: public TokenMgrError() {
044: }
045:
046: public TokenMgrError(String message, int reason) {
047: super (message);
048: errorCode = reason;
049: }
050:
051: public TokenMgrError(boolean EOFSeen,
052: int lexState,
053: int errorLine,
054: int errorColumn,
055: String errorAfter,
056: char curChar,
057: int reason) {
058: this (LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
059: }
060:
061: /**
062: * Replaces unprintable characters by their espaced (or unicode escaped) equivalents in the given string
063: */
064: protected static final String addEscapes(String str) {
065: StringBuffer retval = new StringBuffer();
066: char ch;
067: for (int i = 0; i < str.length(); i++) {
068: switch (str.charAt(i)) {
069: case 0:
070: continue;
071: case '\b':
072: retval.append("\\b");
073: continue;
074: case '\t':
075: retval.append("\\t");
076: continue;
077: case '\n':
078: retval.append("\\n");
079: continue;
080: case '\f':
081: retval.append("\\f");
082: continue;
083: case '\r':
084: retval.append("\\r");
085: continue;
086: case '\"':
087: retval.append("\\\"");
088: continue;
089: case '\'':
090: retval.append("\\\'");
091: continue;
092: case '\\':
093: retval.append("\\\\");
094: continue;
095: default:
096: if (((ch = str.charAt(i)) < 0x20) || (ch > 0x7e)) {
097: String s = "0000" + Integer.toString(ch, 16);
098: retval.append("\\u" + s.substring(s.length() - 4, s.length()));
099: } else {
100: retval.append(ch);
101: }
102: continue;
103: }
104: }
105: return retval.toString();
106: }
107:
108: /**
109: * Returns a detailed message for the Error when it is thrown by the token manager to indicate a lexical error.
110: * Parameters : EOFSeen : indicates if EOF caused the lexicl error curLexState : lexical state in which this error
111: * occured errorLine : line number when the error occured errorColumn : column number when the error occured
112: * errorAfter : prefix that was seen before this error occured curchar : the offending character Note: You can
113: * customize the lexical error message by modifying this method.
114: */
115: protected static String LexicalError(boolean EOFSeen,
116: int lexState,
117: int errorLine,
118: int errorColumn,
119: String errorAfter,
120: char curChar) {
121: return ("Lexical error at line "
122: + errorLine
123: + ", column "
124: + errorColumn
125: + ". Encountered: "
126: + (EOFSeen
127: ? "<EOF> "
128: : (("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), "))
129: + "after : \""
130: + addEscapes(errorAfter) + "\"");
131: }
132:
133: /**
134: * You can also modify the body of this method to customize your error messages. For example, cases like
135: * LOOP_DETECTED and INVALID_LEXICAL_STATE are not of end-users concern, so you can return something like :
136: * <p/>"Internal Error : Please file a bug report .... " <p/>from this method for such cases in the release version
137: * of your parser.
138: */
139: public String getMessage() {
140: return super.getMessage();
141: }
142:}
|