aboutsummaryrefslogtreecommitdiff
path: root/src/utils/lombok/javac
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2013-06-18 03:33:13 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2013-06-18 03:33:13 +0200
commite047d2b94e1206bbf304725c20ee20afbd1681fb (patch)
tree7a029712048261591be7d49409a3772618a1c3f4 /src/utils/lombok/javac
parent359b7845f21ac7ad023ce1a13af8f6b5d1833068 (diff)
downloadlombok-e047d2b94e1206bbf304725c20ee20afbd1681fb.tar.gz
lombok-e047d2b94e1206bbf304725c20ee20afbd1681fb.tar.bz2
lombok-e047d2b94e1206bbf304725c20ee20afbd1681fb.zip
Added a ClassDef wrapper, because its signature changed between javac1.6 and javac1.7. (The wrapper uses reflection). Need for: javac @Builder impl.
Also added some utilities to JavacHandlerUtil.
Diffstat (limited to 'src/utils/lombok/javac')
-rw-r--r--src/utils/lombok/javac/Javac.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java
index 08c7c957..4f316d9f 100644
--- a/src/utils/lombok/javac/Javac.java
+++ b/src/utils/lombok/javac/Javac.java
@@ -22,17 +22,25 @@
package lombok.javac;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
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.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
import com.sun.tools.javac.tree.JCTree.JCIdent;
import com.sun.tools.javac.tree.JCTree.JCLiteral;
+import com.sun.tools.javac.tree.JCTree.JCModifiers;
+import com.sun.tools.javac.tree.JCTree.JCTypeParameter;
+import com.sun.tools.javac.tree.TreeMaker;
+import com.sun.tools.javac.util.List;
+import com.sun.tools.javac.util.Name;
/**
* Container for static utility methods relevant to lombok's operation on javac.
@@ -161,4 +169,38 @@ public class Javac {
}
}
+ private static Method method;
+
+ public static JCClassDecl ClassDef(TreeMaker maker, JCModifiers mods, Name name, List<JCTypeParameter> typarams, JCExpression extending, List<JCExpression> implementing, List<JCTree> defs) {
+ if (method == null) try {
+ method = TreeMaker.class.getDeclaredMethod("ClassDef", JCModifiers.class, Name.class, List.class, JCExpression.class, List.class, List.class);
+ } catch (NoSuchMethodException ignore) {}
+ if (method == null) try {
+ method = TreeMaker.class.getDeclaredMethod("ClassDef", JCModifiers.class, Name.class, List.class, JCTree.class, List.class, List.class);
+ } catch (NoSuchMethodException ignore) {}
+
+ if (method == null) throw new IllegalStateException("Lombok bug #20130617-1310: ClassDef doesn't look like anything we thought it would look like.");
+ if (!Modifier.isPublic(method.getModifiers()) && !method.isAccessible()) {
+ method.setAccessible(true);
+ }
+
+ try {
+ return (JCClassDecl) method.invoke(maker, mods, name, typarams, extending, implementing, defs);
+ } catch (InvocationTargetException e) {
+ throw sneakyThrow(e.getCause());
+ } catch (IllegalAccessException e) {
+ throw sneakyThrow(e.getCause());
+ }
+ }
+
+ private static RuntimeException sneakyThrow(Throwable t) {
+ if (t == null) throw new NullPointerException("t");
+ Javac.<RuntimeException>sneakyThrow0(t);
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T extends Throwable> void sneakyThrow0(Throwable t) throws T {
+ throw (T)t;
+ }
}