changeset 3333:571ee117bb25

8130450: JShell: events are not generated for repeated source 8139835: JShell API: Snippet.id() doc -- specify: no meaning, dynamic Reviewed-by: jlahoda
author rfield
date Fri, 08 Apr 2016 10:51:57 -0700
parents 482c38db3637
children 859998e32f58
files src/jdk.jshell/share/classes/jdk/jshell/Eval.java src/jdk.jshell/share/classes/jdk/jshell/Snippet.java src/jdk.jshell/share/classes/jdk/jshell/Unit.java test/jdk/jshell/SimpleRegressionTest.java
diffstat 4 files changed, 17 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jshell/share/classes/jdk/jshell/Eval.java	Fri Apr 08 11:52:46 2016 +0200
+++ b/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/src/jdk.jshell/share/classes/jdk/jshell/Snippet.java	Fri Apr 08 11:52:46 2016 +0200
+++ b/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/src/jdk.jshell/share/classes/jdk/jshell/Unit.java	Fri Apr 08 11:52:46 2016 +0200
+++ b/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/test/jdk/jshell/SimpleRegressionTest.java	Fri Apr 08 11:52:46 2016 +0200
+++ b/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));
+    }
 }