1 /* |
1 /* |
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
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. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
56 |
56 |
57 public void testSignature2() { |
57 public void testSignature2() { |
58 MethodSnippet m1 = (MethodSnippet) assertDeclareFail("void f() { return g(); }", "compiler.err.prob.found.req"); |
58 MethodSnippet m1 = (MethodSnippet) assertDeclareFail("void f() { return g(); }", "compiler.err.prob.found.req"); |
59 assertMethodDeclSnippet(m1, "f", "()void", REJECTED, 0, 2); |
59 assertMethodDeclSnippet(m1, "f", "()void", REJECTED, 0, 2); |
60 MethodSnippet m2 = methodKey(assertEval("int f() { return g(); }", |
60 MethodSnippet m2 = methodKey(assertEval("int f() { return g(); }", |
61 ste(m1, REJECTED, RECOVERABLE_DEFINED, true, null))); |
61 added(RECOVERABLE_DEFINED))); |
62 assertMethodDeclSnippet(m1, "f", "()void", REJECTED, 0, 2); |
62 assertMethodDeclSnippet(m1, "f", "()void", REJECTED, 0, 2); |
63 assertMethodDeclSnippet(m2, "f", "()int", RECOVERABLE_DEFINED, 1, 0); |
63 assertMethodDeclSnippet(m2, "f", "()int", RECOVERABLE_DEFINED, 1, 0); |
64 } |
64 } |
65 |
65 |
66 @Test(enabled = false) // TODO 8081690 |
66 @Test(enabled = false) // TODO 8081690 |
113 assertEval("m(7, \"eight\");", "5"); |
113 assertEval("m(7, \"eight\");", "5"); |
114 assertEval("m(7, \"eight\", 9L);", "6"); |
114 assertEval("m(7, \"eight\", 9L);", "6"); |
115 assertActiveKeys(); |
115 assertActiveKeys(); |
116 } |
116 } |
117 |
117 |
|
118 /*** |
|
119 public void methodOverloadDependent() { |
|
120 assertEval("String m(String s) { return s + s; }"); |
|
121 assertEval("String m(double d) { return m(\"#\" + d); }"); |
|
122 assertEval("String m(int x) { return m(2.25 * x); }"); |
|
123 assertEval("String m() { return m(3); }"); |
|
124 assertMethods( |
|
125 method("(String)String", "m"), |
|
126 method("(double)String", "m"), |
|
127 method("(int)String", "m"), |
|
128 method("()String", "m") |
|
129 ); |
|
130 assertEval("m();", "\"#6.75#6.75\""); |
|
131 assertEval("m(2);", "\"#4.5#4.5\""); |
|
132 assertEval("m(3.14);", "\"#3.14#3.14\""); |
|
133 assertEval("m(\"hi\");", "\"hihi\""); |
|
134 assertActiveKeys(); |
|
135 } |
|
136 ***/ |
|
137 |
118 public void methodsRedeclaration1() { |
138 public void methodsRedeclaration1() { |
119 Snippet x = methodKey(assertEval("int x() { return 10; }")); |
139 Snippet x = methodKey(assertEval("int x() { return 10; }")); |
120 Snippet y = methodKey(assertEval("String y() { return \"\"; }")); |
140 Snippet y = methodKey(assertEval("String y() { return \"\"; }")); |
121 assertMethods(method("()int", "x"), method("()String", "y")); |
141 assertMethods(method("()int", "x"), method("()String", "y")); |
122 assertActiveKeys(); |
142 assertActiveKeys(); |
147 assertMethods(method("()int", "a"), method("()Integer", "b"), method("()double", "c")); |
167 assertMethods(method("()int", "a"), method("()Integer", "b"), method("()double", "c")); |
148 assertActiveKeys(); |
168 assertActiveKeys(); |
149 |
169 |
150 assertEval("double b() { return 3.14159; }", |
170 assertEval("double b() { return 3.14159; }", |
151 ste(MAIN_SNIPPET, VALID, VALID, true, null), |
171 ste(MAIN_SNIPPET, VALID, VALID, true, null), |
152 ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET), |
172 ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
153 ste(c, VALID, VALID, false, MAIN_SNIPPET)); |
|
154 assertMethods(method("()int", "a"), method("()double", "b"), method("()double", "c")); |
173 assertMethods(method("()int", "a"), method("()double", "b"), method("()double", "c")); |
155 assertEval("c();", "3.14159"); |
174 assertEval("c();", "3.14159"); |
156 assertActiveKeys(); |
175 assertActiveKeys(); |
157 } |
176 } |
158 |
177 |
200 new ExpectedDiagnostic("jdk.eval.error.illegal.modifiers", 0, 12, 0, -1, -1, Diagnostic.Kind.ERROR)); |
219 new ExpectedDiagnostic("jdk.eval.error.illegal.modifiers", 0, 12, 0, -1, -1, Diagnostic.Kind.ERROR)); |
201 assertNumberOfActiveMethods(0); |
220 assertNumberOfActiveMethods(0); |
202 assertActiveKeys(); |
221 assertActiveKeys(); |
203 |
222 |
204 assertDeclareFail("int f() {}", "compiler.err.missing.ret.stmt", |
223 assertDeclareFail("int f() {}", "compiler.err.missing.ret.stmt", |
205 ste(MAIN_SNIPPET, REJECTED, REJECTED, false, null)); |
224 added(REJECTED)); |
206 assertNumberOfActiveMethods(0); |
225 assertNumberOfActiveMethods(0); |
207 assertActiveKeys(); |
226 assertActiveKeys(); |
208 |
227 |
209 assertEval("String x() { return \"\"; };"); |
228 assertEval("String x() { return \"\"; };"); |
210 assertMethods(method("()String", "x")); |
229 assertMethods(method("()String", "x")); |