diff options
Diffstat (limited to 'src/core/lombok/eclipse')
-rw-r--r-- | src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java | 21 | ||||
-rw-r--r-- | src/core/lombok/eclipse/handlers/HandleGetter.java | 10 | ||||
-rw-r--r-- | src/core/lombok/eclipse/handlers/HandleSetter.java | 4 |
3 files changed, 32 insertions, 3 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index f795197b..67a2d07c 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -245,6 +245,27 @@ public class EclipseHandlerUtil { return node; } + public static MarkerAnnotation generateDeprecatedAnnotation(ASTNode source) { + QualifiedTypeReference qtr = new QualifiedTypeReference(new char[][] { + {'j', 'a', 'v', 'a'}, {'l', 'a', 'n', 'g'}, {'D', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd'}}, poss(source, 3)); + setGeneratedBy(qtr, source); + return new MarkerAnnotation(qtr, source.sourceStart); + } + + public static boolean isFieldDeprecated(EclipseNode fieldNode) { + FieldDeclaration field = (FieldDeclaration) fieldNode.get(); + if ((field.modifiers & ClassFileConstants.AccDeprecated) != 0) { + return true; + } + if (field.annotations == null) return false; + for (Annotation annotation : field.annotations) { + if (typeMatches(Deprecated.class, fieldNode, annotation.type)) { + return true; + } + } + return false; + } + /** * Checks if the given TypeReference node is likely to be a reference to the provided class. * diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java index 92f1177f..3bdba74e 100644 --- a/src/core/lombok/eclipse/handlers/HandleGetter.java +++ b/src/core/lombok/eclipse/handlers/HandleGetter.java @@ -212,14 +212,20 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> { } MethodDeclaration method = generateGetter((TypeDeclaration) fieldNode.up().get(), fieldNode, getterName, modifier, source, lazy); - Annotation[] copiedAnnotations = copyAnnotations(source, findAnnotations(field, TransformationsUtil.NON_NULL_PATTERN), findAnnotations(field, TransformationsUtil.NULLABLE_PATTERN), findDelegatesAndMarkAsHandled(fieldNode)); + + Annotation[] deprecated = null; + if (isFieldDeprecated(fieldNode)) { + deprecated = new Annotation[] { generateDeprecatedAnnotation(source) }; + } + + Annotation[] copiedAnnotations = copyAnnotations(source, findAnnotations(field, TransformationsUtil.NON_NULL_PATTERN), findAnnotations(field, TransformationsUtil.NULLABLE_PATTERN), findDelegatesAndMarkAsHandled(fieldNode), deprecated); if (copiedAnnotations.length != 0) { method.annotations = copiedAnnotations; } injectMethod(fieldNode.up(), method); } - + private static Annotation[] findDelegatesAndMarkAsHandled(EclipseNode fieldNode) { List<Annotation> delegates = new ArrayList<Annotation>(); for (EclipseNode child : fieldNode.down()) { diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java index ea81965b..8599fca7 100644 --- a/src/core/lombok/eclipse/handlers/HandleSetter.java +++ b/src/core/lombok/eclipse/handlers/HandleSetter.java @@ -184,7 +184,9 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> { method.returnType = TypeReference.baseTypeReference(TypeIds.T_void, 0); method.returnType.sourceStart = pS; method.returnType.sourceEnd = pE; setGeneratedBy(method.returnType, source); - method.annotations = null; + if (isFieldDeprecated(fieldNode)) { + method.annotations = new Annotation[] { generateDeprecatedAnnotation(source) }; + } Argument param = new Argument(field.name, p, copyType(field.type, source), Modifier.FINAL); param.sourceStart = pS; param.sourceEnd = pE; setGeneratedBy(param, source); |