8130450: JShell: events are not generated for repeated source
authorrfield
Fri, 08 Apr 2016 10:51:57 -0700
changeset 37005 71210037624f
parent 37004 ff77b7986967
child 37006 73ca1e844343
8130450: JShell: events are not generated for repeated source 8139835: JShell API: Snippet.id() doc -- specify: no meaning, dynamic Reviewed-by: jlahoda
langtools/src/jdk.jshell/share/classes/jdk/jshell/Eval.java
langtools/src/jdk.jshell/share/classes/jdk/jshell/Snippet.java
langtools/src/jdk.jshell/share/classes/jdk/jshell/Unit.java
langtools/test/jdk/jshell/SimpleRegressionTest.java
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/Eval.java	Fri Apr 08 11:52:46 2016 +0200
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/Eval.java	Fri Apr 08 10:51:57 2016 -0700
@@ -449,13 +449,6 @@
 
     private List<SnippetEvent> declare(Snippet si, DiagList generatedDiagnostics) {
         Unit c = new Unit(state, si, null, generatedDiagnostics);
-
-        // Ignores duplicates
-        //TODO: remove, modify, or move to edit
-        if (c.isRedundant()) {
-            return Collections.emptyList();
-        }
-
         Set<Unit> ins = new LinkedHashSet<>();
         ins.add(c);
         Set<Unit> outs = compileAndLoad(ins);
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/Snippet.java	Fri Apr 08 11:52:46 2016 +0200
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/Snippet.java	Fri Apr 08 10:51:57 2016 -0700
@@ -524,7 +524,9 @@
 
     /**
      * The unique identifier for the snippet. No two active snippets will have
-     * the same id().
+     * the same id().  Value of id has no prescribed meaning.  The details of
+     * how the id is generated and the mechanism to change it is documented in
+     * {@link JShell.Builder#idGenerator()}.
      * @return the snippet id string.
      */
     public String id() {
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/Unit.java	Fri Apr 08 11:52:46 2016 +0200
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/Unit.java	Fri Apr 08 10:51:57 2016 -0700
@@ -140,12 +140,6 @@
         return isNew;
     }
 
-    boolean isRedundant() {
-        return !isNew && !isDependency() && !si.isExecutable() &&
-                prevStatus.isDefined &&
-                siOld.source().equals(si.source());
-    }
-
     void initialize(Collection<Unit> working) {
         isAttemptingCorral = false;
         dependenciesNeeded = false;
--- a/langtools/test/jdk/jshell/SimpleRegressionTest.java	Fri Apr 08 11:52:46 2016 +0200
+++ b/langtools/test/jdk/jshell/SimpleRegressionTest.java	Fri Apr 08 10:51:57 2016 -0700
@@ -22,7 +22,7 @@
  */
 
 /*
- * @test
+ * @test 8130450
  * @summary simple regression test
  * @build KullaTesting TestingInputStream
  * @run testng SimpleRegressionTest
@@ -39,6 +39,7 @@
 import org.testng.annotations.Test;
 
 import static org.testng.Assert.assertEquals;
+import static jdk.jshell.Snippet.Status.OVERWRITTEN;
 import static jdk.jshell.Snippet.SubKind.TEMP_VAR_EXPRESSION_SUBKIND;
 import static jdk.jshell.Snippet.Status.VALID;
 
@@ -98,4 +99,16 @@
         VarSnippet sne = varKey(assertEval("n(5)", added(VALID)));
         assertEquals(sne.typeName(), "Integer");
     }
+
+    // 8130450
+    public void testDuplicate() {
+        Snippet snm = methodKey(assertEval("void mm() {}", added(VALID)));
+        assertEval("void mm() {}",
+                ste(MAIN_SNIPPET, VALID, VALID, false, null),
+                ste(snm, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
+        Snippet snv = varKey(assertEval("boolean b;", added(VALID)));
+        assertEval("boolean b;",
+                ste(MAIN_SNIPPET, VALID, VALID, false, null),
+                ste(snv, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
+    }
 }