author | jlahoda |
Tue, 09 May 2017 12:22:15 +0200 | |
changeset 45044 | 7c50549b7744 |
parent 38535 | 4a25025e0b0d |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
2 |
* Copyright (c) 2015-2016, Oracle and/or its affiliates. All rights reserved. |
33362 | 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 |
*/ |
|
34752
9c262a013456
8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents:
33362
diff
changeset
|
25 |
|
33362 | 26 |
package jdk.jshell; |
27 |
||
28 |
import java.util.Locale; |
|
29 |
import javax.tools.Diagnostic; |
|
30 |
import javax.tools.JavaFileObject; |
|
38535
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
37644
diff
changeset
|
31 |
import static jdk.jshell.Util.PARSED_LOCALE; |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
37644
diff
changeset
|
32 |
import static jdk.jshell.Util.REPL_CLASS_PREFIX; |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
37644
diff
changeset
|
33 |
import static jdk.jshell.Util.REPL_DOESNOTMATTER_CLASS_NAME; |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
37644
diff
changeset
|
34 |
import static jdk.jshell.Util.REPL_PACKAGE; |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
37644
diff
changeset
|
35 |
import static jdk.jshell.Util.expunge; |
33362 | 36 |
|
37 |
/** |
|
38 |
* |
|
39 |
* @author Robert Field |
|
40 |
*/ |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
41 |
class OuterWrap implements GeneralWrap { |
33362 | 42 |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
43 |
protected final Wrap w; |
33362 | 44 |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
45 |
OuterWrap(Wrap wrap) { |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
46 |
this.w = wrap; |
33362 | 47 |
} |
48 |
||
49 |
@Override |
|
50 |
public final String wrapped() { |
|
51 |
return w.wrapped(); |
|
52 |
} |
|
53 |
||
54 |
@Override |
|
55 |
public int snippetIndexToWrapIndex(int ui) { |
|
56 |
return w.snippetIndexToWrapIndex(ui); |
|
57 |
} |
|
58 |
||
59 |
@Override |
|
60 |
public int wrapIndexToSnippetIndex(int si) { |
|
61 |
return w.wrapIndexToSnippetIndex(si); |
|
62 |
} |
|
63 |
||
64 |
@Override |
|
65 |
public int firstSnippetIndex() { |
|
66 |
return w.firstSnippetIndex(); |
|
67 |
} |
|
68 |
||
69 |
@Override |
|
70 |
public int lastSnippetIndex() { |
|
71 |
return w.lastSnippetIndex(); |
|
72 |
} |
|
73 |
||
74 |
@Override |
|
75 |
public int snippetLineToWrapLine(int snline) { |
|
76 |
return w.snippetLineToWrapLine(snline); |
|
77 |
} |
|
78 |
||
79 |
@Override |
|
80 |
public int wrapLineToSnippetLine(int wline) { |
|
81 |
return w.wrapLineToSnippetLine(wline); |
|
82 |
} |
|
83 |
||
84 |
@Override |
|
85 |
public int firstSnippetLine() { |
|
86 |
return w.firstSnippetLine(); |
|
87 |
} |
|
88 |
||
89 |
@Override |
|
90 |
public int lastSnippetLine() { |
|
91 |
return w.lastSnippetLine(); |
|
92 |
} |
|
93 |
||
94 |
public String className() { |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
95 |
return REPL_DOESNOTMATTER_CLASS_NAME; |
33362 | 96 |
} |
97 |
||
98 |
public String classFullName() { |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
99 |
return REPL_PACKAGE + "." + className(); |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
100 |
} |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
101 |
|
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
102 |
@Override |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
103 |
public int hashCode() { |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
104 |
return className().hashCode(); |
33362 | 105 |
} |
106 |
||
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
107 |
@Override |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
108 |
public boolean equals(Object o) { |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
109 |
return (o instanceof OuterWrap) |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
110 |
? className().equals(((OuterWrap) o).className()) |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
111 |
: false; |
33362 | 112 |
} |
113 |
||
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
114 |
@Override |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
115 |
public String toString() { |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
116 |
return "OW(" + w + ")"; |
33362 | 117 |
} |
118 |
||
119 |
Diag wrapDiag(Diagnostic<? extends JavaFileObject> d) { |
|
120 |
return new WrappedDiagnostic(d); |
|
121 |
} |
|
122 |
||
123 |
class WrappedDiagnostic extends Diag { |
|
124 |
||
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
125 |
final Diagnostic<? extends JavaFileObject> diag; |
33362 | 126 |
|
127 |
WrappedDiagnostic(Diagnostic<? extends JavaFileObject> diag) { |
|
128 |
this.diag = diag; |
|
129 |
} |
|
130 |
||
131 |
@Override |
|
132 |
public boolean isError() { |
|
133 |
return diag.getKind() == Diagnostic.Kind.ERROR; |
|
134 |
} |
|
135 |
||
136 |
@Override |
|
137 |
public long getPosition() { |
|
138 |
return wrapIndexToSnippetIndex(diag.getPosition()); |
|
139 |
} |
|
140 |
||
141 |
@Override |
|
142 |
public long getStartPosition() { |
|
143 |
return wrapIndexToSnippetIndex(diag.getStartPosition()); |
|
144 |
} |
|
145 |
||
146 |
@Override |
|
147 |
public long getEndPosition() { |
|
148 |
return wrapIndexToSnippetIndex(diag.getEndPosition()); |
|
149 |
} |
|
150 |
||
151 |
@Override |
|
152 |
public String getCode() { |
|
153 |
return diag.getCode(); |
|
154 |
} |
|
155 |
||
156 |
@Override |
|
157 |
public String getMessage(Locale locale) { |
|
158 |
return expunge(diag.getMessage(locale)); |
|
159 |
} |
|
160 |
||
161 |
@Override |
|
35736
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
35000
diff
changeset
|
162 |
boolean isResolutionError() { |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
35000
diff
changeset
|
163 |
if (!super.isResolutionError()) { |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
35000
diff
changeset
|
164 |
return false; |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
35000
diff
changeset
|
165 |
} |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
35000
diff
changeset
|
166 |
for (String line : diag.getMessage(PARSED_LOCALE).split("\\r?\\n")) { |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
35000
diff
changeset
|
167 |
if (line.trim().startsWith("location:")) { |
38535
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
37644
diff
changeset
|
168 |
if (!line.contains(REPL_CLASS_PREFIX)) { |
35736
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
35000
diff
changeset
|
169 |
// Resolution error must occur within a REPL class or it is not resolvable |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
35000
diff
changeset
|
170 |
return false; |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
35000
diff
changeset
|
171 |
} |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
35000
diff
changeset
|
172 |
} |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
35000
diff
changeset
|
173 |
} |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
35000
diff
changeset
|
174 |
return true; |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
35000
diff
changeset
|
175 |
} |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
35000
diff
changeset
|
176 |
|
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
35000
diff
changeset
|
177 |
@Override |
35000
952a7b4652f0
8146368: JShell: couldn't smash the error when it's Japanese locale
rfield
parents:
34752
diff
changeset
|
178 |
public String toString() { |
952a7b4652f0
8146368: JShell: couldn't smash the error when it's Japanese locale
rfield
parents:
34752
diff
changeset
|
179 |
return "WrappedDiagnostic(" + getMessage(null) + ":" + getPosition() + ")"; |
952a7b4652f0
8146368: JShell: couldn't smash the error when it's Japanese locale
rfield
parents:
34752
diff
changeset
|
180 |
} |
33362 | 181 |
} |
182 |
} |