author | mchung |
Sat, 24 Feb 2018 09:41:42 -0800 (2018-02-24) | |
changeset 48984 | b5d1fb0701d4 |
parent 47499 | b3ea71b70f7b |
child 49416 | f14852315495 |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
47499
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, 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. |
|
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 |
|
47499
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
26 |
* @bug 8080357 8167643 8187359 |
33362 | 27 |
* @summary Tests for EvaluationState.methods |
28 |
* @build KullaTesting TestingInputStream ExpectedDiagnostic |
|
29 |
* @run testng MethodsTest |
|
30 |
*/ |
|
31 |
||
32 |
import javax.tools.Diagnostic; |
|
33 |
||
34 |
import jdk.jshell.Snippet; |
|
35 |
import jdk.jshell.MethodSnippet; |
|
36 |
import jdk.jshell.Snippet.Status; |
|
37 |
import org.testng.annotations.Test; |
|
38 |
||
39 |
import static jdk.jshell.Snippet.Status.*; |
|
40 |
||
41 |
@Test |
|
42 |
public class MethodsTest extends KullaTesting { |
|
43 |
||
44 |
public void noMethods() { |
|
45 |
assertNumberOfActiveMethods(0); |
|
46 |
} |
|
47 |
||
48 |
public void testSignature1() { |
|
49 |
MethodSnippet m1 = methodKey(assertEval("void f() { g(); }", added(RECOVERABLE_DEFINED))); |
|
50 |
assertMethodDeclSnippet(m1, "f", "()void", RECOVERABLE_DEFINED, 1, 0); |
|
51 |
MethodSnippet m2 = methodKey(assertEval("void g() { }", |
|
52 |
added(VALID), |
|
53 |
ste(m1, RECOVERABLE_DEFINED, VALID, false, null))); |
|
54 |
assertMethodDeclSnippet(m2, "g", "()void", VALID, 0, 0); |
|
55 |
} |
|
56 |
||
57 |
public void testSignature2() { |
|
58 |
MethodSnippet m1 = (MethodSnippet) assertDeclareFail("void f() { return g(); }", "compiler.err.prob.found.req"); |
|
59 |
assertMethodDeclSnippet(m1, "f", "()void", REJECTED, 0, 2); |
|
60 |
MethodSnippet m2 = methodKey(assertEval("int f() { return g(); }", |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
61 |
added(RECOVERABLE_DEFINED))); |
33362 | 62 |
assertMethodDeclSnippet(m1, "f", "()void", REJECTED, 0, 2); |
63 |
assertMethodDeclSnippet(m2, "f", "()int", RECOVERABLE_DEFINED, 1, 0); |
|
64 |
} |
|
65 |
||
66 |
@Test(enabled = false) // TODO 8081690 |
|
67 |
public void testSignature3() { |
|
68 |
MethodSnippet m1 = methodKey(assertEval("void f(Bar b) { }", added(RECOVERABLE_NOT_DEFINED))); |
|
69 |
assertMethodDeclSnippet(m1, "f", "(Bar)void", RECOVERABLE_NOT_DEFINED, 1, 0); |
|
70 |
MethodSnippet m2 = methodKey(assertEval("void f(A.Bar b) { }", added(RECOVERABLE_NOT_DEFINED))); |
|
71 |
assertMethodDeclSnippet(m1, "f", "(Bar)void", RECOVERABLE_NOT_DEFINED, 1, 0); |
|
72 |
assertMethodDeclSnippet(m2, "f", "(A.Bar)void", RECOVERABLE_NOT_DEFINED, 1, 0); |
|
73 |
assertDrop(m1, ste(m1, RECOVERABLE_NOT_DEFINED, DROPPED, false, null)); |
|
74 |
assertMethodDeclSnippet(m1, "f", "(Bar)void", DROPPED, 1, 0); |
|
75 |
} |
|
76 |
||
35736
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
33362
diff
changeset
|
77 |
// 8080357 |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
33362
diff
changeset
|
78 |
public void testNonReplUnresolved() { |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
33362
diff
changeset
|
79 |
// internal case |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
33362
diff
changeset
|
80 |
assertEval("class CCC {}", added(VALID)); |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
33362
diff
changeset
|
81 |
assertEval("void f1() { CCC.xxxx(); }", added(RECOVERABLE_DEFINED)); |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
33362
diff
changeset
|
82 |
// external case, not recoverable |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
33362
diff
changeset
|
83 |
assertDeclareFail("void f2() { System.xxxx(); }", "compiler.err.cant.resolve.location.args"); |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
33362
diff
changeset
|
84 |
} |
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
33362
diff
changeset
|
85 |
|
33362 | 86 |
public void methods() { |
87 |
assertEval("int x() { return 10; }"); |
|
88 |
assertEval("String y() { return null; }"); |
|
89 |
assertEval("long z() { return 0; }"); |
|
90 |
assertMethods(method("()int", "x"), method("()String", "y"), method("()long", "z")); |
|
91 |
assertActiveKeys(); |
|
92 |
} |
|
93 |
||
94 |
public void methodOverload() { |
|
95 |
assertEval("int m() { return 1; }"); |
|
96 |
assertEval("int m(int x) { return 2; }"); |
|
97 |
assertEval("int m(String s) { return 3; }"); |
|
98 |
assertEval("int m(int x, int y) { return 4; }"); |
|
99 |
assertEval("int m(int x, String z) { return 5; }"); |
|
100 |
assertEval("int m(int x, String z, long g) { return 6; }"); |
|
101 |
assertMethods( |
|
102 |
method("()int", "m"), |
|
103 |
method("(int)int", "m"), |
|
104 |
method("(String)int", "m"), |
|
105 |
method("(int,int)int", "m"), |
|
106 |
method("(int,String)int", "m"), |
|
107 |
method("(int,String,long)int", "m") |
|
108 |
); |
|
109 |
assertEval("m();", "1"); |
|
110 |
assertEval("m(3);", "2"); |
|
111 |
assertEval("m(\"hi\");", "3"); |
|
112 |
assertEval("m(7, 8);", "4"); |
|
113 |
assertEval("m(7, \"eight\");", "5"); |
|
114 |
assertEval("m(7, \"eight\", 9L);", "6"); |
|
115 |
assertActiveKeys(); |
|
116 |
} |
|
117 |
||
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
118 |
/*** |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
119 |
public void methodOverloadDependent() { |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
120 |
assertEval("String m(String s) { return s + s; }"); |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
121 |
assertEval("String m(double d) { return m(\"#\" + d); }"); |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
122 |
assertEval("String m(int x) { return m(2.25 * x); }"); |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
123 |
assertEval("String m() { return m(3); }"); |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
124 |
assertMethods( |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
125 |
method("(String)String", "m"), |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
126 |
method("(double)String", "m"), |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
127 |
method("(int)String", "m"), |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
128 |
method("()String", "m") |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
129 |
); |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
130 |
assertEval("m();", "\"#6.75#6.75\""); |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
131 |
assertEval("m(2);", "\"#4.5#4.5\""); |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
132 |
assertEval("m(3.14);", "\"#3.14#3.14\""); |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
133 |
assertEval("m(\"hi\");", "\"hihi\""); |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
134 |
assertActiveKeys(); |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
135 |
} |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
136 |
***/ |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
137 |
|
33362 | 138 |
public void methodsRedeclaration1() { |
139 |
Snippet x = methodKey(assertEval("int x() { return 10; }")); |
|
140 |
Snippet y = methodKey(assertEval("String y() { return \"\"; }")); |
|
141 |
assertMethods(method("()int", "x"), method("()String", "y")); |
|
142 |
assertActiveKeys(); |
|
143 |
||
144 |
assertEval("long x() { return 0; }", |
|
145 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
146 |
ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
147 |
assertMethods(method("()long", "x"), method("()String", "y")); |
|
148 |
assertActiveKeys(); |
|
149 |
||
150 |
assertEval("String y() { return null; }", |
|
151 |
ste(MAIN_SNIPPET, VALID, VALID, false, null), |
|
152 |
ste(y, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
153 |
assertMethods(method("()long", "x"), method("()String", "y")); |
|
154 |
assertActiveKeys(); |
|
155 |
} |
|
156 |
||
157 |
public void methodsRedeclaration2() { |
|
158 |
assertEval("int a() { return 1; }"); |
|
159 |
assertMethods(method("()int", "a")); |
|
160 |
assertActiveKeys(); |
|
161 |
||
162 |
Snippet b = methodKey(assertEval("Integer b() { return a(); }")); |
|
163 |
assertMethods(method("()int", "a"), method("()Integer", "b")); |
|
164 |
assertActiveKeys(); |
|
165 |
||
166 |
Snippet c = methodKey(assertEval("double c() { return b(); }")); |
|
167 |
assertMethods(method("()int", "a"), method("()Integer", "b"), method("()double", "c")); |
|
168 |
assertActiveKeys(); |
|
169 |
||
170 |
assertEval("double b() { return 3.14159; }", |
|
171 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
172 |
ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
33362 | 173 |
assertMethods(method("()int", "a"), method("()double", "b"), method("()double", "c")); |
174 |
assertEval("c();", "3.14159"); |
|
175 |
assertActiveKeys(); |
|
176 |
} |
|
177 |
||
178 |
public void methodsRedeclaration3() { |
|
179 |
Snippet x = methodKey(assertEval("int x(Object...a) { return 10; }")); |
|
180 |
assertMethods(method("(Object...)int", "x")); |
|
181 |
assertActiveKeys(); |
|
182 |
||
183 |
assertEval("int x(Object[]a) { return 10; }", |
|
184 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
185 |
ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
186 |
assertMethods(method("(Object[])int", "x")); |
|
187 |
assertActiveKeys(); |
|
188 |
} |
|
189 |
||
190 |
||
191 |
public void methodsRedeclaration4() { |
|
192 |
Snippet a = methodKey(assertEval("int foo(int a) { return a; }")); |
|
193 |
assertEval("int x = foo(10);"); |
|
194 |
assertActiveKeys(); |
|
195 |
assertMethods(method("(int)int", "foo")); |
|
196 |
assertEval("int foo(int a) { return a * a; }", |
|
197 |
ste(MAIN_SNIPPET, VALID, VALID, false, null), |
|
198 |
ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
199 |
assertActiveKeys(); |
|
200 |
} |
|
201 |
||
202 |
public void methodsErrors() { |
|
203 |
assertDeclareFail("String f();", |
|
204 |
new ExpectedDiagnostic("compiler.err.missing.meth.body.or.decl.abstract", 0, 11, 7, -1, -1, Diagnostic.Kind.ERROR)); |
|
205 |
assertNumberOfActiveMethods(0); |
|
206 |
assertActiveKeys(); |
|
207 |
||
208 |
assertDeclareFail("abstract String f();", |
|
209 |
new ExpectedDiagnostic("jdk.eval.error.illegal.modifiers", 0, 8, 0, -1, -1, Diagnostic.Kind.ERROR)); |
|
210 |
assertNumberOfActiveMethods(0); |
|
211 |
assertActiveKeys(); |
|
212 |
||
213 |
assertDeclareFail("native String f();", |
|
214 |
new ExpectedDiagnostic("jdk.eval.error.illegal.modifiers", 0, 6, 0, -1, -1, Diagnostic.Kind.ERROR)); |
|
215 |
assertNumberOfActiveMethods(0); |
|
216 |
assertActiveKeys(); |
|
217 |
||
218 |
assertDeclareFail("synchronized String f() {return null;}", |
|
219 |
new ExpectedDiagnostic("jdk.eval.error.illegal.modifiers", 0, 12, 0, -1, -1, Diagnostic.Kind.ERROR)); |
|
220 |
assertNumberOfActiveMethods(0); |
|
221 |
assertActiveKeys(); |
|
222 |
||
223 |
assertDeclareFail("int f() {}", "compiler.err.missing.ret.stmt", |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
35736
diff
changeset
|
224 |
added(REJECTED)); |
33362 | 225 |
assertNumberOfActiveMethods(0); |
226 |
assertActiveKeys(); |
|
227 |
||
228 |
assertEval("String x() { return \"\"; };"); |
|
229 |
assertMethods(method("()String", "x")); |
|
230 |
assertActiveKeys(); |
|
231 |
} |
|
232 |
||
47499
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
233 |
public void objectMethodNamedMethodsErrors() { |
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
234 |
assertDeclareFail("boolean equals(double d1, double d2) { return d1 == d2; }", |
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
235 |
new ExpectedDiagnostic("jdk.eval.error.object.method", 8, 14, 8, -1, -1, Diagnostic.Kind.ERROR)); |
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
236 |
assertNumberOfActiveMethods(0); |
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
237 |
assertActiveKeys(); |
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
238 |
|
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
239 |
assertDeclareFail("void wait() { }", |
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
240 |
new ExpectedDiagnostic("jdk.eval.error.object.method", 14, 18, 14, -1, -1, Diagnostic.Kind.ERROR)); |
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
241 |
assertNumberOfActiveMethods(0); |
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
242 |
assertActiveKeys(); |
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
243 |
|
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
244 |
assertDeclareFail(" String toString() throws NullPointerException{ }", |
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
245 |
new ExpectedDiagnostic("jdk.eval.error.object.method", 11, 19, 11, -1, -1, Diagnostic.Kind.ERROR)); |
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
246 |
assertNumberOfActiveMethods(0); |
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
247 |
assertActiveKeys(); |
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
248 |
|
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
249 |
} |
b3ea71b70f7b
8187359: JShell: Give comprehensible error when user method name matches Object method
rfield
parents:
47216
diff
changeset
|
250 |
|
41858
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
37644
diff
changeset
|
251 |
|
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
37644
diff
changeset
|
252 |
public void methodsAccessModifierIgnored() { |
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
37644
diff
changeset
|
253 |
Snippet f = methodKey(assertEval("public String f() {return null;}", |
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
37644
diff
changeset
|
254 |
added(VALID))); |
33362 | 255 |
assertNumberOfActiveMethods(1); |
256 |
assertActiveKeys(); |
|
257 |
||
41858
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
37644
diff
changeset
|
258 |
f = methodKey(assertEval("protected String f() {return null;}", |
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
37644
diff
changeset
|
259 |
ste(MAIN_SNIPPET, VALID, VALID, false, null), |
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
37644
diff
changeset
|
260 |
ste(f, VALID, OVERWRITTEN, false, MAIN_SNIPPET))); |
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
37644
diff
changeset
|
261 |
assertNumberOfActiveMethods(1); |
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
37644
diff
changeset
|
262 |
assertActiveKeys(); |
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
37644
diff
changeset
|
263 |
|
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
37644
diff
changeset
|
264 |
assertEval("private String f() {return null;}", |
33362 | 265 |
ste(MAIN_SNIPPET, VALID, VALID, false, null), |
266 |
ste(f, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
267 |
assertNumberOfActiveMethods(1); |
|
268 |
assertActiveKeys(); |
|
41858
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
37644
diff
changeset
|
269 |
} |
33362 | 270 |
|
41858
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
37644
diff
changeset
|
271 |
public void methodsWarn() { |
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
37644
diff
changeset
|
272 |
Snippet f = assertDeclareWarn1("static String f() {return null;}", |
33362 | 273 |
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 6, 0, -1, -1, Diagnostic.Kind.WARNING), |
41858
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
37644
diff
changeset
|
274 |
added(VALID)); |
33362 | 275 |
assertNumberOfActiveMethods(1); |
276 |
assertActiveKeys(); |
|
277 |
||
278 |
assertDeclareWarn1("final String f() {return null;}", |
|
279 |
new ExpectedDiagnostic("jdk.eval.warn.illegal.modifiers", 0, 5, 0, -1, -1, Diagnostic.Kind.WARNING), |
|
280 |
ste(MAIN_SNIPPET, VALID, VALID, false, null), |
|
281 |
ste(f, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
282 |
assertNumberOfActiveMethods(1); |
|
283 |
assertActiveKeys(); |
|
284 |
} |
|
285 |
||
286 |
public void methodSignatureUnresolved() { |
|
287 |
MethodSnippet key = (MethodSnippet) methodKey(assertEval("und m() { return new und(); }", added(RECOVERABLE_NOT_DEFINED))); |
|
288 |
assertMethodDeclSnippet(key, "m", "()und", RECOVERABLE_NOT_DEFINED, 1, 0); |
|
289 |
assertUnresolvedDependencies1(key, Status.RECOVERABLE_NOT_DEFINED, "class und"); |
|
290 |
assertEval("class und {}", |
|
291 |
added(VALID), |
|
292 |
ste(key, RECOVERABLE_NOT_DEFINED, VALID, true, null)); |
|
293 |
assertMethodDeclSnippet(key, "m", "()und", Status.VALID, 0, 0); |
|
294 |
assertNumberOfActiveMethods(1); |
|
295 |
assertActiveKeys(); |
|
296 |
} |
|
297 |
||
298 |
@Test(enabled = false) // TODO 8081689 |
|
299 |
public void classMethodsAreNotVisible() { |
|
300 |
assertEval( |
|
301 |
"class A {" + |
|
302 |
"int foo() {" + |
|
303 |
"int x = 10;" + |
|
304 |
"int y = 2 * x;" + |
|
305 |
"return x * y;" + |
|
306 |
"}" + |
|
307 |
"}"); |
|
308 |
assertNumberOfActiveMethods(0); |
|
309 |
assertEval("int x = 10;", "10"); |
|
310 |
assertEval("int foo() {" + |
|
311 |
"int y = 2 * x;" + |
|
312 |
"return x * y;" + |
|
313 |
"}"); |
|
314 |
assertMethods(method("()int", "foo")); |
|
315 |
assertEval("foo();", "200"); |
|
316 |
assertActiveKeys(); |
|
317 |
} |
|
318 |
||
319 |
public void lambdas() { |
|
320 |
assertEval("class Inner1 implements Runnable {" + |
|
321 |
"public Runnable lambda1 = () -> {};" + |
|
322 |
"public void function() {}" + |
|
323 |
"public void run() {}" + |
|
324 |
"}"); |
|
325 |
||
326 |
assertEval("class Inner2 {" + |
|
327 |
"private Runnable lambda1 = () -> {};" + |
|
328 |
"private static void staticFunction() {}" + |
|
329 |
"}"); |
|
330 |
||
331 |
// the following method references and lambda functions |
|
332 |
// generate synthetic methods |
|
333 |
assertEval("Runnable run = () -> {};"); |
|
334 |
assertEval("Inner1 inner = new Inner1();"); |
|
335 |
assertEval("Runnable l1 = inner::function;"); |
|
336 |
assertEval("Runnable l2 = Inner1::new;"); |
|
337 |
assertEval("inner.lambda1 = inner::function;"); |
|
338 |
assertEval("java.util.stream.IntStream.of(2).mapToObj(int[]::new);"); |
|
339 |
assertNumberOfActiveMethods(0); |
|
340 |
assertActiveKeys(); |
|
341 |
} |
|
342 |
} |