Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove obsolete compiler option assignments #3206

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading