diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-17 21:35:51 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-17 21:35:51 +0200 |
commit | 8fa50054449d88380ce45ba91881df6655737f20 (patch) | |
tree | 08117208cfa6d2ed870e76489c031ee6f74c5aea /src/lombok/javac/handlers/HandleGetter.java | |
parent | 1929a28c9def0dd276dcf3fdb70ada8b84b1c64a (diff) | |
download | lombok-8fa50054449d88380ce45ba91881df6655737f20.tar.gz lombok-8fa50054449d88380ce45ba91881df6655737f20.tar.bz2 lombok-8fa50054449d88380ce45ba91881df6655737f20.zip |
Added 'does setX/getX already exist' check to javac's HandleGetter/Setter. If they exist (with any returntype/paramlist), no getter/setter is generated, and instead a warning is added on the annotation.
Diffstat (limited to 'src/lombok/javac/handlers/HandleGetter.java')
-rw-r--r-- | src/lombok/javac/handlers/HandleGetter.java | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lombok/javac/handlers/HandleGetter.java b/src/lombok/javac/handlers/HandleGetter.java index 781598a2..da1b7107 100644 --- a/src/lombok/javac/handlers/HandleGetter.java +++ b/src/lombok/javac/handlers/HandleGetter.java @@ -25,12 +25,19 @@ import com.sun.tools.javac.util.Name; @ProviderFor(JavacAnnotationHandler.class) public class HandleGetter implements JavacAnnotationHandler<Getter> { @Override public void handle(AnnotationValues<Getter> annotation, JCAnnotation ast, JavacAST.Node annotationNode) { - //TODO Check for existence of the getter and skip it (+ warn) if it's already there. if ( annotationNode.up().getKind() != Kind.FIELD ) { annotationNode.addError("@Getter is only supported on a field."); return; } + String methodName = toGetterName((JCVariableDecl) annotationNode.up().get()); + + if ( methodExists(methodName, annotationNode.up()) ) { + annotationNode.addWarning( + String.format("Not generating %s(): A method with that name already exists", methodName)); + return; + } + Getter getter = annotation.getInstance(); JCClassDecl javacClassTree = (JCClassDecl) annotationNode.up().up().get(); |