Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/jdk/jshell/DropTest.java
40931 views
1
/*
2
* Copyright (c) 2015, 2016, 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
* @bug 8081431 8080069 8167128 8199623
27
* @summary Test of JShell#drop().
28
* @build KullaTesting TestingInputStream
29
* @run testng DropTest
30
*/
31
32
import jdk.jshell.DeclarationSnippet;
33
import jdk.jshell.Snippet;
34
import jdk.jshell.MethodSnippet;
35
import jdk.jshell.VarSnippet;
36
import org.testng.annotations.Test;
37
38
import static jdk.jshell.Snippet.Status.*;
39
40
@Test
41
public class DropTest extends KullaTesting {
42
43
public void testDrop() {
44
Snippet var = varKey(assertEval("int x;"));
45
Snippet method = methodKey(assertEval("int mu() { return x * 4; }"));
46
Snippet clazz = classKey(assertEval("class C { String v() { return \"#\" + mu(); } }"));
47
assertDrop(var,
48
ste(var, VALID, DROPPED, true, null),
49
ste(method, VALID, RECOVERABLE_DEFINED, false, var));
50
assertDrop(method,
51
ste(method, RECOVERABLE_DEFINED, DROPPED, true, null),
52
ste(clazz, VALID, RECOVERABLE_DEFINED, false, method));
53
VarSnippet cc = varKey(assertEval("C c;"));
54
assertEvalUnresolvedException("new C();", "C", 1, 0);
55
assertVariables();
56
assertMethods();
57
assertClasses();
58
assertActiveKeys();
59
60
method = methodKey(assertEval("int mu() { return x * 4; }",
61
added(RECOVERABLE_DEFINED),
62
ste(clazz, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET)));
63
assertEval("int x = 10;", "10",
64
added(VALID),
65
ste(method, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET));
66
Snippet c0 = varKey(assertEval("C c0 = new C();"));
67
assertEval("c0.v();", "\"#40\"");
68
assertEval("C c = new C();",
69
ste(MAIN_SNIPPET, VALID, VALID, false, null),
70
ste(cc, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
71
assertEval("c.v();", "\"#40\"");
72
assertEval("int mu() { return x * 3; }",
73
ste(MAIN_SNIPPET, VALID, VALID, false, null),
74
ste(method, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
75
assertEval("c.v();", "\"#30\"");
76
assertEval("class C { String v() { return \"@\" + mu(); } }",
77
ste(MAIN_SNIPPET, VALID, VALID, false, null),
78
ste(clazz, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
79
assertEval("c0.v();", "\"@30\"");
80
assertDrop(c0,
81
ste(c0, VALID, DROPPED, true, null));
82
assertEval("c = new C();");
83
assertEval("c.v();", "\"@30\"");
84
85
assertVariables();
86
assertMethods();
87
assertClasses();
88
assertActiveKeys();
89
}
90
91
public void testDropImport() {
92
Snippet imp = importKey(assertEval("import java.util.*;"));
93
Snippet decl = varKey(
94
assertEval("List<Integer> list = Arrays.asList(1, 2, 3);", "[1, 2, 3]"));
95
assertEval("list;", "[1, 2, 3]");
96
assertDrop(imp,
97
DiagCheck.DIAG_OK,
98
DiagCheck.DIAG_ERROR,
99
ste(imp, VALID, DROPPED, true, null),
100
ste(decl, VALID, RECOVERABLE_NOT_DEFINED, true, imp));
101
assertDeclareFail("list;", "compiler.err.cant.resolve.location");
102
}
103
104
public void testDropStatement() {
105
Snippet x = key(assertEval("if (true);"));
106
assertDrop(x, ste(x, VALID, DROPPED, true, null));
107
}
108
109
public void testDropVarToMethod() {
110
Snippet x = varKey(assertEval("int x;"));
111
DeclarationSnippet method = methodKey(assertEval("double mu() { return x * 4; }"));
112
assertEval("x == 0;", "true");
113
assertEval("mu() == 0.0;", "true");
114
115
assertDrop(x,
116
ste(x, VALID, DROPPED, true, null),
117
ste(method, VALID, RECOVERABLE_DEFINED, false, x));
118
assertUnresolvedDependencies1(method, RECOVERABLE_DEFINED, "variable x");
119
assertEvalUnresolvedException("mu();", "mu", 1, 0);
120
121
assertVariables();
122
assertMethods();
123
assertActiveKeys();
124
}
125
126
public void testDropMethodToMethod() {
127
Snippet a = methodKey(assertEval("double a() { return 2; }"));
128
DeclarationSnippet b = methodKey(assertEval("double b() { return a() * 10; }"));
129
assertEval("double c() { return b() * 3; }");
130
DeclarationSnippet d = methodKey(assertEval("double d() { return c() + 1000; }"));
131
assertEval("d();", "1060.0");
132
assertDrop(a,
133
ste(a, VALID, DROPPED, true, null),
134
ste(b, VALID, RECOVERABLE_DEFINED, false, a));
135
assertUnresolvedDependencies1(b, RECOVERABLE_DEFINED, "method a()");
136
assertUnresolvedDependencies(d, 0);
137
assertEvalUnresolvedException("d();", "b", 1, 0);
138
assertMethods();
139
assertActiveKeys();
140
}
141
142
public void testDropClassToMethod() {
143
Snippet c = classKey(assertEval("class C { int f() { return 7; } }"));
144
DeclarationSnippet m = methodKey(assertEval("int m() { return new C().f(); }"));
145
assertDrop(c,
146
ste(c, VALID, DROPPED, true, null),
147
ste(m, VALID, RECOVERABLE_DEFINED, false, c));
148
assertUnresolvedDependencies1(m, RECOVERABLE_DEFINED, "class C");
149
assertEvalUnresolvedException("m();", "m", 1, 0);
150
assertActiveKeys();
151
}
152
153
public void testDropVarToClass() {
154
Snippet x = varKey(assertEval("int x;"));
155
DeclarationSnippet a = classKey(assertEval("class A { double a = 4 * x; }"));
156
assertDrop(x,
157
DiagCheck.DIAG_OK,
158
DiagCheck.DIAG_ERROR,
159
ste(x, VALID, DROPPED, true, null),
160
ste(a, VALID, RECOVERABLE_DEFINED, false, x));
161
assertEval("A foo() { return null; }");
162
assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable x");
163
assertEvalUnresolvedException("new A();", "A", 1, 0);
164
assertVariables();
165
assertActiveKeys();
166
}
167
168
public void testDropMethodToClass() {
169
Snippet x = methodKey(assertEval("int x() { return 0; }"));
170
DeclarationSnippet a = classKey(assertEval("class A { double a = 4 * x(); }"));
171
assertDrop(x,
172
DiagCheck.DIAG_OK,
173
DiagCheck.DIAG_ERROR,
174
ste(x, VALID, DROPPED, true, null),
175
ste(a, VALID, RECOVERABLE_DEFINED, false, x));
176
assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "method x()");
177
assertEvalUnresolvedException("new A();", "A", 1, 0);
178
assertMethods();
179
assertActiveKeys();
180
}
181
182
public void testDropClassToClass() {
183
Snippet a = classKey(assertEval("class A {}"));
184
Snippet b = classKey(assertEval("class B extends A {}"));
185
Snippet c = classKey(assertEval("class C extends B {}"));
186
Snippet d = classKey(assertEval("class D extends C {}"));
187
assertDrop(a,
188
DiagCheck.DIAG_OK,
189
DiagCheck.DIAG_ERROR,
190
ste(a, VALID, DROPPED, true, null),
191
ste(b, VALID, RECOVERABLE_NOT_DEFINED, true, a),
192
ste(c, VALID, RECOVERABLE_NOT_DEFINED, true, b),
193
ste(d, VALID, RECOVERABLE_NOT_DEFINED, true, c));
194
assertUnresolvedDependencies1((DeclarationSnippet) b, RECOVERABLE_NOT_DEFINED, "class A");
195
assertDrop(c,
196
DiagCheck.DIAG_OK,
197
DiagCheck.DIAG_ERROR,
198
ste(c, RECOVERABLE_NOT_DEFINED, DROPPED, false, null));
199
assertEval("interface A {}", null, null,
200
DiagCheck.DIAG_OK,
201
DiagCheck.DIAG_ERROR,
202
added(VALID));
203
assertClasses();
204
assertActiveKeys();
205
}
206
207
public void testDropNoUpdate() {
208
String as1 = "class A {}";
209
String as2 = "class A extends java.util.ArrayList<Boolean> {}";
210
Snippet a = classKey(assertEval(as1, added(VALID)));
211
Snippet b = classKey(assertEval("class B extends A {}", added(VALID)));
212
Snippet ax = classKey(assertEval(as2,
213
ste(MAIN_SNIPPET, VALID, VALID, true, null),
214
ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
215
ste(b, VALID, VALID, true, MAIN_SNIPPET)));
216
ax = classKey(assertEval(as1,
217
ste(MAIN_SNIPPET, VALID, VALID, true, null),
218
ste(ax, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
219
ste(b, VALID, VALID, true, MAIN_SNIPPET)));
220
assertDrop(b,
221
ste(b, VALID, DROPPED, true, null));
222
ax = classKey(assertEval(as2,
223
ste(MAIN_SNIPPET, VALID, VALID, true, null),
224
ste(ax, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
225
assertEval(as1,
226
ste(MAIN_SNIPPET, VALID, VALID, true, null),
227
ste(ax, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
228
}
229
230
// 8199623
231
public void testTwoForkedDrop() {
232
MethodSnippet p = methodKey(assertEval("void p() throws Exception { ((String) null).toString(); }"));
233
MethodSnippet n = methodKey(assertEval("void n() throws Exception { try { p(); } catch (Exception ex) { throw new RuntimeException(\"bar\", ex); }}"));
234
MethodSnippet m = methodKey(assertEval("void m() { try { n(); } catch (Exception ex) { throw new RuntimeException(\"foo\", ex); }}"));
235
MethodSnippet c = methodKey(assertEval("void c() throws Throwable { p(); }"));
236
assertDrop(p,
237
ste(p, VALID, DROPPED, true, null),
238
ste(n, VALID, RECOVERABLE_DEFINED, false, p),
239
ste(c, VALID, RECOVERABLE_DEFINED, false, p));
240
assertActiveKeys();
241
}
242
}
243
244