langtools/src/jdk.jshell/share/classes/jdk/jshell/JShell.java
changeset 40515 819fc588bd19
parent 40304 0318f4e75c6d
child 40764 29ded021f809
equal deleted inserted replaced
40514:fa42e8040550 40515:819fc588bd19
   501     }
   501     }
   502 
   502 
   503     /**
   503     /**
   504      * Return all snippets.
   504      * Return all snippets.
   505      * @return the snippets for all current snippets in id order.
   505      * @return the snippets for all current snippets in id order.
   506      * @throws IllegalStateException if this JShell instance is closed.
   506      */
   507      */
   507     public Stream<Snippet> snippets() {
   508     public Stream<Snippet> snippets() throws IllegalStateException {
       
   509         checkIfAlive();
       
   510         return maps.snippetList().stream();
   508         return maps.snippetList().stream();
   511     }
   509     }
   512 
   510 
   513     /**
   511     /**
   514      * Returns the active variable snippets.
   512      * Returns the active variable snippets.
   515      * This convenience method is equivalent to {@code snippets()} filtered for
   513      * This convenience method is equivalent to {@code snippets()} filtered for
   516      * {@link jdk.jshell.Snippet.Status#isActive() status(snippet).isActive()}
   514      * {@link jdk.jshell.Snippet.Status#isActive() status(snippet).isActive()}
   517      * {@code && snippet.kind() == Kind.VARIABLE}
   515      * {@code && snippet.kind() == Kind.VARIABLE}
   518      * and cast to {@code VarSnippet}.
   516      * and cast to {@code VarSnippet}.
   519      * @return the active declared variables.
   517      * @return the active declared variables.
   520      * @throws IllegalStateException if this JShell instance is closed.
   518      */
   521      */
   519     public Stream<VarSnippet> variables() {
   522     public Stream<VarSnippet> variables() throws IllegalStateException {
       
   523         return snippets()
   520         return snippets()
   524                      .filter(sn -> status(sn).isActive() && sn.kind() == Snippet.Kind.VAR)
   521                      .filter(sn -> status(sn).isActive() && sn.kind() == Snippet.Kind.VAR)
   525                      .map(sn -> (VarSnippet) sn);
   522                      .map(sn -> (VarSnippet) sn);
   526     }
   523     }
   527 
   524 
   530      * This convenience method is equivalent to {@code snippets()} filtered for
   527      * This convenience method is equivalent to {@code snippets()} filtered for
   531      * {@link jdk.jshell.Snippet.Status#isActive() status(snippet).isActive()}
   528      * {@link jdk.jshell.Snippet.Status#isActive() status(snippet).isActive()}
   532      * {@code && snippet.kind() == Kind.METHOD}
   529      * {@code && snippet.kind() == Kind.METHOD}
   533      * and cast to MethodSnippet.
   530      * and cast to MethodSnippet.
   534      * @return the active declared methods.
   531      * @return the active declared methods.
   535      * @throws IllegalStateException if this JShell instance is closed.
   532      */
   536      */
   533     public Stream<MethodSnippet> methods() {
   537     public Stream<MethodSnippet> methods() throws IllegalStateException {
       
   538         return snippets()
   534         return snippets()
   539                      .filter(sn -> status(sn).isActive() && sn.kind() == Snippet.Kind.METHOD)
   535                      .filter(sn -> status(sn).isActive() && sn.kind() == Snippet.Kind.METHOD)
   540                      .map(sn -> (MethodSnippet)sn);
   536                      .map(sn -> (MethodSnippet)sn);
   541     }
   537     }
   542 
   538 
   545      * This convenience method is equivalent to {@code snippets()} filtered for
   541      * This convenience method is equivalent to {@code snippets()} filtered for
   546      * {@link jdk.jshell.Snippet.Status#isActive() status(snippet).isActive()}
   542      * {@link jdk.jshell.Snippet.Status#isActive() status(snippet).isActive()}
   547      * {@code && snippet.kind() == Kind.TYPE_DECL}
   543      * {@code && snippet.kind() == Kind.TYPE_DECL}
   548      * and cast to TypeDeclSnippet.
   544      * and cast to TypeDeclSnippet.
   549      * @return the active declared type declarations.
   545      * @return the active declared type declarations.
   550      * @throws IllegalStateException if this JShell instance is closed.
   546      */
   551      */
   547     public Stream<TypeDeclSnippet> types() {
   552     public Stream<TypeDeclSnippet> types() throws IllegalStateException {
       
   553         return snippets()
   548         return snippets()
   554                 .filter(sn -> status(sn).isActive() && sn.kind() == Snippet.Kind.TYPE_DECL)
   549                 .filter(sn -> status(sn).isActive() && sn.kind() == Snippet.Kind.TYPE_DECL)
   555                 .map(sn -> (TypeDeclSnippet) sn);
   550                 .map(sn -> (TypeDeclSnippet) sn);
   556     }
   551     }
   557 
   552 
   560      * This convenience method is equivalent to {@code snippets()} filtered for
   555      * This convenience method is equivalent to {@code snippets()} filtered for
   561      * {@link jdk.jshell.Snippet.Status#isActive() status(snippet).isActive()}
   556      * {@link jdk.jshell.Snippet.Status#isActive() status(snippet).isActive()}
   562      * {@code && snippet.kind() == Kind.IMPORT}
   557      * {@code && snippet.kind() == Kind.IMPORT}
   563      * and cast to ImportSnippet.
   558      * and cast to ImportSnippet.
   564      * @return the active declared import declarations.
   559      * @return the active declared import declarations.
   565      * @throws IllegalStateException if this JShell instance is closed.
   560      */
   566      */
   561     public Stream<ImportSnippet> imports() {
   567     public Stream<ImportSnippet> imports() throws IllegalStateException {
       
   568         return snippets()
   562         return snippets()
   569                 .filter(sn -> status(sn).isActive() && sn.kind() == Snippet.Kind.IMPORT)
   563                 .filter(sn -> status(sn).isActive() && sn.kind() == Snippet.Kind.IMPORT)
   570                 .map(sn -> (ImportSnippet) sn);
   564                 .map(sn -> (ImportSnippet) sn);
   571     }
   565     }
   572 
   566