diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2012-10-22 09:48:11 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2012-10-22 09:49:19 +0200 |
commit | bde859c8532ae9cc99e1080fd9d27a945b1f68de (patch) | |
tree | 81d533c929e020d30eed7288d3a29d8d62e47fde /src | |
parent | a295c4fc12247eedfe5747b547d8ac7079f33533 (diff) | |
download | lombok-bde859c8532ae9cc99e1080fd9d27a945b1f68de.tar.gz lombok-bde859c8532ae9cc99e1080fd9d27a945b1f68de.tar.bz2 lombok-bde859c8532ae9cc99e1080fd9d27a945b1f68de.zip |
Fixes issue 422: VerifyError when running delombok in a javac7 environment.
Diffstat (limited to 'src')
-rw-r--r-- | src/delombok/lombok/delombok/Delombok.java | 51 |
1 files changed, 49 insertions, 2 deletions
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(); |