diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2013-05-24 00:52:37 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2013-05-24 00:52:37 +0200 |
commit | 6b5a0e2cb349a4fb7d8bb5f943e57a0b65596ca0 (patch) | |
tree | d6f4fca9704322b301fb0b8901c8ab84ad357f58 /src/utils | |
parent | 9c1e29842e65bf20895db9e19336b2ca948236ad (diff) | |
download | lombok-6b5a0e2cb349a4fb7d8bb5f943e57a0b65596ca0.tar.gz lombok-6b5a0e2cb349a4fb7d8bb5f943e57a0b65596ca0.tar.bz2 lombok-6b5a0e2cb349a4fb7d8bb5f943e57a0b65596ca0.zip |
Fixed more issues related to java7's try-with-resources,
and updated ECJ version detection.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/lombok/eclipse/Eclipse.java | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/utils/lombok/eclipse/Eclipse.java b/src/utils/lombok/eclipse/Eclipse.java index edfe1536..c2a863d5 100644 --- a/src/utils/lombok/eclipse/Eclipse.java +++ b/src/utils/lombok/eclipse/Eclipse.java @@ -37,8 +37,10 @@ import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; import org.eclipse.jdt.internal.compiler.ast.Literal; import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference; import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; +import org.eclipse.jdt.internal.compiler.ast.TryStatement; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.lookup.TypeIds; @@ -180,8 +182,31 @@ public class Eclipse { return null; } - private static int ecjCompilerVersionCached = -1; + private static long latestEcjCompilerVersionConstantCached = 0; + + public static long getLatestEcjCompilerVersionConstant() { + if (latestEcjCompilerVersionConstantCached != 0) return latestEcjCompilerVersionConstantCached; + + int highestVersionSoFar = 0; + for (Field f : ClassFileConstants.class.getDeclaredFields()) { + try { + if (f.getName().startsWith("JDK1_")) { + int thisVersion = Integer.parseInt(f.getName().substring("JDK1_".length())); + if (thisVersion > highestVersionSoFar) { + highestVersionSoFar = thisVersion; + latestEcjCompilerVersionConstantCached = (Long) f.get(null); + } + } + } catch (Exception ignore) {} + } + + if (highestVersionSoFar > 6 && !ecjSupportsJava7Features()) { + latestEcjCompilerVersionConstantCached = ClassFileConstants.JDK1_6; + } + return latestEcjCompilerVersionConstantCached; + } + private static int ecjCompilerVersionCached = -1; public static int getEcjCompilerVersion() { if (ecjCompilerVersionCached >= 0) return ecjCompilerVersionCached; @@ -194,6 +219,20 @@ public class Eclipse { } if (ecjCompilerVersionCached < 5) ecjCompilerVersionCached = 5; + if (!ecjSupportsJava7Features()) ecjCompilerVersionCached = Math.min(6, ecjCompilerVersionCached); return ecjCompilerVersionCached; } + + /** + * Certain ECJ versions that only go up to -source 6 report that they support -source 7 and even fail to error when -source 7 is applied. + * We detect this and correctly say that no more than -source 6 is supported. (when this is the case, this method returns false). + */ + private static boolean ecjSupportsJava7Features() { + try { + TryStatement.class.getDeclaredField("resources"); + return true; + } catch (NoSuchFieldException e) { + return false; + } + } } |