aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2010-07-20 07:03:07 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2010-07-20 07:03:07 +0200
commit77ff3ca2c3ad9544e242cc0c29817831485eeb0b (patch)
tree2c21059c65df68aad2bd94f1b28ee12e4aea44c9 /src/core/lombok/javac
parent4e40de2f8816c93805f5deffbe2d2d7ecff3264e (diff)
downloadlombok-77ff3ca2c3ad9544e242cc0c29817831485eeb0b.tar.gz
lombok-77ff3ca2c3ad9544e242cc0c29817831485eeb0b.tar.bz2
lombok-77ff3ca2c3ad9544e242cc0c29817831485eeb0b.zip
import lombok.AccessLevel is now also removed during delomboking.
Also, when NOT running delombok, the javac processors no longer delete the lombok annotations as they process. This is particularly relevant for netbeans. This fixes issue #100 and #103.
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r--src/core/lombok/javac/JavacNode.java6
-rw-r--r--src/core/lombok/javac/handlers/HandleConstructor.java3
-rw-r--r--src/core/lombok/javac/handlers/HandleGetter.java1
-rw-r--r--src/core/lombok/javac/handlers/HandleSetter.java1
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java8
5 files changed, 16 insertions, 3 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) {