From 6dce15450b790500f67a877957f60d16b5c94500 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Tue, 24 Sep 2024 11:27:30 +0200 Subject: [PATCH 1/2] org.apache.commons.commons-logging as dep in SDK feature --- org.eclipse.xtext.sdk.feature/feature.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/org.eclipse.xtext.sdk.feature/feature.xml b/org.eclipse.xtext.sdk.feature/feature.xml index 08f60c1f08a..5f1c2d0cf8a 100644 --- a/org.eclipse.xtext.sdk.feature/feature.xml +++ b/org.eclipse.xtext.sdk.feature/feature.xml @@ -72,6 +72,8 @@ SPDX-License-Identifier: EPL-2.0 + + Date: Thu, 26 Sep 2024 09:38:53 +0200 Subject: [PATCH 2/2] Added workarounds for removed Compileroptions: originalSourceLevel and originalComplianceLevel --- .../resource/JavaDerivedStateComputer.java | 34 +++++++++++++++++-- .../xbase/testing/InMemoryJavaCompiler.java | 34 +++++++++++++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) 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 0cd6059b4ff..da93a8c64d3 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 @@ -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); @@ -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(); } 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 eca033dc340..b6f39a4628d 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 @@ -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; @@ -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 + } + } } /** @@ -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) {