Coverage report

  %line %branch
org.apache.commons.jexl.parser.ParseException
15% 
60% 

 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. ParseException.java Version 2.1 */
 17  
 package org.apache.commons.jexl.parser;
 18  
 
 19  
 /**
 20  
  * This exception is thrown when parse errors are encountered. You can
 21  
  * explicitly create objects of this exception type by calling the method
 22  
  * generateParseException in the generated parser.
 23  
  * 
 24  
  * You can modify this class to customize your error reporting mechanisms so
 25  
  * long as you retain the public fields.
 26  
  */
 27  
 public class ParseException extends Exception {
 28  
 
 29  
     /** serialization version id jdk13 generated. */
 30  
     static final long serialVersionUID = 654626477565941968L;
 31  
 
 32  
     /**
 33  
      * This constructor is used by the method "generateParseException" in the
 34  
      * generated parser. Calling this constructor generates a new object of this
 35  
      * type with the fields "currentToken", "expectedTokenSequences", and
 36  
      * "tokenImage" set. The boolean flag "specialConstructor" is also set to
 37  
      * true to indicate that this constructor was used to create this object.
 38  
      * This constructor calls its super class with the empty string to force the
 39  
      * "toString" method of parent class "Throwable" to print the error message
 40  
      * in the form: ParseException: (result of getMessage)
 41  
      */
 42  
     public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, String[] tokenImageVal) {
 43  3
         super("");
 44  3
         specialConstructor = true;
 45  3
         currentToken = currentTokenVal;
 46  3
         expectedTokenSequences = expectedTokenSequencesVal;
 47  3
         tokenImage = tokenImageVal;
 48  3
     }
 49  
 
 50  
     /**
 51  
      * The following constructors are for use by you for whatever purpose you
 52  
      * can think of. Constructing the exception in this manner makes the
 53  
      * exception behave in the normal way - i.e., as documented in the class
 54  
      * "Throwable". The fields "errorToken", "expectedTokenSequences", and
 55  
      * "tokenImage" do not contain relevant information. The JavaCC generated
 56  
      * code does not use these constructors.
 57  
      */
 58  
 
 59  
     public ParseException() {
 60  0
         super();
 61  0
         specialConstructor = false;
 62  0
     }
 63  
 
 64  
     public ParseException(String message) {
 65  3
         super(message);
 66  3
         specialConstructor = false;
 67  3
     }
 68  
 
 69  
     /**
 70  
      * This variable determines which constructor was used to create this object
 71  
      * and thereby affects the semantics of the "getMessage" method (see below).
 72  
      */
 73  
     protected boolean specialConstructor;
 74  
 
 75  
     /**
 76  
      * This is the last token that has been consumed successfully. If this
 77  
      * object has been created due to a parse error, the token followng this
 78  
      * token will (therefore) be the first error token.
 79  
      */
 80  
     public Token currentToken;
 81  
 
 82  
     /**
 83  
      * Each entry in this array is an array of integers. Each array of integers
 84  
      * represents a sequence of tokens (by their ordinal values) that is
 85  
      * expected at this point of the parse.
 86  
      */
 87  
     public int[][] expectedTokenSequences;
 88  
 
 89  
     /**
 90  
      * This is a reference to the "tokenImage" array of the generated parser
 91  
      * within which the parse error occurred. This array is defined in the
 92  
      * generated ...Constants interface.
 93  
      */
 94  
     public String[] tokenImage;
 95  
 
 96  
     /**
 97  
      * This method has the standard behavior when this object has been created
 98  
      * using the standard constructors. Otherwise, it uses "currentToken" and
 99  
      * "expectedTokenSequences" to generate a parse error message and returns
 100  
      * it. If this object has been created due to a parse error, and you do not
 101  
      * catch it (it gets thrown from the parser), then this method is called
 102  
      * during the printing of the final stack trace, and hence the correct error
 103  
      * message gets displayed.
 104  
      */
 105  
     public String getMessage() {
 106  0
         if (!specialConstructor) {
 107  0
             return super.getMessage();
 108  
         }
 109  0
         String expected = "";
 110  0
         int maxSize = 0;
 111  0
         for (int i = 0; i < expectedTokenSequences.length; i++) {
 112  0
             if (maxSize < expectedTokenSequences[i].length) {
 113  0
                 maxSize = expectedTokenSequences[i].length;
 114  
             }
 115  0
             for (int j = 0; j < expectedTokenSequences[i].length; j++) {
 116  0
                 expected += tokenImage[expectedTokenSequences[i][j]] + " ";
 117  
             }
 118  0
             if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
 119  0
                 expected += "...";
 120  
             }
 121  0
             expected += eol + "    ";
 122  
         }
 123  0
         String retval = "Encountered \"";
 124  0
         Token tok = currentToken.next;
 125  0
         for (int i = 0; i < maxSize; i++) {
 126  0
             if (i != 0)
 127  0
                 retval += " ";
 128  0
             if (tok.kind == 0) {
 129  0
                 retval += tokenImage[0];
 130  0
                 break;
 131  
             }
 132  0
             retval += add_escapes(tok.image);
 133  0
             tok = tok.next;
 134  
         }
 135  0
         retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
 136  0
         retval += "." + eol;
 137  0
         if (expectedTokenSequences.length == 1) {
 138  0
             retval += "Was expecting:" + eol + "    ";
 139  
         } else {
 140  0
             retval += "Was expecting one of:" + eol + "    ";
 141  
         }
 142  0
         retval += expected;
 143  0
         return retval;
 144  
     }
 145  
 
 146  
     /**
 147  
      * The end of line string for this machine.
 148  
      */
 149  6
     protected String eol = System.getProperty("line.separator", "\n");
 150  
 
 151  
     /**
 152  
      * Used to convert raw characters to their escaped version when these raw
 153  
      * version cannot be used as part of an ASCII string literal.
 154  
      */
 155  
     protected String add_escapes(String str) {
 156  0
         StringBuffer retval = new StringBuffer();
 157  
         char ch;
 158  0
         for (int i = 0; i < str.length(); i++) {
 159  0
             switch (str.charAt(i)) {
 160  
                 case 0:
 161  0
                     continue;
 162  
                 case '\b':
 163  0
                     retval.append("\\b");
 164  0
                     continue;
 165  
                 case '\t':
 166  0
                     retval.append("\\t");
 167  0
                     continue;
 168  
                 case '\n':
 169  0
                     retval.append("\\n");
 170  0
                     continue;
 171  
                 case '\f':
 172  0
                     retval.append("\\f");
 173  0
                     continue;
 174  
                 case '\r':
 175  0
                     retval.append("\\r");
 176  0
                     continue;
 177  
                 case '\"':
 178  0
                     retval.append("\\\"");
 179  0
                     continue;
 180  
                 case '\'':
 181  0
                     retval.append("\\\'");
 182  0
                     continue;
 183  
                 case '\\':
 184  0
                     retval.append("\\\\");
 185  0
                     continue;
 186  
                 default:
 187  0
                     if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
 188  0
                         String s = "0000" + Integer.toString(ch, 16);
 189  0
                         retval.append("\\u").append(s.substring(s.length() - 4, s.length()));
 190  
                     } else {
 191  0
                         retval.append(ch);
 192  
                     }
 193  
                     continue;
 194  
             }
 195  
         }
 196  0
         return retval.toString();
 197  
     }
 198  
 
 199  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.