diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2010-11-10 22:19:26 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2010-11-10 22:19:26 +0100 |
commit | 249566813149f8e6984561d9d2ba4e348974dc1a (patch) | |
tree | a6fbc60eb91bc20fa8908a421f58c6bd27281ce2 /src/delombok/lombok | |
parent | 5b5a3713e2436706f80e782ed26479b066205ab4 (diff) | |
download | lombok-249566813149f8e6984561d9d2ba4e348974dc1a.tar.gz lombok-249566813149f8e6984561d9d2ba4e348974dc1a.tar.bz2 lombok-249566813149f8e6984561d9d2ba4e348974dc1a.zip |
Delombok has been fixed to work more like a true javac run now. As a result, its now compatible with resolution again (i.e. resolution based transformers are applied correctly when delomboking).
Diffstat (limited to 'src/delombok/lombok')
-rw-r--r-- | src/delombok/lombok/delombok/Delombok.java | 46 |
1 files changed, 16 insertions, 30 deletions
diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index 95ceb309..6fc77c59 100644 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -41,16 +41,11 @@ import java.util.List; import java.util.ListIterator; import java.util.Map; -import javax.annotation.processing.Messager; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.AnnotationValue; -import javax.lang.model.element.Element; import javax.tools.DiagnosticListener; import javax.tools.JavaFileObject; -import javax.tools.Diagnostic.Kind; import lombok.javac.DeleteLombokAnnotations; -import lombok.javac.JavacTransformer; +import lombok.javac.TrackChangedAsts; import com.sun.tools.javac.main.JavaCompiler; import com.sun.tools.javac.main.OptionName; @@ -358,6 +353,7 @@ public class Delombok { options.put(OptionName.ENCODING, charset.name()); if (classpath != null) options.put(OptionName.CLASSPATH, classpath); if (sourcepath != null) options.put(OptionName.SOURCEPATH, sourcepath); + options.put("compilePolicy", "attr"); CommentCollectingScanner.Factory.preRegister(context); JavaCompiler compiler = new JavaCompiler(context); @@ -367,6 +363,9 @@ public class Delombok { List<JCCompilationUnit> roots = new ArrayList<JCCompilationUnit>(); Map<JCCompilationUnit, Comments> commentsMap = new IdentityHashMap<JCCompilationUnit, Comments>(); Map<JCCompilationUnit, File> baseMap = new IdentityHashMap<JCCompilationUnit, File>(); + + compiler.initProcessAnnotations(Collections.singleton(new lombok.javac.apt.Processor())); + for (File fileToParse : filesToParse) { Comments comments = new Comments(); context.put(Comments.class, comments); @@ -379,14 +378,18 @@ public class Delombok { roots.add(unit); } - if (compiler.errorCount() > 0) return false; - compiler.enterTrees(toJavacList(roots)); + if (compiler.errorCount() > 0) { + // At least one parse error. No point continuing (a real javac run doesn't either). + return false; + } + + TrackChangedAsts tca = new TrackChangedAsts(); + context.put(TrackChangedAsts.class, tca); + + JavaCompiler delegate = compiler.processAnnotations(compiler.enterTrees(toJavacList(roots))); for (JCCompilationUnit unit : roots) { - // Run one single massive transform instead of a lot of singleton calls, as this causes a heck of a lot of refilling of the enter cache. - // XXX This isn't enough - we need to call transform again after resetting everything. - boolean changed = new JavacTransformer(messager).transform(false, context, Collections.singletonList(unit)); - DelombokResult result = new DelombokResult(commentsMap.get(unit).comments, unit, force || changed); + DelombokResult result = new DelombokResult(commentsMap.get(unit).comments, unit, force || tca.changed.contains(unit)); if (verbose) feedback.printf("File: %s [%s]\n", unit.sourcefile.getName(), result.isChanged() ? "delomboked" : "unchanged"); Writer rawWriter; if (presetWriter != null) rawWriter = presetWriter; @@ -399,6 +402,7 @@ public class Delombok { writer.close(); } } + delegate.close(); return true; } @@ -411,24 +415,6 @@ public class Delombok { } } - private static final Messager messager = new Messager() { - @Override public void printMessage(Kind kind, CharSequence msg) { - System.out.printf("%s: %s\n", kind, msg); - } - - @Override public void printMessage(Kind kind, CharSequence msg, Element e) { - System.out.printf("%s: %s\n", kind, msg); - } - - @Override public void printMessage(Kind kind, CharSequence msg, Element e, AnnotationMirror a) { - System.out.printf("%s: %s\n", kind, msg); - } - - @Override public void printMessage(Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v) { - System.out.printf("%s: %s\n", kind, msg); - } - }; - private static String canonical(File dir) { try { return dir.getCanonicalPath(); |