View Javadoc
1   /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 7.0 */
2   /* JavaCCOptions: */
3   package org.apache.maven.surefire.group.parse;
4   
5   /** Token Manager Error. */
6   @SuppressWarnings("all") 
7   public class TokenMgrError extends Error
8   {
9   
10    /**
11     * The version identifier for this Serializable class.
12     * Increment only if the <i>serialized</i> form of the
13     * class changes.
14     */
15    private static final long serialVersionUID = 1L;
16  
17    /*
18     * Ordinals for various reasons why an Error of this type can be thrown.
19     */
20  
21    /**
22     * Lexical error occurred.
23     */
24    public static final int LEXICAL_ERROR = 0;
25  
26    /**
27     * An attempt was made to create a second instance of a static token manager.
28     */
29    public static final int STATIC_LEXER_ERROR = 1;
30  
31    /**
32     * Tried to change to an invalid lexical state.
33     */
34    public static final int INVALID_LEXICAL_STATE = 2;
35  
36    /**
37     * Detected (and bailed out of) an infinite loop in the token manager.
38     */
39    public static final int LOOP_DETECTED = 3;
40  
41    /**
42     * Indicates the reason why the exception is thrown. It will have
43     * one of the above 4 values.
44     */
45    int errorCode;
46  
47    /**
48     * Replaces unprintable characters by their escaped (or unicode escaped)
49     * equivalents in the given string
50     */
51    protected static final String addEscapes(String str) {
52      StringBuilder retval = new StringBuilder();
53      char ch;
54      for (int i = 0; i < str.length(); i++) {
55        switch (str.charAt(i))
56        {
57          case '\b':
58            retval.append("\\b");
59            continue;
60          case '\t':
61            retval.append("\\t");
62            continue;
63          case '\n':
64            retval.append("\\n");
65            continue;
66          case '\f':
67            retval.append("\\f");
68            continue;
69          case '\r':
70            retval.append("\\r");
71            continue;
72          case '\"':
73            retval.append("\\\"");
74            continue;
75          case '\'':
76            retval.append("\\\'");
77            continue;
78          case '\\':
79            retval.append("\\\\");
80            continue;
81          default:
82            if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
83              String s = "0000" + Integer.toString(ch, 16);
84              retval.append("\\u" + s.substring(s.length() - 4, s.length()));
85            } else {
86              retval.append(ch);
87            }
88            continue;
89        }
90      }
91      return retval.toString();
92    }
93  
94    /**
95     * Returns a detailed message for the Error when it is thrown by the
96     * token manager to indicate a lexical error.
97     * Parameters :
98     *    EOFSeen     : indicates if EOF caused the lexical error
99     *    lexState    : lexical state in which this error occurred
100    *    errorLine   : line number when the error occurred
101    *    errorColumn : column number when the error occurred
102    *    errorAfter  : prefix that was seen before this error occurred
103    *    curchar     : the offending character
104    * Note: You can customize the lexical error message by modifying this method.
105    */
106   protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) {
107     return("Lexical error at line " + //
108           errorLine + ", column " + //
109           errorColumn + ".  Encountered: " + //
110           (EOFSeen ? "<EOF>" : ("'" + addEscapes(String.valueOf((char) curChar)) + "' (" + curChar + "),")) + //
111           (errorAfter == null || errorAfter.length() == 0 ? "" : " after prefix \"" + addEscapes(errorAfter) + "\"")) + //
112           (lexState == 0 ? "" : " (in lexical state " + lexState + ")");
113   }
114 
115   /**
116    * You can also modify the body of this method to customize your error messages.
117    * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
118    * of end-users concern, so you can return something like :
119    *
120    *     "Internal Error : Please file a bug report .... "
121    *
122    * from this method for such cases in the release version of your parser.
123    */
124   @Override
125   public String getMessage() {
126     return super.getMessage();
127   }
128 
129   /*
130    * Constructors of various flavors follow.
131    */
132 
133   /** No arg constructor. */
134   public TokenMgrError() {
135   }
136 
137   /** Constructor with message and reason. */
138   public TokenMgrError(String message, int reason) {
139     super(message);
140     errorCode = reason;
141   }
142 
143   /** Full Constructor. */
144   public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar, int reason) {
145     this(LexicalErr(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
146   }
147 }
148 /* JavaCC - OriginalChecksum=da8917245abae756a2ae54def760c7a0 (do not edit this line) */