diff options
author | Roel Spilker <r.spilker@gmail.com> | 2012-03-19 23:18:37 +0100 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2012-03-19 23:18:37 +0100 |
commit | 8bc82cad05b8760aa5a01ffabaa6238b6cc535e1 (patch) | |
tree | 0e02ca81914544fe3df18b5b548ca0916b25e57f /src/core/lombok/javac | |
parent | b4fe2d4e25e164f6063df48891c3a941fabed2e9 (diff) | |
download | lombok-8bc82cad05b8760aa5a01ffabaa6238b6cc535e1.tar.gz lombok-8bc82cad05b8760aa5a01ffabaa6238b6cc535e1.tar.bz2 lombok-8bc82cad05b8760aa5a01ffabaa6238b6cc535e1.zip |
Fix for issue 342: @Deprecated annotation not propagated to generated getter/setter
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r-- | src/core/lombok/javac/handlers/HandleGetter.java | 11 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/HandleSetter.java | 7 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/JavacHandlerUtil.java | 20 |
3 files changed, 31 insertions, 7 deletions
diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java index c286ed24..b3421f86 100644 --- a/src/core/lombok/javac/handlers/HandleGetter.java +++ b/src/core/lombok/javac/handlers/HandleGetter.java @@ -74,11 +74,9 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> { public void generateGetterForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean checkForTypeLevelGetter) { if (checkForTypeLevelGetter) { if (typeNode != null) for (JavacNode child : typeNode.down()) { - if (child.getKind() == Kind.ANNOTATION) { - if (annotationTypeMatches(Getter.class, child)) { - //The annotation will make it happen, so we can skip it. - return; - } + if (annotationTypeMatches(Getter.class, child)) { + //The annotation will make it happen, so we can skip it. + return; } } } @@ -244,6 +242,9 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> { List<JCAnnotation> delegates = findDelegatesAndRemoveFromField(field); List<JCAnnotation> annsOnMethod = nonNulls.appendList(nullables); + if (isFieldDeprecated(field)) { + annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(chainDots(field, "java", "lang", "Deprecated"), List.<JCExpression>nil())); + } JCMethodDecl decl = recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, methodType, methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source); diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java index db1fa724..0298311e 100644 --- a/src/core/lombok/javac/handlers/HandleSetter.java +++ b/src/core/lombok/javac/handlers/HandleSetter.java @@ -208,6 +208,7 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> { JCBlock methodBody = treeMaker.Block(0, statements); Name methodName = field.toName(toSetterName(fieldDecl)); List<JCAnnotation> annsOnParam = nonNulls.appendList(nullables); + JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(Flags.FINAL, annsOnParam), fieldDecl.name, fieldDecl.vartype, null); //WARNING: Do not use field.getSymbolTable().voidType - that field has gone through non-backwards compatible API changes within javac1.6. JCExpression methodType = treeMaker.Type(new JCNoType(getCtcInt(TypeTags.class, "VOID"))); @@ -217,7 +218,11 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> { List<JCExpression> throwsClauses = List.nil(); JCExpression annotationMethodDefaultValue = null; - return recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, List.<JCAnnotation>nil()), methodName, methodType, + List<JCAnnotation> annsOnMethod = List.nil(); + if (isFieldDeprecated(field)) { + annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(chainDots(field, "java", "lang", "Deprecated"), List.<JCExpression>nil())); + } + return recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, methodType, methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source); } diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 244f7d38..32b17322 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2011 The Project Lombok Authors. + * Copyright (C) 2009-2012 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -142,6 +142,24 @@ public class JavacHandlerUtil { } /** + * Returns if a field is marked deprecated, either by {@code @Deprecated} or in javadoc + * @param field the field to check + * @return {@code true} if a field is marked deprecated, either by {@code @Deprecated} or in javadoc, otherwise {@code false} + */ + public static boolean isFieldDeprecated(JavacNode field) { + JCVariableDecl fieldNode = (JCVariableDecl) field.get(); + if ((fieldNode.mods.flags & Flags.DEPRECATED) != 0) { + return true; + } + for (JavacNode child : field.down()) { + if (annotationTypeMatches(Deprecated.class, child)) { + return true; + } + } + return false; + } + + /** * Creates an instance of {@code AnnotationValues} for the provided AST Node. * * @param type An annotation class type, such as {@code lombok.Getter.class}. |