| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| org.apache.commons.jexl.parser.TokenMgrError | 
 | 
 | 
| 1 |  /* | |
| 2 |   * Copyright 2002-2006 The Apache Software Foundation. | |
| 3 |   * | |
| 4 |   * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 |   * you may not use this file except in compliance with the License. | |
| 6 |   * You may obtain a copy of the License at | |
| 7 |   * | |
| 8 |   *      http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 |   * | |
| 10 |   * Unless required by applicable law or agreed to in writing, software | |
| 11 |   * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 |   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 |   * See the License for the specific language governing permissions and | |
| 14 |   * limitations under the License. | |
| 15 |   */ | |
| 16 |  /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 2.1 */ | |
| 17 |  package org.apache.commons.jexl.parser; | |
| 18 | ||
| 19 | public class TokenMgrError extends Error { | |
| 20 |      /** serialization version id jdk13 generated. */ | |
| 21 | static final long serialVersionUID = 2843513002462329650L; | |
| 22 | ||
| 23 |      /* | |
| 24 |       * Ordinals for various reasons why an Error of this type can be thrown. | |
| 25 |       */ | |
| 26 | ||
| 27 |      /** | |
| 28 |       * Lexical error occured. | |
| 29 |       */ | |
| 30 | static final int LEXICAL_ERROR = 0; | |
| 31 | ||
| 32 |      /** | |
| 33 |       * An attempt wass made to create a second instance of a static token | |
| 34 |       * manager. | |
| 35 |       */ | |
| 36 | static final int STATIC_LEXER_ERROR = 1; | |
| 37 | ||
| 38 |      /** | |
| 39 |       * Tried to change to an invalid lexical state. | |
| 40 |       */ | |
| 41 | static final int INVALID_LEXICAL_STATE = 2; | |
| 42 | ||
| 43 |      /** | |
| 44 |       * Detected (and bailed out of) an infinite loop in the token manager. | |
| 45 |       */ | |
| 46 | static final int LOOP_DETECTED = 3; | |
| 47 | ||
| 48 |      /** | |
| 49 |       * Indicates the reason why the exception is thrown. It will have one of the | |
| 50 |       * above 4 values. | |
| 51 |       */ | |
| 52 |      int errorCode; | |
| 53 | ||
| 54 |      /** | |
| 55 |       * Replaces unprintable characters by their espaced (or unicode escaped) | |
| 56 |       * equivalents in the given string | |
| 57 |       */ | |
| 58 | protected static final String addEscapes(String str) { | |
| 59 | 6 |          StringBuffer retval = new StringBuffer(); | 
| 60 |          char ch; | |
| 61 | 9 | for (int i = 0; i < str.length(); i++) { | 
| 62 | 3 |              switch (str.charAt(i)) { | 
| 63 |                  case 0: | |
| 64 | 0 |                      continue; | 
| 65 |                  case '\b': | |
| 66 | 0 |                      retval.append("\\b"); | 
| 67 | 0 |                      continue; | 
| 68 |                  case '\t': | |
| 69 | 0 |                      retval.append("\\t"); | 
| 70 | 0 |                      continue; | 
| 71 |                  case '\n': | |
| 72 | 0 |                      retval.append("\\n"); | 
| 73 | 0 |                      continue; | 
| 74 |                  case '\f': | |
| 75 | 0 |                      retval.append("\\f"); | 
| 76 | 0 |                      continue; | 
| 77 |                  case '\r': | |
| 78 | 0 |                      retval.append("\\r"); | 
| 79 | 0 |                      continue; | 
| 80 |                  case '\"': | |
| 81 | 0 |                      retval.append("\\\""); | 
| 82 | 0 |                      continue; | 
| 83 |                  case '\'': | |
| 84 | 0 |                      retval.append("\\\'"); | 
| 85 | 0 |                      continue; | 
| 86 |                  case '\\': | |
| 87 | 0 |                      retval.append("\\\\"); | 
| 88 | 0 |                      continue; | 
| 89 |                  default: | |
| 90 | 3 |                      if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { | 
| 91 | 0 |                          String s = "0000" + Integer.toString(ch, 16); | 
| 92 | 0 |                          retval.append("\\u" + s.substring(s.length() - 4, s.length())); | 
| 93 |                      } else { | |
| 94 | 3 | retval.append(ch); | 
| 95 | } | |
| 96 |                      continue; | |
| 97 | } | |
| 98 | } | |
| 99 | 6 |          return retval.toString(); | 
| 100 | } | |
| 101 | ||
| 102 |      /** | |
| 103 |       * Returns a detailed message for the Error when it is thrown by the token | |
| 104 |       * manager to indicate a lexical error. Parameters : EOFSeen : indicates if | |
| 105 |       * EOF caused the lexicl error curLexState : lexical state in which this | |
| 106 |       * error occured errorLine : line number when the error occured errorColumn : | |
| 107 |       * column number when the error occured errorAfter : prefix that was seen | |
| 108 |       * before this error occured curchar : the offending character Note: You can | |
| 109 |       * customize the lexical error message by modifying this method. | |
| 110 |       */ | |
| 111 | private static final String LexicalError(boolean EOFSeen, int lexState, class="keyword">int errorLine, class="keyword">int errorColumn, | |
| 112 |          String errorAfter, char curChar) { | |
| 113 | 3 | return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: " | 
| 114 | + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") | |
| 115 | + "after : \"" + addEscapes(errorAfter) + "\""); | |
| 116 | } | |
| 117 | ||
| 118 |      /** | |
| 119 |       * You can also modify the body of this method to customize your error | |
| 120 |       * messages. For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE | |
| 121 |       * are not of end-users concern, so you can return something like : | |
| 122 |       *  | |
| 123 |       * "Internal Error : Please file a bug report .... " | |
| 124 |       *  | |
| 125 |       * from this method for such cases in the release version of your parser. | |
| 126 |       */ | |
| 127 |      public String getMessage() { | |
| 128 | 3 | return super.getMessage(); | 
| 129 | } | |
| 130 | ||
| 131 |      /* | |
| 132 |       * Constructors of various flavors follow. | |
| 133 |       */ | |
| 134 | ||
| 135 | 0 |      public TokenMgrError() { | 
| 136 | 0 |      } | 
| 137 | ||
| 138 | public TokenMgrError(String message, int reason) { | |
| 139 | 3 |          super(message); | 
| 140 | 3 | errorCode = reason; | 
| 141 | 3 | } | 
| 142 | ||
| 143 | public TokenMgrError(boolean EOFSeen, int lexState, class="keyword">int errorLine, class="keyword">int errorColumn, String errorAfter, | |
| 144 | char curChar, int reason) { | |
| 145 | 3 |          this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); | 
| 146 | 3 | } | 
| 147 | } | 
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |