View Javadoc

1   
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one or more
4    * contributor license agreements.  See the NOTICE file distributed with
5    * this work for additional information regarding copyright ownership.
6    * The ASF licenses this file to You under the Apache License, Version 2.0
7    * (the "License"); you may not use this file except in compliance with
8    * the License.  You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.commons.jexl2.parser;
19  
20  /**
21   * This exception is thrown when parse errors are encountered.
22   */
23  public class ParseException extends Exception {
24      /**
25       * The version identifier.
26       */
27      private static final long serialVersionUID = 1L;
28      /**
29       * Last correct input before error occurs.
30       */
31      private String after = "";
32      /**
33       * Error line.
34       */
35      private int line = -1;
36      /**
37       * Error column.
38       */
39      private int column = -1;
40      
41      /**
42       * Gets the line number.
43       * @return line number.
44       */
45      public int getLine() {
46          return line;
47      }
48  
49      /**
50       * Gets the column number.
51       * @return the column.
52       */
53      public int getColumn() {
54          return column;
55      }
56      
57      /**
58       * Gets the last correct input.
59       * @return the string after which the error occured
60       */
61      public String getAfter() {
62          return after;
63      }
64      
65      /**
66       * This constructor is used by the method "generateParseException"
67       * in the generated parser.  Calling this constructor generates
68       * a new object of this type with the fields "currentToken",
69       * "expectedTokenSequences", and "tokenImage" set.
70       * @param currentToken This is the last token that has been consumed successfully.  If
71       * this object has been created due to a parse error, the token
72       * followng this token will (therefore) be the first error token.
73       * @param expectedTokenSequences Each entry in this array is an array of integers.  Each array
74       * of integers represents a sequence of tokens (by their ordinal
75       * values) that is expected at this point of the parse.
76       * @param tokenImage This is a reference to the "tokenImage" array of the generated
77       * parser within which the parse error occurred.  This array is
78       * defined in the generated ...Constants interface.
79       */
80      public ParseException(Token currentToken, int[][] expectedTokenSequences, String[] tokenImage) {
81          super("parse error");
82          Token tok = currentToken.next;
83          after = tok.image;
84          line = tok.beginLine;
85          column = tok.beginColumn;
86      }
87  
88      /**
89       * Default ctor.
90       */
91      public ParseException() {
92          super();
93      }
94  
95      /** Constructor with message. */
96      public ParseException(String message) {
97          super(message);
98      }
99  }