Skip to content

Commit 531d040

Browse files
authored
Merge pull request #3206 from mehmet-karaman/removeObsolete_CompilerOption_assignments
Remove obsolete compiler option assignments
2 parents 4e00f55 + ffc3b15 commit 531d040

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

org.eclipse.xtext.java/src/org/eclipse/xtext/java/resource/JavaDerivedStateComputer.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,21 @@ protected CompilerOptions getCompilerOptions(JavaConfig javaConfig) {
286286
compilerOptions.sourceLevel = sourceLevel;
287287
compilerOptions.produceMethodParameters = true;
288288
compilerOptions.produceReferenceInfo = true;
289-
compilerOptions.originalSourceLevel = targetLevel;
290289
compilerOptions.complianceLevel = sourceLevel;
291-
compilerOptions.originalComplianceLevel = targetLevel;
290+
if (ORIGINAL_SOURCE_LEVEL != null) {
291+
try {
292+
ORIGINAL_SOURCE_LEVEL.invoke(compilerOptions, targetLevel);
293+
} catch (Throwable e) {
294+
// ignore
295+
}
296+
}
297+
if (ORIGINAL_COMPLIANCE_LEVEL != null) {
298+
try {
299+
ORIGINAL_COMPLIANCE_LEVEL.invoke(compilerOptions, targetLevel);
300+
} catch (Throwable e) {
301+
// ignore
302+
}
303+
}
292304
if (INLINE_JSR_BYTECODE != null) {
293305
try {
294306
INLINE_JSR_BYTECODE.invoke(compilerOptions, true);
@@ -308,6 +320,24 @@ private static MethodHandle findInlineJsrBytecode() {
308320
}
309321
}
310322

323+
private final static MethodHandle ORIGINAL_SOURCE_LEVEL = findOriginalSourceLevel();
324+
private static MethodHandle findOriginalSourceLevel() {
325+
try {
326+
return MethodHandles.lookup().findSetter(CompilerOptions.class, "originalSourceLevel", long.class);
327+
} catch (Exception e) {
328+
return null;
329+
}
330+
}
331+
332+
private final static MethodHandle ORIGINAL_COMPLIANCE_LEVEL = findOriginalComplianceLevel();
333+
private static MethodHandle findOriginalComplianceLevel() {
334+
try {
335+
return MethodHandles.lookup().findSetter(CompilerOptions.class, "originalComplianceLevel", long.class);
336+
} catch (Exception e) {
337+
return null;
338+
}
339+
}
340+
311341
protected long toJdtVersion(JavaVersion version) {
312342
return version.toJdtClassFileConstant();
313343
}

org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,24 @@ private static MethodHandle findInlineJsrBytecode() {
225225
}
226226
}
227227

228+
private final static MethodHandle ORIGINAL_SOURCE_LEVEL = findOriginalSourceLevel();
229+
private static MethodHandle findOriginalSourceLevel() {
230+
try {
231+
return MethodHandles.lookup().findSetter(CompilerOptions.class, "originalSourceLevel", long.class);
232+
} catch (Exception e) {
233+
return null;
234+
}
235+
}
236+
237+
private final static MethodHandle ORIGINAL_COMPLIANCE_LEVEL = findOriginalComplianceLevel();
238+
private static MethodHandle findOriginalComplianceLevel() {
239+
try {
240+
return MethodHandles.lookup().findSetter(CompilerOptions.class, "originalComplianceLevel", long.class);
241+
} catch (Exception e) {
242+
return null;
243+
}
244+
}
245+
228246
public InMemoryJavaCompiler(ClassLoader parent, CompilerOptions compilerOptions) {
229247
this.nameEnv = new ClassLoaderBasedNameEnvironment(parent);
230248
this.parentClassLoader = parent;
@@ -257,7 +275,13 @@ private long toClassFmt(JavaVersion version) {
257275
*/
258276
private void setSourceLevel(long jdkVersion) {
259277
compilerOptions.sourceLevel = jdkVersion;
260-
compilerOptions.originalSourceLevel = jdkVersion;
278+
if (ORIGINAL_SOURCE_LEVEL != null) {
279+
try {
280+
ORIGINAL_SOURCE_LEVEL.invoke(compilerOptions, jdkVersion);
281+
} catch (Throwable e) {
282+
// ignore
283+
}
284+
}
261285
}
262286

263287
/**
@@ -266,7 +290,13 @@ private void setSourceLevel(long jdkVersion) {
266290
*/
267291
private void setComplianceLevel(long jdkVersion) {
268292
compilerOptions.complianceLevel = jdkVersion;
269-
compilerOptions.originalComplianceLevel = jdkVersion;
293+
if (ORIGINAL_COMPLIANCE_LEVEL != null) {
294+
try {
295+
ORIGINAL_COMPLIANCE_LEVEL.invoke(compilerOptions, jdkVersion);
296+
} catch (Throwable e) {
297+
// ignore
298+
}
299+
}
270300
}
271301

272302
public Result compile(JavaSource... sources) {

0 commit comments

Comments
 (0)