diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2013-05-23 22:58:34 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2013-05-23 22:58:34 +0200 |
commit | 9c1e29842e65bf20895db9e19336b2ca948236ad (patch) | |
tree | 396adccb0d61e049526622956c5ff59b5a32710c /src/utils | |
parent | 4152eee126bcb6a0403d3e7a79fe336944031268 (diff) | |
download | lombok-9c1e29842e65bf20895db9e19336b2ca948236ad.tar.gz lombok-9c1e29842e65bf20895db9e19336b2ca948236ad.tar.bz2 lombok-9c1e29842e65bf20895db9e19336b2ca948236ad.zip |
Added methods to obtain JLS support-level version information from AST/LombokNode. Tests updates to honour these with //version X at the top
of any test file (now also in eclipse, which until now always said it was v6)
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/lombok/eclipse/Eclipse.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/utils/lombok/eclipse/Eclipse.java b/src/utils/lombok/eclipse/Eclipse.java index 150f3a96..edfe1536 100644 --- a/src/utils/lombok/eclipse/Eclipse.java +++ b/src/utils/lombok/eclipse/Eclipse.java @@ -21,6 +21,7 @@ */ package lombok.eclipse; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -38,6 +39,7 @@ import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference; import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.lookup.TypeIds; public class Eclipse { @@ -177,4 +179,21 @@ public class Eclipse { return null; } + + private static int ecjCompilerVersionCached = -1; + + public static int getEcjCompilerVersion() { + if (ecjCompilerVersionCached >= 0) return ecjCompilerVersionCached; + + for (Field f : CompilerOptions.class.getDeclaredFields()) { + try { + if (f.getName().startsWith("VERSION_1_")) { + ecjCompilerVersionCached = Math.max(ecjCompilerVersionCached, Integer.parseInt(f.getName().substring("VERSION_1_".length()))); + } + } catch (Exception ignore) {} + } + + if (ecjCompilerVersionCached < 5) ecjCompilerVersionCached = 5; + return ecjCompilerVersionCached; + } } |