aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/changelog.markdown1
-rw-r--r--src/delombok/lombok/delombok/Delombok.java51
2 files changed, 50 insertions, 2 deletions
diff --git a/doc/changelog.markdown b/doc/changelog.markdown
index f042f69f..0db4d9bf 100644
--- a/doc/changelog.markdown
+++ b/doc/changelog.markdown
@@ -3,6 +3,7 @@ Lombok Changelog
### v0.11.5 (Edgy Guinea Pig)
* FEATURE: Lombok can be disabled entirely for any given compile run by using JVM switch `-Dlombok.disable`. This might be useful for code style checkers and such.
+* BUGFIX: {Delombok} Running delombok has been causing VerifyError errors when used with javac 1.7 since 0.11.0.
### v0.11.4 (August 13th, 2012)
* FEATURE: {Experimental} `@Value`, `@Wither` and `@FieldDefaults` are now available. These are a lot like `@Data` but geared towards immutable classes. [Documentation on @Value](http://projectlombok.org/features/experimental/Value.html), [Documentation on @Wither](http://projectlombok.org/features/experimental/Wither.html) and [Documentation on @FieldDefaults](http://projectlombok.org/features/experimental/FieldDefaults.html).
diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java
index f67e3724..f4e02786 100644
--- a/src/delombok/lombok/delombok/Delombok.java
+++ b/src/delombok/lombok/delombok/Delombok.java
@@ -30,6 +30,8 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.Writer;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.URI;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
@@ -44,9 +46,11 @@ import java.util.Map;
import javax.tools.DiagnosticListener;
import javax.tools.JavaFileObject;
+import lombok.Lombok;
import lombok.javac.CommentCatcher;
import lombok.javac.LombokOptions;
+import com.sun.tools.javac.comp.Todo;
import com.sun.tools.javac.main.JavaCompiler;
import com.sun.tools.javac.main.OptionName;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
@@ -378,14 +382,13 @@ public class Delombok {
baseMap.put(unit, fileToBase.get(fileToParse));
roots.add(unit);
}
-
if (compiler.errorCount() > 0) {
// At least one parse error. No point continuing (a real javac run doesn't either).
return false;
}
JavaCompiler delegate = compiler.processAnnotations(compiler.enterTrees(toJavacList(roots)));
- delegate.flow(delegate.attribute(delegate.todo));
+ callFlowMethodOnJavaCompiler(delegate, callAttributeMethodOnJavaCompiler(delegate, delegate.todo));
for (JCCompilationUnit unit : roots) {
DelombokResult result = new DelombokResult(catcher.getComments(unit), unit, force || options.isChanged(unit));
if (verbose) feedback.printf("File: %s [%s]\n", unit.sourcefile.getName(), result.isChanged() ? "delomboked" : "unchanged");
@@ -409,6 +412,50 @@ public class Delombok {
return true;
}
+ private static Method attributeMethod;
+ /** Method is needed because the call signature has changed between javac6 and javac7; no matter what we compile against, using delombok in the other means VerifyErrors. */
+ private static Object callAttributeMethodOnJavaCompiler(JavaCompiler compiler, Todo arg) {
+ if (attributeMethod == null) {
+ try {
+ attributeMethod = JavaCompiler.class.getDeclaredMethod("attribute", java.util.Queue.class);
+ } catch (NoSuchMethodException e) {
+ try {
+ attributeMethod = JavaCompiler.class.getDeclaredMethod("attribute", com.sun.tools.javac.util.ListBuffer.class);
+ } catch (NoSuchMethodException e2) {
+ throw Lombok.sneakyThrow(e2);
+ }
+ }
+ }
+ try {
+ return attributeMethod.invoke(compiler, arg);
+ } catch (Exception e) {
+ if (e instanceof InvocationTargetException) throw Lombok.sneakyThrow(e.getCause());
+ throw Lombok.sneakyThrow(e);
+ }
+ }
+
+ private static Method flowMethod;
+ /** Method is needed because the call signature has changed between javac6 and javac7; no matter what we compile against, using delombok in the other means VerifyErrors. */
+ private static void callFlowMethodOnJavaCompiler(JavaCompiler compiler, Object arg) {
+ if (flowMethod == null) {
+ try {
+ flowMethod = JavaCompiler.class.getDeclaredMethod("flow", java.util.Queue.class);
+ } catch (NoSuchMethodException e) {
+ try {
+ flowMethod = JavaCompiler.class.getDeclaredMethod("flow", com.sun.tools.javac.util.List.class);
+ } catch (NoSuchMethodException e2) {
+ throw Lombok.sneakyThrow(e2);
+ }
+ }
+ }
+ try {
+ flowMethod.invoke(compiler, arg);
+ } catch (Exception e) {
+ if (e instanceof InvocationTargetException) throw Lombok.sneakyThrow(e.getCause());
+ throw Lombok.sneakyThrow(e);
+ }
+ }
+
private static String canonical(File dir) {
try {
return dir.getCanonicalPath();