8080357: JShell: Only unqualified unresolved references should be corralled
authorrfield
Tue, 02 Feb 2016 16:11:09 -0800
changeset 35736 bae6ea327651
parent 35735 2ef377e41902
child 35737 3977b3940b92
8080357: JShell: Only unqualified unresolved references should be corralled 8081431: JShell: Dropping import should update dependencies Reviewed-by: jlahoda
langtools/src/jdk.jshell/share/classes/jdk/jshell/OuterWrap.java
langtools/test/jdk/jshell/DropTest.java
langtools/test/jdk/jshell/MethodsTest.java
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/OuterWrap.java	Tue Feb 02 12:56:35 2016 +0000
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/OuterWrap.java	Tue Feb 02 16:11:09 2016 -0800
@@ -31,6 +31,7 @@
 import javax.tools.Diagnostic;
 import javax.tools.JavaFileObject;
 import jdk.jshell.MemoryFileManager.SourceMemoryJavaFileObject;
+import static jdk.internal.jshell.debug.InternalDebugControl.DBG_GEN;
 
 /**
  *
@@ -183,6 +184,22 @@
         }
 
         @Override
+        boolean isResolutionError() {
+            if (!super.isResolutionError()) {
+                return false;
+            }
+            for (String line : diag.getMessage(PARSED_LOCALE).split("\\r?\\n")) {
+                if (line.trim().startsWith("location:")) {
+                    if (!line.contains(REPL_CLASS_PREFIX)) {
+                        // Resolution error must occur within a REPL class or it is not resolvable
+                        return false;
+                    }
+                }
+            }
+            return true;
+        }
+
+        @Override
         public String toString() {
             return "WrappedDiagnostic(" + getMessage(null) + ":" + getPosition() + ")";
         }
--- a/langtools/test/jdk/jshell/DropTest.java	Tue Feb 02 12:56:35 2016 +0000
+++ b/langtools/test/jdk/jshell/DropTest.java	Tue Feb 02 16:11:09 2016 -0800
@@ -23,6 +23,7 @@
 
 /*
  * @test
+ * @bug 8081431
  * @summary Test of JShell#drop().
  * @build KullaTesting TestingInputStream
  * @run testng DropTest
@@ -79,7 +80,6 @@
         assertActiveKeys();
     }
 
-    @Test(enabled = false) // TODO 8081431
     public void testDropImport() {
         PersistentSnippet imp = importKey(assertEval("import java.util.*;"));
         PersistentSnippet decl = varKey(
--- a/langtools/test/jdk/jshell/MethodsTest.java	Tue Feb 02 12:56:35 2016 +0000
+++ b/langtools/test/jdk/jshell/MethodsTest.java	Tue Feb 02 16:11:09 2016 -0800
@@ -23,6 +23,7 @@
 
 /*
  * @test
+ * @bug 8080357
  * @summary Tests for EvaluationState.methods
  * @build KullaTesting TestingInputStream ExpectedDiagnostic
  * @run testng MethodsTest
@@ -36,7 +37,6 @@
 import org.testng.annotations.Test;
 
 import static jdk.jshell.Snippet.Status.*;
-import static jdk.jshell.Snippet.SubKind.*;
 
 @Test
 public class MethodsTest extends KullaTesting {
@@ -74,6 +74,15 @@
         assertMethodDeclSnippet(m1, "f", "(Bar)void", DROPPED, 1, 0);
     }
 
+    // 8080357
+    public void testNonReplUnresolved() {
+        // internal case
+        assertEval("class CCC {}", added(VALID));
+        assertEval("void f1() { CCC.xxxx(); }", added(RECOVERABLE_DEFINED));
+        // external case, not recoverable
+        assertDeclareFail("void f2() { System.xxxx(); }", "compiler.err.cant.resolve.location.args");
+    }
+
     public void methods() {
         assertEval("int x() { return 10; }");
         assertEval("String y() { return null; }");