33package org .apache .lucene .queryparser .classic ;
44
55/**
6- * This exception is thrown when parse errors are encountered.
7- * You can explicitly create objects of this exception type by
8- * calling the method generateParseException in the generated
9- * parser.
6+ * This exception is thrown when parse errors are encountered. You can explicitly create objects of
7+ * this exception type by calling the method generateParseException in the generated parser.
108 *
11- * You can modify this class to customize your error reporting
12- * mechanisms so long as you retain the public fields.
9+ * <p> You can modify this class to customize your error reporting mechanisms so long as you retain
10+ * the public fields.
1311 */
1412public class ParseException extends Exception {
1513
1614 /**
17- * The version identifier for this Serializable class.
18- * Increment only if the <i>serialized</i> form of the
19- * class changes.
15+ * The version identifier for this Serializable class. Increment only if the <i>serialized</i>
16+ * form of the class changes.
2017 */
2118 private static final long serialVersionUID = 1L ;
2219
23- /**
24- * The end of line string for this machine.
25- */
20+ /** The end of line string for this machine. */
2621 protected static String EOL = System .getProperty ("line.separator" , "\n " );
2722
2823 /**
29- * This constructor is used by the method "generateParseException"
30- * in the generated parser. Calling this constructor generates
31- * a new object of this type with the fields "currentToken",
24+ * This constructor is used by the method "generateParseException" in the generated parser.
25+ * Calling this constructor generates a new object of this type with the fields "currentToken",
3226 * "expectedTokenSequences", and "tokenImage" set.
3327 */
34- public ParseException (Token currentTokenVal ,
35- int [][] expectedTokenSequencesVal ,
36- String [] tokenImageVal
37- )
38- {
28+ public ParseException (
29+ Token currentTokenVal , int [][] expectedTokenSequencesVal , String [] tokenImageVal ) {
3930 super (initialise (currentTokenVal , expectedTokenSequencesVal , tokenImageVal ));
4031 currentToken = currentTokenVal ;
4132 expectedTokenSequences = expectedTokenSequencesVal ;
4233 tokenImage = tokenImageVal ;
4334 }
4435
4536 /**
46- * The following constructors are for use by you for whatever
47- * purpose you can think of. Constructing the exception in this
48- * manner makes the exception behave in the normal way - i.e., as
49- * documented in the class "Throwable". The fields "errorToken",
50- * "expectedTokenSequences", and "tokenImage" do not contain
51- * relevant information. The JavaCC generated code does not use
52- * these constructors.
37+ * The following constructors are for use by you for whatever purpose you can think of.
38+ * Constructing the exception in this manner makes the exception behave in the normal way - i.e.,
39+ * as documented in the class "Throwable". The fields "errorToken", "expectedTokenSequences", and
40+ * "tokenImage" do not contain relevant information. The JavaCC generated code does not use these
41+ * constructors.
5342 */
54-
5543 public ParseException () {
5644 super ();
5745 }
@@ -61,38 +49,31 @@ public ParseException(String message) {
6149 super (message );
6250 }
6351
64-
6552 /**
66- * This is the last token that has been consumed successfully. If
67- * this object has been created due to a parse error, the token
68- * following this token will (therefore) be the first error token.
53+ * This is the last token that has been consumed successfully. If this object has been created due
54+ * to a parse error, the token following this token will (therefore) be the first error token.
6955 */
7056 public Token currentToken ;
7157
7258 /**
73- * 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.
59+ * Each entry in this array is an array of integers. Each array of integers represents a sequence
60+ * of tokens (by their ordinal values) that is expected at this point of the parse.
7661 */
7762 public int [][] expectedTokenSequences ;
7863
7964 /**
80- * This is a reference to the "tokenImage" array of the generated
81- * parser within which the parse error occurred. This array is
82- * defined in the generated ...Constants interface.
65+ * This is a reference to the "tokenImage" array of the generated parser within which the parse
66+ * error occurred. This array is defined in the generated ...Constants interface.
8367 */
8468 public String [] tokenImage ;
8569
8670 /**
87- * It uses "currentToken" and "expectedTokenSequences" to generate a parse
88- * error message and returns it. If this object has been created
89- * due to a parse error, and you do not catch it (it gets thrown
90- * from the parser) the correct error message
91- * gets displayed.
71+ * It uses "currentToken" and "expectedTokenSequences" to generate a parse error message and
72+ * returns it. If this object has been created due to a parse error, and you do not catch it (it
73+ * gets thrown from the parser) the correct error message gets displayed.
9274 */
93- private static String initialise (Token currentToken ,
94- int [][] expectedTokenSequences ,
95- String [] tokenImage ) {
75+ private static String initialise (
76+ Token currentToken , int [][] expectedTokenSequences , String [] tokenImage ) {
9677
9778 StringBuilder expected = new StringBuilder ();
9879 int maxSize = 0 ;
@@ -123,73 +104,69 @@ private static String initialise(Token currentToken,
123104 tok = tok .next ;
124105 }
125106 if (currentToken .next != null ) {
126- retval += "\" at line " + currentToken .next .beginLine + ", column " + currentToken .next .beginColumn ;
107+ retval +=
108+ "\" at line " + currentToken .next .beginLine + ", column " + currentToken .next .beginColumn ;
127109 }
128110 retval += "." + EOL ;
129-
130-
111+
131112 if (expectedTokenSequences .length == 0 ) {
132- // Nothing to add here
113+ // Nothing to add here
133114 } else {
134- if (expectedTokenSequences .length == 1 ) {
135- retval += "Was expecting:" + EOL + " " ;
136- } else {
137- retval += "Was expecting one of:" + EOL + " " ;
138- }
139- retval += expected .toString ();
115+ if (expectedTokenSequences .length == 1 ) {
116+ retval += "Was expecting:" + EOL + " " ;
117+ } else {
118+ retval += "Was expecting one of:" + EOL + " " ;
119+ }
120+ retval += expected .toString ();
140121 }
141-
122+
142123 return retval ;
143124 }
144125
145-
146126 /**
147- * Used to convert raw characters to their escaped version
148- * when these raw version cannot be used as part of an ASCII
149- * string literal.
127+ * Used to convert raw characters to their escaped version when these raw version cannot be used
128+ * as part of an ASCII string literal.
150129 */
151130 static String add_escapes (String str ) {
152- StringBuilder retval = new StringBuilder ();
153- char ch ;
154- for (int i = 0 ; i < str .length (); i ++) {
155- switch (str .charAt (i ))
156- {
157- case '\b' :
158- retval .append ("\\ b" );
159- continue ;
160- case '\t' :
161- retval .append ("\\ t" );
162- continue ;
163- case '\n' :
164- retval .append ("\\ n" );
165- continue ;
166- case '\f' :
167- retval .append ("\\ f" );
168- continue ;
169- case '\r' :
170- retval .append ("\\ r" );
171- continue ;
172- case '\"' :
173- retval .append ("\\ \" " );
174- continue ;
175- case '\'' :
176- retval .append ("\\ \' " );
177- continue ;
178- case '\\' :
179- retval .append ("\\ \\ " );
180- continue ;
181- default :
182- if ((ch = str .charAt (i )) < 0x20 || ch > 0x7e ) {
183- String s = "0000" + Integer .toString (ch , 16 );
184- retval .append ("\\ u" + s .substring (s .length () - 4 , s .length ()));
185- } else {
186- retval .append (ch );
187- }
188- continue ;
189- }
131+ StringBuilder retval = new StringBuilder ();
132+ char ch ;
133+ for (int i = 0 ; i < str .length (); i ++) {
134+ switch (str .charAt (i )) {
135+ case '\b' :
136+ retval .append ("\\ b" );
137+ continue ;
138+ case '\t' :
139+ retval .append ("\\ t" );
140+ continue ;
141+ case '\n' :
142+ retval .append ("\\ n" );
143+ continue ;
144+ case '\f' :
145+ retval .append ("\\ f" );
146+ continue ;
147+ case '\r' :
148+ retval .append ("\\ r" );
149+ continue ;
150+ case '\"' :
151+ retval .append ("\\ \" " );
152+ continue ;
153+ case '\'' :
154+ retval .append ("\\ \' " );
155+ continue ;
156+ case '\\' :
157+ retval .append ("\\ \\ " );
158+ continue ;
159+ default :
160+ if ((ch = str .charAt (i )) < 0x20 || ch > 0x7e ) {
161+ String s = "0000" + Integer .toString (ch , 16 );
162+ retval .append ("\\ u" + s .substring (s .length () - 4 , s .length ()));
163+ } else {
164+ retval .append (ch );
165+ }
166+ continue ;
190167 }
191- return retval . toString ();
192- }
193-
168+ }
169+ return retval . toString ();
170+ }
194171}
195172/* (filtered)*/
0 commit comments