author | weijun |
Thu, 11 Dec 2014 15:23:02 +0800 | |
changeset 27957 | 24b4e6082f19 |
parent 25859 | 3317bb8137f4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
2 |
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
26 |
/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */ |
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
27 |
/* JavaCCOptions:KEEP_LINE_COL=null */ |
2 | 28 |
package com.sun.tools.example.debug.expr; |
29 |
||
30 |
/** |
|
31 |
* This exception is thrown when parse errors are encountered. |
|
32 |
* You can explicitly create objects of this exception type by |
|
33 |
* calling the method generateParseException in the generated |
|
34 |
* parser. |
|
35 |
* |
|
36 |
* You can modify this class to customize your error reporting |
|
37 |
* mechanisms so long as you retain the public fields. |
|
38 |
*/ |
|
39 |
public class ParseException extends Exception { |
|
40 |
||
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
41 |
/** |
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
42 |
* The version identifier for this Serializable class. |
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
43 |
* Increment only if the <i>serialized</i> form of the |
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
44 |
* class changes. |
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
45 |
*/ |
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
46 |
private static final long serialVersionUID = 1L; |
9520 | 47 |
|
2 | 48 |
/** |
49 |
* This constructor is used by the method "generateParseException" |
|
50 |
* in the generated parser. Calling this constructor generates |
|
51 |
* a new object of this type with the fields "currentToken", |
|
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
52 |
* "expectedTokenSequences", and "tokenImage" set. |
2 | 53 |
*/ |
54 |
public ParseException(Token currentTokenVal, |
|
55 |
int[][] expectedTokenSequencesVal, |
|
56 |
String[] tokenImageVal |
|
57 |
) |
|
58 |
{ |
|
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
59 |
super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); |
2 | 60 |
currentToken = currentTokenVal; |
61 |
expectedTokenSequences = expectedTokenSequencesVal; |
|
62 |
tokenImage = tokenImageVal; |
|
63 |
} |
|
64 |
||
65 |
/** |
|
66 |
* The following constructors are for use by you for whatever |
|
67 |
* purpose you can think of. Constructing the exception in this |
|
68 |
* manner makes the exception behave in the normal way - i.e., as |
|
69 |
* documented in the class "Throwable". The fields "errorToken", |
|
70 |
* "expectedTokenSequences", and "tokenImage" do not contain |
|
71 |
* relevant information. The JavaCC generated code does not use |
|
72 |
* these constructors. |
|
73 |
*/ |
|
74 |
||
75 |
public ParseException() { |
|
76 |
super(); |
|
77 |
} |
|
78 |
||
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
79 |
/** Constructor with message. */ |
2 | 80 |
public ParseException(String message) { |
81 |
super(message); |
|
82 |
} |
|
83 |
||
84 |
||
85 |
/** |
|
86 |
* This is the last token that has been consumed successfully. If |
|
87 |
* this object has been created due to a parse error, the token |
|
88 |
* followng this token will (therefore) be the first error token. |
|
89 |
*/ |
|
90 |
public Token currentToken; |
|
91 |
||
92 |
/** |
|
93 |
* Each entry in this array is an array of integers. Each array |
|
94 |
* of integers represents a sequence of tokens (by their ordinal |
|
95 |
* values) that is expected at this point of the parse. |
|
96 |
*/ |
|
97 |
public int[][] expectedTokenSequences; |
|
98 |
||
99 |
/** |
|
100 |
* This is a reference to the "tokenImage" array of the generated |
|
101 |
* parser within which the parse error occurred. This array is |
|
102 |
* defined in the generated ...Constants interface. |
|
103 |
*/ |
|
104 |
public String[] tokenImage; |
|
105 |
||
106 |
/** |
|
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
107 |
* It uses "currentToken" and "expectedTokenSequences" to generate a parse |
2 | 108 |
* error message and returns it. If this object has been created |
109 |
* due to a parse error, and you do not catch it (it gets thrown |
|
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
110 |
* from the parser) the correct error message |
2 | 111 |
* gets displayed. |
112 |
*/ |
|
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
113 |
private static String initialise(Token currentToken, |
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
114 |
int[][] expectedTokenSequences, |
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
115 |
String[] tokenImage) { |
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
116 |
String eol = System.getProperty("line.separator", "\n"); |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
22050
diff
changeset
|
117 |
StringBuilder expected = new StringBuilder(); |
2 | 118 |
int maxSize = 0; |
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
119 |
for (int i = 0; i < expectedTokenSequences.length; i++) { |
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
120 |
if (maxSize < expectedTokenSequences[i].length) { |
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
121 |
maxSize = expectedTokenSequences[i].length; |
2 | 122 |
} |
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
123 |
for (int j = 0; j < expectedTokenSequences[i].length; j++) { |
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
124 |
expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); |
2 | 125 |
} |
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
126 |
if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { |
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
127 |
expected.append("..."); |
2 | 128 |
} |
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
129 |
expected.append(eol).append(" "); |
2 | 130 |
} |
131 |
String retval = "Encountered \""; |
|
132 |
Token tok = currentToken.next; |
|
133 |
for (int i = 0; i < maxSize; i++) { |
|
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
134 |
if (i != 0) retval += " "; |
2 | 135 |
if (tok.kind == 0) { |
136 |
retval += tokenImage[0]; |
|
137 |
break; |
|
138 |
} |
|
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
139 |
retval += " " + tokenImage[tok.kind]; |
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
140 |
retval += " \""; |
2 | 141 |
retval += add_escapes(tok.image); |
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
142 |
retval += " \""; |
2 | 143 |
tok = tok.next; |
144 |
} |
|
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
145 |
retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; |
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
146 |
retval += "." + eol; |
2 | 147 |
if (expectedTokenSequences.length == 1) { |
148 |
retval += "Was expecting:" + eol + " "; |
|
149 |
} else { |
|
150 |
retval += "Was expecting one of:" + eol + " "; |
|
151 |
} |
|
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
152 |
retval += expected.toString(); |
2 | 153 |
return retval; |
154 |
} |
|
155 |
||
156 |
/** |
|
157 |
* The end of line string for this machine. |
|
158 |
*/ |
|
159 |
protected String eol = System.getProperty("line.separator", "\n"); |
|
160 |
||
161 |
/** |
|
162 |
* Used to convert raw characters to their escaped version |
|
163 |
* when these raw version cannot be used as part of an ASCII |
|
164 |
* string literal. |
|
165 |
*/ |
|
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
166 |
static String add_escapes(String str) { |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
22050
diff
changeset
|
167 |
StringBuilder retval = new StringBuilder(); |
2 | 168 |
char ch; |
169 |
for (int i = 0; i < str.length(); i++) { |
|
170 |
switch (str.charAt(i)) |
|
171 |
{ |
|
172 |
case 0 : |
|
173 |
continue; |
|
174 |
case '\b': |
|
175 |
retval.append("\\b"); |
|
176 |
continue; |
|
177 |
case '\t': |
|
178 |
retval.append("\\t"); |
|
179 |
continue; |
|
180 |
case '\n': |
|
181 |
retval.append("\\n"); |
|
182 |
continue; |
|
183 |
case '\f': |
|
184 |
retval.append("\\f"); |
|
185 |
continue; |
|
186 |
case '\r': |
|
187 |
retval.append("\\r"); |
|
188 |
continue; |
|
189 |
case '\"': |
|
190 |
retval.append("\\\""); |
|
191 |
continue; |
|
192 |
case '\'': |
|
193 |
retval.append("\\\'"); |
|
194 |
continue; |
|
195 |
case '\\': |
|
196 |
retval.append("\\\\"); |
|
197 |
continue; |
|
198 |
default: |
|
199 |
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { |
|
200 |
String s = "0000" + Integer.toString(ch, 16); |
|
27957
24b4e6082f19
8055723: Replace concat String to append in StringBuilder parameters (dev)
weijun
parents:
25859
diff
changeset
|
201 |
retval.append("\\u").append(s.substring(s.length() - 4, s.length())); |
2 | 202 |
} else { |
203 |
retval.append(ch); |
|
204 |
} |
|
205 |
continue; |
|
206 |
} |
|
207 |
} |
|
208 |
return retval.toString(); |
|
209 |
} |
|
210 |
||
211 |
} |
|
22050
72e7501ac569
4660158: TTY: NumberFormatException while trying to set values by 'set' command
sla
parents:
14342
diff
changeset
|
212 |
/* JavaCC - OriginalChecksum=3c9f049ed2bb6ade635c5bf58a386169 (do not edit this line) */ |