diff --git a/org.eclipse.xtext.java/META-INF/MANIFEST.MF b/org.eclipse.xtext.java/META-INF/MANIFEST.MF index 4f91e2af579..f02bd6faa8b 100644 --- a/org.eclipse.xtext.java/META-INF/MANIFEST.MF +++ b/org.eclipse.xtext.java/META-INF/MANIFEST.MF @@ -10,7 +10,8 @@ Require-Bundle: org.eclipse.xtext;bundle-version="2.37.0", org.eclipse.xtend.lib;bundle-version="2.37.0", org.eclipse.jdt.core;bundle-version="3.29.0", org.eclipse.emf.common;bundle-version="2.24.0", - org.eclipse.emf.ecore;bundle-version="2.26.0" + org.eclipse.emf.ecore;bundle-version="2.26.0", + org.eclipse.core.runtime Export-Package: org.eclipse.xtext.java;version="2.37.0", org.eclipse.xtext.java.resource;version="2.37.0" Import-Package: org.apache.log4j;version="1.2.24" diff --git a/org.eclipse.xtext.java/src/org/eclipse/xtext/java/resource/JavaDerivedStateComputer.java b/org.eclipse.xtext.java/src/org/eclipse/xtext/java/resource/JavaDerivedStateComputer.java index 152bbd9e199..bb27fd331ef 100644 --- a/org.eclipse.xtext.java/src/org/eclipse/xtext/java/resource/JavaDerivedStateComputer.java +++ b/org.eclipse.xtext.java/src/org/eclipse/xtext/java/resource/JavaDerivedStateComputer.java @@ -8,6 +8,8 @@ */ package org.eclipse.xtext.java.resource; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -21,6 +23,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ClassFile; import org.eclipse.jdt.internal.compiler.CompilationResult; @@ -53,6 +56,7 @@ import org.eclipse.xtext.util.JavaVersion; import org.eclipse.xtext.xbase.lib.Exceptions; import org.eclipse.xtext.xbase.lib.Procedures.Procedure2; +import org.osgi.framework.Version; import com.google.inject.Inject; @@ -281,15 +285,34 @@ protected CompilerOptions getCompilerOptions(JavaConfig javaConfig) { long targetLevel = toJdtVersion(targetVersion); CompilerOptions compilerOptions = new CompilerOptions(); compilerOptions.targetJDK = targetLevel; - compilerOptions.inlineJsrBytecode = true; compilerOptions.sourceLevel = sourceLevel; compilerOptions.produceMethodParameters = true; compilerOptions.produceReferenceInfo = true; compilerOptions.originalSourceLevel = targetLevel; compilerOptions.complianceLevel = sourceLevel; compilerOptions.originalComplianceLevel = targetLevel; + if (INLINE_JSR_BYTECODE != null) { + try { + INLINE_JSR_BYTECODE.invoke(compilerOptions, true); + } catch (Throwable e) { + // ignore + } + } return compilerOptions; } + + private final static MethodHandle INLINE_JSR_BYTECODE = findInlineJsrBytecode(); + private static MethodHandle findInlineJsrBytecode() { + try { + if (JavaCore.getPlugin().getBundle().getVersion().compareTo(new Version(3, 39, 100)) >= 0) { + return null; + } else { + return MethodHandles.lookup().findSetter(CompilerOptions.class, "inlineJsrBytecode", boolean.class); + } + } catch (Exception e) { + return null; + } + } protected long toJdtVersion(JavaVersion version) { return version.toJdtClassFileConstant(); diff --git a/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler.java b/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler.java index e0a6abac066..f45291b1dd6 100644 --- a/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler.java +++ b/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler.java @@ -11,11 +11,14 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; @@ -23,6 +26,7 @@ import java.util.Set; import org.apache.log4j.Logger; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ClassFile; @@ -37,8 +41,10 @@ import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo; import org.eclipse.xtext.util.JavaVersion; import org.eclipse.xtext.xbase.lib.Exceptions; +import org.osgi.framework.Version; import com.google.common.collect.Lists; @@ -204,9 +210,28 @@ public InMemoryJavaCompiler(ClassLoader parent, JavaVersion javaVersion) { this.parentClassLoader = parent; this.compilerOptions = new CompilerOptions(); this.setJavaVersion(javaVersion); - this.compilerOptions.inlineJsrBytecode = true; + if (INLINE_JSR_BYTECODE != null) { + try { + INLINE_JSR_BYTECODE.invoke(this.compilerOptions, true); + } catch (Throwable e) { + // ignore + } + } this.compilerOptions.preserveAllLocalVariables = true; } + + private final static MethodHandle INLINE_JSR_BYTECODE = findInlineJsrBytecode(); + private static MethodHandle findInlineJsrBytecode() { + try { + if (JavaCore.getPlugin().getBundle().getVersion().compareTo(new Version(3, 39, 100)) >= 0) { + return null; + } else { + return MethodHandles.lookup().findSetter(CompilerOptions.class, "inlineJsrBytecode", boolean.class); + } + } catch (Exception e) { + return null; + } + } public InMemoryJavaCompiler(ClassLoader parent, CompilerOptions compilerOptions) { this.nameEnv = new ClassLoaderBasedNameEnvironment(parent);