1 2 3 9 package org.codehaus.aspectwerkz.annotation.expression.ast; 10 11 public class TokenMgrError extends Error { 12 15 16 19 static final int LEXICAL_ERROR = 0; 20 21 24 static final int STATIC_LEXER_ERROR = 1; 25 26 29 static final int INVALID_LEXICAL_STATE = 2; 30 31 34 static final int LOOP_DETECTED = 3; 35 36 39 int errorCode; 40 41 44 public TokenMgrError() { 45 } 46 47 public TokenMgrError(String 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 errorAfter, 57 char curChar, 58 int reason) { 59 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); 60 } 61 62 65 protected static final String addEscapes(String str) { 66 StringBuffer retval = new StringBuffer (); 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 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 116 protected static String LexicalError(boolean EOFSeen, 117 int lexState, 118 int errorLine, 119 int errorColumn, 120 String 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 140 public String getMessage() { 141 return super.getMessage(); 142 } 143 } | Popular Tags |