Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 148   Methods: 8
NCLOC: 75   Classes: 1
This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
TokenMgrError.java 0% 0% 0% 0%
 1   
 /*
 2   
  * JBind
 3   
  *
 4   
  * Copyright (c) by Stefan Wachter. All rights reserved.
 5   
  *
 6   
  * Usage, modification, and redistribution is subject to license terms that are
 7   
  * available at 'http://www.jbind.org'. The JBind license is like the
 8   
  * 'Apache Software License V 1.1'.
 9   
  */
 10   
 package org.jbind.xml.parser;
 11   
 
 12   
 public class TokenMgrError extends Error {
 13   
 
 14   
   /*
 15   
    * Ordinals for various reasons why an Error of this type can be thrown.
 16   
    */
 17   
 
 18   
   /**
 19   
    * Lexical error occured.
 20   
    */
 21   
   static final int LEXICAL_ERROR = 0;
 22   
 
 23   
   /**
 24   
    * An attempt wass made to create a second instance of a static token manager.
 25   
    */
 26   
   static final int STATIC_LEXER_ERROR = 1;
 27   
 
 28   
   /**
 29   
    * Tried to change to an invalid lexical state.
 30   
    */
 31   
   static final int INVALID_LEXICAL_STATE = 2;
 32   
 
 33   
   /**
 34   
    * Detected (and bailed out of) an infinite loop in the token manager.
 35   
    */
 36   
   static final int LOOP_DETECTED = 3;
 37   
 
 38   
   /**
 39   
    * Indicates the reason why the exception is thrown. It will have
 40   
    * one of the above 4 values.
 41   
    */
 42   
   int errorCode;
 43   
 
 44   
   /**
 45   
    * Replaces unprintable characters by their espaced (or unicode escaped)
 46   
    * equivalents in the given string
 47   
    */
 48  0
   protected static final String addEscapes(String str) {
 49  0
     StringBuffer retval = new StringBuffer();
 50  0
     char ch;
 51  0
     for (int i = 0; i < str.length(); i++) {
 52  0
       switch (str.charAt(i)) {
 53   
         case 0:
 54  0
           continue;
 55   
         case '\b':
 56  0
           retval.append("\\b");
 57  0
           continue;
 58   
         case '\t':
 59  0
           retval.append("\\t");
 60  0
           continue;
 61   
         case '\n':
 62  0
           retval.append("\\n");
 63  0
           continue;
 64   
         case '\f':
 65  0
           retval.append("\\f");
 66  0
           continue;
 67   
         case '\r':
 68  0
           retval.append("\\r");
 69  0
           continue;
 70   
         case '\"':
 71  0
           retval.append("\\\"");
 72  0
           continue;
 73   
         case '\'':
 74  0
           retval.append("\\\'");
 75  0
           continue;
 76   
         case '\\':
 77  0
           retval.append("\\\\");
 78  0
           continue;
 79   
         default:
 80  0
           if ((ch = str.charAt(i)) < 0x20 || (ch > 0x7e)) {
 81  0
             String s = "0000" + Integer.toString(ch, 16);
 82  0
             retval.append("\\u" + s.substring(s.length() - 4, s.length()));
 83   
           } else {
 84  0
             retval.append(ch);
 85   
           }
 86  0
           continue;
 87   
       }
 88   
     }
 89  0
     return retval.toString();
 90   
   }
 91   
 
 92   
   /**
 93   
    * Returns a detailed message for the Error when it is thrown by the
 94   
    * token manager to indicate a lexical error.
 95   
    * Parameters :
 96   
    *    EOFSeen     : indicates if EOF caused the lexicl error
 97   
    *    curLexState : lexical state in which this error occured
 98   
    *    errorLine   : line number when the error occured
 99   
    *    errorColumn : column number when the error occured
 100   
    *    errorAfter  : prefix that was seen before this error occured
 101   
    *    curchar     : the offending character
 102   
    * Note: You can customize the lexical error message by modifying this method.
 103   
    */
 104  0
   private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
 105  0
     return ("Lexical error at line " + errorLine + ", column " + errorColumn + ".  Encountered: " + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + "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  0
   public String getMessage() {
 118  0
     return super.getMessage();
 119   
   }
 120   
 
 121   
   /*
 122   
    * Constructors of various flavors follow.
 123   
    */
 124   
 
 125  0
   public TokenMgrError() {}
 126   
 
 127  0
   public TokenMgrError(String message, int reason) {
 128  0
     super(message);
 129  0
     errorCode = reason;
 130   
   }
 131   
 
 132  0
   public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
 133  0
     this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
 134  0
     myErrorLine = errorLine;
 135  0
     myErrorColumn = errorColumn;
 136   
   }
 137   
 
 138  0
   public int getErrorLine() {
 139  0
     return myErrorLine;
 140   
   }
 141  0
   public int getErrorColumn() {
 142  0
     return myErrorColumn;
 143   
   }
 144   
 
 145   
   private int myErrorLine = -1;
 146   
   private int myErrorColumn = -1;
 147   
 }
 148