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