aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/core/AST.java8
-rw-r--r--src/core/lombok/core/LombokNode.java9
-rw-r--r--src/core/lombok/javac/JavacAST.java4
-rw-r--r--src/utils/lombok/javac/CommentCatcher.java4
-rw-r--r--src/utils/lombok/javac/Javac.java20
5 files changed, 42 insertions, 3 deletions
diff --git a/src/core/lombok/core/AST.java b/src/core/lombok/core/AST.java
index 644d9449..a2279efe 100644
--- a/src/core/lombok/core/AST.java
+++ b/src/core/lombok/core/AST.java
@@ -146,6 +146,14 @@ public abstract class AST<A extends AST<A, L, N>, L extends LombokNode<A, L, N>,
return nodeMap.get(node);
}
+ /**
+ * Returns the latest version of the java language specification supported by the host compiler.
+ * For example, if compiling with javac v1.7, this returns {@code 7}.
+ */
+ public int getLatestJavaSpecSupported() {
+ return 6;
+ }
+
@SuppressWarnings({"unchecked", "rawtypes"})
L replaceNewWithExistingOld(Map<N, L> oldNodes, L newNode) {
L oldNode = oldNodes.get(newNode.get());
diff --git a/src/core/lombok/core/LombokNode.java b/src/core/lombok/core/LombokNode.java
index 588adc55..aa161a8d 100644
--- a/src/core/lombok/core/LombokNode.java
+++ b/src/core/lombok/core/LombokNode.java
@@ -181,6 +181,15 @@ public abstract class LombokNode<A extends AST<A, L, N>, L extends LombokNode<A,
}
/**
+ * Convenient shortcut to the owning ast object's getLatestJavaSpecSupported method.
+ *
+ * @see AST#getLatestJavaSpecSupported()
+ */
+ public int getLatestJavaSpecSupported() {
+ return ast.getLatestJavaSpecSupported();
+ }
+
+ /**
* Convenient shortcut to the owning ast object's top method.
*
* @see AST#top()
diff --git a/src/core/lombok/javac/JavacAST.java b/src/core/lombok/javac/JavacAST.java
index 93ea9754..9e15516e 100644
--- a/src/core/lombok/javac/JavacAST.java
+++ b/src/core/lombok/javac/JavacAST.java
@@ -113,6 +113,10 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
for (JavacNode child : node.down()) child.traverse(visitor);
}
+ @Override public int getLatestJavaSpecSupported() {
+ return Javac.getJavaCompilerVersion();
+ }
+
/** @return A Name object generated for the proper name table belonging to this AST. */
public Name toName(String name) {
return elements.getName(name);
diff --git a/src/utils/lombok/javac/CommentCatcher.java b/src/utils/lombok/javac/CommentCatcher.java
index 474dc43d..2825cd30 100644
--- a/src/utils/lombok/javac/CommentCatcher.java
+++ b/src/utils/lombok/javac/CommentCatcher.java
@@ -62,7 +62,7 @@ public class CommentCatcher {
private static void registerCommentsCollectingScannerFactory(Context context) {
try {
- if (JavaCompiler.version().startsWith("1.6")) {
+ if (Javac.getJavaCompilerVersion() <= 6) {
Class.forName("lombok.javac.java6.CommentCollectingScannerFactory").getMethod("preRegister", Context.class).invoke(null, context);
} else {
Class.forName("lombok.javac.java7.CommentCollectingScannerFactory").getMethod("preRegister", Context.class).invoke(null, context);
@@ -76,7 +76,7 @@ public class CommentCatcher {
private static void setInCompiler(JavaCompiler compiler, Context context, Map<JCCompilationUnit, List<CommentInfo>> commentsMap) {
try {
- if (JavaCompiler.version().startsWith("1.6")) {
+ if (Javac.getJavaCompilerVersion() <= 6) {
Class<?> parserFactory = Class.forName("lombok.javac.java6.CommentCollectingParserFactory");
parserFactory.getMethod("setInCompiler",JavaCompiler.class, Context.class, Map.class).invoke(null, compiler, context, commentsMap);
} else {
diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java
index 75bb2dbf..b4e58b8f 100644
--- a/src/utils/lombok/javac/Javac.java
+++ b/src/utils/lombok/javac/Javac.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2012 The Project Lombok Authors.
+ * Copyright (C) 2009-2013 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -21,9 +21,11 @@
*/
package lombok.javac;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.sun.tools.javac.code.TypeTags;
+import com.sun.tools.javac.main.JavaCompiler;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
@@ -42,6 +44,22 @@ public class Javac {
private static final Pattern PRIMITIVE_TYPE_NAME_PATTERN = Pattern.compile(
"^(boolean|byte|short|int|long|float|double|char)$");
+ private static final Pattern VERSION_PARSER = Pattern.compile("^(\\d{1,6})\\.(\\d{1,6}).*$");
+
+ /**
+ * Returns the version of this java compiler, i.e. the JDK that it shipped in. For example, for javac v1.7, this returns {@code 7}.
+ */
+ public static int getJavaCompilerVersion() {
+ Matcher m = VERSION_PARSER.matcher(JavaCompiler.version());
+ if (m.matches()) {
+ int major = Integer.parseInt(m.group(1));
+ int minor = Integer.parseInt(m.group(2));
+ if (major == 1) return minor;
+ }
+
+ return 6;
+ }
+
/**
* Checks if the given expression (that really ought to refer to a type expression) represents a primitive type.
*/