8182268: JShell: CompletionInfo.source() for CONSIDERED_INCOMPLETE missing semicolon
authorrfield
Mon, 26 Jun 2017 14:16:34 -0700
changeset 45748 0202b55d8e08
parent 45747 bdf4b1b26697
child 45749 11797433fbc0
8182268: JShell: CompletionInfo.source() for CONSIDERED_INCOMPLETE missing semicolon Reviewed-by: jlahoda
langtools/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java
langtools/test/jdk/jshell/CompletenessTest.java
langtools/test/jdk/jshell/KullaTesting.java
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java	Sun Jun 25 13:42:31 2017 -0700
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java	Mon Jun 26 14:16:34 2017 -0700
@@ -188,7 +188,7 @@
         int nonCommentNonWhiteLength = trimmedInput.length();
         String src = srcInput.substring(0, unitEndPos);
         switch (status) {
-            case COMPLETE:
+            case COMPLETE: {
                 if (unitEndPos == nonCommentNonWhiteLength) {
                     // The unit is the whole non-coment/white input plus semicolon
                     String compileSource = src
@@ -202,7 +202,8 @@
                     proc.debug(DBG_COMPA, "          remaining: %s\n", remain);
                     return new CompletionInfoImpl(status, src, remain);
                 }
-            case COMPLETE_WITH_SEMI:
+            }
+            case COMPLETE_WITH_SEMI: {
                 // The unit is the whole non-coment/white input plus semicolon
                 String compileSource = src
                         + ";"
@@ -210,12 +211,18 @@
                 proc.debug(DBG_COMPA, "Complete with semi: %s\n", compileSource);
                 proc.debug(DBG_COMPA, "   nothing remains.\n");
                 return new CompletionInfoImpl(status, compileSource, "");
+            }
             case DEFINITELY_INCOMPLETE:
                 proc.debug(DBG_COMPA, "Incomplete: %s\n", srcInput);
                 return new CompletionInfoImpl(status, null, srcInput + '\n');
-            case CONSIDERED_INCOMPLETE:
+            case CONSIDERED_INCOMPLETE: {
+                // Since the source is potentually valid, construct the complete source
+                String compileSource = src
+                        + ";"
+                        + mcm.mask().substring(nonCommentNonWhiteLength);
                 proc.debug(DBG_COMPA, "Considered incomplete: %s\n", srcInput);
-                return new CompletionInfoImpl(status, null, srcInput + '\n');
+                return new CompletionInfoImpl(status, compileSource, srcInput + '\n');
+            }
             case EMPTY:
                 proc.debug(DBG_COMPA, "Detected empty: %s\n", srcInput);
                 return new CompletionInfoImpl(status, srcInput, "");
--- a/langtools/test/jdk/jshell/CompletenessTest.java	Sun Jun 25 13:42:31 2017 -0700
+++ b/langtools/test/jdk/jshell/CompletenessTest.java	Mon Jun 26 14:16:34 2017 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8149524 8131024 8165211 8080071 8130454 8167343 8129559 8114842
+ * @bug 8149524 8131024 8165211 8080071 8130454 8167343 8129559 8114842 8182268
  * @summary Test SourceCodeAnalysis
  * @build KullaTesting TestingInputStream
  * @run testng CompletenessTest
@@ -208,8 +208,11 @@
                 break;
 
             case DEFINITELY_INCOMPLETE:
+                augSrc = null;
+                break;
+
             case CONSIDERED_INCOMPLETE:
-                augSrc = null;
+                augSrc = source + ";";
                 break;
 
             case EMPTY:
--- a/langtools/test/jdk/jshell/KullaTesting.java	Sun Jun 25 13:42:31 2017 -0700
+++ b/langtools/test/jdk/jshell/KullaTesting.java	Mon Jun 26 14:16:34 2017 -0700
@@ -793,7 +793,7 @@
     public void assertAnalyze(String input, Completeness status, String source, String remaining, Boolean isComplete) {
         CompletionInfo ci = getAnalysis().analyzeCompletion(input);
         if (status != null) assertEquals(ci.completeness(), status, "Input : " + input + ", status: ");
-        if (source != null) assertEquals(ci.source(), source, "Input : " + input + ", source: ");
+        assertEquals(ci.source(), source, "Input : " + input + ", source: ");
         if (remaining != null) assertEquals(ci.remaining(), remaining, "Input : " + input + ", remaining: ");
         if (isComplete != null) {
             boolean isExpectedComplete = isComplete;