Skip to content

Initial Release with new API

Compare
Choose a tag to compare
@miho miho released this 10 Mar 19:11
· 25 commits to master since this release
8a59b17

The new API separates the steps between compilation and classloading:

CompilationResult result = JCompiler.newInstance().compile("public class MyClass {}").checkErrors();
Class<?> myClass = result.loadClasses().get("MyClass");    

Additionally, it is not necessary anymore to specify the class name manually:

JCompiler.newInstance().addSource("MyClass", "public class MyClass {}").compileAll();

is now reduced to

JCompiler.newInstance().addSource("public class MyClass {}").compileAll();

The name is inferred from the code.

Classes are grouped by compilation unit:

CompilationResult result = //...
List<CompiledUnit> compiledUnits = result.getCompiledUnits();

for(CompiledUnit cu : compiledUnits) {
  List<CompiledClass> classes = cu.getClasses();
  for(CompiledClass cc : classes) {
     // do something with cc
  }
}

Internal classes and non public classes are also loaded and included in the result.

Furthermore, this version is compatible with the old InMemoryJavaCompiler API. The old API is driven by the new JCompiler class. It is tested against the existing test cases for the old API.

The new API is partly inspired by PRs from @ruediste and @benor1470.