author | coleenp |
Wed, 15 Nov 2017 08:14:31 -0500 | |
changeset 47894 | 352b17f62ff7 |
parent 47216 | 71c04702a3d5 |
child 48208 | 0a8db756a7e7 |
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. |
|
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 |
|
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
26 |
* @bug 8145239 8129559 8080354 |
33362 | 27 |
* @summary Tests for EvaluationState.classes |
28 |
* @build KullaTesting TestingInputStream ExpectedDiagnostic |
|
29 |
* @run testng ClassesTest |
|
30 |
*/ |
|
31 |
||
32 |
import java.util.ArrayList; |
|
33 |
import java.util.List; |
|
34 |
||
35 |
import javax.tools.Diagnostic; |
|
36 |
||
37 |
import jdk.jshell.Snippet; |
|
38 |
import jdk.jshell.TypeDeclSnippet; |
|
39 |
import jdk.jshell.VarSnippet; |
|
40 |
import org.testng.annotations.DataProvider; |
|
41 |
import org.testng.annotations.Test; |
|
42 |
||
43 |
import jdk.jshell.Diag; |
|
40304
0318f4e75c6d
8143964: JShell API: convert query responses to Stream instead of List
rfield
parents:
37644
diff
changeset
|
44 |
import static java.util.stream.Collectors.toList; |
33362 | 45 |
import static jdk.jshell.Snippet.Status.VALID; |
46 |
import static jdk.jshell.Snippet.Status.RECOVERABLE_NOT_DEFINED; |
|
36499 | 47 |
import static jdk.jshell.Snippet.Status.RECOVERABLE_DEFINED; |
33362 | 48 |
import static jdk.jshell.Snippet.Status.DROPPED; |
49 |
import static jdk.jshell.Snippet.Status.REJECTED; |
|
36499 | 50 |
import static jdk.jshell.Snippet.Status.OVERWRITTEN; |
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
36499
diff
changeset
|
51 |
import static jdk.jshell.Snippet.Status.NONEXISTENT; |
33362 | 52 |
import static jdk.jshell.Snippet.SubKind.*; |
53 |
import static org.testng.Assert.assertEquals; |
|
54 |
import static org.testng.Assert.assertTrue; |
|
55 |
||
56 |
@Test |
|
57 |
public class ClassesTest extends KullaTesting { |
|
58 |
||
59 |
public void noClasses() { |
|
60 |
assertNumberOfActiveClasses(0); |
|
61 |
} |
|
62 |
||
63 |
public void testSignature1() { |
|
64 |
TypeDeclSnippet c1 = classKey(assertEval("class A extends B {}", added(RECOVERABLE_NOT_DEFINED))); |
|
65 |
assertTypeDeclSnippet(c1, "A", RECOVERABLE_NOT_DEFINED, CLASS_SUBKIND, 1, 0); |
|
66 |
TypeDeclSnippet c2 = classKey(assertEval("@interface A { Class<B> f() default B.class; }", |
|
67 |
ste(MAIN_SNIPPET, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, null), |
|
68 |
ste(c1, RECOVERABLE_NOT_DEFINED, OVERWRITTEN, false, MAIN_SNIPPET))); |
|
69 |
assertTypeDeclSnippet(c2, "A", RECOVERABLE_NOT_DEFINED, ANNOTATION_TYPE_SUBKIND, 1, 0); |
|
70 |
TypeDeclSnippet c3 = classKey(assertEval("enum A {; private A(B b) {} }", |
|
71 |
ste(MAIN_SNIPPET, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, null), |
|
72 |
ste(c2, RECOVERABLE_NOT_DEFINED, OVERWRITTEN, false, MAIN_SNIPPET))); |
|
73 |
assertTypeDeclSnippet(c3, "A", RECOVERABLE_NOT_DEFINED, ENUM_SUBKIND, 1, 0); |
|
74 |
TypeDeclSnippet c4 = classKey(assertEval("interface A extends B {}", |
|
75 |
ste(MAIN_SNIPPET, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, null), |
|
76 |
ste(c3, RECOVERABLE_NOT_DEFINED, OVERWRITTEN, false, MAIN_SNIPPET))); |
|
77 |
assertTypeDeclSnippet(c4, "A", RECOVERABLE_NOT_DEFINED, INTERFACE_SUBKIND, 1, 0); |
|
78 |
TypeDeclSnippet c5 = classKey(assertEval("class A { void f(B b) {} }", |
|
79 |
ste(MAIN_SNIPPET, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, null), |
|
80 |
ste(c4, RECOVERABLE_NOT_DEFINED, OVERWRITTEN, false, MAIN_SNIPPET))); |
|
81 |
assertTypeDeclSnippet(c5, "A", RECOVERABLE_NOT_DEFINED, CLASS_SUBKIND, 1, 0); |
|
82 |
} |
|
83 |
||
84 |
public void testSignature2() { |
|
85 |
TypeDeclSnippet c1 = (TypeDeclSnippet) assertDeclareFail("class A { void f() { return g(); } }", "compiler.err.prob.found.req"); |
|
86 |
assertTypeDeclSnippet(c1, "A", REJECTED, CLASS_SUBKIND, 0, 2); |
|
87 |
TypeDeclSnippet c2 = classKey(assertEval("class A { int f() { return g(); } }", |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
36499
diff
changeset
|
88 |
ste(c1, NONEXISTENT, RECOVERABLE_DEFINED, true, null))); |
36499 | 89 |
assertTypeDeclSnippet(c2, "A", RECOVERABLE_DEFINED, CLASS_SUBKIND, 1, 0); |
33362 | 90 |
assertDrop(c2, |
36499 | 91 |
ste(c2, RECOVERABLE_DEFINED, DROPPED, true, null)); |
33362 | 92 |
} |
93 |
||
94 |
public void classDeclaration() { |
|
95 |
assertEval("class A { }"); |
|
96 |
assertClasses(clazz(KullaTesting.ClassType.CLASS, "A")); |
|
97 |
} |
|
98 |
||
99 |
||
100 |
public void interfaceDeclaration() { |
|
101 |
assertEval("interface A { }"); |
|
102 |
assertClasses(clazz(KullaTesting.ClassType.INTERFACE, "A")); |
|
103 |
} |
|
104 |
||
105 |
public void annotationDeclaration() { |
|
106 |
assertEval("@interface A { }"); |
|
107 |
assertClasses(clazz(KullaTesting.ClassType.ANNOTATION, "A")); |
|
108 |
} |
|
109 |
||
110 |
public void enumDeclaration() { |
|
111 |
assertEval("enum A { }"); |
|
112 |
assertClasses(clazz(KullaTesting.ClassType.ENUM, "A")); |
|
113 |
} |
|
114 |
||
115 |
public void classesDeclaration() { |
|
116 |
assertEval("interface A { }"); |
|
117 |
assertEval("class B implements A { }"); |
|
118 |
assertEval("interface C extends A { }"); |
|
119 |
assertEval("enum D implements C { }"); |
|
120 |
assertEval("@interface E { }"); |
|
121 |
assertClasses( |
|
122 |
clazz(KullaTesting.ClassType.INTERFACE, "A"), |
|
123 |
clazz(KullaTesting.ClassType.CLASS, "B"), |
|
124 |
clazz(KullaTesting.ClassType.INTERFACE, "C"), |
|
125 |
clazz(KullaTesting.ClassType.ENUM, "D"), |
|
126 |
clazz(KullaTesting.ClassType.ANNOTATION, "E")); |
|
127 |
assertActiveKeys(); |
|
128 |
} |
|
129 |
||
130 |
public void classesRedeclaration1() { |
|
131 |
Snippet a = classKey(assertEval("class A { }")); |
|
132 |
Snippet b = classKey(assertEval("interface B { }")); |
|
133 |
assertClasses(clazz(KullaTesting.ClassType.CLASS, "A"), clazz(KullaTesting.ClassType.INTERFACE, "B")); |
|
134 |
assertActiveKeys(); |
|
135 |
||
136 |
assertEval("interface A { }", |
|
137 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
138 |
ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
139 |
assertClasses(clazz(KullaTesting.ClassType.INTERFACE, "A"), |
|
140 |
clazz(KullaTesting.ClassType.INTERFACE, "B")); |
|
141 |
assertActiveKeys(); |
|
142 |
||
143 |
assertEval("interface B { } //again", |
|
144 |
ste(MAIN_SNIPPET, VALID, VALID, false, null), |
|
145 |
ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
146 |
assertClasses(clazz(KullaTesting.ClassType.INTERFACE, "A"), |
|
147 |
clazz(KullaTesting.ClassType.INTERFACE, "B")); |
|
148 |
assertActiveKeys(); |
|
149 |
} |
|
150 |
||
151 |
public void classesRedeclaration2() { |
|
152 |
assertEval("class A { }"); |
|
153 |
assertClasses(clazz(KullaTesting.ClassType.CLASS, "A")); |
|
154 |
assertActiveKeys(); |
|
155 |
||
156 |
Snippet b = classKey(assertEval("class B extends A { }")); |
|
157 |
assertClasses(clazz(KullaTesting.ClassType.CLASS, "A"), |
|
158 |
clazz(KullaTesting.ClassType.CLASS, "B")); |
|
159 |
assertActiveKeys(); |
|
160 |
||
161 |
Snippet c = classKey(assertEval("class C extends B { }")); |
|
162 |
assertClasses(clazz(KullaTesting.ClassType.CLASS, "A"), |
|
163 |
clazz(KullaTesting.ClassType.CLASS, "B"), clazz(KullaTesting.ClassType.CLASS, "C")); |
|
164 |
assertActiveKeys(); |
|
165 |
||
166 |
assertEval("interface B { }", |
|
167 |
DiagCheck.DIAG_OK, |
|
168 |
DiagCheck.DIAG_ERROR, |
|
169 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
170 |
ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET), |
|
171 |
ste(c, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET)); |
|
172 |
assertClasses(clazz(KullaTesting.ClassType.CLASS, "A"), |
|
173 |
clazz(KullaTesting.ClassType.INTERFACE, "B"), clazz(KullaTesting.ClassType.CLASS, "C")); |
|
174 |
assertEval("new C();", |
|
175 |
DiagCheck.DIAG_ERROR, |
|
176 |
DiagCheck.DIAG_ERROR, |
|
177 |
added(REJECTED)); |
|
178 |
assertActiveKeys(); |
|
179 |
} |
|
180 |
||
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
36499
diff
changeset
|
181 |
//8154496: test3 update: sig change should false |
34857
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
182 |
public void classesRedeclaration3() { |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
183 |
Snippet a = classKey(assertEval("class A { }")); |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
184 |
assertClasses(clazz(KullaTesting.ClassType.CLASS, "A")); |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
185 |
assertActiveKeys(); |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
186 |
|
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
187 |
Snippet test1 = methodKey(assertEval("A test() { return null; }")); |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
188 |
Snippet test2 = methodKey(assertEval("void test(A a) { }")); |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
189 |
Snippet test3 = methodKey(assertEval("void test(int n) {A a;}")); |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
190 |
assertActiveKeys(); |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
191 |
|
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
192 |
assertEval("interface A { }", |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
193 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
194 |
ste(test1, VALID, VALID, true, MAIN_SNIPPET), |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
195 |
ste(test2, VALID, VALID, true, MAIN_SNIPPET), |
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
36499
diff
changeset
|
196 |
ste(test3, VALID, VALID, true, MAIN_SNIPPET), |
34857
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
197 |
ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
198 |
assertClasses(clazz(KullaTesting.ClassType.INTERFACE, "A")); |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
199 |
assertMethods(method("()A", "test"), method("(A)void", "test"), method("(int)void", "test")); |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
200 |
assertActiveKeys(); |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
201 |
} |
14d1224cfed3
8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents:
33362
diff
changeset
|
202 |
|
33362 | 203 |
public void classesCyclic1() { |
204 |
Snippet b = classKey(assertEval("class B extends A { }", |
|
205 |
added(RECOVERABLE_NOT_DEFINED))); |
|
206 |
Snippet a = classKey(assertEval("class A extends B { }", DiagCheck.DIAG_IGNORE, DiagCheck.DIAG_IGNORE, |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
36499
diff
changeset
|
207 |
added(REJECTED))); |
33362 | 208 |
/*** |
209 |
assertDeclareFail("class A extends B { }", "****", |
|
210 |
added(REJECTED), |
|
211 |
ste(b, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, MAIN_SNIPPET)); |
|
212 |
***/ |
|
213 |
// It is random which one it shows up in, but cyclic error should be there |
|
40304
0318f4e75c6d
8143964: JShell API: convert query responses to Stream instead of List
rfield
parents:
37644
diff
changeset
|
214 |
List<Diag> diagsA = getState().diagnostics(a).collect(toList()); |
0318f4e75c6d
8143964: JShell API: convert query responses to Stream instead of List
rfield
parents:
37644
diff
changeset
|
215 |
List<Diag> diagsB = getState().diagnostics(b).collect(toList()); |
33362 | 216 |
List<Diag> diags; |
217 |
if (diagsA.isEmpty()) { |
|
218 |
diags = diagsB; |
|
219 |
} else { |
|
220 |
diags = diagsA; |
|
221 |
assertTrue(diagsB.isEmpty()); |
|
222 |
} |
|
223 |
assertEquals(diags.size(), 1, "Expected one error"); |
|
224 |
assertEquals(diags.get(0).getCode(), "compiler.err.cyclic.inheritance", "Expected cyclic inheritance error"); |
|
225 |
assertActiveKeys(); |
|
226 |
} |
|
227 |
||
228 |
public void classesCyclic2() { |
|
229 |
Snippet d = classKey(assertEval("class D extends E { }", added(RECOVERABLE_NOT_DEFINED))); |
|
230 |
assertEval("class E { D d; }", |
|
231 |
added(VALID), |
|
232 |
ste(d, RECOVERABLE_NOT_DEFINED, VALID, true, MAIN_SNIPPET)); |
|
233 |
assertActiveKeys(); |
|
234 |
} |
|
235 |
||
236 |
public void classesCyclic3() { |
|
237 |
Snippet outer = classKey(assertEval("class Outer { class Inner extends Foo { } }", |
|
238 |
added(RECOVERABLE_NOT_DEFINED))); |
|
239 |
Snippet foo = classKey(assertEval("class Foo { } ", |
|
240 |
added(VALID), |
|
241 |
ste(outer, RECOVERABLE_NOT_DEFINED, VALID, true, MAIN_SNIPPET))); |
|
242 |
assertEval(" class Foo extends Outer { }", |
|
243 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
244 |
ste(foo, VALID, OVERWRITTEN, false, MAIN_SNIPPET), |
|
245 |
ste(outer, VALID, VALID, true, MAIN_SNIPPET)); |
|
246 |
assertActiveKeys(); |
|
247 |
} |
|
248 |
||
249 |
public void classesIgnoredModifiers() { |
|
41858
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
40304
diff
changeset
|
250 |
assertEval("public interface A { }"); |
33362 | 251 |
assertDeclareWarn1("static class B implements A { }", |
252 |
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 6, 0, -1, -1, Diagnostic.Kind.WARNING)); |
|
253 |
assertDeclareWarn1("final interface C extends A { }", |
|
254 |
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 5, 0, -1, -1, Diagnostic.Kind.WARNING)); |
|
255 |
assertActiveKeys(); |
|
256 |
} |
|
257 |
||
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
258 |
public void classesIgnoredModifiersAnnotation() { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
259 |
assertEval("public @interface X { }"); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
260 |
assertEval("@X public interface A { }"); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
261 |
assertDeclareWarn1("@X static class B implements A { }", |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
262 |
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 9, 0, -1, -1, Diagnostic.Kind.WARNING)); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
263 |
assertDeclareWarn1("@X final interface C extends A { }", |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
264 |
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 8, 0, -1, -1, Diagnostic.Kind.WARNING)); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
265 |
assertActiveKeys(); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
266 |
} |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
267 |
|
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
268 |
public void classesIgnoredModifiersOtherModifiers() { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
269 |
assertEval("strictfp public interface A { }"); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
270 |
assertDeclareWarn1("strictfp static class B implements A { }", |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
271 |
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 15, 0, -1, -1, Diagnostic.Kind.WARNING)); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
272 |
assertDeclareWarn1("strictfp final interface C extends A { }", |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
273 |
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 14, 0, -1, -1, Diagnostic.Kind.WARNING)); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
274 |
assertActiveKeys(); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
275 |
} |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
41858
diff
changeset
|
276 |
|
33362 | 277 |
public void ignoreModifierSpaceIssue() { |
278 |
assertEval("interface I { void f(); } "); |
|
279 |
// there should not be a space between 'I' and '{' to reproduce the failure |
|
280 |
assertEval("class C implements I{ public void f() {}}"); |
|
281 |
assertClasses(clazz(KullaTesting.ClassType.CLASS, "C"), clazz(KullaTesting.ClassType.INTERFACE, "I")); |
|
282 |
assertActiveKeys(); |
|
283 |
} |
|
284 |
||
285 |
@DataProvider(name = "innerClasses") |
|
286 |
public Object[][] innerClasses() { |
|
287 |
List<Object[]> list = new ArrayList<>(); |
|
288 |
for (ClassType outerClassType : ClassType.values()) { |
|
289 |
for (ClassType innerClassType : ClassType.values()) { |
|
290 |
list.add(new Object[]{outerClassType, innerClassType}); |
|
291 |
} |
|
292 |
} |
|
293 |
return list.toArray(new Object[list.size()][]); |
|
294 |
} |
|
295 |
||
296 |
@Test(dataProvider = "innerClasses") |
|
297 |
public void innerClasses(ClassType outerClassType, ClassType innerClassType) { |
|
298 |
String source = |
|
299 |
outerClassType + " A {" + (outerClassType == ClassType.ENUM ? ";" : "") + |
|
300 |
innerClassType + " B { }" + |
|
301 |
"}"; |
|
302 |
assertEval(source); |
|
303 |
assertNumberOfActiveClasses(1); |
|
304 |
assertActiveKeys(); |
|
305 |
} |
|
306 |
||
307 |
public void testInnerClassesCrash() { |
|
308 |
Snippet a = classKey(assertEval("class A { class B extends A {} }")); |
|
309 |
Snippet a2 = classKey(assertEval("class A { interface I1 extends I2 {} interface I2 {} }", |
|
310 |
ste(MAIN_SNIPPET, VALID, VALID, false, null), |
|
311 |
ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET))); |
|
312 |
assertEval("class A { A a = new A() {}; }", |
|
313 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
314 |
ste(a2, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
315 |
} |
|
316 |
||
317 |
public void testInnerClassesCrash1() { |
|
318 |
assertEval("class A { class B extends A {} B getB() { return new B();} }"); |
|
319 |
assertEquals(varKey(assertEval("A a = new A();")).name(), "a"); |
|
320 |
VarSnippet variableKey = varKey(assertEval("a.getB();")); |
|
321 |
assertEquals(variableKey.typeName(), "A.B"); |
|
322 |
} |
|
323 |
||
324 |
public void testInnerClassesCrash2() { |
|
325 |
assertEval("class A { interface I1 extends I2 {} interface I2 {} I1 x; }"); |
|
326 |
assertEquals(varKey(assertEval("A a = new A();")).name(), "a"); |
|
327 |
VarSnippet variableKey = varKey(assertEval("a.x;")); |
|
328 |
assertEquals(variableKey.typeName(), "A.I1"); |
|
329 |
} |
|
330 |
} |