Skip to content

Commit

Permalink
include also #3206
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Oct 7, 2024
1 parent ac25df7 commit c6989bb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
*/
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 Down Expand Up @@ -288,42 +286,12 @@ protected CompilerOptions getCompilerOptions(JavaConfig javaConfig) {
compilerOptions.produceMethodParameters = true;
compilerOptions.produceReferenceInfo = true;
compilerOptions.complianceLevel = sourceLevel;
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
}
}
JdtFacade.setOriginalSourceLevel(compilerOptions, targetLevel);
JdtFacade.setOriginalComplianceLevel(compilerOptions, targetLevel);
JdtFacade.setInlineJsrBytecode(compilerOptions, true);
return compilerOptions;
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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;
}
}

/**
* If still present in JDT compiler options, set inlineJsrBytecode.
*
Expand All @@ -46,4 +64,36 @@ public static void setInlineJsrBytecode(CompilerOptions compilerOptions, boolean
}
}
}

/**
* If still present in JDT compiler options, set originalSourceLevel.
*
* @param compilerOptions
* @param targetLevel
*/
public static void setOriginalSourceLevel(CompilerOptions compilerOptions, long targetLevel) {
if (ORIGINAL_SOURCE_LEVEL != null) {
try {
ORIGINAL_SOURCE_LEVEL.invoke(compilerOptions, targetLevel);
} catch (Throwable e) {
// ignore
}
}
}

/**
* If still present in JDT compiler options, set originalComplianceLevel.
*
* @param compilerOptions
* @param targetLevel
*/
public static void setOriginalComplianceLevel(CompilerOptions compilerOptions, long targetLevel) {
if (ORIGINAL_COMPLIANCE_LEVEL != null) {
try {
ORIGINAL_COMPLIANCE_LEVEL.invoke(compilerOptions, targetLevel);
} catch (Throwable e) {
// ignore
}
}
}
}

0 comments on commit c6989bb

Please sign in to comment.