mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-15 06:16:14 +00:00
Fixes issue 422: VerifyError when running delombok in a javac7 environment.
This commit is contained in:
1 parent
a295c4fc12
commit
bde859c853
2 files changed
+50
-2
No files matched your search
@@ -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).
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user