diff options
Diffstat (limited to 'src')
8 files changed, 65 insertions, 6 deletions
diff --git a/src/core/lombok/javac/JavacNode.java b/src/core/lombok/javac/JavacNode.java index a0ee2789..3d7ce73f 100644 --- a/src/core/lombok/javac/JavacNode.java +++ b/src/core/lombok/javac/JavacNode.java @@ -26,6 +26,7 @@ import java.util.List; import javax.tools.Diagnostic; import lombok.core.AST.Kind; +import lombok.delombok.DeleteLombokAnnotations; import com.sun.tools.javac.code.Symtab; import com.sun.tools.javac.tree.JCTree; @@ -173,6 +174,11 @@ public class JavacNode extends lombok.core.LombokNode<JavacAST, JavacNode, JCTre return ast.getContext(); } + public boolean shouldDeleteLombokAnnotations() { + DeleteLombokAnnotations dla = ast.getContext().get(DeleteLombokAnnotations.class); + return dla != null && dla.isDeleteLombokAnnotations(); + } + /** * Convenient shortcut to the owning JavacAST object's toName method. * diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java index 4331761f..fe5f8566 100644 --- a/src/core/lombok/javac/handlers/HandleConstructor.java +++ b/src/core/lombok/javac/handlers/HandleConstructor.java @@ -58,6 +58,7 @@ public class HandleConstructor { public static class HandleNoArgsConstructor implements JavacAnnotationHandler<NoArgsConstructor> { @Override public boolean handle(AnnotationValues<NoArgsConstructor> annotation, JCAnnotation ast, JavacNode annotationNode) { markAnnotationAsProcessed(annotationNode, NoArgsConstructor.class); + deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel"); JavacNode typeNode = annotationNode.up(); NoArgsConstructor ann = annotation.getInstance(); AccessLevel level = ann.access(); @@ -73,6 +74,7 @@ public class HandleConstructor { public static class HandleRequiredArgsConstructor implements JavacAnnotationHandler<RequiredArgsConstructor> { @Override public boolean handle(AnnotationValues<RequiredArgsConstructor> annotation, JCAnnotation ast, JavacNode annotationNode) { markAnnotationAsProcessed(annotationNode, RequiredArgsConstructor.class); + deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel"); JavacNode typeNode = annotationNode.up(); RequiredArgsConstructor ann = annotation.getInstance(); AccessLevel level = ann.access(); @@ -102,6 +104,7 @@ public class HandleConstructor { public static class HandleAllArgsConstructor implements JavacAnnotationHandler<AllArgsConstructor> { @Override public boolean handle(AnnotationValues<AllArgsConstructor> annotation, JCAnnotation ast, JavacNode annotationNode) { markAnnotationAsProcessed(annotationNode, AllArgsConstructor.class); + deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel"); JavacNode typeNode = annotationNode.up(); AllArgsConstructor ann = annotation.getInstance(); AccessLevel level = ann.access(); diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java index 16185e9c..9c0ce32f 100644 --- a/src/core/lombok/javac/handlers/HandleGetter.java +++ b/src/core/lombok/javac/handlers/HandleGetter.java @@ -95,6 +95,7 @@ public class HandleGetter implements JavacAnnotationHandler<Getter> { @Override public boolean handle(AnnotationValues<Getter> annotation, JCAnnotation ast, JavacNode annotationNode) { markAnnotationAsProcessed(annotationNode, Getter.class); + deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel"); JavacNode node = annotationNode.up(); AccessLevel level = annotation.getInstance().value(); if (level == AccessLevel.NONE) return true; diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java index a3822daa..dfc9c8ba 100644 --- a/src/core/lombok/javac/handlers/HandleSetter.java +++ b/src/core/lombok/javac/handlers/HandleSetter.java @@ -104,6 +104,7 @@ public class HandleSetter implements JavacAnnotationHandler<Setter> { @Override public boolean handle(AnnotationValues<Setter> annotation, JCAnnotation ast, JavacNode annotationNode) { markAnnotationAsProcessed(annotationNode, Setter.class); + deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel"); JavacNode node = annotationNode.up(); AccessLevel level = annotation.getInstance().value(); diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index a4949a58..0df48358 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -92,13 +92,15 @@ public class JavacHandlerUtil { return; } - JCCompilationUnit unit = (JCCompilationUnit) annotation.top().get(); - deleteImportFromCompilationUnit(unit, annotationType.getName()); + deleteImportFromCompilationUnit(annotation, annotationType.getName()); } - private static void deleteImportFromCompilationUnit(JCCompilationUnit unit, String name) { + public static void deleteImportFromCompilationUnit(JavacNode node, String name) { + if (!node.shouldDeleteLombokAnnotations()) return; List<JCTree> newDefs = List.nil(); + JCCompilationUnit unit = (JCCompilationUnit) node.top().get(); + for (JCTree def : unit.defs) { boolean delete = false; if (def instanceof JCImport) { diff --git a/src/delombok/lombok/delombok/CommentPreservingParser.java b/src/delombok/lombok/delombok/CommentPreservingParser.java index 186d70b0..8536075d 100644 --- a/src/delombok/lombok/delombok/CommentPreservingParser.java +++ b/src/delombok/lombok/delombok/CommentPreservingParser.java @@ -1,5 +1,5 @@ /* - * Copyright © 2009 Reinier Zwitserloot and Roel Spilker. + * Copyright © 2009-2010 Reinier Zwitserloot and Roel Spilker. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -44,6 +44,7 @@ import com.sun.tools.javac.util.Options; public class CommentPreservingParser { private final String encoding; + private boolean deleteLombokAnnotations = false; public CommentPreservingParser() { this("utf-8"); @@ -53,6 +54,10 @@ public class CommentPreservingParser { this.encoding = encoding; } + public void setDeleteLombokAnnotations(boolean deleteLombokAnnotations) { + this.deleteLombokAnnotations = deleteLombokAnnotations; + } + public ParseResult parse(JavaFileObject source, boolean forceProcessing) throws IOException { return doParse(source, forceProcessing); } @@ -78,7 +83,8 @@ public class CommentPreservingParser { Comments comments = new Comments(); context.put(Comments.class, comments); - + if (deleteLombokAnnotations) context.put(DeleteLombokAnnotations.class, new DeleteLombokAnnotations(true)); + comments.comments = List.nil(); JCCompilationUnit cu; diff --git a/src/delombok/lombok/delombok/DeleteLombokAnnotations.java b/src/delombok/lombok/delombok/DeleteLombokAnnotations.java new file mode 100644 index 00000000..335cf6e9 --- /dev/null +++ b/src/delombok/lombok/delombok/DeleteLombokAnnotations.java @@ -0,0 +1,35 @@ +/* + * Copyright © 2010 Reinier Zwitserloot and Roel Spilker. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.delombok; + +/** Used as marker in javac's Context object when delombok is running to signal that all lombok annotations should be deleted as they are processed. */ +public class DeleteLombokAnnotations { + private final boolean deleteLombokAnnotations; + + public DeleteLombokAnnotations(boolean deleteLombokAnnotations) { + this.deleteLombokAnnotations = deleteLombokAnnotations; + } + + public boolean isDeleteLombokAnnotations() { + return deleteLombokAnnotations; + } +} diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index b38d3ef5..4ec5e270 100644 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -1,5 +1,5 @@ /* - * Copyright © 2009 Reinier Zwitserloot and Roel Spilker. + * Copyright © 2009-2010 Reinier Zwitserloot and Roel Spilker. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -50,6 +50,11 @@ import com.zwitserloot.cmdreader.Shorthand; public class Delombok { private Charset charset = Charset.defaultCharset(); private CommentPreservingParser parser = new CommentPreservingParser(); + + { + parser.setDeleteLombokAnnotations(true); + } + private PrintStream feedback = System.err; private boolean verbose; private boolean noCopy; |