diff options
author | Roel Spilker <r.spilker@gmail.com> | 2012-01-30 19:48:12 +0100 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2012-01-30 19:48:12 +0100 |
commit | 55384884d380fba1a5fe024e1d82329d71c36f02 (patch) | |
tree | a19f69b9a4da56b58abb96e0a79d852eeb659bb0 /src/core/lombok/javac/handlers/HandleGetter.java | |
parent | 98875218ea3f6ba68f7f83d3e0458c9901db00f3 (diff) | |
parent | fc7ca61aeb3ee06c426573b5059e97532b601172 (diff) | |
download | lombok-55384884d380fba1a5fe024e1d82329d71c36f02.tar.gz lombok-55384884d380fba1a5fe024e1d82329d71c36f02.tar.bz2 lombok-55384884d380fba1a5fe024e1d82329d71c36f02.zip |
Merge branch 'master' of github.com:rzwitserloot/lombok
Diffstat (limited to 'src/core/lombok/javac/handlers/HandleGetter.java')
-rw-r--r-- | src/core/lombok/javac/handlers/HandleGetter.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java index fe3b86a4..c9d67d7f 100644 --- a/src/core/lombok/javac/handlers/HandleGetter.java +++ b/src/core/lombok/javac/handlers/HandleGetter.java @@ -30,6 +30,7 @@ import java.util.HashMap; import java.util.Map; import lombok.AccessLevel; +import lombok.Delegate; import lombok.Getter; import lombok.core.AnnotationValues; import lombok.core.TransformationsUtil; @@ -240,16 +241,42 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> { List<JCAnnotation> nonNulls = findAnnotations(field, TransformationsUtil.NON_NULL_PATTERN); List<JCAnnotation> nullables = findAnnotations(field, TransformationsUtil.NULLABLE_PATTERN); + List<JCAnnotation> delegates = findDelegatesAndRemoveFromField(field); + List<JCAnnotation> annsOnMethod = nonNulls.appendList(nullables); JCMethodDecl decl = recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, methodType, methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source); if (toClearOfMarkers != null) recursiveSetGeneratedBy(toClearOfMarkers, null); + decl.mods.annotations = decl.mods.annotations.appendList(delegates); return decl; } + private static List<JCAnnotation> findDelegatesAndRemoveFromField(JavacNode field) { + JCVariableDecl fieldNode = (JCVariableDecl) field.get(); + + List<JCAnnotation> delegates = List.nil(); + for (JCAnnotation annotation : fieldNode.mods.annotations) { + if (typeMatches(Delegate.class, field, annotation.annotationType)) { + delegates = delegates.append(annotation); + } + } + + if (!delegates.isEmpty()) { + ListBuffer<JCAnnotation> withoutDelegates = ListBuffer.lb(); + for (JCAnnotation annotation : fieldNode.mods.annotations) { + if (!delegates.contains(annotation)) { + withoutDelegates.append(annotation); + } + } + fieldNode.mods.annotations = withoutDelegates.toList(); + field.rebuild(); + } + return delegates; + } + private List<JCStatement> createSimpleGetterBody(TreeMaker treeMaker, JavacNode field) { return List.<JCStatement>of(treeMaker.Return(createFieldAccessor(treeMaker, field, FieldAccess.ALWAYS_FIELD))); } |