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 Tests for EvaluationState.methods
27 * @build KullaTesting TestingInputStream ExpectedDiagnostic
28 * @run testng MethodsTest
29 */
30
31 import javax.tools.Diagnostic;
32
33 import jdk.jshell.Snippet;
34 import jdk.jshell.MethodSnippet;
35 import jdk.jshell.Snippet.Status;
36 import org.testng.annotations.Test;
37
38 import static jdk.jshell.Snippet.Status.*;
39 import static jdk.jshell.Snippet.SubKind.*;
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(); }",
61 ste(m1, REJECTED, RECOVERABLE_DEFINED, true, null)));
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
77 public void methods() {
78 assertEval("int x() { return 10; }");
79 assertEval("String y() { return null; }");
80 assertEval("long z() { return 0; }");
81 assertMethods(method("()int", "x"), method("()String", "y"), method("()long", "z"));
82 assertActiveKeys();
83 }
84
85 public void methodOverload() {
86 assertEval("int m() { return 1; }");
87 assertEval("int m(int x) { return 2; }");
88 assertEval("int m(String s) { return 3; }");
89 assertEval("int m(int x, int y) { return 4; }");
90 assertEval("int m(int x, String z) { return 5; }");
91 assertEval("int m(int x, String z, long g) { return 6; }");
92 assertMethods(
93 method("()int", "m"),
94 method("(int)int", "m"),
|
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 8080357
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(); }",
61 ste(m1, REJECTED, RECOVERABLE_DEFINED, true, null)));
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
77 // 8080357
78 public void testNonReplUnresolved() {
79 // internal case
80 assertEval("class CCC {}", added(VALID));
81 assertEval("void f1() { CCC.xxxx(); }", added(RECOVERABLE_DEFINED));
82 // external case, not recoverable
83 assertDeclareFail("void f2() { System.xxxx(); }", "compiler.err.cant.resolve.location.args");
84 }
85
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"),
|