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