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