Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8341200

Permit access to diagnostics for transient snippets

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 24
    • tools
    • None
    • behavioral
    • minimal
    • JDK

      Summary

      Allow to gather best-effort diagnostics for JShell transient snippets.

      Problem

      JShell permits to create transient JShell snippets, using SourceCodeAnalysis.sourceToSnippets. These provide several features intended for alternate UI clients. But, there's no way to get diagnostics out from JShell for these transient snippets.

      Solution

      JShell.diagnostics(Snippet) will return diagnostics for any snippet. It will return the real diagnostic for permanent snippets, and best-effort diagnostics for the transient snippets.

      Specification

      diff --git a/src/jdk.jshell/share/classes/jdk/jshell/JShell.java b/src/jdk.jshell/share/classes/jdk/jshell/JShell.java
      index ffa46cf8be4..afb7c5751ac 100644
      --- a/src/jdk.jshell/share/classes/jdk/jshell/JShell.java
      +++ b/src/jdk.jshell/share/classes/jdk/jshell/JShell.java
      @@ -678,6 +678,12 @@ public Status status(Snippet snippet) {
            * Return the diagnostics of the most recent evaluation of the snippet.
            * The evaluation can either because of an explicit {@code eval()} call or
            * an automatic update triggered by a dependency.
      +     *
      +     * <p>This method will return best-effort diagnostics for snippets returned
      +     * from {@link SourceCodeAnalysis#sourceToSnippets(java.lang.String) }. The
      +     * diagnostics returned for such snippets may differ from diagnostics provided
      +     * after the snippet is {@link #eval(java.lang.String) }-ed.
      +     *
            * @param snippet the {@code Snippet} to look up
            * @return the diagnostics corresponding to this snippet.  This does not
            * include unresolvedDependencies references reported in {@code unresolvedDependencies()}.
      diff --git a/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysis.java b/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysis.java
      index 99bfd870f37..0375a2ead65 100644
      --- a/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysis.java
      +++ b/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysis.java
      @@ -145,7 +145,8 @@ public abstract class SourceCodeAnalysis {
            * will be {@code "*UNASSOCIATED*"}.
            * The returned snippets are not associated with the
            * {@link JShell} instance, so attempts to pass them to {@code JShell}
      -     * methods will throw an {@code IllegalArgumentException}.
      +     * methods will throw an {@code IllegalArgumentException}, unless otherwise
      +     * noted.
            * They will not appear in queries for snippets --
            * for example, {@link JShell#snippets() }.
            * <p>

            jlahoda Jan Lahoda
            jlahoda Jan Lahoda
            Vicente Arturo Romero Zaldivar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: