From 8fa50054449d88380ce45ba91881df6655737f20 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 17 Jun 2009 21:35:51 +0200 Subject: 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. --- src/lombok/javac/handlers/HandleGetter.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/lombok/javac/handlers/HandleGetter.java') 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 { @Override public void handle(AnnotationValues 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(); -- cgit