author | rfield |
Fri, 08 Apr 2016 10:51:57 -0700 | |
changeset 37005 | 71210037624f |
parent 35000 | 952a7b4652f0 |
child 37644 | 33cf53901cac |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
|
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 |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
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 |
* |
|
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. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.jshell; |
|
27 |
||
28 |
import java.util.ArrayList; |
|
29 |
import java.util.Collection; |
|
30 |
import java.util.Collections; |
|
31 |
import java.util.LinkedHashSet; |
|
32 |
import java.util.List; |
|
33 |
import java.util.Map; |
|
34 |
import java.util.Set; |
|
35 |
import java.util.stream.Stream; |
|
36 |
import com.sun.jdi.ReferenceType; |
|
37 |
import jdk.jshell.Snippet.Kind; |
|
38 |
import jdk.jshell.Snippet.Status; |
|
39 |
import jdk.jshell.Snippet.SubKind; |
|
40 |
import jdk.jshell.TaskFactory.AnalyzeTask; |
|
41 |
import jdk.jshell.ClassTracker.ClassInfo; |
|
42 |
import jdk.jshell.TaskFactory.CompileTask; |
|
43 |
import static java.util.stream.Collectors.toList; |
|
44 |
import static java.util.stream.Collectors.toMap; |
|
45 |
import static java.util.stream.Collectors.toSet; |
|
46 |
import static jdk.internal.jshell.debug.InternalDebugControl.DBG_EVNT; |
|
47 |
import static jdk.internal.jshell.debug.InternalDebugControl.DBG_GEN; |
|
48 |
import static jdk.jshell.Snippet.Status.OVERWRITTEN; |
|
49 |
import static jdk.jshell.Snippet.Status.RECOVERABLE_DEFINED; |
|
50 |
import static jdk.jshell.Snippet.Status.RECOVERABLE_NOT_DEFINED; |
|
51 |
import static jdk.jshell.Snippet.Status.REJECTED; |
|
52 |
import static jdk.jshell.Snippet.Status.VALID; |
|
35000
952a7b4652f0
8146368: JShell: couldn't smash the error when it's Japanese locale
rfield
parents:
34857
diff
changeset
|
53 |
import static jdk.jshell.Util.PARSED_LOCALE; |
33362 | 54 |
import static jdk.jshell.Util.expunge; |
55 |
||
56 |
/** |
|
57 |
* Tracks the compilation and load of a new or updated snippet. |
|
58 |
* @author Robert Field |
|
59 |
*/ |
|
60 |
final class Unit { |
|
61 |
||
62 |
private final JShell state; |
|
63 |
private final Snippet si; |
|
64 |
private final Snippet siOld; |
|
65 |
private final boolean isDependency; |
|
66 |
private final boolean isNew; |
|
67 |
private final Snippet causalSnippet; |
|
68 |
private final DiagList generatedDiagnostics; |
|
69 |
||
70 |
private int seq; |
|
71 |
private int seqInitial; |
|
72 |
private Wrap activeGuts; |
|
73 |
private Status status; |
|
74 |
private Status prevStatus; |
|
75 |
private boolean signatureChanged; |
|
76 |
private DiagList compilationDiagnostics; |
|
77 |
private DiagList recompilationDiagnostics = null; |
|
78 |
private List<String> unresolved; |
|
79 |
private SnippetEvent replaceOldEvent; |
|
80 |
private List<SnippetEvent> secondaryEvents; |
|
81 |
private boolean isAttemptingCorral; |
|
82 |
private List<ClassInfo> toRedefine; |
|
83 |
private boolean dependenciesNeeded; |
|
84 |
||
85 |
Unit(JShell state, Snippet si, Snippet causalSnippet, |
|
86 |
DiagList generatedDiagnostics) { |
|
87 |
this.state = state; |
|
88 |
this.si = si; |
|
89 |
this.isDependency = causalSnippet != null; |
|
90 |
this.siOld = isDependency |
|
91 |
? si |
|
92 |
: state.maps.getSnippet(si.key()); |
|
93 |
this.isNew = siOld == null; |
|
94 |
this.causalSnippet = causalSnippet; |
|
95 |
this.generatedDiagnostics = generatedDiagnostics; |
|
96 |
||
97 |
this.seq = isNew? 0 : siOld.sequenceNumber(); |
|
98 |
this.seqInitial = seq; |
|
99 |
this.prevStatus = (isNew || isDependency) |
|
100 |
? si.status() |
|
101 |
: siOld.status(); |
|
102 |
si.setSequenceNumber(seq); |
|
103 |
} |
|
104 |
||
105 |
// Drop entry |
|
106 |
Unit(JShell state, Snippet si) { |
|
107 |
this.state = state; |
|
108 |
this.si = si; |
|
109 |
this.siOld = null; |
|
110 |
this.isDependency = false; |
|
111 |
this.isNew = false; |
|
112 |
this.causalSnippet = null; |
|
113 |
this.generatedDiagnostics = new DiagList(); |
|
114 |
this.prevStatus = si.status(); |
|
115 |
si.setDropped(); |
|
116 |
this.status = si.status(); |
|
117 |
} |
|
118 |
||
119 |
@Override |
|
120 |
public int hashCode() { |
|
121 |
return si.hashCode(); |
|
122 |
} |
|
123 |
||
124 |
@Override |
|
125 |
public boolean equals(Object o) { |
|
126 |
return (o instanceof Unit) |
|
127 |
? si.equals(((Unit) o).si) |
|
128 |
: false; |
|
129 |
} |
|
130 |
||
131 |
Snippet snippet() { |
|
132 |
return si; |
|
133 |
} |
|
134 |
||
135 |
boolean isDependency() { |
|
136 |
return isDependency; |
|
137 |
} |
|
138 |
||
139 |
boolean isNew() { |
|
140 |
return isNew; |
|
141 |
} |
|
142 |
||
143 |
void initialize(Collection<Unit> working) { |
|
144 |
isAttemptingCorral = false; |
|
145 |
dependenciesNeeded = false; |
|
146 |
toRedefine = null; // assure NPE if classToLoad not called |
|
147 |
activeGuts = si.guts(); |
|
148 |
markOldDeclarationOverwritten(); |
|
149 |
setWrap(working, working); |
|
150 |
} |
|
151 |
||
152 |
void setWrap(Collection<Unit> except, Collection<Unit> plus) { |
|
153 |
si.setOuterWrap(isImport() |
|
154 |
? OuterWrap.wrapImport(si.source(), activeGuts) |
|
155 |
: state.eval.wrapInClass(si, |
|
156 |
except.stream().map(u -> u.snippet().key()).collect(toSet()), |
|
157 |
activeGuts, |
|
158 |
plus.stream().map(u -> u.snippet()) |
|
159 |
.filter(sn -> sn != si) |
|
160 |
.collect(toList()))); |
|
161 |
} |
|
162 |
||
163 |
void setDiagnostics(AnalyzeTask ct) { |
|
164 |
setDiagnostics(ct.getDiagnostics().ofUnit(this)); |
|
165 |
} |
|
166 |
||
167 |
void setDiagnostics(DiagList diags) { |
|
168 |
compilationDiagnostics = diags; |
|
169 |
UnresolvedExtractor ue = new UnresolvedExtractor(diags); |
|
170 |
unresolved = ue.unresolved(); |
|
171 |
state.debug(DBG_GEN, "++setCompilationInfo() %s\n%s\n-- diags: %s\n", |
|
172 |
si, si.outerWrap().wrapped(), diags); |
|
173 |
} |
|
174 |
||
175 |
private boolean isRecoverable() { |
|
176 |
// Unit failed, use corralling if it is defined on this Snippet, |
|
177 |
// and either all the errors are resolution errors or this is a |
|
178 |
// redeclare of an existing method |
|
179 |
return compilationDiagnostics.hasErrors() |
|
180 |
&& si instanceof DeclarationSnippet |
|
181 |
&& (isDependency() |
|
182 |
|| (si.subKind() != SubKind.VAR_DECLARATION_WITH_INITIALIZER_SUBKIND |
|
183 |
&& compilationDiagnostics.hasResolutionErrorsAndNoOthers())); |
|
184 |
} |
|
185 |
||
186 |
/** |
|
187 |
* If it meets the conditions for corralling, install the corralled wrap |
|
188 |
* @return true is the corralled wrap was installed |
|
189 |
*/ |
|
190 |
boolean corralIfNeeded(Collection<Unit> working) { |
|
191 |
if (isRecoverable() |
|
192 |
&& si.corralled() != null) { |
|
193 |
activeGuts = si.corralled(); |
|
194 |
setWrap(working, working); |
|
195 |
return isAttemptingCorral = true; |
|
196 |
} |
|
197 |
return isAttemptingCorral = false; |
|
198 |
} |
|
199 |
||
200 |
void setCorralledDiagnostics(AnalyzeTask cct) { |
|
201 |
// set corralled diagnostics, but don't reset unresolved |
|
202 |
recompilationDiagnostics = cct.getDiagnostics().ofUnit(this); |
|
203 |
state.debug(DBG_GEN, "++recomp %s\n%s\n-- diags: %s\n", |
|
204 |
si, si.outerWrap().wrapped(), recompilationDiagnostics); |
|
205 |
} |
|
206 |
||
207 |
boolean smashingErrorDiagnostics(CompileTask ct) { |
|
208 |
if (isDefined()) { |
|
209 |
// set corralled diagnostics, but don't reset unresolved |
|
210 |
DiagList dl = ct.getDiagnostics().ofUnit(this); |
|
211 |
if (dl.hasErrors()) { |
|
212 |
setDiagnostics(dl); |
|
213 |
status = RECOVERABLE_NOT_DEFINED; |
|
214 |
// overwrite orginal bytes |
|
215 |
state.debug(DBG_GEN, "++smashingErrorDiagnostics %s\n%s\n-- diags: %s\n", |
|
216 |
si, si.outerWrap().wrapped(), dl); |
|
217 |
return true; |
|
218 |
} |
|
219 |
} |
|
220 |
return false; |
|
221 |
} |
|
222 |
||
34857
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
223 |
void setStatus(AnalyzeTask at) { |
33362 | 224 |
if (!compilationDiagnostics.hasErrors()) { |
225 |
status = VALID; |
|
226 |
} else if (isRecoverable()) { |
|
227 |
if (isAttemptingCorral && !recompilationDiagnostics.hasErrors()) { |
|
228 |
status = RECOVERABLE_DEFINED; |
|
229 |
} else { |
|
230 |
status = RECOVERABLE_NOT_DEFINED; |
|
231 |
} |
|
232 |
} else { |
|
233 |
status = REJECTED; |
|
234 |
} |
|
34857
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
235 |
checkForOverwrite(at); |
33362 | 236 |
|
237 |
state.debug(DBG_GEN, "setStatus() %s - status: %s\n", |
|
238 |
si, status); |
|
239 |
} |
|
240 |
||
241 |
/** |
|
242 |
* Must be called for each unit |
|
243 |
* @return |
|
244 |
*/ |
|
245 |
boolean isDefined() { |
|
246 |
return status.isDefined; |
|
247 |
} |
|
248 |
||
249 |
/** |
|
250 |
* Process the class information from the last compile. |
|
251 |
* Requires loading of returned list. |
|
252 |
* @return the list of classes to load |
|
253 |
*/ |
|
254 |
Stream<ClassInfo> classesToLoad(List<ClassInfo> cil) { |
|
255 |
toRedefine = new ArrayList<>(); |
|
256 |
List<ClassInfo> toLoad = new ArrayList<>(); |
|
257 |
if (status.isDefined && !isImport()) { |
|
258 |
cil.stream().forEach(ci -> { |
|
259 |
if (!ci.isLoaded()) { |
|
260 |
if (ci.getReferenceTypeOrNull() == null) { |
|
261 |
toLoad.add(ci); |
|
262 |
ci.setLoaded(); |
|
263 |
dependenciesNeeded = true; |
|
264 |
} else { |
|
265 |
toRedefine.add(ci); |
|
266 |
} |
|
267 |
} |
|
268 |
}); |
|
269 |
} |
|
270 |
return toLoad.stream(); |
|
271 |
} |
|
272 |
||
273 |
/** |
|
274 |
* Redefine classes needing redefine. |
|
275 |
* classesToLoad() must be called first. |
|
276 |
* @return true if all redefines succeeded (can be vacuously true) |
|
277 |
*/ |
|
278 |
boolean doRedefines() { |
|
279 |
if (toRedefine.isEmpty()) { |
|
280 |
return true; |
|
281 |
} |
|
282 |
Map<ReferenceType, byte[]> mp = toRedefine.stream() |
|
283 |
.collect(toMap(ci -> ci.getReferenceTypeOrNull(), ci -> ci.getBytes())); |
|
284 |
if (state.executionControl().commandRedefine(mp)) { |
|
285 |
// success, mark as loaded |
|
286 |
toRedefine.stream().forEach(ci -> ci.setLoaded()); |
|
287 |
return true; |
|
288 |
} else { |
|
289 |
// failed to redefine |
|
290 |
return false; |
|
291 |
} |
|
292 |
} |
|
293 |
||
294 |
void markForReplacement() { |
|
295 |
// increment for replace class wrapper |
|
296 |
si.setSequenceNumber(++seq); |
|
297 |
} |
|
298 |
||
299 |
private boolean isImport() { |
|
300 |
return si.kind() == Kind.IMPORT; |
|
301 |
} |
|
302 |
||
303 |
private boolean sigChanged() { |
|
304 |
return (status.isDefined != prevStatus.isDefined) |
|
305 |
|| (seq != seqInitial && status.isDefined) |
|
306 |
|| signatureChanged; |
|
307 |
} |
|
308 |
||
309 |
Stream<Unit> effectedDependents() { |
|
310 |
return sigChanged() || dependenciesNeeded || status == RECOVERABLE_NOT_DEFINED |
|
311 |
? dependents() |
|
312 |
: Stream.empty(); |
|
313 |
} |
|
314 |
||
315 |
Stream<Unit> dependents() { |
|
316 |
return state.maps.getDependents(si) |
|
317 |
.stream() |
|
318 |
.filter(xsi -> xsi != si && xsi.status().isActive) |
|
319 |
.map(xsi -> new Unit(state, xsi, si, new DiagList())); |
|
320 |
} |
|
321 |
||
322 |
void finish() { |
|
323 |
recordCompilation(); |
|
324 |
state.maps.installSnippet(si); |
|
325 |
} |
|
326 |
||
327 |
private void markOldDeclarationOverwritten() { |
|
328 |
if (si != siOld && siOld != null && siOld.status().isActive) { |
|
329 |
// Mark the old declaraion as replaced |
|
330 |
replaceOldEvent = new SnippetEvent(siOld, |
|
331 |
siOld.status(), OVERWRITTEN, |
|
332 |
false, si, null, null); |
|
333 |
siOld.setOverwritten(); |
|
334 |
} |
|
335 |
} |
|
336 |
||
337 |
private DiagList computeDiagnostics() { |
|
338 |
DiagList diagnostics = new DiagList(); |
|
339 |
DiagList diags = compilationDiagnostics; |
|
340 |
if (status == RECOVERABLE_DEFINED || status == RECOVERABLE_NOT_DEFINED) { |
|
341 |
UnresolvedExtractor ue = new UnresolvedExtractor(diags); |
|
342 |
diagnostics.addAll(ue.otherAll()); |
|
343 |
} else { |
|
344 |
unresolved = Collections.emptyList(); |
|
345 |
diagnostics.addAll(diags); |
|
346 |
} |
|
347 |
diagnostics.addAll(generatedDiagnostics); |
|
348 |
return diagnostics; |
|
349 |
} |
|
350 |
||
351 |
private void recordCompilation() { |
|
352 |
state.maps.mapDependencies(si); |
|
353 |
DiagList diags = computeDiagnostics(); |
|
354 |
si.setCompilationStatus(status, unresolved, diags); |
|
355 |
state.debug(DBG_GEN, "recordCompilation: %s -- status %s, unresolved %s\n", |
|
356 |
si, status, unresolved); |
|
357 |
} |
|
358 |
||
34857
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
359 |
private void checkForOverwrite(AnalyzeTask at) { |
33362 | 360 |
secondaryEvents = new ArrayList<>(); |
361 |
if (replaceOldEvent != null) secondaryEvents.add(replaceOldEvent); |
|
362 |
||
363 |
// Defined methods can overwrite methods of other (equivalent) snippets |
|
364 |
if (si.kind() == Kind.METHOD && status.isDefined) { |
|
34857
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
365 |
MethodSnippet msi = (MethodSnippet)si; |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
366 |
String oqpt = msi.qualifiedParameterTypes(); |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
367 |
String nqpt = computeQualifiedParameterTypes(at, msi); |
33362 | 368 |
if (!nqpt.equals(oqpt)) { |
34857
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
369 |
msi.setQualifiedParamaterTypes(nqpt); |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
370 |
Status overwrittenStatus = overwriteMatchingMethod(msi); |
33362 | 371 |
if (overwrittenStatus != null) { |
372 |
prevStatus = overwrittenStatus; |
|
373 |
signatureChanged = true; |
|
374 |
} |
|
375 |
} |
|
376 |
} |
|
377 |
} |
|
378 |
||
379 |
// Check if there is a method whose user-declared parameter types are |
|
380 |
// different (and thus has a different snippet) but whose compiled parameter |
|
381 |
// types are the same. if so, consider it an overwrite replacement. |
|
34857
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
382 |
private Status overwriteMatchingMethod(MethodSnippet msi) { |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
383 |
String qpt = msi.qualifiedParameterTypes(); |
33362 | 384 |
|
385 |
// Look through all methods for a method of the same name, with the |
|
386 |
// same computed qualified parameter types |
|
387 |
Status overwrittenStatus = null; |
|
388 |
for (MethodSnippet sn : state.methods()) { |
|
34857
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
389 |
if (sn != null && sn != msi && sn.status().isActive && sn.name().equals(msi.name())) { |
33362 | 390 |
if (qpt.equals(sn.qualifiedParameterTypes())) { |
391 |
overwrittenStatus = sn.status(); |
|
392 |
SnippetEvent se = new SnippetEvent( |
|
393 |
sn, overwrittenStatus, OVERWRITTEN, |
|
34857
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
394 |
false, msi, null, null); |
33362 | 395 |
sn.setOverwritten(); |
396 |
secondaryEvents.add(se); |
|
397 |
state.debug(DBG_EVNT, |
|
398 |
"Overwrite event #%d -- key: %s before: %s status: %s sig: %b cause: %s\n", |
|
399 |
secondaryEvents.size(), se.snippet(), se.previousStatus(), |
|
400 |
se.status(), se.isSignatureChange(), se.causeSnippet()); |
|
401 |
} |
|
402 |
} |
|
403 |
} |
|
404 |
return overwrittenStatus; |
|
405 |
} |
|
406 |
||
34857
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
407 |
private String computeQualifiedParameterTypes(AnalyzeTask at, MethodSnippet msi) { |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
408 |
String rawSig = TreeDissector.createBySnippet(at, msi).typeOfMethod(); |
33362 | 409 |
String signature = expunge(rawSig); |
410 |
int paren = signature.lastIndexOf(')'); |
|
34857
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
411 |
|
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
412 |
// Extract the parameter type string from the method signature, |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
413 |
// if method did not compile use the user-supplied parameter types |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
414 |
return paren >= 0 |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
415 |
? signature.substring(0, paren + 1) |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
416 |
: msi.parameterTypes(); |
33362 | 417 |
} |
418 |
||
419 |
SnippetEvent event(String value, Exception exception) { |
|
420 |
boolean wasSignatureChanged = sigChanged(); |
|
421 |
state.debug(DBG_EVNT, "Snippet: %s id: %s before: %s status: %s sig: %b cause: %s\n", |
|
422 |
si, si.id(), prevStatus, si.status(), wasSignatureChanged, causalSnippet); |
|
423 |
return new SnippetEvent(si, prevStatus, si.status(), |
|
424 |
wasSignatureChanged, causalSnippet, value, exception); |
|
425 |
} |
|
426 |
||
427 |
List<SnippetEvent> secondaryEvents() { |
|
428 |
return secondaryEvents; |
|
429 |
} |
|
430 |
||
431 |
@Override |
|
432 |
public String toString() { |
|
433 |
return "Unit(" + si.name() + ")"; |
|
434 |
} |
|
435 |
||
436 |
/** |
|
437 |
* Separate out the unresolvedDependencies errors from both the other |
|
438 |
* corralling errors and the overall errors. |
|
439 |
*/ |
|
440 |
private static class UnresolvedExtractor { |
|
441 |
||
442 |
private static final String RESOLVE_ERROR_SYMBOL = "symbol:"; |
|
443 |
private static final String RESOLVE_ERROR_LOCATION = "location:"; |
|
444 |
||
445 |
//TODO extract from tree instead -- note: internationalization |
|
446 |
private final Set<String> unresolved = new LinkedHashSet<>(); |
|
447 |
private final DiagList otherErrors = new DiagList(); |
|
448 |
private final DiagList otherAll = new DiagList(); |
|
449 |
||
450 |
UnresolvedExtractor(DiagList diags) { |
|
451 |
for (Diag diag : diags) { |
|
452 |
if (diag.isError()) { |
|
453 |
if (diag.isResolutionError()) { |
|
35000
952a7b4652f0
8146368: JShell: couldn't smash the error when it's Japanese locale
rfield
parents:
34857
diff
changeset
|
454 |
String m = diag.getMessage(PARSED_LOCALE); |
33362 | 455 |
int symPos = m.indexOf(RESOLVE_ERROR_SYMBOL); |
456 |
if (symPos >= 0) { |
|
457 |
m = m.substring(symPos + RESOLVE_ERROR_SYMBOL.length()); |
|
458 |
int symLoc = m.indexOf(RESOLVE_ERROR_LOCATION); |
|
459 |
if (symLoc >= 0) { |
|
460 |
m = m.substring(0, symLoc); |
|
461 |
} |
|
462 |
m = m.trim(); |
|
463 |
unresolved.add(m); |
|
464 |
continue; |
|
465 |
} |
|
466 |
} |
|
467 |
otherErrors.add(diag); |
|
468 |
} |
|
469 |
otherAll.add(diag); |
|
470 |
} |
|
471 |
} |
|
472 |
||
473 |
DiagList otherCorralledErrors() { |
|
474 |
return otherErrors; |
|
475 |
} |
|
476 |
||
477 |
DiagList otherAll() { |
|
478 |
return otherAll; |
|
479 |
} |
|
480 |
||
481 |
List<String> unresolved() { |
|
482 |
return new ArrayList<>(unresolved); |
|
483 |
} |
|
484 |
} |
|
485 |
} |