aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2011-01-29 16:54:14 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2011-02-07 21:35:34 +0100
commitc98cec7d2ddceddcc0f127185912be4f826a6caa (patch)
treedc8c50a3ac256a08faac8adde76904bca004cbd8 /src/core/lombok/eclipse
parentaab3faa3cb43b4a854b5d094f1ef80eb39543bfb (diff)
downloadlombok-c98cec7d2ddceddcc0f127185912be4f826a6caa.tar.gz
lombok-c98cec7d2ddceddcc0f127185912be4f826a6caa.tar.bz2
lombok-c98cec7d2ddceddcc0f127185912be4f826a6caa.zip
Presence of isFoo(), hasFoo(), and getFoo(), as well as properties named 'isFoo', 'hasFoo', or 'getFoo' would trigger specialized handling for @Getter/@Setter. However, this special handling broke the bean spec, and has been simplified: Only fields named 'isFoo', and only if that field's type is 'boolean', results in both 'isFoo' and 'foo' being considered as possible property names for this property, with 'foo' preferred, so that @Getter boolean isFoo will generate setFoo and isFoo methods, not setIsFoo and isIsFoo.
Fixes issue #148
Diffstat (limited to 'src/core/lombok/eclipse')
-rw-r--r--src/core/lombok/eclipse/handlers/HandleSetter.java31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java
index 14ff0e10..945495c6 100644
--- a/src/core/lombok/eclipse/handlers/HandleSetter.java
+++ b/src/core/lombok/eclipse/handlers/HandleSetter.java
@@ -157,21 +157,28 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> {
}
FieldDeclaration field = (FieldDeclaration) fieldNode.get();
- String setterName = TransformationsUtil.toSetterName(new String(field.name));
+ TypeReference fieldType = copyType(field.type, source);
+ boolean isBoolean = nameEquals(fieldType.getTypeName(), "boolean") && fieldType.dimensions() == 0;
+ String setterName = TransformationsUtil.toSetterName(new String(field.name), isBoolean);
int modifier = toEclipseModifier(level) | (field.modifiers & ClassFileConstants.AccStatic);
- switch (methodExists(setterName, fieldNode, false)) {
- case EXISTS_BY_LOMBOK:
- return true;
- case EXISTS_BY_USER:
- if (whineIfExists) errorNode.addWarning(
- String.format("Not generating %s(%s %s): A method with that name already exists",
- setterName, field.type, new String(field.name)));
- return true;
- default:
- case NOT_EXISTS:
- //continue with creating the setter
+ for (String altName : TransformationsUtil.toAllSetterNames(new String(field.name), isBoolean)) {
+ switch (methodExists(altName, fieldNode, false)) {
+ case EXISTS_BY_LOMBOK:
+ return true;
+ case EXISTS_BY_USER:
+ if (whineIfExists) {
+ String altNameExpl = "";
+ if (!altName.equals(setterName)) altNameExpl = String.format(" (%s)", altName);
+ errorNode.addWarning(
+ String.format("Not generating %s(): A method with that name already exists%s", setterName, altNameExpl));
+ }
+ return true;
+ default:
+ case NOT_EXISTS:
+ //continue scanning the other alt names.
+ }
}
MethodDeclaration method = generateSetter((TypeDeclaration) fieldNode.up().get(), fieldNode, setterName, modifier, source, onParam);