[
https://issues.apache.org/jira/browse/GROOVY-12025?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18082461#comment-18082461
]
ASF GitHub Bot commented on GROOVY-12025:
-----------------------------------------
Copilot commented on code in PR #2548:
URL: https://github.com/apache/groovy/pull/2548#discussion_r3278148572
##########
src/main/java/org/apache/groovy/util/JavaShell.java:
##########
@@ -188,6 +221,56 @@ private void doCompile(String className, String src,
Iterable<String> options) t
}
}
+ /**
+ * Compile {@code src} and write each resulting class file beneath {@code
outputDir}
+ * as a standard package directory tree (e.g. {@code com.example.Foo$Bar}
becomes
+ * {@code <outputDir>/com/example/Foo$Bar.class}). Intermediate
directories are
+ * created as needed; existing class files at those locations are
overwritten.
+ * The compiled classes also remain available through {@link
#getClassLoader()}.
+ *
+ * @param className the main class name (binary name, e.g. {@code
com.example.Foo})
+ * @param options compiler options; see the
+ * {@linkplain JavaShell class-level documentation} for
the expected format
+ * @param src the source code
+ * @param outputDir root directory under which class files are written;
created if absent
+ * @return a map from binary class name to the {@link Path} of the written
+ * {@code .class} file, in compilation order
+ * @throws IOException if compilation fails or writing a class file fails
Review Comment:
The Javadoc says `@throws IOException if compilation fails`, but compilation
failures from `doCompile` are reported via `JavaShellCompilationException` (an
unchecked `GroovyRuntimeException`), not an `IOException`. Please update the
`@throws` clause (and/or method signature) so the documented exceptions match
actual behavior.
##########
src/main/java/org/apache/groovy/util/JavaShell.java:
##########
@@ -188,6 +221,56 @@ private void doCompile(String className, String src,
Iterable<String> options) t
}
}
+ /**
+ * Compile {@code src} and write each resulting class file beneath {@code
outputDir}
+ * as a standard package directory tree (e.g. {@code com.example.Foo$Bar}
becomes
+ * {@code <outputDir>/com/example/Foo$Bar.class}). Intermediate
directories are
+ * created as needed; existing class files at those locations are
overwritten.
+ * The compiled classes also remain available through {@link
#getClassLoader()}.
+ *
+ * @param className the main class name (binary name, e.g. {@code
com.example.Foo})
+ * @param options compiler options; see the
+ * {@linkplain JavaShell class-level documentation} for
the expected format
+ * @param src the source code
+ * @param outputDir root directory under which class files are written;
created if absent
+ * @return a map from binary class name to the {@link Path} of the written
+ * {@code .class} file, in compilation order
Review Comment:
The Javadoc promises the returned map is "in compilation order", but the
underlying class bytes map originates from a `HashMap` in
`BytesJavaFileManager`, so iteration order is not guaranteed. Either make the
underlying collection order-preserving (e.g., use a `LinkedHashMap` for
captured outputs / sort by class name) or remove the ordering guarantee from
the API docs.
> Provide a JavaShell compileAllTo method
> ---------------------------------------
>
> Key: GROOVY-12025
> URL: https://issues.apache.org/jira/browse/GROOVY-12025
> Project: Groovy
> Issue Type: Improvement
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
>
> You can already do it but only by reaching down into implementation detail
> methods.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)