Added a method to obtain latest java language spec supported by host

platform and implemented it for javac BUT NOT FOR ECJ!
This commit is contained in:
Reinier Zwitserloot committed 2013-05-23 21:25:30 +02:00
1 parent ffb3527daa
commit 4152eee126
6 files changed
+45 -14

No files matched your search

+8
View File
@@ -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());
+9
View File
@@ -180,6 +180,15 @@ public abstract class LombokNode<A extends AST<A, L, N>, L extends LombokNode<A,
return children;
}
/**
* 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.
*
+4
View File
@@ -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);
+2 -2
View File
@@ -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 {
+19 -1
View File
@@ -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.
*/
+3 -11
View File
@@ -32,25 +32,18 @@ import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.javac.Javac;
import org.junit.runner.Description;
import org.junit.runner.Runner;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
import com.sun.tools.javac.main.JavaCompiler;
public class DirectoryRunner extends Runner {
public enum Compiler {
DELOMBOK {
@Override public int getVersion() {
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;
return Javac.getJavaCompilerVersion();
}
},
JAVAC {
@@ -64,7 +57,6 @@ public class DirectoryRunner extends Runner {
}
};
private static final Pattern VERSION_PARSER = Pattern.compile("^(\\d+)\\.(\\d+).*$");
public abstract int getVersion();
}