Skip to content

Conversation

Marcono1234
Copy link
Contributor

@Marcono1234 Marcono1234 commented Jul 21, 2024

Resolves #93

Adds a new CachedCompiler#loadFromJava overload with javax.tools.DiagnosticListener parameter. The behavior of the existing loadFromJava methods remains the same.

Also adds Javadoc to some of the methods and constructors.
Edit: Sorry I overlooked that there is already #140 for adding Javadoc. Feel free to merge that first and then I can try to resolve conflicts here and maybe make some small Javadoc adjustments.

Any feedback is appreciated!

}

@NotNull
Map<String, byte[]> compileFromJava(@NotNull String className,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved this method down a few lines so that all loadFromJava methods are grouped together.

@NotNull String javaCode,
@Nullable PrintWriter writer) throws ClassNotFoundException {
@Nullable PrintWriter writer,
@Nullable DiagnosticListener<? super JavaFileObject> diagnosticListener) throws ClassNotFoundException {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not completely sure about the ? super JavaFileObject; maybe users make assumptions then about the JavaFileObject of the diagnostics, which are actually implementation details of Java-Runtime-Compiler, e.g. the file paths.

compiler.loadFromJava(
classLoader, "TestClass",
// definition with a mandatory warning for deprecated `Date.getDay()`
"import java.util.Date; class TestClass { int i = new Date().getDay(); }",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this line there is one of the reasons why I changed this test class to create a new CachedCompiler instance for every test method, instead of using CompilerUtils.CACHED_COMPILER and getClass().getClassLoader():
It seems this source code was missing the import java.util.Date, which should normally cause a compiler error. However, previously no compilation error occurred, probably because one of the other test methods had already successfully loaded TestClass and therefore the CachedCompiler#loadFromJava call just returned that class instead of compiling the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Support collecting non-error diagnostics

1 participant