Skip to content

Commit

Permalink
Merge branch 'eclipse:main' into replace_reflection_by_original_metho…
Browse files Browse the repository at this point in the history
…d_calls
  • Loading branch information
mehmet-karaman authored Sep 26, 2024
2 parents 20314d1 + 531d040 commit d4b2a1d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,21 @@ protected CompilerOptions getCompilerOptions(JavaConfig javaConfig) {
compilerOptions.sourceLevel = sourceLevel;
compilerOptions.produceMethodParameters = true;
compilerOptions.produceReferenceInfo = true;
compilerOptions.originalSourceLevel = targetLevel;
compilerOptions.complianceLevel = sourceLevel;
compilerOptions.originalComplianceLevel = targetLevel;
if (ORIGINAL_SOURCE_LEVEL != null) {
try {
ORIGINAL_SOURCE_LEVEL.invoke(compilerOptions, targetLevel);
} catch (Throwable e) {
// ignore
}
}
if (ORIGINAL_COMPLIANCE_LEVEL != null) {
try {
ORIGINAL_COMPLIANCE_LEVEL.invoke(compilerOptions, targetLevel);
} catch (Throwable e) {
// ignore
}
}
if (INLINE_JSR_BYTECODE != null) {
try {
INLINE_JSR_BYTECODE.invoke(compilerOptions, true);
Expand All @@ -308,6 +320,24 @@ private static MethodHandle findInlineJsrBytecode() {
}
}

private final static MethodHandle ORIGINAL_SOURCE_LEVEL = findOriginalSourceLevel();
private static MethodHandle findOriginalSourceLevel() {
try {
return MethodHandles.lookup().findSetter(CompilerOptions.class, "originalSourceLevel", long.class);
} catch (Exception e) {
return null;
}
}

private final static MethodHandle ORIGINAL_COMPLIANCE_LEVEL = findOriginalComplianceLevel();
private static MethodHandle findOriginalComplianceLevel() {
try {
return MethodHandles.lookup().findSetter(CompilerOptions.class, "originalComplianceLevel", long.class);
} catch (Exception e) {
return null;
}
}

protected long toJdtVersion(JavaVersion version) {
return version.toJdtClassFileConstant();
}
Expand Down
2 changes: 2 additions & 0 deletions org.eclipse.xtext.sdk.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ SPDX-License-Identifier: EPL-2.0
<import plugin="org.eclipse.emf.ecore.source" version="2.26.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.emf.common.source" version="2.24.0" match="greaterOrEqual"/>
<import feature="org.eclipse.emf.mwe2.language.sdk" version="2.19.0" match="greaterOrEqual"/>
<import plugin="org.apache.commons.commons-logging" version="1.3.4" match="greaterOrEqual"/>
<import plugin="org.apache.commons.commons-logging.source" version="1.3.4" match="greaterOrEqual"/>
</requires>

<plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,24 @@ private static MethodHandle findInlineJsrBytecode() {
}
}

private final static MethodHandle ORIGINAL_SOURCE_LEVEL = findOriginalSourceLevel();
private static MethodHandle findOriginalSourceLevel() {
try {
return MethodHandles.lookup().findSetter(CompilerOptions.class, "originalSourceLevel", long.class);
} catch (Exception e) {
return null;
}
}

private final static MethodHandle ORIGINAL_COMPLIANCE_LEVEL = findOriginalComplianceLevel();
private static MethodHandle findOriginalComplianceLevel() {
try {
return MethodHandles.lookup().findSetter(CompilerOptions.class, "originalComplianceLevel", long.class);
} catch (Exception e) {
return null;
}
}

public InMemoryJavaCompiler(ClassLoader parent, CompilerOptions compilerOptions) {
this.nameEnv = new ClassLoaderBasedNameEnvironment(parent);
this.parentClassLoader = parent;
Expand Down Expand Up @@ -257,7 +275,13 @@ private long toClassFmt(JavaVersion version) {
*/
private void setSourceLevel(long jdkVersion) {
compilerOptions.sourceLevel = jdkVersion;
compilerOptions.originalSourceLevel = jdkVersion;
if (ORIGINAL_SOURCE_LEVEL != null) {
try {
ORIGINAL_SOURCE_LEVEL.invoke(compilerOptions, jdkVersion);
} catch (Throwable e) {
// ignore
}
}
}

/**
Expand All @@ -266,7 +290,13 @@ private void setSourceLevel(long jdkVersion) {
*/
private void setComplianceLevel(long jdkVersion) {
compilerOptions.complianceLevel = jdkVersion;
compilerOptions.originalComplianceLevel = jdkVersion;
if (ORIGINAL_COMPLIANCE_LEVEL != null) {
try {
ORIGINAL_COMPLIANCE_LEVEL.invoke(compilerOptions, jdkVersion);
} catch (Throwable e) {
// ignore
}
}
}

public Result compile(JavaSource... sources) {
Expand Down

0 comments on commit d4b2a1d

Please sign in to comment.