1 2 package net.sourceforge.pmd.ast; 3 4 public class TokenMgrError extends RuntimeException { 5 8 9 12 static final int LEXICAL_ERROR = 0; 13 14 17 static final int STATIC_LEXER_ERROR = 1; 18 19 22 static final int INVALID_LEXICAL_STATE = 2; 23 24 27 static final int LOOP_DETECTED = 3; 28 29 33 int errorCode; 34 35 39 protected static final String addEscapes(String str) { 40 StringBuffer retval = new StringBuffer (); 41 char ch; 42 for (int i = 0; i < str.length(); i++) { 43 switch (str.charAt(i)) { 44 case 0: 45 continue; 46 case '\b': 47 retval.append("\\b"); 48 continue; 49 case '\t': 50 retval.append("\\t"); 51 continue; 52 case '\n': 53 retval.append("\\n"); 54 continue; 55 case '\f': 56 retval.append("\\f"); 57 continue; 58 case '\r': 59 retval.append("\\r"); 60 continue; 61 case '\"': 62 retval.append("\\\""); 63 continue; 64 case '\'': 65 retval.append("\\\'"); 66 continue; 67 case '\\': 68 retval.append("\\\\"); 69 continue; 70 default: 71 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 72 String s = "0000" + Integer.toString(ch, 16); 73 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 74 } else { 75 retval.append(ch); 76 } 77 continue; 78 } 79 } 80 return retval.toString(); 81 } 82 83 95 protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { 96 return ("Lexical error at line " + 97 errorLine + ", column " + 98 errorColumn + ". Encountered: " + 99 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") + 100 "after : \"" + addEscapes(errorAfter) + "\""); 101 } 102 103 112 public String getMessage() { 113 return super.getMessage(); 114 } 115 116 119 120 public TokenMgrError() { 121 } 122 123 public TokenMgrError(String message, int reason) { 124 super(message); 125 errorCode = reason; 126 } 127 128 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { 129 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); 130 } 131 } 132 | Popular Tags |