< prev index next >

test/langtools/jdk/jshell/CompletionSuggestionTest.java

Print this page
rev 48744 : 8197439: Crash with -XDfind=lambda for anonymous class in anonymous class.
Summary: Ensuring unresolvable anonymous classes are attributed.
Reviewed-by: TBD


   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 8131025 8141092 8153761 8145263 8131019 8175886 8176184 8176241 8176110 8177466
  27  * @summary Test Completion and Documentation
  28  * @library /tools/lib
  29  * @modules jdk.compiler/com.sun.tools.javac.api
  30  *          jdk.compiler/com.sun.tools.javac.main
  31  *          jdk.jdeps/com.sun.tools.javap
  32  *          jdk.jshell/jdk.jshell:open
  33  * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
  34  * @build KullaTesting TestingInputStream Compiler
  35  * @run testng CompletionSuggestionTest
  36  */
  37 
  38 import java.io.IOException;
  39 import java.lang.reflect.Field;
  40 import java.nio.file.Files;
  41 import java.nio.file.Path;
  42 import java.nio.file.Paths;
  43 import java.util.Arrays;
  44 import java.util.Collections;
  45 import java.util.Set;
  46 import java.util.HashSet;


 642         assertCompletion("new Baz<String>(|", true, "str");
 643         assertCompletion("Baz<String> bz = new Baz<>(|", true, "str");
 644         assertEval("class Foo { static void m(String str) {} static void m(Baz<String> baz) {} }");
 645         assertCompletion("Foo.m(new Baz<>(|", true, "str");
 646     }
 647 
 648     public void testIntersection() {
 649         assertEval("<Z extends Runnable & CharSequence> Z get() { return null; }");
 650         assertEval("var v = get();");
 651         assertCompletionIncludesExcludes("v.|", true, Set.of("run()", "length()"), Set.of());
 652         assertCompletion("Runnable r = |", true, "get()", "v");
 653         assertCompletion("CharSequence r = |", true, "get()", "v");
 654         assertCompletion("Number r = |", true);
 655     }
 656 
 657     public void testAnonymous() {
 658         assertEval("var v = new Runnable() { public void run() { } public int length() { return 0; } };");
 659         assertCompletionIncludesExcludes("v.|", true, Set.of("run()", "length()"), Set.of());
 660         assertCompletion("Runnable r = |", true, "v");
 661         assertCompletion("CharSequence r = |", true);




 662     }
 663 
 664     @BeforeMethod
 665     public void setUp() {
 666         super.setUp();
 667 
 668         Path srcZip = Paths.get("src.zip");
 669 
 670         try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(srcZip))) {
 671             out.putNextEntry(new JarEntry("java/lang/System.java"));
 672             out.write(("package java.lang;\n" +
 673                        "public class System {\n" +
 674                        "    public String getProperty(String key) { return null; }\n" +
 675                        "    public String getProperty(String key, String def) { return def; }\n" +
 676                        "}\n").getBytes());
 677         } catch (IOException ex) {
 678             throw new IllegalStateException(ex);
 679         }
 680 
 681         try {




   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 8131025 8141092 8153761 8145263 8131019 8175886 8176184 8176241 8176110 8177466 8197439
  27  * @summary Test Completion and Documentation
  28  * @library /tools/lib
  29  * @modules jdk.compiler/com.sun.tools.javac.api
  30  *          jdk.compiler/com.sun.tools.javac.main
  31  *          jdk.jdeps/com.sun.tools.javap
  32  *          jdk.jshell/jdk.jshell:open
  33  * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
  34  * @build KullaTesting TestingInputStream Compiler
  35  * @run testng CompletionSuggestionTest
  36  */
  37 
  38 import java.io.IOException;
  39 import java.lang.reflect.Field;
  40 import java.nio.file.Files;
  41 import java.nio.file.Path;
  42 import java.nio.file.Paths;
  43 import java.util.Arrays;
  44 import java.util.Collections;
  45 import java.util.Set;
  46 import java.util.HashSet;


 642         assertCompletion("new Baz<String>(|", true, "str");
 643         assertCompletion("Baz<String> bz = new Baz<>(|", true, "str");
 644         assertEval("class Foo { static void m(String str) {} static void m(Baz<String> baz) {} }");
 645         assertCompletion("Foo.m(new Baz<>(|", true, "str");
 646     }
 647 
 648     public void testIntersection() {
 649         assertEval("<Z extends Runnable & CharSequence> Z get() { return null; }");
 650         assertEval("var v = get();");
 651         assertCompletionIncludesExcludes("v.|", true, Set.of("run()", "length()"), Set.of());
 652         assertCompletion("Runnable r = |", true, "get()", "v");
 653         assertCompletion("CharSequence r = |", true, "get()", "v");
 654         assertCompletion("Number r = |", true);
 655     }
 656 
 657     public void testAnonymous() {
 658         assertEval("var v = new Runnable() { public void run() { } public int length() { return 0; } };");
 659         assertCompletionIncludesExcludes("v.|", true, Set.of("run()", "length()"), Set.of());
 660         assertCompletion("Runnable r = |", true, "v");
 661         assertCompletion("CharSequence r = |", true);
 662     }
 663 
 664     public void testCompletionInAnonymous() {
 665         assertCompletionIncludesExcludes("new Undefined() { int i = \"\".l|", Set.of("length()"), Set.of());
 666     }
 667 
 668     @BeforeMethod
 669     public void setUp() {
 670         super.setUp();
 671 
 672         Path srcZip = Paths.get("src.zip");
 673 
 674         try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(srcZip))) {
 675             out.putNextEntry(new JarEntry("java/lang/System.java"));
 676             out.write(("package java.lang;\n" +
 677                        "public class System {\n" +
 678                        "    public String getProperty(String key) { return null; }\n" +
 679                        "    public String getProperty(String key, String def) { return def; }\n" +
 680                        "}\n").getBytes());
 681         } catch (IOException ex) {
 682             throw new IllegalStateException(ex);
 683         }
 684 
 685         try {


< prev index next >