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>
- csr of
-
JDK-8341176 Permit access to diagnostics for transient snippets
-
- Resolved
-