Skip to content

Commit

Permalink
Merge pull request #3189 from eclipse/cd-jdt-rem
Browse files Browse the repository at this point in the history
remove inlineJsrBytecode following upstream removal in jdt
  • Loading branch information
LorenzoBettini authored Sep 11, 2024
2 parents 98d5516 + 03f3d51 commit a189bea
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
3 changes: 2 additions & 1 deletion org.eclipse.xtext.java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@
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;
import java.util.Map;
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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a189bea

Please sign in to comment.