diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-19 16:24:10 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-19 16:24:10 +0200 |
commit | ff306fa5d97a09d69332c76a33596bb053222855 (patch) | |
tree | 00124b2190b36f13381d9513717e558aacbad973 /src/lombok/eclipse/handlers/HandleData.java | |
parent | e56ab6c2457531c0ce8556097f945b6e7946f6f2 (diff) | |
download | lombok-ff306fa5d97a09d69332c76a33596bb053222855.tar.gz lombok-ff306fa5d97a09d69332c76a33596bb053222855.tar.bz2 lombok-ff306fa5d97a09d69332c76a33596bb053222855.zip |
Added initial support for the @Data annotation. Currently produces getters and setters only,
not yet a constructor, toString, hashCode, or equals.
HandleGetter and HandleSetter have been updated to handle static (theoretic; you can't put annotations on static fields normally).
You can now make AnnotationValue objects using just an annotationNode and a target type, as well as check if a given annotationNode is likely to represent a target annotation type. This is in Javac and Eclipse classes.
HandleGetter and HandleSetter can now be asked to make a getter/setter, and will grab access level off of a Getter/Setter annotation, if present.
Diffstat (limited to 'src/lombok/eclipse/handlers/HandleData.java')
-rw-r--r-- | src/lombok/eclipse/handlers/HandleData.java | 49 |
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; + } +} |