2
* Cobertura - http://cobertura.sourceforge.net/
4
* This file was taken from JavaNCSS
5
* http://www.kclee.com/clemens/java/javancss/
6
* Copyright (C) 2000 Chr. Clemens Lee <clemens a.t kclee d.o.t com>
8
* Cobertura is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published
10
* by the Free Software Foundation; either version 2 of the License,
11
* or (at your option) any later version.
13
* Cobertura is distributed in the hope that it will be useful, but
14
* WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with Cobertura; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
29
* WARNING TO COBERTURA DEVELOPERS
31
* DO NOT MODIFY THIS FILE!
33
* MODIFY THE FILES UNDER THE JAVANCSS DIRECTORY LOCATED AT THE ROOT OF THE COBERTURA PROJECT.
35
* FOLLOW THE PROCEDURE FOR MERGING THE LATEST JAVANCSS INTO COBERTURA LOCATED AT
36
* javancss/coberturaREADME.txt
38
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
40
/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 4.1 */
41
/* JavaCCOptions:KEEP_LINE_COL=null */
42
package net.sourceforge.cobertura.javancss.parser;
45
* This exception is thrown when parse errors are encountered.
46
* You can explicitly create objects of this exception type by
47
* calling the method generateParseException in the generated
50
* You can modify this class to customize your error reporting
51
* mechanisms so long as you retain the public fields.
53
public class ParseException extends Exception {
56
* This constructor is used by the method "generateParseException"
57
* in the generated parser. Calling this constructor generates
58
* a new object of this type with the fields "currentToken",
59
* "expectedTokenSequences", and "tokenImage" set. The boolean
60
* flag "specialConstructor" is also set to true to indicate that
61
* this constructor was used to create this object.
62
* This constructor calls its super class with the empty string
63
* to force the "toString" method of parent class "Throwable" to
64
* print the error message in the form:
65
* ParseException: <result of getMessage>
67
public ParseException(Token currentTokenVal,
68
int[][] expectedTokenSequencesVal,
69
String[] tokenImageVal
73
specialConstructor = true;
74
currentToken = currentTokenVal;
75
expectedTokenSequences = expectedTokenSequencesVal;
76
tokenImage = tokenImageVal;
80
* The following constructors are for use by you for whatever
81
* purpose you can think of. Constructing the exception in this
82
* manner makes the exception behave in the normal way - i.e., as
83
* documented in the class "Throwable". The fields "errorToken",
84
* "expectedTokenSequences", and "tokenImage" do not contain
85
* relevant information. The JavaCC generated code does not use
89
public ParseException() {
91
specialConstructor = false;
94
/** Constructor with message. */
95
public ParseException(String message) {
97
specialConstructor = false;
101
* This variable determines which constructor was used to create
102
* this object and thereby affects the semantics of the
103
* "getMessage" method (see below).
105
protected boolean specialConstructor;
108
* This is the last token that has been consumed successfully. If
109
* this object has been created due to a parse error, the token
110
* followng this token will (therefore) be the first error token.
112
public Token currentToken;
115
* Each entry in this array is an array of integers. Each array
116
* of integers represents a sequence of tokens (by their ordinal
117
* values) that is expected at this point of the parse.
119
public int[][] expectedTokenSequences;
122
* This is a reference to the "tokenImage" array of the generated
123
* parser within which the parse error occurred. This array is
124
* defined in the generated ...Constants interface.
126
public String[] tokenImage;
129
* This method has the standard behavior when this object has been
130
* created using the standard constructors. Otherwise, it uses
131
* "currentToken" and "expectedTokenSequences" to generate a parse
132
* error message and returns it. If this object has been created
133
* due to a parse error, and you do not catch it (it gets thrown
134
* from the parser), then this method is called during the printing
135
* of the final stack trace, and hence the correct error message
138
public String getMessage() {
139
if (!specialConstructor) {
140
return super.getMessage();
142
StringBuffer expected = new StringBuffer();
144
for (int i = 0; i < expectedTokenSequences.length; i++) {
145
if (maxSize < expectedTokenSequences[i].length) {
146
maxSize = expectedTokenSequences[i].length;
148
for (int j = 0; j < expectedTokenSequences[i].length; j++) {
149
expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
151
if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
152
expected.append("...");
154
expected.append(eol).append(" ");
156
String retval = "Encountered \"";
157
Token tok = currentToken.next;
158
for (int i = 0; i < maxSize; i++) {
159
if (i != 0) retval += " ";
161
retval += tokenImage[0];
164
retval += " " + tokenImage[tok.kind];
166
retval += add_escapes(tok.image);
170
retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
172
if (expectedTokenSequences.length == 1) {
173
retval += "Was expecting:" + eol + " ";
175
retval += "Was expecting one of:" + eol + " ";
177
retval += expected.toString();
182
* The end of line string for this machine.
184
protected String eol = System.getProperty("line.separator", "\n");
187
* Used to convert raw characters to their escaped version
188
* when these raw version cannot be used as part of an ASCII
191
protected String add_escapes(String str) {
192
StringBuffer retval = new StringBuffer();
194
for (int i = 0; i < str.length(); i++) {
195
switch (str.charAt(i))
200
retval.append("\\b");
203
retval.append("\\t");
206
retval.append("\\n");
209
retval.append("\\f");
212
retval.append("\\r");
215
retval.append("\\\"");
218
retval.append("\\\'");
221
retval.append("\\\\");
224
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
225
String s = "0000" + Integer.toString(ch, 16);
226
retval.append("\\u" + s.substring(s.length() - 4, s.length()));
233
return retval.toString();
237
/* JavaCC - OriginalChecksum=849b618d99607c5b3309cfe8560c9c1d (do not edit this line) */