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.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to