aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/eclipse/handlers/HandleData.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/lombok/eclipse/handlers/HandleData.java')
-rw-r--r--src/lombok/eclipse/handlers/HandleData.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/lombok/eclipse/handlers/HandleData.java b/src/lombok/eclipse/handlers/HandleData.java
new file mode 100644
index 00000000..64540e95
--- /dev/null
+++ b/src/lombok/eclipse/handlers/HandleData.java
@@ -0,0 +1,49 @@
+package lombok.eclipse.handlers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.internal.compiler.ast.Annotation;
+import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
+import org.mangosdk.spi.ProviderFor;
+
+import lombok.Data;
+import lombok.core.AnnotationValues;
+import lombok.core.AST.Kind;
+import lombok.eclipse.EclipseAnnotationHandler;
+import lombok.eclipse.EclipseAST.Node;
+
+@ProviderFor(EclipseAnnotationHandler.class)
+public class HandleData implements EclipseAnnotationHandler<Data> {
+ @Override public boolean handle(AnnotationValues<Data> annotation, Annotation ast, Node annotationNode) {
+ Node typeNode = annotationNode.up();
+
+ TypeDeclaration typeDecl = null;
+ if ( typeNode.get() instanceof TypeDeclaration ) typeDecl = (TypeDeclaration) typeNode.get();
+ int modifiers = typeDecl == null ? 0 : typeDecl.modifiers;
+ boolean notAClass = (modifiers &
+ (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | ClassFileConstants.AccEnum)) != 0;
+
+ if ( typeDecl == null || notAClass ) {
+ annotationNode.addError("@Data is only supported on a class.");
+ return false;
+ }
+
+ List<Node> nodesForEquality = new ArrayList<Node>();
+ for ( Node child : typeNode.down() ) {
+ if ( child.getKind() != Kind.FIELD ) continue;
+ FieldDeclaration fieldDecl = (FieldDeclaration) child.get();
+ //Skip static fields.
+ if ( (fieldDecl.modifiers & ClassFileConstants.AccStatic) != 0 ) continue;
+ if ( (fieldDecl.modifiers & ClassFileConstants.AccTransient) == 0 ) nodesForEquality.add(child);
+ new HandleGetter().generateGetterForField(child, annotationNode.get());
+ if ( (fieldDecl.modifiers & ClassFileConstants.AccFinal) == 0 )
+ new HandleSetter().generateSetterForField(child, annotationNode.get());
+ }
+
+ //TODO generate constructor, hashCode, equals, toString.
+ return true;
+ }
+}