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