[527218] JLS8 and JLS9 should be supported when available
diff --git a/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/generator/AbstractGeneratorAdapter.java b/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/generator/AbstractGeneratorAdapter.java
index ee54da6..02c1120 100644
--- a/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/generator/AbstractGeneratorAdapter.java
+++ b/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/generator/AbstractGeneratorAdapter.java
@@ -2781,7 +2781,7 @@
// Create a parser that will produce errors for unused imports.
//
- ASTParser astParser = CodeGenUtil.EclipseUtil.newASTParser();
+ ASTParser astParser = CodeGenUtil.EclipseUtil.newASTParser(true);
astParser.setCompilerOptions(Collections.singletonMap(JavaCore.COMPILER_PB_UNUSED_IMPORT, JavaCore.ERROR));
astParser.setResolveBindings(true);
astParser.setProject(javaProject);
diff --git a/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/util/CodeGenUtil.java b/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/util/CodeGenUtil.java
index 6e59fd4..a88f7a2 100644
--- a/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/util/CodeGenUtil.java
+++ b/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/util/CodeGenUtil.java
@@ -1111,6 +1111,7 @@
* It will determine the
*/
private static final int JLS;
+ private static final int JLS4;
static
{
@SuppressWarnings("deprecation")
@@ -1124,16 +1125,44 @@
{
// Ignore the absence of the new version support in older runtimes.
}
+ JLS4 = jls;
+ try
+ {
+ Field field = AST.class.getField("JLS8");
+ jls = (Integer)field.get(null);
+ }
+ catch (Throwable exception)
+ {
+ // Ignore the absence of the new version support in older runtimes.
+ }
+ try
+ {
+ Field field = AST.class.getField("JLS9");
+ jls = (Integer)field.get(null);
+ }
+ catch (Throwable exception)
+ {
+ // Ignore the absence of the new version support in older runtimes.
+ }
JLS = jls;
}
/**
- * Return an ASTParser that supports the latest language level in the version of the JDT in the installed runtime.
+ * Return an ASTParser that supports the latest language level in the version of the JDT in the installed runtime, up to JLS4.
* @since 2.9
*/
public static ASTParser newASTParser()
{
- return ASTParser.newParser(JLS);
+ return ASTParser.newParser(JLS4);
+ }
+
+ /**
+ * Return an ASTParser that supports the latest language level in the version of the JDT in the installed runtime or JLS4 otherwise.
+ * @since 2.14
+ */
+ public static ASTParser newASTParser(boolean latest)
+ {
+ return ASTParser.newParser(latest ? JLS : JLS4);
}
public static class StreamProgressMonitor extends NullProgressMonitor