|
|
|
|
|
|
Re: Specifying Java version when running xtext.generator.GeneratorComponent from mwe2 [message #1731123 is a reply to message #1727316] |
Mon, 02 May 2016 22:47   |
Eclipse User |
|
|
|
Thanks for the pointer.
I attempted to solve this by making a custom injector for my tests project, with custom bindings for GeneratorConfigProvider and GeneratorConfig to supply JavaVersion.JAVA8 as the Java version.
Unfortunately, for my tests, the Java compiler being injected for CompilationTestHelper wasn't being initialized with this value. It looks like, in this case, CompilationTestHelper was using the @Inject version of the OnTheFlyJavaCompiler2 constructor, which is hard-coded to initialize the Java Compiler to JavaVersion.JAVA6.
So, for now, my solution has been to just copy the entire logic of CompilationTestHelper into my own version, where I've customized the compile method like this. Maybe not the most elegant solution, but it's working.
public void compile(final ResourceSet resourceSet, IAcceptor<Result> acceptor) {
try {
List<Resource> resourcesToCheck = newArrayList(resourceSet.getResources());
Result result = resultProvider.get();
// create a new java compiler, using Java 1.8
this.javaCompiler = new OnTheFlyJavaCompiler2(new ClassLoader() {}, JavaVersion.JAVA8);
result.setJavaCompiler(javaCompiler);
result.setCheckMode(getCheckMode());
result.setResources(resourcesToCheck);
result.setResourceSet(resourceSet);
result.setOutputConfigurations(getOutputConfigurations());
result.doGenerate();
acceptor.accept(result);
} catch (Exception e) {
Exceptions.throwUncheckedException(e);
}
}
So,
|
|
|
|
Powered by
FUDForum. Page generated in 0.04301 seconds