langtools/src/jdk.jshell/share/classes/jdk/jshell/JShell.java
changeset 41514 a75c2b869d8d
parent 40764 29ded021f809
child 41628 664e7664343d
equal deleted inserted replaced
41455:0875007901f7 41514:a75c2b869d8d
    56 /**
    56 /**
    57  * The JShell evaluation state engine.  This is the central class in the JShell
    57  * The JShell evaluation state engine.  This is the central class in the JShell
    58  * API.  A {@code JShell} instance holds the evolving compilation and
    58  * API.  A {@code JShell} instance holds the evolving compilation and
    59  * execution state.  The state is changed with the instance methods
    59  * execution state.  The state is changed with the instance methods
    60  * {@link jdk.jshell.JShell#eval(java.lang.String) eval(String)},
    60  * {@link jdk.jshell.JShell#eval(java.lang.String) eval(String)},
    61  * {@link jdk.jshell.JShell#drop(jdk.jshell.PersistentSnippet) drop(PersistentSnippet)} and
    61  * {@link jdk.jshell.JShell#drop(jdk.jshell.Snippet) drop(Snippet)} and
    62  * {@link jdk.jshell.JShell#addToClasspath(java.lang.String) addToClasspath(String)}.
    62  * {@link jdk.jshell.JShell#addToClasspath(java.lang.String) addToClasspath(String)}.
    63  * The majority of methods query the state.
    63  * The majority of methods query the state.
    64  * A {@code JShell} instance also allows registering for events with
    64  * A {@code JShell} instance also allows registering for events with
    65  * {@link jdk.jshell.JShell#onSnippetEvent(java.util.function.Consumer) onSnippetEvent(Consumer)}
    65  * {@link jdk.jshell.JShell#onSnippetEvent(java.util.function.Consumer) onSnippetEvent(Consumer)}
    66  * and {@link jdk.jshell.JShell#onShutdown(java.util.function.Consumer) onShutdown(Consumer)}, which
    66  * and {@link jdk.jshell.JShell#onShutdown(java.util.function.Consumer) onShutdown(Consumer)}, which
   426             }
   426             }
   427         }
   427         }
   428     }
   428     }
   429 
   429 
   430     /**
   430     /**
   431      * Remove a declaration from the state.
   431      * Remove a declaration from the state.  That is, if the snippet is an
       
   432      * {@linkplain jdk.jshell.Snippet.Status#isActive() active}
       
   433      * {@linkplain jdk.jshell.PersistentSnippet persistent} snippet, remove the
       
   434      * snippet and update the JShell evaluation state accordingly.
       
   435      * For all active snippets, change the {@linkplain #status status} to
       
   436      * {@link jdk.jshell.Snippet.Status#DROPPED DROPPED}.
   432      * @param snippet The snippet to remove
   437      * @param snippet The snippet to remove
   433      * @return The list of events from updating declarations dependent on the
   438      * @return The list of events from updating declarations dependent on the
   434      * dropped snippet.
   439      * dropped snippet.
   435      * @throws IllegalStateException if this {@code JShell} instance is closed.
   440      * @throws IllegalStateException if this {@code JShell} instance is closed.
   436      * @throws IllegalArgumentException if the snippet is not associated with
   441      * @throws IllegalArgumentException if the snippet is not associated with
   437      * this {@code JShell} instance.
   442      * this {@code JShell} instance.
   438      */
   443      */
   439     public List<SnippetEvent> drop(PersistentSnippet snippet) throws IllegalStateException {
   444     public List<SnippetEvent> drop(Snippet snippet) throws IllegalStateException {
   440         checkIfAlive();
   445         checkIfAlive();
   441         checkValidSnippet(snippet);
   446         checkValidSnippet(snippet);
   442         List<SnippetEvent> events = eval.drop(snippet);
   447         List<SnippetEvent> events = eval.drop(snippet);
   443         events.forEach(this::notifyKeyStatusEvent);
   448         events.forEach(this::notifyKeyStatusEvent);
   444         return Collections.unmodifiableList(events);
   449         return Collections.unmodifiableList(events);