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.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @summary Test of Snippet redefinition and replacement.
|
|
27 |
* @build KullaTesting TestingInputStream
|
|
28 |
* @run testng ReplaceTest
|
|
29 |
*/
|
|
30 |
|
|
31 |
import java.util.Collection;
|
|
32 |
|
|
33 |
import jdk.jshell.Snippet;
|
|
34 |
import jdk.jshell.MethodSnippet;
|
|
35 |
import jdk.jshell.PersistentSnippet;
|
|
36 |
import jdk.jshell.TypeDeclSnippet;
|
|
37 |
import jdk.jshell.VarSnippet;
|
|
38 |
import jdk.jshell.DeclarationSnippet;
|
|
39 |
import org.testng.annotations.Test;
|
|
40 |
|
|
41 |
import static jdk.jshell.Snippet.Status.*;
|
|
42 |
import static jdk.jshell.Snippet.SubKind.*;
|
|
43 |
import static org.testng.Assert.assertEquals;
|
|
44 |
import static org.testng.Assert.assertTrue;
|
|
45 |
|
|
46 |
@Test
|
|
47 |
public class ReplaceTest extends KullaTesting {
|
|
48 |
|
|
49 |
public void testRedefine() {
|
|
50 |
Snippet vx = varKey(assertEval("int x;"));
|
|
51 |
Snippet mu = methodKey(assertEval("int mu() { return x * 4; }"));
|
|
52 |
Snippet c = classKey(assertEval("class C { String v() { return \"#\" + mu(); } }"));
|
|
53 |
assertEval("C c0 = new C();");
|
|
54 |
assertEval("c0.v();", "\"#0\"");
|
|
55 |
assertEval("int x = 10;", "10",
|
|
56 |
ste(MAIN_SNIPPET, VALID, VALID, false, null),
|
|
57 |
ste(vx, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
|
|
58 |
assertEval("c0.v();", "\"#40\"");
|
|
59 |
assertEval("C c = new C();");
|
|
60 |
assertEval("c.v();", "\"#40\"");
|
|
61 |
assertEval("int mu() { return x * 3; }",
|
|
62 |
ste(MAIN_SNIPPET, VALID, VALID, false, null),
|
|
63 |
ste(mu, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
|
|
64 |
assertEval("c.v();", "\"#30\"");
|
|
65 |
assertEval("class C { String v() { return \"@\" + mu(); } }",
|
|
66 |
ste(MAIN_SNIPPET, VALID, VALID, false, null),
|
|
67 |
ste(c, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
|
|
68 |
assertEval("c0.v();", "\"@30\"");
|
|
69 |
assertEval("c = new C();");
|
|
70 |
assertEval("c.v();", "\"@30\"");
|
|
71 |
assertActiveKeys();
|
|
72 |
}
|
|
73 |
|
|
74 |
public void testReplaceClassToVar() {
|
|
75 |
Snippet oldA = classKey(assertEval("class A { public String toString() { return \"old\"; } }"));
|
|
76 |
Snippet v = varKey(assertEval("A a = new A();", "old"));
|
|
77 |
assertEval("a;", "old");
|
|
78 |
Snippet midA = classKey(assertEval("class A { public String toString() { return \"middle\"; } }",
|
|
79 |
ste(MAIN_SNIPPET, VALID, VALID, false, null),
|
|
80 |
ste(oldA, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
|
|
81 |
assertEval("a;", "middle");
|
|
82 |
assertEval("class A { int x; public String toString() { return \"new\"; } }",
|
|
83 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
84 |
ste(midA, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
85 |
ste(v, VALID, VALID, true, MAIN_SNIPPET));
|
|
86 |
assertEval("a;", "null");
|
|
87 |
assertActiveKeys();
|
|
88 |
}
|
|
89 |
|
|
90 |
public void testReplaceVarToMethod() {
|
|
91 |
Snippet x = varKey(assertEval("int x;"));
|
|
92 |
Snippet musn = methodKey(assertEval("double mu() { return x * 4; }"));
|
|
93 |
assertEval("x == 0;", "true");
|
|
94 |
assertEval("mu() == 0.0;", "true");
|
|
95 |
assertEval("double x = 2.5;",
|
|
96 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
97 |
ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
98 |
ste(musn, VALID, VALID, false, MAIN_SNIPPET));
|
|
99 |
Collection<MethodSnippet> meths = getState().methods();
|
|
100 |
assertEquals(meths.size(), 1);
|
|
101 |
assertTrue(musn == meths.iterator().next(), "Identity must not change");
|
|
102 |
assertEval("x == 2.5;", "true");
|
|
103 |
assertEval("mu() == 10.0;", "true"); // Auto redefine
|
|
104 |
assertActiveKeys();
|
|
105 |
}
|
|
106 |
|
|
107 |
public void testReplaceMethodToMethod() {
|
|
108 |
Snippet a = methodKey(assertEval("double a() { return 2; }"));
|
|
109 |
Snippet b = methodKey(assertEval("double b() { return a() * 10; }"));
|
|
110 |
assertEval("double c() { return b() * 3; }");
|
|
111 |
assertEval("double d() { return c() + 1000; }");
|
|
112 |
assertEval("d();", "1060.0");
|
|
113 |
assertEval("int a() { return 5; }",
|
|
114 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
115 |
ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
116 |
ste(b, VALID, VALID, false, MAIN_SNIPPET));
|
|
117 |
assertEval("d();", "1150.0");
|
|
118 |
assertActiveKeys();
|
|
119 |
}
|
|
120 |
|
|
121 |
public void testReplaceClassToMethod() {
|
|
122 |
Snippet c = classKey(assertEval("class C { int f() { return 7; } }"));
|
|
123 |
Snippet m = methodKey(assertEval("int m() { return new C().f(); }"));
|
|
124 |
assertEval("m();", "7");
|
|
125 |
assertEval("class C { int x = 99; int f() { return x; } }",
|
|
126 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
127 |
ste(c, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
128 |
ste(m, VALID, VALID, false, MAIN_SNIPPET));
|
|
129 |
assertEval("m();", "99");
|
|
130 |
assertActiveKeys();
|
|
131 |
}
|
|
132 |
|
|
133 |
public void testReplaceVarToClass() {
|
|
134 |
Snippet x = varKey(assertEval("int x;"));
|
|
135 |
Snippet c = classKey(assertEval("class A { double a = 4 * x; }"));
|
|
136 |
assertEval("x == 0;", "true");
|
|
137 |
assertEval("new A().a == 0.0;", "true");
|
|
138 |
assertEval("double x = 2.5;",
|
|
139 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
140 |
ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
141 |
ste(c, VALID, VALID, false, MAIN_SNIPPET));
|
|
142 |
Collection<TypeDeclSnippet> classes = getState().types();
|
|
143 |
assertEquals(classes.size(), 1);
|
|
144 |
assertTrue(c == classes.iterator().next(), "Identity must not change");
|
|
145 |
assertEval("x == 2.5;", "true");
|
|
146 |
assertEval("new A().a == 10.0;", "true");
|
|
147 |
assertActiveKeys();
|
|
148 |
}
|
|
149 |
|
|
150 |
public void testReplaceMethodToClass() {
|
|
151 |
Snippet x = methodKey(assertEval("int x() { return 0; }"));
|
|
152 |
Snippet c = classKey(assertEval("class A { double a = 4 * x(); }"));
|
|
153 |
assertEval("x() == 0;", "true");
|
|
154 |
assertEval("new A().a == 0.0;", "true");
|
|
155 |
assertEval("double x() { return 2.5; }",
|
|
156 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
157 |
ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
158 |
ste(c, VALID, VALID, false, MAIN_SNIPPET));
|
|
159 |
assertEval("x();", "2.5");
|
|
160 |
Collection<TypeDeclSnippet> classes = getState().types();
|
|
161 |
assertEquals(classes.size(), 1);
|
|
162 |
assertTrue(c == classes.iterator().next(), "Identity must not change");
|
|
163 |
assertEval("x() == 2.5;", "true");
|
|
164 |
assertEval("new A().a == 10.0;", "true");
|
|
165 |
assertActiveKeys();
|
|
166 |
}
|
|
167 |
|
|
168 |
public void testReplaceClassToClass() {
|
|
169 |
TypeDeclSnippet a = classKey(assertEval("class A {}"));
|
|
170 |
assertTypeDeclSnippet(a, "A", VALID, CLASS_SUBKIND, 0, 0);
|
|
171 |
TypeDeclSnippet b = classKey(assertEval("class B extends A {}"));
|
|
172 |
TypeDeclSnippet c = classKey(assertEval("class C extends B {}"));
|
|
173 |
TypeDeclSnippet d = classKey(assertEval("class D extends C {}"));
|
|
174 |
assertEval("class A { int x; public String toString() { return \"NEW\"; } }",
|
|
175 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
176 |
ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
177 |
ste(b, VALID, VALID, true, MAIN_SNIPPET),
|
|
178 |
ste(c, VALID, VALID, true, b),
|
|
179 |
ste(d, VALID, VALID, true, c));
|
|
180 |
assertTypeDeclSnippet(b, "B", VALID, CLASS_SUBKIND, 0, 0);
|
|
181 |
assertTypeDeclSnippet(c, "C", VALID, CLASS_SUBKIND, 0, 0);
|
|
182 |
assertTypeDeclSnippet(d, "D", VALID, CLASS_SUBKIND, 0, 0);
|
|
183 |
assertEval("new D();", "NEW");
|
|
184 |
assertActiveKeys();
|
|
185 |
}
|
|
186 |
|
|
187 |
public void testOverwriteReplaceMethod() {
|
|
188 |
MethodSnippet k1 = methodKey(assertEval("String m(Integer i) { return i.toString(); }"));
|
|
189 |
MethodSnippet k2 = methodKey(assertEval("String m(java.lang.Integer i) { return \"java.lang.\" + i.toString(); }",
|
|
190 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
191 |
ste(k1, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
|
|
192 |
assertMethodDeclSnippet(k1, "m", "(Integer)String", OVERWRITTEN, 0, 0);
|
|
193 |
assertEval("m(6);", "\"java.lang.6\"");
|
|
194 |
assertEval("String m(Integer i) { return i.toString(); }",
|
|
195 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
196 |
ste(k2, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
|
|
197 |
assertMethodDeclSnippet(k2, "m", "(java.lang.Integer)String", OVERWRITTEN, 0, 0);
|
|
198 |
assertEval("m(6);", "\"6\"");
|
|
199 |
assertActiveKeys();
|
|
200 |
}
|
|
201 |
|
|
202 |
public void testOverwriteMethodForwardReferenceClass() {
|
|
203 |
Snippet k1 = methodKey(assertEval("int q(Boo b) { return b.x; }",
|
|
204 |
added(RECOVERABLE_NOT_DEFINED)));
|
|
205 |
assertUnresolvedDependencies1((MethodSnippet) k1, RECOVERABLE_NOT_DEFINED, "class Boo");
|
|
206 |
assertEval("class Boo { int x = 55; }",
|
|
207 |
added(VALID),
|
|
208 |
ste(k1, RECOVERABLE_NOT_DEFINED, VALID, true, null));
|
|
209 |
assertMethodDeclSnippet((MethodSnippet) k1, "q", "(Boo)int", VALID, 0, 0);
|
|
210 |
assertEval("q(new Boo());", "55");
|
|
211 |
assertActiveKeys();
|
|
212 |
}
|
|
213 |
|
|
214 |
public void testOverwriteMethodForwardReferenceClassImport() {
|
|
215 |
MethodSnippet k1 = methodKey(assertEval("int ff(List lis) { return lis.size(); }",
|
|
216 |
added(RECOVERABLE_NOT_DEFINED)));
|
|
217 |
assertUnresolvedDependencies1(k1, RECOVERABLE_NOT_DEFINED, "class List");
|
|
218 |
assertEval("import java.util.*;",
|
|
219 |
added(VALID),
|
|
220 |
ste(k1, RECOVERABLE_NOT_DEFINED, VALID, true, null));
|
|
221 |
assertMethodDeclSnippet(k1, "ff", "(List)int", VALID, 0, 0);
|
|
222 |
assertEval("ff(new ArrayList());", "0");
|
|
223 |
assertActiveKeys();
|
|
224 |
}
|
|
225 |
|
|
226 |
public void testForwardVarToMethod() {
|
|
227 |
DeclarationSnippet t = methodKey(assertEval("int t() { return x; }", added(RECOVERABLE_DEFINED)));
|
|
228 |
assertUnresolvedDependencies1(t, RECOVERABLE_DEFINED, "variable x");
|
|
229 |
assertEvalUnresolvedException("t();", "t", 1, 0);
|
|
230 |
Snippet x = varKey(assertEval("int x = 33;", "33",
|
|
231 |
added(VALID),
|
|
232 |
ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
|
|
233 |
assertEval("t();", "33");
|
|
234 |
assertEval("double x = 0.88;",
|
|
235 |
"0.88", null,
|
|
236 |
DiagCheck.DIAG_OK,
|
|
237 |
DiagCheck.DIAG_ERROR,
|
|
238 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
239 |
ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
240 |
ste(t, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
|
|
241 |
assertEvalUnresolvedException("t();", "t", 0, 1);
|
|
242 |
assertActiveKeys();
|
|
243 |
}
|
|
244 |
|
|
245 |
public void testForwardMethodToMethod() {
|
|
246 |
Snippet t = methodKey(assertEval("int t() { return f(); }", added(RECOVERABLE_DEFINED)));
|
|
247 |
Snippet f = methodKey(assertEval("int f() { return g(); }",
|
|
248 |
added(RECOVERABLE_DEFINED),
|
|
249 |
ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
|
|
250 |
assertUnresolvedDependencies1((DeclarationSnippet) f, RECOVERABLE_DEFINED, "method g()");
|
|
251 |
assertEvalUnresolvedException("t();", "f", 1, 0);
|
|
252 |
Snippet g = methodKey(assertEval("int g() { return 55; }",
|
|
253 |
added(VALID),
|
|
254 |
ste(f, RECOVERABLE_DEFINED, VALID, false, null)));
|
|
255 |
assertEval("t();", "55");
|
|
256 |
assertEval("double g() { return 3.14159; }",
|
|
257 |
DiagCheck.DIAG_OK,
|
|
258 |
DiagCheck.DIAG_ERROR,
|
|
259 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
260 |
ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
261 |
ste(f, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
|
|
262 |
MethodSnippet exsn = assertEvalUnresolvedException("t();", "f", 0, 1);
|
|
263 |
assertTrue(exsn == f, "Identity must not change");
|
|
264 |
assertActiveKeys();
|
|
265 |
}
|
|
266 |
|
|
267 |
public void testForwardClassToMethod() {
|
|
268 |
DeclarationSnippet t = methodKey(assertEval("int t() { return new A().f(); }", added(RECOVERABLE_DEFINED)));
|
|
269 |
assertUnresolvedDependencies1(t, RECOVERABLE_DEFINED, "class A");
|
|
270 |
assertEvalUnresolvedException("t();", "t", 1, 0);
|
|
271 |
Snippet a = classKey(assertEval(
|
|
272 |
"class A {\n" +
|
|
273 |
" int f() { return 10; }\n" +
|
|
274 |
"}",
|
|
275 |
added(VALID),
|
|
276 |
ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
|
|
277 |
assertEval("t();", "10");
|
|
278 |
assertEval(
|
|
279 |
"class A {\n" +
|
|
280 |
" double f() { return 88.0; }\n" +
|
|
281 |
"}",
|
|
282 |
DiagCheck.DIAG_OK,
|
|
283 |
DiagCheck.DIAG_ERROR,
|
|
284 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
285 |
ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
286 |
ste(t, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
|
|
287 |
assertEvalUnresolvedException("t();", "t", 0, 1);
|
|
288 |
assertActiveKeys();
|
|
289 |
}
|
|
290 |
|
|
291 |
public void testForwardVarToClass() {
|
|
292 |
DeclarationSnippet a = classKey(assertEval("class A { int f() { return g; } }", added(RECOVERABLE_NOT_DEFINED)));
|
|
293 |
assertUnresolvedDependencies1(a, RECOVERABLE_NOT_DEFINED, "variable g");
|
|
294 |
Snippet g = varKey(assertEval("int g = 10;", "10",
|
|
295 |
added(VALID),
|
|
296 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
|
|
297 |
assertEval("new A().f();", "10");
|
|
298 |
assertEval("double g = 10;", "10.0", null,
|
|
299 |
DiagCheck.DIAG_OK,
|
|
300 |
DiagCheck.DIAG_ERROR,
|
|
301 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
302 |
ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
303 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
|
|
304 |
assertUnresolvedDependencies(a, 0);
|
|
305 |
assertActiveKeys();
|
|
306 |
}
|
|
307 |
|
|
308 |
|
|
309 |
public void testForwardMethodToClass() {
|
|
310 |
DeclarationSnippet a = classKey(assertEval("class A { int f() { return g(); } }", added(RECOVERABLE_NOT_DEFINED)));
|
|
311 |
assertUnresolvedDependencies1(a, RECOVERABLE_NOT_DEFINED, "method g()");
|
|
312 |
Snippet g = methodKey(assertEval("int g() { return 10; }",
|
|
313 |
added(VALID),
|
|
314 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
|
|
315 |
assertEval("new A().f();", "10");
|
|
316 |
assertEval("double g() { return 10; }",
|
|
317 |
DiagCheck.DIAG_OK,
|
|
318 |
DiagCheck.DIAG_ERROR,
|
|
319 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
320 |
ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
321 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
|
|
322 |
assertUnresolvedDependencies(a, 0);
|
|
323 |
assertActiveKeys();
|
|
324 |
}
|
|
325 |
|
|
326 |
public void testForwardClassToClass1() {
|
|
327 |
Snippet a = classKey(assertEval("class A { B b = new B(); }", added(RECOVERABLE_NOT_DEFINED)));
|
|
328 |
assertDeclareFail("new A().b;", "compiler.err.cant.resolve.location");
|
|
329 |
|
|
330 |
Snippet b = classKey(assertEval("class B { public String toString() { return \"B\"; } }",
|
|
331 |
added(VALID),
|
|
332 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
|
|
333 |
assertEval("new A().b;", "B");
|
|
334 |
assertEval("interface B { }",
|
|
335 |
DiagCheck.DIAG_OK,
|
|
336 |
DiagCheck.DIAG_ERROR,
|
|
337 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
338 |
ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
339 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
|
|
340 |
assertDeclareFail("new A().b;", "compiler.err.cant.resolve.location");
|
|
341 |
assertActiveKeys();
|
|
342 |
}
|
|
343 |
|
|
344 |
public void testForwardClassToClass2() {
|
|
345 |
Snippet a = classKey(assertEval("class A extends B { }", added(RECOVERABLE_NOT_DEFINED)));
|
|
346 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
347 |
|
|
348 |
Snippet b = classKey(assertEval("class B { public String toString() { return \"B\"; } }",
|
|
349 |
added(VALID),
|
|
350 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
|
|
351 |
assertEval("new A();", "B");
|
|
352 |
assertEval("interface B { }",
|
|
353 |
DiagCheck.DIAG_OK,
|
|
354 |
DiagCheck.DIAG_ERROR,
|
|
355 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
356 |
ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
357 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
|
|
358 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
359 |
assertActiveKeys();
|
|
360 |
}
|
|
361 |
|
|
362 |
public void testForwardClassToClass3() {
|
|
363 |
Snippet a = classKey(assertEval("interface A extends B { static int f() { return 10; } }", added(RECOVERABLE_NOT_DEFINED)));
|
|
364 |
assertDeclareFail("A.f();", "compiler.err.cant.resolve.location");
|
|
365 |
|
|
366 |
Snippet b = classKey(assertEval("interface B { }",
|
|
367 |
added(VALID),
|
|
368 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
|
|
369 |
assertEval("A.f();", "10");
|
|
370 |
assertEval("class B { }",
|
|
371 |
DiagCheck.DIAG_OK,
|
|
372 |
DiagCheck.DIAG_ERROR,
|
|
373 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
374 |
ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
375 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
|
|
376 |
assertDeclareFail("A.f();", "compiler.err.cant.resolve.location");
|
|
377 |
assertActiveKeys();
|
|
378 |
}
|
|
379 |
|
|
380 |
public void testImportDeclare() {
|
|
381 |
Snippet singleImport = importKey(assertEval("import java.util.List;", added(VALID)));
|
|
382 |
Snippet importOnDemand = importKey(assertEval("import java.util.*;", added(VALID)));
|
|
383 |
Snippet singleStaticImport = importKey(assertEval("import static java.lang.Math.abs;", added(VALID)));
|
|
384 |
Snippet staticImportOnDemand = importKey(assertEval("import static java.lang.Math.*;", added(VALID)));
|
|
385 |
assertEval("import java.util.List; //again",
|
|
386 |
ste(MAIN_SNIPPET, VALID, VALID, false, null),
|
|
387 |
ste(singleImport, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
|
|
388 |
assertEval("import java.util.*; //again",
|
|
389 |
ste(MAIN_SNIPPET, VALID, VALID, false, null),
|
|
390 |
ste(importOnDemand, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
|
|
391 |
assertEval("import static java.lang.Math.abs; //again",
|
|
392 |
ste(MAIN_SNIPPET, VALID, VALID, false, null),
|
|
393 |
ste(singleStaticImport, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
|
|
394 |
assertEval("import static java.lang.Math.*; //again",
|
|
395 |
ste(MAIN_SNIPPET, VALID, VALID, false, null),
|
|
396 |
ste(staticImportOnDemand, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
|
|
397 |
assertActiveKeys();
|
|
398 |
}
|
|
399 |
|
|
400 |
public void testForwardVariable() {
|
|
401 |
assertEval("int f() { return x; }", added(RECOVERABLE_DEFINED));
|
|
402 |
assertEvalUnresolvedException("f();", "f", 1, 0);
|
|
403 |
assertActiveKeys();
|
|
404 |
}
|
|
405 |
|
|
406 |
public void testLocalClassInUnresolved() {
|
|
407 |
Snippet f = methodKey(assertEval("void f() { class A {} g(); }", added(RECOVERABLE_DEFINED)));
|
|
408 |
assertEval("void g() {}",
|
|
409 |
added(VALID),
|
|
410 |
ste(f, RECOVERABLE_DEFINED, VALID, false, null));
|
|
411 |
assertEval("f();", "");
|
|
412 |
}
|
|
413 |
|
|
414 |
@Test(enabled = false) // TODO 8129420
|
|
415 |
public void testLocalClassEvolve() {
|
|
416 |
Snippet j = methodKey(assertEval("Object j() { return null; }", added(VALID)));
|
|
417 |
assertEval("Object j() { class B {}; return null; }",
|
|
418 |
ste(MAIN_SNIPPET, VALID, VALID, false, null));
|
|
419 |
assertEval("Object j() { class B {}; return new B(); }",
|
|
420 |
ste(MAIN_SNIPPET, VALID, VALID, false, null));
|
|
421 |
assertEval("j().getClass().getSimpleName();", "\"B\"");
|
|
422 |
assertEval("Object j() { class B { int p; public String toString() { return \"Yep\";} }; return new B(); }",
|
|
423 |
ste(MAIN_SNIPPET, VALID, VALID, false, null));
|
|
424 |
assertEval("j().getClass().getSimpleName();", "\"B\"");
|
|
425 |
assertEval("j();", "Yep");
|
|
426 |
}
|
|
427 |
|
|
428 |
public void testForwardSingleImportMethodToMethod() {
|
|
429 |
DeclarationSnippet string = methodKey(assertEval("String string() { return format(\"string\"); }",
|
|
430 |
added(RECOVERABLE_DEFINED)));
|
|
431 |
assertUnresolvedDependencies1(string, RECOVERABLE_DEFINED, "method format(java.lang.String)");
|
|
432 |
assertEvalUnresolvedException("string();", "string", 1, 0);
|
|
433 |
assertEval("import static java.lang.String.format;",
|
|
434 |
added(VALID),
|
|
435 |
ste(string, RECOVERABLE_DEFINED, VALID, false, null));
|
|
436 |
assertEval("string();", "\"string\"");
|
|
437 |
|
|
438 |
assertEval("double format(String s) { return 0; }",
|
|
439 |
DiagCheck.DIAG_OK,
|
|
440 |
DiagCheck.DIAG_ERROR,
|
|
441 |
added(VALID),
|
|
442 |
ste(string, VALID, RECOVERABLE_DEFINED, false, null));
|
|
443 |
assertEvalUnresolvedException("string();", "string", 0, 1);
|
|
444 |
assertActiveKeys();
|
|
445 |
}
|
|
446 |
|
|
447 |
public void testForwardImportMethodOnDemandToMethod() {
|
|
448 |
DeclarationSnippet string = methodKey(assertEval("String string() { return format(\"string\"); }",
|
|
449 |
added(RECOVERABLE_DEFINED)));
|
|
450 |
assertUnresolvedDependencies1(string, RECOVERABLE_DEFINED, "method format(java.lang.String)");
|
|
451 |
assertEvalUnresolvedException("string();", "string", 1, 0);
|
|
452 |
assertEval("import static java.lang.String.*;",
|
|
453 |
added(VALID),
|
|
454 |
ste(string, RECOVERABLE_DEFINED, VALID, false, null));
|
|
455 |
assertEval("string();", "\"string\"");
|
|
456 |
|
|
457 |
assertEval("double format(String s) { return 0; }",
|
|
458 |
DiagCheck.DIAG_OK,
|
|
459 |
DiagCheck.DIAG_ERROR,
|
|
460 |
added(VALID),
|
|
461 |
ste(string, VALID, RECOVERABLE_DEFINED, false, null));
|
|
462 |
assertEvalUnresolvedException("string();", "string", 0, 1);
|
|
463 |
assertActiveKeys();
|
|
464 |
}
|
|
465 |
|
|
466 |
public void testForwardSingleImportFieldToMethod() {
|
|
467 |
DeclarationSnippet pi = methodKey(assertEval("double pi() { return PI; }",
|
|
468 |
added(RECOVERABLE_DEFINED)));
|
|
469 |
assertUnresolvedDependencies1(pi, RECOVERABLE_DEFINED, "variable PI");
|
|
470 |
assertEvalUnresolvedException("pi();", "pi", 1, 0);
|
|
471 |
assertEval("import static java.lang.Math.PI;",
|
|
472 |
added(VALID),
|
|
473 |
ste(pi, RECOVERABLE_DEFINED, VALID, false, null));
|
|
474 |
assertEval("Math.abs(pi() - 3.1415) < 0.001;", "true");
|
|
475 |
|
|
476 |
assertEval("String PI;",
|
|
477 |
DiagCheck.DIAG_OK,
|
|
478 |
DiagCheck.DIAG_ERROR,
|
|
479 |
added(VALID),
|
|
480 |
ste(pi, VALID, RECOVERABLE_DEFINED, false, null));
|
|
481 |
assertEvalUnresolvedException("pi();", "pi", 0, 1);
|
|
482 |
assertActiveKeys();
|
|
483 |
}
|
|
484 |
|
|
485 |
public void testForwardImportFieldOnDemandToMethod() {
|
|
486 |
DeclarationSnippet pi = methodKey(assertEval("double pi() { return PI; }",
|
|
487 |
added(RECOVERABLE_DEFINED)));
|
|
488 |
assertUnresolvedDependencies1(pi, RECOVERABLE_DEFINED, "variable PI");
|
|
489 |
assertEvalUnresolvedException("pi();", "pi", 1, 0);
|
|
490 |
assertEval("import static java.lang.Math.*;",
|
|
491 |
added(VALID),
|
|
492 |
ste(pi, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET));
|
|
493 |
assertEval("Math.abs(pi() - 3.1415) < 0.001;", "true");
|
|
494 |
|
|
495 |
assertEval("String PI;",
|
|
496 |
DiagCheck.DIAG_OK,
|
|
497 |
DiagCheck.DIAG_ERROR,
|
|
498 |
added(VALID),
|
|
499 |
ste(pi, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
|
|
500 |
assertEvalUnresolvedException("pi();", "pi", 0, 1);
|
|
501 |
assertActiveKeys();
|
|
502 |
}
|
|
503 |
|
|
504 |
public void testForwardSingleImportMethodToClass1() {
|
|
505 |
PersistentSnippet a = classKey(assertEval("class A { String s = format(\"%d\", 10); }",
|
|
506 |
added(RECOVERABLE_NOT_DEFINED)));
|
|
507 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
508 |
assertEval("import static java.lang.String.format;",
|
|
509 |
added(VALID),
|
|
510 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
|
|
511 |
assertEval("new A().s;", "\"10\"");
|
|
512 |
PersistentSnippet format = methodKey(assertEval("void format(String s, int d) { }",
|
|
513 |
DiagCheck.DIAG_OK,
|
|
514 |
DiagCheck.DIAG_ERROR,
|
|
515 |
added(VALID),
|
|
516 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET)));
|
|
517 |
assertDeclareFail("new A().s;", "compiler.err.cant.resolve.location");
|
|
518 |
assertActiveKeys();
|
|
519 |
assertDrop(format,
|
|
520 |
ste(format, VALID, DROPPED, true, null),
|
|
521 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, format));
|
|
522 |
}
|
|
523 |
|
|
524 |
public void testForwardSingleImportMethodToClass2() {
|
|
525 |
PersistentSnippet a = classKey(assertEval("class A { String s() { return format(\"%d\", 10); } }",
|
|
526 |
added(RECOVERABLE_NOT_DEFINED)));
|
|
527 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
528 |
assertEval("import static java.lang.String.format;",
|
|
529 |
added(VALID),
|
|
530 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
|
|
531 |
assertEval("new A().s();", "\"10\"");
|
|
532 |
PersistentSnippet format = methodKey(assertEval("void format(String s, int d) { }",
|
|
533 |
DiagCheck.DIAG_OK,
|
|
534 |
DiagCheck.DIAG_ERROR,
|
|
535 |
added(VALID),
|
|
536 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
|
|
537 |
assertDeclareFail("new A().s();", "compiler.err.cant.resolve.location");
|
|
538 |
assertActiveKeys();
|
|
539 |
assertDrop(format,
|
|
540 |
ste(format, VALID, DROPPED, true, null),
|
|
541 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, format));
|
|
542 |
}
|
|
543 |
|
|
544 |
public void testForwardSingleImportClassToClass1() {
|
|
545 |
PersistentSnippet a = classKey(assertEval("class A { static List<Integer> list; }",
|
|
546 |
added(RECOVERABLE_NOT_DEFINED)));
|
|
547 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
548 |
assertEval("import java.util.List;",
|
|
549 |
added(VALID),
|
|
550 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
|
|
551 |
assertEval("import java.util.Arrays;", added(VALID));
|
|
552 |
assertEval("A.list = Arrays.asList(1, 2, 3);", "[1, 2, 3]");
|
|
553 |
|
|
554 |
PersistentSnippet list = classKey(assertEval("class List {}",
|
|
555 |
DiagCheck.DIAG_OK,
|
|
556 |
DiagCheck.DIAG_ERROR,
|
|
557 |
added(VALID),
|
|
558 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
|
|
559 |
assertDeclareFail("A.list = Arrays.asList(1, 2, 3);", "compiler.err.already.defined.static.single.import");
|
|
560 |
assertActiveKeys();
|
|
561 |
assertDrop(list,
|
|
562 |
ste(list, VALID, DROPPED, true, null),
|
|
563 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, list));
|
|
564 |
}
|
|
565 |
|
|
566 |
public void testForwardSingleImportClassToClass2() {
|
|
567 |
PersistentSnippet clsA = classKey(assertEval("class A extends ArrayList<Integer> { }",
|
|
568 |
added(RECOVERABLE_NOT_DEFINED)));
|
|
569 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
570 |
assertEval("import java.util.ArrayList;",
|
|
571 |
added(VALID),
|
|
572 |
ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, MAIN_SNIPPET));
|
|
573 |
Snippet vara = varKey(assertEval("A a = new A();", "[]"));
|
|
574 |
|
|
575 |
PersistentSnippet arraylist = classKey(assertEval("class ArrayList {}",
|
|
576 |
DiagCheck.DIAG_OK,
|
|
577 |
DiagCheck.DIAG_ERROR,
|
|
578 |
added(VALID),
|
|
579 |
ste(clsA, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET),
|
|
580 |
ste(vara, VALID, RECOVERABLE_NOT_DEFINED, true, clsA)));
|
|
581 |
assertDeclareFail("A a = new A();", "compiler.err.cant.resolve.location",
|
|
582 |
ste(MAIN_SNIPPET, RECOVERABLE_NOT_DEFINED, REJECTED, false, null),
|
|
583 |
ste(vara, RECOVERABLE_NOT_DEFINED, OVERWRITTEN, false, MAIN_SNIPPET));
|
|
584 |
assertActiveKeys();
|
|
585 |
assertDrop(arraylist,
|
|
586 |
ste(arraylist, VALID, DROPPED, true, null),
|
|
587 |
ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, arraylist));
|
|
588 |
}
|
|
589 |
|
|
590 |
public void testForwardImportOnDemandMethodToClass1() {
|
|
591 |
PersistentSnippet a = classKey(assertEval("class A { String s = format(\"%d\", 10); }",
|
|
592 |
added(RECOVERABLE_NOT_DEFINED)));
|
|
593 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
594 |
assertEval("import static java.lang.String.*;",
|
|
595 |
added(VALID),
|
|
596 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
|
|
597 |
assertEval("new A().s;", "\"10\"");
|
|
598 |
PersistentSnippet format = methodKey(assertEval("void format(String s, int d) { }",
|
|
599 |
DiagCheck.DIAG_OK,
|
|
600 |
DiagCheck.DIAG_ERROR,
|
|
601 |
added(VALID),
|
|
602 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
|
|
603 |
assertDeclareFail("new A().s;", "compiler.err.cant.resolve.location");
|
|
604 |
assertActiveKeys();
|
|
605 |
assertDrop(format,
|
|
606 |
ste(format, VALID, DROPPED, true, null),
|
|
607 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, format));
|
|
608 |
}
|
|
609 |
|
|
610 |
public void testForwardImportOnDemandMethodToClass2() {
|
|
611 |
PersistentSnippet a = classKey(assertEval("class A { String s() { return format(\"%d\", 10); } }",
|
|
612 |
added(RECOVERABLE_NOT_DEFINED)));
|
|
613 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
614 |
assertEval("import static java.lang.String.*;",
|
|
615 |
added(VALID),
|
|
616 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
|
|
617 |
assertEval("new A().s();", "\"10\"");
|
|
618 |
PersistentSnippet format = methodKey(assertEval("void format(String s, int d) { }",
|
|
619 |
DiagCheck.DIAG_OK,
|
|
620 |
DiagCheck.DIAG_ERROR,
|
|
621 |
added(VALID),
|
|
622 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
|
|
623 |
assertDeclareFail("new A().s();", "compiler.err.cant.resolve.location");
|
|
624 |
assertActiveKeys();
|
|
625 |
assertDrop(format,
|
|
626 |
ste(format, VALID, DROPPED, true, null),
|
|
627 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, format));
|
|
628 |
}
|
|
629 |
|
|
630 |
public void testForwardImportOnDemandClassToClass1() {
|
|
631 |
PersistentSnippet a = classKey(assertEval("class A { static List<Integer> list; }",
|
|
632 |
added(RECOVERABLE_NOT_DEFINED)));
|
|
633 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
634 |
assertEval("import java.util.*;",
|
|
635 |
added(VALID),
|
|
636 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
|
|
637 |
assertEval("A.list = Arrays.asList(1, 2, 3);", "[1, 2, 3]");
|
|
638 |
|
|
639 |
PersistentSnippet list = classKey(assertEval("class List {}",
|
|
640 |
DiagCheck.DIAG_OK,
|
|
641 |
DiagCheck.DIAG_ERROR,
|
|
642 |
added(VALID),
|
|
643 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
|
|
644 |
assertDeclareFail("A.list = Arrays.asList(1, 2, 3);", "compiler.err.cant.resolve.location");
|
|
645 |
assertActiveKeys();
|
|
646 |
assertDrop(list,
|
|
647 |
ste(list, VALID, DROPPED, true, null),
|
|
648 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, list));
|
|
649 |
}
|
|
650 |
|
|
651 |
public void testForwardImportOnDemandClassToClass2() {
|
|
652 |
PersistentSnippet clsA = classKey(assertEval("class A extends ArrayList<Integer> { }",
|
|
653 |
added(RECOVERABLE_NOT_DEFINED)));
|
|
654 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
655 |
assertEval("import java.util.*;",
|
|
656 |
added(VALID),
|
|
657 |
ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, MAIN_SNIPPET));
|
|
658 |
Snippet vara = varKey(assertEval("A a = new A();", "[]"));
|
|
659 |
|
|
660 |
PersistentSnippet arraylist = classKey(assertEval("class ArrayList {}",
|
|
661 |
DiagCheck.DIAG_OK,
|
|
662 |
DiagCheck.DIAG_ERROR,
|
|
663 |
added(VALID),
|
|
664 |
ste(clsA, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET),
|
|
665 |
ste(vara, VALID, RECOVERABLE_NOT_DEFINED, true, clsA)));
|
|
666 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
667 |
assertActiveKeys();
|
|
668 |
assertDrop(arraylist,
|
|
669 |
ste(arraylist, VALID, DROPPED, true, null),
|
|
670 |
ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, arraylist),
|
|
671 |
ste(vara, RECOVERABLE_NOT_DEFINED, VALID, true, clsA));
|
|
672 |
}
|
|
673 |
|
|
674 |
public void testForwardSingleImportFieldToClass1() {
|
|
675 |
PersistentSnippet a = classKey(assertEval("class A { static double pi() { return PI; } }",
|
|
676 |
added(RECOVERABLE_NOT_DEFINED)));
|
|
677 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
678 |
assertEval("import static java.lang.Math.PI;",
|
|
679 |
added(VALID),
|
|
680 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
|
|
681 |
assertEval("Math.abs(A.pi() - 3.1415) < 0.001;", "true");
|
|
682 |
|
|
683 |
PersistentSnippet list = varKey(assertEval("String PI;",
|
|
684 |
DiagCheck.DIAG_OK,
|
|
685 |
DiagCheck.DIAG_ERROR,
|
|
686 |
added(VALID),
|
|
687 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
|
|
688 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
689 |
assertActiveKeys();
|
|
690 |
assertDrop(list,
|
|
691 |
ste(list, VALID, DROPPED, true, null),
|
|
692 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, list));
|
|
693 |
}
|
|
694 |
|
|
695 |
public void testForwardSingleImportFieldToClass2() {
|
|
696 |
PersistentSnippet a = classKey(assertEval("class A { static double pi = PI; }",
|
|
697 |
added(RECOVERABLE_NOT_DEFINED)));
|
|
698 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
699 |
assertEval("import static java.lang.Math.PI;",
|
|
700 |
added(VALID),
|
|
701 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
|
|
702 |
assertEval("Math.abs(A.pi - 3.1415) < 0.001;", "true");
|
|
703 |
|
|
704 |
PersistentSnippet list = varKey(assertEval("String PI;",
|
|
705 |
DiagCheck.DIAG_OK,
|
|
706 |
DiagCheck.DIAG_ERROR,
|
|
707 |
added(VALID),
|
|
708 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
|
|
709 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
710 |
assertActiveKeys();
|
|
711 |
assertDrop(list,
|
|
712 |
ste(list, VALID, DROPPED, true, null),
|
|
713 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, list));
|
|
714 |
}
|
|
715 |
|
|
716 |
public void testForwardImportOnDemandFieldToClass1() {
|
|
717 |
PersistentSnippet a = classKey(assertEval("class A { static double pi() { return PI; } }",
|
|
718 |
added(RECOVERABLE_NOT_DEFINED)));
|
|
719 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
720 |
assertEval("import static java.lang.Math.*;",
|
|
721 |
added(VALID),
|
|
722 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
|
|
723 |
assertEval("Math.abs(A.pi() - 3.1415) < 0.001;", "true");
|
|
724 |
|
|
725 |
PersistentSnippet list = varKey(assertEval("String PI;",
|
|
726 |
DiagCheck.DIAG_OK,
|
|
727 |
DiagCheck.DIAG_ERROR,
|
|
728 |
added(VALID),
|
|
729 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
|
|
730 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
731 |
assertActiveKeys();
|
|
732 |
assertDrop(list,
|
|
733 |
ste(list, VALID, DROPPED, true, null),
|
|
734 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, list));
|
|
735 |
}
|
|
736 |
|
|
737 |
public void testForwardImportOnDemandFieldToClass2() {
|
|
738 |
PersistentSnippet a = classKey(assertEval("class A { static double pi = PI; }",
|
|
739 |
added(RECOVERABLE_NOT_DEFINED)));
|
|
740 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
741 |
assertEval("import static java.lang.Math.*;",
|
|
742 |
added(VALID),
|
|
743 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
|
|
744 |
assertEval("Math.abs(A.pi - 3.1415) < 0.001;", "true");
|
|
745 |
|
|
746 |
PersistentSnippet list = varKey(assertEval("String PI;",
|
|
747 |
DiagCheck.DIAG_OK,
|
|
748 |
DiagCheck.DIAG_ERROR,
|
|
749 |
added(VALID),
|
|
750 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
|
|
751 |
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
|
|
752 |
assertActiveKeys();
|
|
753 |
assertDrop(list,
|
|
754 |
ste(list, VALID, DROPPED, true, null),
|
|
755 |
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, list));
|
|
756 |
}
|
|
757 |
|
|
758 |
public void testReplaceCausesMethodReferenceError() {
|
|
759 |
Snippet l = classKey(assertEval("interface Logger { public void log(String message); }", added(VALID)));
|
|
760 |
Snippet v = varKey(assertEval("Logger l = System.out::println;", added(VALID)));
|
|
761 |
assertEval("interface Logger { public boolean accept(String message); }",
|
|
762 |
DiagCheck.DIAG_OK,
|
|
763 |
DiagCheck.DIAG_ERROR,
|
|
764 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
765 |
ste(l, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
766 |
ste(v, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
|
|
767 |
}
|
|
768 |
|
|
769 |
public void testReplaceCausesClassCompilationError() {
|
|
770 |
Snippet l = classKey(assertEval("interface L { }", added(VALID)));
|
|
771 |
Snippet c = classKey(assertEval("class C implements L { }", added(VALID)));
|
|
772 |
assertEval("interface L { void m(); }",
|
|
773 |
DiagCheck.DIAG_OK,
|
|
774 |
DiagCheck.DIAG_ERROR,
|
|
775 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
776 |
ste(l, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
777 |
ste(c, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
|
|
778 |
}
|
|
779 |
|
|
780 |
public void testOverwriteNoUpdate() {
|
|
781 |
String xsi = "int x = 5;";
|
|
782 |
String xsd = "double x = 3.14159;";
|
|
783 |
VarSnippet xi = varKey(assertEval(xsi, added(VALID)));
|
|
784 |
String ms1 = "double m(Integer i) { return i + x; }";
|
|
785 |
String ms2 = "double m(java.lang.Integer i) { return i + x; }";
|
|
786 |
MethodSnippet k1 = methodKey(assertEval(ms1, added(VALID)));
|
|
787 |
VarSnippet xd = varKey(assertEval(xsd,
|
|
788 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
789 |
ste(xi, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
790 |
ste(k1, VALID, VALID, false, MAIN_SNIPPET)));
|
|
791 |
MethodSnippet k2 = methodKey(assertEval(ms2,
|
|
792 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), //TODO: technically, should be false
|
|
793 |
ste(k1, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
|
|
794 |
VarSnippet xi2 = varKey(assertEval(xsi,
|
|
795 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
796 |
ste(xd, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
797 |
ste(k2, VALID, VALID, false, MAIN_SNIPPET)));
|
|
798 |
varKey(assertEval(xsd,
|
|
799 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
800 |
ste(xi2, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
801 |
ste(k2, VALID, VALID, false, MAIN_SNIPPET)));
|
|
802 |
}
|
|
803 |
}
|