changeset 45747:bdf4b1b26697

8176110: JShell: completions with package results should, in most cases, be dot terminated Reviewed-by: jlahoda
author rfield
date Sun, 25 Jun 2017 13:42:31 -0700
parents a64c9a565bb7
children 0202b55d8e08
files langtools/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java langtools/test/jdk/jshell/CompletionSuggestionTest.java
diffstat 2 files changed, 24 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java	Sun Jun 25 13:38:26 2017 -0700
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java	Sun Jun 25 13:42:31 2017 -0700
@@ -673,8 +673,16 @@
                 continue;
             }
             String simpleName = simpleName(c);
-            if (c.getKind() == ElementKind.CONSTRUCTOR || c.getKind() == ElementKind.METHOD) {
-                simpleName += paren.apply(hasParams.contains(simpleName));
+            switch (c.getKind()) {
+                case CONSTRUCTOR:
+                case METHOD:
+                    // add trailing open or matched parenthesis, as approriate
+                    simpleName += paren.apply(hasParams.contains(simpleName));
+                    break;
+                case PACKAGE:
+                    // add trailing dot to package names
+                    simpleName += ".";
+                    break;
             }
             result.add(new SuggestionImpl(simpleName, smart.test(c)));
         }
--- a/langtools/test/jdk/jshell/CompletionSuggestionTest.java	Sun Jun 25 13:38:26 2017 -0700
+++ b/langtools/test/jdk/jshell/CompletionSuggestionTest.java	Sun Jun 25 13:42:31 2017 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8131025 8141092 8153761 8145263 8131019 8175886 8176184 8176241
+ * @bug 8131025 8141092 8153761 8145263 8131019 8175886 8176184 8176241 8176110
  * @summary Test Completion and Documentation
  * @library /tools/lib
  * @modules jdk.compiler/com.sun.tools.javac.api
@@ -180,7 +180,7 @@
         assertCompletion("list.add(0, |", true, "ccTest3");
         assertCompletion("new String(|", true, "ccTest3");
         assertCompletion("new String(new char[0], |", true, "ccTest1", "ccTest2");
-        assertCompletionIncludesExcludes("new jav|", new HashSet<>(Arrays.asList("java", "javax")), Collections.emptySet());
+        assertCompletionIncludesExcludes("new jav|", new HashSet<>(Arrays.asList("java.", "javax.")), Collections.emptySet());
         assertCompletion("Class<String> clazz = String.c|", true, "class");
 
         Snippet klass = classKey(assertEval("class Klass {void method(int n) {} private void method(String str) {}}"));
@@ -241,14 +241,14 @@
     }
 
     public void testFullyQualified() {
-        assertCompletion("Optional<String> opt = java.u|", "util");
+        assertCompletion("Optional<String> opt = java.u|", "util.");
         assertCompletionIncludesExcludes("Optional<Strings> opt = java.util.O|", new HashSet<>(Collections.singletonList("Optional")), Collections.emptySet());
 
         assertEval("void method(java.util.Optional<String> opt) {}");
-        assertCompletion("method(java.u|", "util");
+        assertCompletion("method(java.u|", "util.");
 
         assertCompletion("Object.notElement.|");
-        assertCompletion("Object o = com.su|", "sun");
+        assertCompletion("Object o = com.su|", "sun.");
 
         Path p1 = outDir.resolve("dir1");
         compiler.compile(p1,
@@ -262,8 +262,8 @@
         compiler.jar(p1, jarName, "p1/p2/Test.class", "p1/p3/Test.class");
         addToClasspath(compiler.getPath(p1.resolve(jarName)));
 
-        assertCompletionIncludesExcludes("|", new HashSet<>(Collections.singletonList("p1")), Collections.emptySet());
-        assertCompletion("p1.|", "p2", "p3");
+        assertCompletionIncludesExcludes("|", new HashSet<>(Collections.singletonList("p1.")), Collections.emptySet());
+        assertCompletion("p1.|", "p2.", "p3.");
         assertCompletion("p1.p2.|", "Test");
         assertCompletion("p1.p3.|", "Test");
     }
@@ -273,15 +273,15 @@
     }
 
     public void testCompletePackages() {
-        assertCompletion("java.u|", "util");
-        assertCompletionIncludesExcludes("jav|", new HashSet<>(Arrays.asList("java", "javax")), Collections.emptySet());
+        assertCompletion("java.u|", "util.");
+        assertCompletionIncludesExcludes("jav|", new HashSet<>(Arrays.asList("java.", "javax.")), Collections.emptySet());
     }
 
     public void testImports() {
-        assertCompletion("import java.u|", "util");
-        assertCompletionIncludesExcludes("import jav|", new HashSet<>(Arrays.asList("java", "javax")), Collections.emptySet());
-        assertCompletion("import static java.u|", "util");
-        assertCompletionIncludesExcludes("import static jav|", new HashSet<>(Arrays.asList("java", "javax")), Collections.emptySet());
+        assertCompletion("import java.u|", "util.");
+        assertCompletionIncludesExcludes("import jav|", new HashSet<>(Arrays.asList("java.", "javax.")), Collections.emptySet());
+        assertCompletion("import static java.u|", "util.");
+        assertCompletionIncludesExcludes("import static jav|", new HashSet<>(Arrays.asList("java.", "javax.")), Collections.emptySet());
         assertCompletion("import static java.lang.Boolean.g|", "getBoolean");
         assertCompletion("import java.util.*|");
         assertCompletionIncludesExcludes("import java.lang.String.|",
@@ -296,7 +296,7 @@
     }
 
     public void testImportStart() {
-        assertCompletionIncludesExcludes("import c|", Set.of("com"), Set.of());
+        assertCompletionIncludesExcludes("import c|", Set.of("com."), Set.of());
     }
 
     public void testBrokenClassFile() throws Exception {