aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/handlers/HandleSetter.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2010-07-22 14:19:23 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2010-07-22 14:19:23 +0200
commitceda2e5efe229650d4e95de6b8a2632d9f616592 (patch)
tree1af7964267dc2ce40e0efb02ee767d58303bfab5 /src/core/lombok/eclipse/handlers/HandleSetter.java
parent868d8b0f93c0801f638b8c5523291aacd35d9ce2 (diff)
downloadlombok-ceda2e5efe229650d4e95de6b8a2632d9f616592.tar.gz
lombok-ceda2e5efe229650d4e95de6b8a2632d9f616592.tar.bz2
lombok-ceda2e5efe229650d4e95de6b8a2632d9f616592.zip
toString(), equals(), and hashCode() now use getX() instead of x if either it exists OR it will be generated by some other lombok annotation, addressing issue #110.
code deduplication by removing HandleData's scanning for fields, which is now no longer done; the sub-parts of Data (Getter, Setter, RequiredArgsConstructor, etc) take care of it now. fix for class-level @Getter/@Setter, which used to go for every field. Now they skip the usual fields (static, for setters final, and $ prefixed fields). Bugfix for @Data not recognizing that it should let field-level @Getter/@Setter take care of generating the getter/setter for multi field declarations (@Getter int x, y);
Diffstat (limited to 'src/core/lombok/eclipse/handlers/HandleSetter.java')
-rw-r--r--src/core/lombok/eclipse/handlers/HandleSetter.java71
1 files changed, 41 insertions, 30 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java
index ccdbbb2c..1583de1b 100644
--- a/src/core/lombok/eclipse/handlers/HandleSetter.java
+++ b/src/core/lombok/eclipse/handlers/HandleSetter.java
@@ -58,6 +58,44 @@ import org.mangosdk.spi.ProviderFor;
*/
@ProviderFor(EclipseAnnotationHandler.class)
public class HandleSetter implements EclipseAnnotationHandler<Setter> {
+ public boolean generateSetterForType(EclipseNode typeNode, EclipseNode pos, AccessLevel level, boolean checkForTypeLevelSetter) {
+ if (checkForTypeLevelSetter) {
+ if (typeNode != null) for (EclipseNode child : typeNode.down()) {
+ if (child.getKind() == Kind.ANNOTATION) {
+ if (annotationTypeMatches(Setter.class, child)) {
+ //The annotation will make it happen, so we can skip it.
+ return true;
+ }
+ }
+ }
+ }
+
+ TypeDeclaration typeDecl = null;
+ if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get();
+ int modifiers = typeDecl == null ? 0 : typeDecl.modifiers;
+ boolean notAClass = (modifiers &
+ (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | ClassFileConstants.AccEnum)) != 0;
+
+ if (typeDecl == null || notAClass) {
+ pos.addError("@Setter is only supported on a class or a field.");
+ return false;
+ }
+
+ for (EclipseNode field : typeNode.down()) {
+ if (field.getKind() != Kind.FIELD) continue;
+ FieldDeclaration fieldDecl = (FieldDeclaration) field.get();
+ //Skip fields that start with $
+ if (fieldDecl.name.length > 0 && fieldDecl.name[0] == '$') continue;
+ //Skip static fields.
+ if ((fieldDecl.modifiers & ClassFileConstants.AccStatic) != 0) continue;
+ //Skip final fields.
+ if ((fieldDecl.modifiers & ClassFileConstants.AccFinal) != 0) continue;
+
+ generateSetterForField(field, pos.get(), level);
+ }
+ return true;
+ }
+
/**
* Generates a setter on the stated field.
*
@@ -70,7 +108,7 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> {
* If not, the setter is still generated if it isn't already there, though there will not
* be a warning if its already there. The default access level is used.
*/
- public void generateSetterForField(EclipseNode fieldNode, ASTNode pos, AccessLevel level, boolean checkForTypeLevelSetter) {
+ public void generateSetterForField(EclipseNode fieldNode, ASTNode pos, AccessLevel level) {
for (EclipseNode child : fieldNode.down()) {
if (child.getKind() == Kind.ANNOTATION) {
if (annotationTypeMatches(Setter.class, child)) {
@@ -80,18 +118,6 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> {
}
}
- if (checkForTypeLevelSetter) {
- EclipseNode containingType = fieldNode.up();
- if (containingType != null) for (EclipseNode child : containingType.down()) {
- if (child.getKind() == Kind.ANNOTATION) {
- if (annotationTypeMatches(Setter.class, child)) {
- //The annotation will make it happen, so we can skip it.
- return;
- }
- }
- }
- }
-
createSetterForField(level, fieldNode, fieldNode, pos, false);
}
@@ -105,22 +131,7 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> {
return createSetterForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, annotationNode.get(), true);
}
if (node.getKind() == Kind.TYPE) {
- TypeDeclaration typeDecl = null;
- if (node.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) node.get();
- int modifiers = typeDecl == null ? 0 : typeDecl.modifiers;
- boolean notAClass = (modifiers &
- (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | ClassFileConstants.AccEnum)) != 0;
-
- if (typeDecl == null || notAClass) {
- annotationNode.addError("@Setter is only supported on a class.");
- return false;
- }
-
- for (EclipseNode field : node.down()) {
- if (field.getKind() != Kind.FIELD) continue;
- generateSetterForField(field, ast, level, false);
- }
- return true;
+ return generateSetterForType(node, annotationNode, level, false);
}
return false;
}
@@ -135,7 +146,7 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> {
private boolean createSetterForField(AccessLevel level,
EclipseNode fieldNode, EclipseNode errorNode, ASTNode pos, boolean whineIfExists) {
if (fieldNode.getKind() != Kind.FIELD) {
- errorNode.addError("@Setter is only supported on a field.");
+ errorNode.addError("@Setter is only supported on a class or a field.");
return true;
}