author | jlahoda |
Thu, 08 Sep 2016 15:48:28 +0200 | |
changeset 40837 | d071bcc8d32e |
parent 40770 | dfccc36b61b6 |
child 41527 | e8f487b79e24 |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
36526 | 2 |
* Copyright (c) 2015, 2016, 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 |
|
40837
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
26 |
* @bug 8131025 8141092 8153761 |
33362 | 27 |
* @summary Test Completion |
35359 | 28 |
* @modules jdk.compiler/com.sun.tools.javac.api |
29 |
* jdk.compiler/com.sun.tools.javac.main |
|
36526 | 30 |
* jdk.jdeps/com.sun.tools.javap |
33362 | 31 |
* @library /tools/lib |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
32 |
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
33 |
* @build KullaTesting TestingInputStream Compiler |
33362 | 34 |
* @run testng CompletionSuggestionTest |
35 |
*/ |
|
36 |
||
37939
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
37 |
import java.io.IOException; |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
38 |
import java.lang.reflect.Field; |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
39 |
import java.nio.file.Files; |
33362 | 40 |
import java.nio.file.Path; |
41 |
import java.nio.file.Paths; |
|
42 |
import java.util.Arrays; |
|
43 |
import java.util.Collections; |
|
44 |
import java.util.Set; |
|
45 |
import java.util.HashSet; |
|
37939
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
46 |
import java.util.jar.JarEntry; |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
47 |
import java.util.jar.JarOutputStream; |
33362 | 48 |
|
49 |
import jdk.jshell.Snippet; |
|
37939
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
50 |
import org.testng.annotations.BeforeMethod; |
33362 | 51 |
import org.testng.annotations.Test; |
52 |
||
53 |
import static jdk.jshell.Snippet.Status.VALID; |
|
54 |
import static jdk.jshell.Snippet.Status.OVERWRITTEN; |
|
55 |
||
56 |
@Test |
|
57 |
public class CompletionSuggestionTest extends KullaTesting { |
|
58 |
||
33715
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
59 |
private final Compiler compiler = new Compiler(); |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
60 |
private final Path outDir = Paths.get("completion_suggestion_test"); |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
61 |
|
33362 | 62 |
public void testMemberExpr() { |
63 |
assertEval("class Test { static void test() { } }"); |
|
64 |
assertCompletion("Test.t|", "test()"); |
|
65 |
assertEval("Test ccTestInstance = new Test();"); |
|
66 |
assertCompletion("ccTestInstance.t|", "toString()"); |
|
67 |
assertCompletion(" ccTe|", "ccTestInstance"); |
|
68 |
assertCompletion("String value = ccTestInstance.to|", "toString()"); |
|
69 |
assertCompletion("java.util.Coll|", "Collection", "Collections"); |
|
70 |
assertCompletion("String.cla|", "class"); |
|
71 |
assertCompletion("boolean.cla|", "class"); |
|
72 |
assertCompletion("byte.cla|", "class"); |
|
73 |
assertCompletion("short.cla|", "class"); |
|
74 |
assertCompletion("char.cla|", "class"); |
|
75 |
assertCompletion("int.cla|", "class"); |
|
76 |
assertCompletion("float.cla|", "class"); |
|
77 |
assertCompletion("long.cla|", "class"); |
|
78 |
assertCompletion("double.cla|", "class"); |
|
79 |
assertCompletion("void.cla|", "class"); |
|
80 |
assertCompletion("Object[].|", "class"); |
|
81 |
assertCompletion("int[].|", "class"); |
|
82 |
assertEval("Object[] ao = null;"); |
|
83 |
assertCompletion("int i = ao.|", "length"); |
|
84 |
assertEval("int[] ai = null;"); |
|
85 |
assertCompletion("int i = ai.|", "length"); |
|
86 |
assertCompletionIncludesExcludes("\"\".|", |
|
87 |
new HashSet<>(Collections.emptyList()), |
|
88 |
new HashSet<>(Arrays.asList("String("))); |
|
89 |
assertEval("double d = 0;"); |
|
90 |
assertEval("void m() {}"); |
|
91 |
assertCompletionIncludesExcludes("d.|", |
|
92 |
new HashSet<>(Collections.emptyList()), |
|
93 |
new HashSet<>(Arrays.asList("class"))); |
|
94 |
assertCompletionIncludesExcludes("m().|", |
|
95 |
new HashSet<>(Collections.emptyList()), |
|
96 |
new HashSet<>(Arrays.asList("class"))); |
|
97 |
assertEval("class C {class D {} static class E {} enum F {} interface H {} void method() {} int number;}"); |
|
98 |
assertCompletionIncludesExcludes("C.|", |
|
99 |
new HashSet<>(Arrays.asList("D", "E", "F", "H", "class")), |
|
100 |
new HashSet<>(Arrays.asList("method()", "number"))); |
|
101 |
assertCompletionIncludesExcludes("new C().|", |
|
102 |
new HashSet<>(Arrays.asList("method()", "number")), |
|
103 |
new HashSet<>(Arrays.asList("D", "E", "F", "H", "class"))); |
|
104 |
assertCompletionIncludesExcludes("new C() {}.|", |
|
105 |
new HashSet<>(Arrays.asList("method()", "number")), |
|
106 |
new HashSet<>(Arrays.asList("D", "E", "F", "H", "class"))); |
|
107 |
} |
|
108 |
||
109 |
public void testStartOfExpression() { |
|
110 |
assertEval("int ccTest = 0;"); |
|
111 |
assertCompletion("System.err.println(cc|", "ccTest"); |
|
112 |
assertCompletion("for (int i = cc|", "ccTest"); |
|
113 |
} |
|
114 |
||
115 |
public void testParameter() { |
|
116 |
assertCompletion("class C{void method(int num){num|", "num"); |
|
117 |
} |
|
118 |
||
119 |
public void testPrimitive() { |
|
120 |
Set<String> primitives = new HashSet<>(Arrays.asList("boolean", "char", "byte", "short", "int", "long", "float", "double")); |
|
121 |
Set<String> onlyVoid = new HashSet<>(Collections.singletonList("void")); |
|
122 |
Set<String> primitivesOrVoid = new HashSet<>(primitives); |
|
123 |
primitivesOrVoid.addAll(onlyVoid); |
|
124 |
||
125 |
assertCompletionIncludesExcludes("|", |
|
126 |
primitivesOrVoid, |
|
127 |
new HashSet<>(Collections.emptyList())); |
|
128 |
assertCompletionIncludesExcludes("int num = |", |
|
129 |
primitivesOrVoid, |
|
130 |
new HashSet<>(Collections.emptyList())); |
|
131 |
assertCompletionIncludesExcludes("num = |", |
|
132 |
primitivesOrVoid, |
|
133 |
new HashSet<>(Collections.emptyList())); |
|
134 |
assertCompletionIncludesExcludes("class C{void m() {|", |
|
135 |
primitivesOrVoid, |
|
136 |
new HashSet<>(Collections.emptyList())); |
|
137 |
assertCompletionIncludesExcludes("void method(|", |
|
138 |
primitives, |
|
139 |
onlyVoid); |
|
140 |
assertCompletionIncludesExcludes("void method(int num, |", |
|
141 |
primitives, |
|
142 |
onlyVoid); |
|
143 |
assertCompletion("new java.util.ArrayList<doub|"); |
|
144 |
assertCompletion("class A extends doubl|"); |
|
145 |
assertCompletion("class A implements doubl|"); |
|
146 |
assertCompletion("interface A extends doubl|"); |
|
147 |
assertCompletion("enum A implements doubl|"); |
|
148 |
assertCompletion("class A<T extends doubl|"); |
|
149 |
} |
|
150 |
||
151 |
public void testEmpty() { |
|
152 |
assertCompletionIncludesExcludes("|", |
|
153 |
new HashSet<>(Arrays.asList("Object", "Void")), |
|
154 |
new HashSet<>(Arrays.asList("$REPL00DOESNOTMATTER"))); |
|
155 |
assertCompletionIncludesExcludes("V|", |
|
156 |
new HashSet<>(Collections.singletonList("Void")), |
|
157 |
new HashSet<>(Collections.singletonList("Object"))); |
|
158 |
assertCompletionIncludesExcludes("{ |", |
|
159 |
new HashSet<>(Arrays.asList("Object", "Void")), |
|
160 |
new HashSet<>(Arrays.asList("$REPL00DOESNOTMATTER"))); |
|
161 |
} |
|
162 |
||
163 |
public void testSmartCompletion() { |
|
164 |
assertEval("int ccTest1 = 0;"); |
|
165 |
assertEval("int ccTest2 = 0;"); |
|
166 |
assertEval("String ccTest3 = null;"); |
|
167 |
assertEval("void method(int i, String str) { }"); |
|
168 |
assertEval("void method(String str, int i) { }"); |
|
169 |
assertEval("java.util.List<String> list = null;"); |
|
170 |
assertCompletion("int ccTest4 = |", true, "ccTest1", "ccTest2"); |
|
171 |
assertCompletion("ccTest2 = |", true, "ccTest1", "ccTest2"); |
|
172 |
assertCompletion("int ccTest4 = ccTe|", "ccTest1", "ccTest2", "ccTest3"); |
|
173 |
assertCompletion("int ccTest4 = ccTest3.len|", true, "length()"); |
|
174 |
assertCompletion("method(|", true, "ccTest1", "ccTest2", "ccTest3"); |
|
175 |
assertCompletion("method(0, |", true, "ccTest3"); |
|
176 |
assertCompletion("list.add(|", true, "ccTest1", "ccTest2", "ccTest3"); |
|
177 |
assertCompletion("list.add(0, |", true, "ccTest3"); |
|
178 |
assertCompletion("new String(|", true, "ccTest3"); |
|
179 |
assertCompletion("new String(new char[0], |", true, "ccTest1", "ccTest2"); |
|
180 |
assertCompletionIncludesExcludes("new jav|", new HashSet<>(Arrays.asList("java", "javax")), Collections.emptySet()); |
|
181 |
assertCompletion("Class<String> clazz = String.c|", true, "class"); |
|
182 |
||
183 |
Snippet klass = classKey(assertEval("class Klass {void method(int n) {} private void method(String str) {}}")); |
|
184 |
assertCompletion("new Klass().method(|", true, "ccTest1", "ccTest2"); |
|
185 |
Snippet klass2 = classKey(assertEval("class Klass {static void method(int n) {} void method(String str) {}}", |
|
186 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
187 |
ste(klass, VALID, OVERWRITTEN, false, MAIN_SNIPPET))); |
|
188 |
assertCompletion("Klass.method(|", true, "ccTest1", "ccTest2"); |
|
189 |
assertEval("class Klass {Klass(int n) {} private Klass(String str) {}}", |
|
190 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
191 |
ste(klass2, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
192 |
assertCompletion("new Klass(|", true, "ccTest1", "ccTest2"); |
|
193 |
} |
|
194 |
||
195 |
public void testSmartCompletionInOverriddenMethodInvocation() { |
|
196 |
assertEval("int ccTest1 = 0;"); |
|
197 |
assertEval("int ccTest2 = 0;"); |
|
198 |
assertEval("String ccTest3 = null;"); |
|
199 |
assertCompletion("\"\".wait(|", true, "ccTest1", "ccTest2"); |
|
200 |
assertEval("class Base {void method(int n) {}}"); |
|
201 |
assertEval("class Extend extends Base {}"); |
|
202 |
assertCompletion("new Extend().method(|", true, "ccTest1", "ccTest2"); |
|
203 |
} |
|
204 |
||
205 |
public void testSmartCompletionForBoxedType() { |
|
206 |
assertEval("int ccTest1 = 0;"); |
|
207 |
assertEval("Integer ccTest2 = 0;"); |
|
208 |
assertEval("Object ccTest3 = null;"); |
|
209 |
assertEval("int method1(int n) {return n;}"); |
|
210 |
assertEval("Integer method2(Integer n) {return n;}"); |
|
211 |
assertEval("Object method3(Object o) {return o;}"); |
|
212 |
assertCompletion("int ccTest4 = |", true, "ccTest1", "ccTest2", "method1(", "method2("); |
|
213 |
assertCompletion("Integer ccTest4 = |", true, "ccTest1", "ccTest2", "method1(", "method2("); |
|
214 |
assertCompletion("Object ccTest4 = |", true, "ccTest1", "ccTest2", "ccTest3", "method1(", "method2(", "method3("); |
|
215 |
assertCompletion("method1(|", true, "ccTest1", "ccTest2", "method1(", "method2("); |
|
216 |
assertCompletion("method2(|", true, "ccTest1", "ccTest2", "method1(", "method2("); |
|
217 |
assertCompletion("method3(|", true, "ccTest1", "ccTest2", "ccTest3", "method1(", "method2(", "method3("); |
|
218 |
} |
|
219 |
||
220 |
public void testNewClass() { |
|
221 |
assertCompletion("String str = new Strin|", "String(", "StringBuffer(", "StringBuilder(", "StringIndexOutOfBoundsException("); |
|
222 |
assertCompletion("String str = new java.lang.Strin|", "String(", "StringBuffer(", "StringBuilder(", "StringIndexOutOfBoundsException("); |
|
223 |
assertCompletion("String str = new |", true, "String("); |
|
224 |
assertCompletion("String str = new java.lang.|", true, "String("); |
|
225 |
assertCompletion("throw new Strin|", true, "StringIndexOutOfBoundsException("); |
|
226 |
||
227 |
assertEval("class A{class B{} class C {C(int n) {}} static class D {} interface I {}}"); |
|
228 |
assertEval("A a;"); |
|
229 |
assertCompletion("new A().new |", "B()", "C("); |
|
230 |
assertCompletion("a.new |", "B()", "C("); |
|
231 |
assertCompletion("new A.|", "D()"); |
|
232 |
||
233 |
assertEval("enum E{; class A {}}"); |
|
234 |
assertEval("interface I{; class A {}}"); |
|
235 |
assertCompletion("new E.|", "A()"); |
|
236 |
assertCompletion("new I.|", "A()"); |
|
237 |
assertCompletion("new String(I.A|", "A"); |
|
238 |
} |
|
239 |
||
240 |
public void testFullyQualified() { |
|
241 |
assertCompletion("Optional<String> opt = java.u|", "util"); |
|
242 |
assertCompletionIncludesExcludes("Optional<Strings> opt = java.util.O|", new HashSet<>(Collections.singletonList("Optional")), Collections.emptySet()); |
|
243 |
||
244 |
assertEval("void method(java.util.Optional<String> opt) {}"); |
|
245 |
assertCompletion("method(java.u|", "util"); |
|
246 |
||
247 |
assertCompletion("Object.notElement.|"); |
|
248 |
assertCompletion("Object o = com.su|", "sun"); |
|
33715
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
249 |
|
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
250 |
Path p1 = outDir.resolve("dir1"); |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
251 |
compiler.compile(p1, |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
252 |
"package p1.p2;\n" + |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
253 |
"public class Test {\n" + |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
254 |
"}", |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
255 |
"package p1.p3;\n" + |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
256 |
"public class Test {\n" + |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
257 |
"}"); |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
258 |
String jarName = "test.jar"; |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
259 |
compiler.jar(p1, jarName, "p1/p2/Test.class", "p1/p3/Test.class"); |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
260 |
addToClasspath(compiler.getPath(p1.resolve(jarName))); |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
261 |
|
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
262 |
assertCompletionIncludesExcludes("|", new HashSet<>(Collections.singletonList("p1")), Collections.emptySet()); |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
263 |
assertCompletion("p1.|", "p2", "p3"); |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
264 |
assertCompletion("p1.p2.|", "Test"); |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
265 |
assertCompletion("p1.p3.|", "Test"); |
33362 | 266 |
} |
267 |
||
268 |
public void testCheckAccessibility() { |
|
269 |
assertCompletion("java.util.regex.Pattern.co|", "compile("); |
|
270 |
} |
|
271 |
||
272 |
public void testCompletePackages() { |
|
273 |
assertCompletion("java.u|", "util"); |
|
274 |
assertCompletionIncludesExcludes("jav|", new HashSet<>(Arrays.asList("java", "javax")), Collections.emptySet()); |
|
275 |
} |
|
276 |
||
277 |
public void testImports() { |
|
278 |
assertCompletion("import java.u|", "util"); |
|
279 |
assertCompletionIncludesExcludes("import jav|", new HashSet<>(Arrays.asList("java", "javax")), Collections.emptySet()); |
|
280 |
assertCompletion("import static java.u|", "util"); |
|
281 |
assertCompletionIncludesExcludes("import static jav|", new HashSet<>(Arrays.asList("java", "javax")), Collections.emptySet()); |
|
282 |
assertCompletion("import static java.lang.Boolean.g|", "getBoolean"); |
|
283 |
assertCompletion("import java.util.*|"); |
|
284 |
assertCompletionIncludesExcludes("import java.lang.String.|", |
|
285 |
Collections.emptySet(), |
|
286 |
new HashSet<>(Arrays.asList("CASE_INSENSITIVE_ORDER", "copyValueOf", "format", "join", "valueOf", "class", "length"))); |
|
287 |
assertCompletionIncludesExcludes("import static java.lang.String.|", |
|
288 |
new HashSet<>(Arrays.asList("CASE_INSENSITIVE_ORDER", "copyValueOf", "format", "join", "valueOf")), |
|
289 |
new HashSet<>(Arrays.asList("class", "length"))); |
|
290 |
assertCompletionIncludesExcludes("import java.util.Map.|", |
|
291 |
new HashSet<>(Arrays.asList("Entry")), |
|
292 |
new HashSet<>(Arrays.asList("class"))); |
|
293 |
} |
|
294 |
||
295 |
public void testBrokenClassFile() throws Exception { |
|
296 |
Compiler compiler = new Compiler(); |
|
297 |
Path testOutDir = Paths.get("CompletionTestBrokenClassFile"); |
|
298 |
String input = "package test.inner; public class Test {}"; |
|
299 |
compiler.compile(testOutDir, input); |
|
300 |
addToClasspath(compiler.getPath(testOutDir).resolve("test")); |
|
301 |
assertCompletion("import inner.|"); |
|
302 |
} |
|
303 |
||
37939
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
304 |
public void testDocumentation() throws Exception { |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
305 |
dontReadParameterNamesFromClassFile(); |
33362 | 306 |
assertDocumentation("System.getProperty(|", |
37939
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
307 |
"java.lang.System.getProperty(java.lang.String key)", |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
308 |
"java.lang.System.getProperty(java.lang.String key, java.lang.String def)"); |
33362 | 309 |
assertEval("char[] chars = null;"); |
310 |
assertDocumentation("new String(chars, |", |
|
311 |
"java.lang.String(char[] arg0, int arg1, int arg2)"); |
|
312 |
assertDocumentation("String.format(|", |
|
313 |
"java.lang.String.format(java.lang.String arg0, java.lang.Object... arg1)", |
|
314 |
"java.lang.String.format(java.util.Locale arg0, java.lang.String arg1, java.lang.Object... arg2)"); |
|
315 |
assertDocumentation("\"\".getBytes(\"\"|", "java.lang.String.getBytes(int arg0, int arg1, byte[] arg2, int arg3)", |
|
316 |
"java.lang.String.getBytes(java.lang.String arg0)", |
|
317 |
"java.lang.String.getBytes(java.nio.charset.Charset arg0)"); |
|
318 |
assertDocumentation("\"\".getBytes(\"\" |", "java.lang.String.getBytes(int arg0, int arg1, byte[] arg2, int arg3)", |
|
319 |
"java.lang.String.getBytes(java.lang.String arg0)", |
|
320 |
"java.lang.String.getBytes(java.nio.charset.Charset arg0)"); |
|
321 |
} |
|
322 |
||
37939
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
323 |
public void testMethodsWithNoArguments() throws Exception { |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
324 |
dontReadParameterNamesFromClassFile(); |
33362 | 325 |
assertDocumentation("System.out.println(|", |
326 |
"java.io.PrintStream.println()", |
|
327 |
"java.io.PrintStream.println(boolean arg0)", |
|
328 |
"java.io.PrintStream.println(char arg0)", |
|
329 |
"java.io.PrintStream.println(int arg0)", |
|
330 |
"java.io.PrintStream.println(long arg0)", |
|
331 |
"java.io.PrintStream.println(float arg0)", |
|
332 |
"java.io.PrintStream.println(double arg0)", |
|
333 |
"java.io.PrintStream.println(char[] arg0)", |
|
334 |
"java.io.PrintStream.println(java.lang.String arg0)", |
|
335 |
"java.io.PrintStream.println(java.lang.Object arg0)"); |
|
336 |
} |
|
337 |
||
338 |
public void testErroneous() { |
|
339 |
assertCompletion("Undefined.|"); |
|
340 |
} |
|
341 |
||
342 |
public void testClinit() { |
|
343 |
assertEval("enum E{;}"); |
|
344 |
assertEval("class C{static{}}"); |
|
345 |
assertCompletionIncludesExcludes("E.|", Collections.emptySet(), new HashSet<>(Collections.singletonList("<clinit>"))); |
|
346 |
assertCompletionIncludesExcludes("C.|", Collections.emptySet(), new HashSet<>(Collections.singletonList("<clinit>"))); |
|
347 |
} |
|
348 |
||
349 |
public void testMethodHeaderContext() { |
|
350 |
assertCompletion("private void f(Runn|", "Runnable"); |
|
351 |
assertCompletion("void f(Runn|", "Runnable"); |
|
352 |
assertCompletion("void f(Object o1, Runn|", "Runnable"); |
|
353 |
assertCompletion("void f(Object o1) throws Num|", true, "NumberFormatException"); |
|
354 |
assertCompletion("void f(Object o1) throws java.lang.Num|", true, "NumberFormatException"); |
|
355 |
assertEval("class HogeHoge {static class HogeHogeException extends Exception {}}"); |
|
356 |
assertCompletion("void f(Object o1) throws Hoge|", "HogeHoge"); |
|
357 |
assertCompletion("void f(Object o1) throws HogeHoge.|", true, "HogeHogeException"); |
|
358 |
} |
|
359 |
||
360 |
public void testTypeVariables() { |
|
361 |
assertCompletion("class A<TYPE> { public void test() { TY|", "TYPE"); |
|
362 |
assertCompletion("class A<TYPE> { public static void test() { TY|"); |
|
363 |
assertCompletion("class A<TYPE> { public <TYPE> void test() { TY|", "TYPE"); |
|
364 |
assertCompletion("class A<TYPE> { public static <TYPE> void test() { TY|", "TYPE"); |
|
365 |
} |
|
366 |
||
367 |
public void testGeneric() { |
|
368 |
assertEval("import java.util.concurrent.*;"); |
|
369 |
assertCompletion("java.util.List<Integ|", "Integer"); |
|
370 |
assertCompletion("class A<TYPE extends Call|", "Callable"); |
|
371 |
assertCompletion("class A<TYPE extends Callable<TY|", "TYPE"); |
|
372 |
assertCompletion("<TYPE> void f(TY|", "TYPE"); |
|
373 |
assertCompletion("class A<TYPE extends Callable<? sup|", "super"); |
|
374 |
assertCompletion("class A<TYPE extends Callable<? super TY|", "TYPE"); |
|
375 |
} |
|
376 |
||
377 |
public void testFields() { |
|
378 |
assertEval("interface Interface { int field = 0; }"); |
|
379 |
Snippet clazz = classKey(assertEval("class Clazz {" + |
|
380 |
"static int staticField = 0;" + |
|
381 |
"int field = 0;" + |
|
382 |
" }")); |
|
383 |
assertCompletion("Interface.fiel|", "field"); |
|
384 |
assertCompletion("Clazz.staticFiel|", "staticField"); |
|
385 |
assertCompletion("new Interface() {}.fiel|"); |
|
386 |
assertCompletion("new Clazz().staticFiel|"); |
|
387 |
assertCompletion("new Clazz().fiel|", "field"); |
|
388 |
assertCompletion("new Clazz() {}.fiel|", "field"); |
|
389 |
assertEval("class Clazz implements Interface {}", |
|
390 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
391 |
ste(clazz, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
392 |
assertCompletion("Clazz.fiel|", "field"); |
|
393 |
assertCompletion("new Clazz().fiel|"); |
|
394 |
assertCompletion("new Clazz() {}.fiel|"); |
|
395 |
} |
|
396 |
||
397 |
public void testMethods() { |
|
398 |
assertEval("interface Interface {" + |
|
399 |
"default int defaultMethod() { return 0; }" + |
|
400 |
"static int staticMethod() { return 0; }" + |
|
401 |
"}"); |
|
402 |
Snippet clazz = classKey(assertEval("class Clazz {" + |
|
403 |
"static int staticMethod() { return 0; }" + |
|
404 |
"int method() { return 0; }" + |
|
405 |
"}")); |
|
406 |
assertCompletion("Interface.staticMeth|", "staticMethod()"); |
|
407 |
assertCompletion("Clazz.staticMeth|", "staticMethod()"); |
|
408 |
assertCompletion("new Interface() {}.defaultMe||", "defaultMethod()"); |
|
409 |
assertCompletion("new Clazz().staticMeth|"); |
|
410 |
assertCompletion("new Clazz().meth|", "method()"); |
|
411 |
assertEval("class Clazz implements Interface {}", |
|
412 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
413 |
ste(clazz, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
414 |
assertCompletion("Clazz.staticMeth|"); |
|
415 |
assertCompletion("new Clazz() {}.defaultM|", "defaultMethod()"); |
|
416 |
} |
|
417 |
||
40318
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
418 |
@Test |
33362 | 419 |
public void testUncompletedDeclaration() { |
420 |
assertCompletion("class Clazz { Claz|", "Clazz"); |
|
421 |
assertCompletion("class Clazz { class A extends Claz|", "Clazz"); |
|
40770
dfccc36b61b6
8164952: JShell tests: jdk/jshell/CompletionSuggestionTest.testUncompletedDeclaration(): failure
jlahoda
parents:
40318
diff
changeset
|
422 |
assertCompletion("class Clazz { Clazz clazz; Object o = claz|", "clazz"); |
dfccc36b61b6
8164952: JShell tests: jdk/jshell/CompletionSuggestionTest.testUncompletedDeclaration(): failure
jlahoda
parents:
40318
diff
changeset
|
423 |
assertCompletion("class Clazz { static Clazz clazz; Object o = claz|", "clazz"); |
dfccc36b61b6
8164952: JShell tests: jdk/jshell/CompletionSuggestionTest.testUncompletedDeclaration(): failure
jlahoda
parents:
40318
diff
changeset
|
424 |
assertCompletion("class Clazz { Clazz clazz; static Object o = claz|", true); |
33362 | 425 |
assertCompletion("class Clazz { void method(Claz|", "Clazz"); |
40318
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
426 |
assertCompletion("class A { int method() { return 0; } int a = meth|", "method()"); |
33362 | 427 |
assertCompletion("class A { int field = 0; int method() { return fiel|", "field"); |
40318
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
428 |
assertCompletion("class A { static int method() { return 0; } int a = meth|", "method()"); |
33362 | 429 |
assertCompletion("class A { static int field = 0; int method() { return fiel|", "field"); |
430 |
assertCompletion("class A { int method() { return 0; } static int a = meth|", true); |
|
431 |
assertCompletion("class A { int field = 0; static int method() { return fiel|", true); |
|
432 |
} |
|
433 |
||
40318
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
434 |
@Test |
33362 | 435 |
public void testClassDeclaration() { |
40318
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
436 |
assertEval("void ClazzM() {}"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
437 |
assertEval("void InterfaceM() {}"); |
33362 | 438 |
assertEval("interface Interface {}"); |
439 |
assertCompletion("interface A extends Interf|", "Interface"); |
|
440 |
assertCompletion("class A implements Interf|", "Interface"); |
|
441 |
assertEval("class Clazz {}"); |
|
442 |
assertCompletion("class A extends Claz|", "Clazz"); |
|
443 |
assertCompletion("class A extends Clazz implements Interf|", "Interface"); |
|
444 |
assertEval("interface Interface1 {}"); |
|
445 |
assertCompletion("class A extends Clazz implements Interface, Interf|", "Interface", "Interface1"); |
|
446 |
assertCompletion("interface A implements Claz|"); |
|
447 |
assertCompletion("interface A implements Inter|"); |
|
448 |
assertCompletion("class A implements Claz|", true); |
|
449 |
assertCompletion("class A extends Clazz implements Interface, Interf|", true, "Interface1"); |
|
40318
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
450 |
assertCompletion("class A extends Clazz implements Interface, Interf|", true, "Interface1"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
451 |
assertEval("class InterfaceClazz {}"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
452 |
assertCompletion("class A <T extends Claz|", "Clazz"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
453 |
assertCompletion("class A <T extends Interf|", "Interface", "Interface1", "InterfaceClazz"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
454 |
assertCompletion("class A <T extends Interface & Interf|", "Interface", "Interface1", "InterfaceClazz"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
455 |
assertCompletion("class A <T extends Clazz & Interf|", "Interface", "Interface1", "InterfaceClazz"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
456 |
assertCompletion("class A <T extends Claz|", true, "Clazz"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
457 |
assertCompletion("class A <T extends Interf|", true, "Interface", "Interface1", "InterfaceClazz"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
458 |
assertCompletion("class A <T extends Interface & Interf|", true, "Interface1"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
459 |
assertCompletion("class A <T extends Clazz & Interf|", true, "Interface", "Interface1"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
460 |
} |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
461 |
|
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
462 |
public void testMethodDeclaration() { |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
463 |
assertEval("void ClazzM() {}"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
464 |
assertEval("void InterfaceM() {}"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
465 |
assertEval("interface Interface {}"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
466 |
assertCompletion("void m(Interf|", "Interface"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
467 |
assertCompletion("void m(Interface i1, Interf|", "Interface"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
468 |
assertEval("class InterfaceException extends Exception {}"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
469 |
assertCompletion("void m(Interface i1) throws Interf|", "Interface", "InterfaceException"); |
3f7eb1205cee
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents:
37939
diff
changeset
|
470 |
assertCompletion("void m(Interface i1) throws Interf|", true, "InterfaceException"); |
33362 | 471 |
} |
472 |
||
473 |
public void testDocumentationOfUserDefinedMethods() { |
|
474 |
assertEval("void f() {}"); |
|
475 |
assertDocumentation("f(|", "f()"); |
|
37939
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
476 |
assertEval("void f(int i) {}"); |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
477 |
assertDocumentation("f(|", "f()", "f(int i)"); |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
478 |
assertEval("<T> void f(T... ts) {}", DiagCheck.DIAG_WARNING, DiagCheck.DIAG_OK); |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
479 |
assertDocumentation("f(|", "f()", "f(int i)", "f(T... ts)"); |
33362 | 480 |
assertEval("class A {}"); |
481 |
assertEval("void f(A a) {}"); |
|
37939
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
482 |
assertDocumentation("f(|", "f()", "f(int i)", "f(T... ts)", "f(A a)"); |
33362 | 483 |
} |
484 |
||
485 |
public void testDocumentationOfUserDefinedConstructors() { |
|
486 |
Snippet a = classKey(assertEval("class A {}")); |
|
487 |
assertDocumentation("new A(|", "A()"); |
|
37939
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
488 |
Snippet a2 = classKey(assertEval("class A { A() {} A(int i) {}}", |
33362 | 489 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
490 |
ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET))); |
|
37939
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
491 |
assertDocumentation("new A(|", "A()", "A(int i)"); |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
492 |
assertEval("class A<T> { A(T t) {} A(int i) {}}", |
33362 | 493 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
494 |
ste(a2, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
37939
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
495 |
assertDocumentation("new A(|", "A(T t)", "A(int i)"); |
33362 | 496 |
} |
497 |
||
37939
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
498 |
public void testDocumentationOfOverriddenMethods() throws Exception { |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
499 |
dontReadParameterNamesFromClassFile(); |
33362 | 500 |
assertDocumentation("\"\".wait(|", |
501 |
"java.lang.Object.wait(long arg0)", |
|
502 |
"java.lang.Object.wait(long arg0, int arg1)", |
|
503 |
"java.lang.Object.wait()"); |
|
504 |
assertEval("class Base {void method() {}}"); |
|
505 |
Snippet e = classKey(assertEval("class Extend extends Base {}")); |
|
506 |
assertDocumentation("new Extend().method(|", "Base.method()"); |
|
507 |
assertEval("class Extend extends Base {void method() {}}", |
|
508 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
509 |
ste(e, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
510 |
assertDocumentation("new Extend().method(|", "Extend.method()"); |
|
511 |
} |
|
512 |
||
513 |
public void testDocumentationOfInvisibleMethods() { |
|
514 |
assertDocumentation("Object.wait(|", ""); |
|
515 |
assertDocumentation("\"\".indexOfSupplementary(|", ""); |
|
516 |
Snippet a = classKey(assertEval("class A {void method() {}}")); |
|
517 |
assertDocumentation("A.method(|", ""); |
|
518 |
assertEval("class A {private void method() {}}", |
|
519 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
520 |
ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
521 |
assertDocumentation("new A().method(|", ""); |
|
522 |
} |
|
523 |
||
524 |
public void testDocumentationOfInvisibleConstructors() { |
|
525 |
assertDocumentation("new Compiler(|", ""); |
|
526 |
assertEval("class A { private A() {} }"); |
|
527 |
assertDocumentation("new A(|", ""); |
|
528 |
} |
|
529 |
||
530 |
public void testDocumentationWithBoxing() { |
|
531 |
assertEval("int primitive = 0;"); |
|
532 |
assertEval("Integer boxed = 0;"); |
|
533 |
assertEval("Object object = null;"); |
|
534 |
assertEval("void method(int n, Object o) { }"); |
|
535 |
assertEval("void method(Object n, int o) { }"); |
|
536 |
assertDocumentation("method(primitive,|", |
|
37939
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
537 |
"method(int n, java.lang.Object o)", |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
538 |
"method(java.lang.Object n, int o)"); |
33362 | 539 |
assertDocumentation("method(boxed,|", |
37939
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
540 |
"method(int n, java.lang.Object o)", |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
541 |
"method(java.lang.Object n, int o)"); |
33362 | 542 |
assertDocumentation("method(object,|", |
37939
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
543 |
"method(java.lang.Object n, int o)"); |
33362 | 544 |
} |
545 |
||
546 |
public void testVarArgs() { |
|
547 |
assertEval("int i = 0;"); |
|
548 |
assertEval("class Foo1 { static void m(int... i) { } } "); |
|
549 |
assertCompletion("Foo1.m(|", true, "i"); |
|
550 |
assertCompletion("Foo1.m(i, |", true, "i"); |
|
551 |
assertCompletion("Foo1.m(i, i, |", true, "i"); |
|
552 |
assertEval("class Foo2 { static void m(String s, int... i) { } } "); |
|
553 |
assertCompletion("Foo2.m(|", true); |
|
554 |
assertCompletion("Foo2.m(i, |", true); |
|
555 |
assertCompletion("Foo2.m(\"\", |", true, "i"); |
|
556 |
assertCompletion("Foo2.m(\"\", i, |", true, "i"); |
|
557 |
assertCompletion("Foo2.m(\"\", i, i, |", true, "i"); |
|
558 |
assertEval("class Foo3 { Foo3(String s, int... i) { } } "); |
|
559 |
assertCompletion("new Foo3(|", true); |
|
560 |
assertCompletion("new Foo3(i, |", true); |
|
561 |
assertCompletion("new Foo3(\"\", |", true, "i"); |
|
562 |
assertCompletion("new Foo3(\"\", i, |", true, "i"); |
|
563 |
assertCompletion("new Foo3(\"\", i, i, |", true, "i"); |
|
564 |
assertEval("int[] ia = null;"); |
|
565 |
assertCompletion("Foo1.m(ia, |", true); |
|
566 |
assertEval("class Foo4 { static void m(int... i) { } static void m(int[] ia, String str) { } } "); |
|
567 |
assertEval("String str = null;"); |
|
568 |
assertCompletion("Foo4.m(ia, |", true, "str"); |
|
569 |
} |
|
570 |
||
571 |
public void testConstructorAsMemberOf() { |
|
572 |
assertEval("class Baz<X> { Baz(X x) { } } "); |
|
573 |
assertEval("String str = null;"); |
|
574 |
assertEval("Integer i = null;"); |
|
575 |
assertCompletion("new Baz(|", true, "i", "str"); |
|
576 |
assertCompletion("new Baz<String>(|", true, "str"); |
|
577 |
assertCompletion("Baz<String> bz = new Baz<>(|", true, "str"); |
|
578 |
assertEval("class Foo { static void m(String str) {} static void m(Baz<String> baz) {} }"); |
|
579 |
assertCompletion("Foo.m(new Baz<>(|", true, "str"); |
|
580 |
} |
|
37939
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
581 |
|
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
582 |
@BeforeMethod |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
583 |
public void setUp() { |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
584 |
super.setUp(); |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
585 |
|
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
586 |
Path srcZip = Paths.get("src.zip"); |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
587 |
|
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
588 |
try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(srcZip))) { |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
589 |
out.putNextEntry(new JarEntry("java/lang/System.java")); |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
590 |
out.write(("package java.lang;\n" + |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
591 |
"public class System {\n" + |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
592 |
" public String getProperty(String key) { return null; }\n" + |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
593 |
" public String getProperty(String key, String def) { return def; }\n" + |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
594 |
"}\n").getBytes()); |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
595 |
} catch (IOException ex) { |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
596 |
throw new IllegalStateException(ex); |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
597 |
} |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
598 |
|
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
599 |
try { |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
600 |
Field availableSources = getAnalysis().getClass().getDeclaredField("availableSources"); |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
601 |
availableSources.setAccessible(true); |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
602 |
availableSources.set(getAnalysis(), Arrays.asList(srcZip)); |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
603 |
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) { |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
604 |
throw new IllegalStateException(ex); |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
605 |
} |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
606 |
} |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
607 |
|
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
608 |
private void dontReadParameterNamesFromClassFile() throws Exception { |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
609 |
Field keepParameterNames = getAnalysis().getClass().getDeclaredField("keepParameterNames"); |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
610 |
keepParameterNames.setAccessible(true); |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
611 |
keepParameterNames.set(getAnalysis(), new String[0]); |
3eb8c2a89b77
8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents:
36778
diff
changeset
|
612 |
} |
40837
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
613 |
|
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
614 |
public void testBrokenClassFile2() throws IOException { |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
615 |
Path broken = outDir.resolve("broken"); |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
616 |
compiler.compile(broken, |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
617 |
"package p;\n" + |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
618 |
"public class BrokenA {\n" + |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
619 |
"}", |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
620 |
"package p.q;\n" + |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
621 |
"public class BrokenB {\n" + |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
622 |
"}", |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
623 |
"package p;\n" + |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
624 |
"public class BrokenC {\n" + |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
625 |
"}"); |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
626 |
Path cp = compiler.getPath(broken); |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
627 |
Path target = cp.resolve("p").resolve("BrokenB.class"); |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
628 |
Files.deleteIfExists(target); |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
629 |
Files.move(cp.resolve("p").resolve("q").resolve("BrokenB.class"), target); |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
630 |
addToClasspath(cp); |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
631 |
|
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
632 |
assertEval("import p.*;"); |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
633 |
assertCompletion("Broke|", "BrokenA", "BrokenC"); |
d071bcc8d32e
8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents:
40770
diff
changeset
|
634 |
} |
33362 | 635 |
} |