Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/lombok/eclipse/handlers/HandleBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ private void makePrefixedSetterMethodForBuilder(BuilderJob job, BuilderFieldData
if (methodAnns != null && methodAnns.length > 0) methodAnnsList = Arrays.asList(methodAnns);
ASTNode source = job.sourceNode.get();
MethodDeclaration setter = HandleSetter.createSetter(td, deprecate, fieldNode, setterName, bfd.name, bfd.nameOfSetFlag, job.oldChain, toEclipseModifier(job.accessInners),
job.sourceNode, methodAnnsList, bfd.annotations != null ? Arrays.asList(copyAnnotations(source, bfd.annotations)) : Collections.<Annotation>emptyList());
job.sourceNode, methodAnnsList, bfd.annotations != null ? Arrays.asList(copyAnnotations(source, bfd.annotations)) : Collections.<Annotation>emptyList(), false);
if (job.sourceNode.up().getKind() == Kind.METHOD) {
copyJavadocFromParam(bfd.originalFieldNode.up(), setter, td, new String(bfd.name));
} else {
Expand Down
19 changes: 7 additions & 12 deletions src/core/lombok/eclipse/handlers/HandleSetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,6 @@ public void generateSetterForField(EclipseNode fieldNode, EclipseNode sourceNode
return;
}

// If a fluent setter should be generated, force-copy annotations from the field.
AnnotationValues<Accessors> accessorsForField = EclipseHandlerUtil.getAccessorsForField(fieldNode);
// Copying Jackson annotations is required for fluent accessors (otherwise Jackson would not find the accessor).
Annotation[] copyableToSetterAnnotations = findCopyableToSetterAnnotations(fieldNode, accessorsForField.isExplicit("fluent"));
onMethod = new ArrayList<Annotation>(onMethod);
onMethod.addAll(Arrays.asList(copyableToSetterAnnotations));

createSetterForField(level, fieldNode, sourceNode, false, onMethod, onParam);
}

Expand Down Expand Up @@ -170,6 +163,7 @@ public void createSetterForField(
AnnotationValues<Accessors> accessors = getAccessorsForField(fieldNode);
String setterName = toSetterName(fieldNode, isBoolean, accessors);
boolean shouldReturnThis = shouldReturnThis(fieldNode, accessors);
boolean fluent = accessors.isExplicit("fluent");

if (setterName == null) {
fieldNode.addWarning("Not generating setter for this field: It does not fit your @Accessors prefix list.");
Expand All @@ -196,11 +190,11 @@ public void createSetterForField(
}
}

MethodDeclaration method = createSetter((TypeDeclaration) fieldNode.up().get(), false, fieldNode, setterName, null, null, shouldReturnThis, modifier, sourceNode, onMethod, onParam);
MethodDeclaration method = createSetter((TypeDeclaration) fieldNode.up().get(), false, fieldNode, setterName, null, null, shouldReturnThis, modifier, sourceNode, onMethod, onParam, fluent);
injectMethod(fieldNode.up(), method);
}

static MethodDeclaration createSetter(TypeDeclaration parent, boolean deprecate, EclipseNode fieldNode, String name, char[] paramName, char[] booleanFieldToSet, boolean shouldReturnThis, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam) {
static MethodDeclaration createSetter(TypeDeclaration parent, boolean deprecate, EclipseNode fieldNode, String name, char[] paramName, char[] booleanFieldToSet, boolean shouldReturnThis, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam, boolean fluent) {
ASTNode source = sourceNode.get();
int pS = source.sourceStart, pE = source.sourceEnd;

Expand All @@ -213,11 +207,11 @@ static MethodDeclaration createSetter(TypeDeclaration parent, boolean deprecate,
returnThis = new ReturnStatement(thisRef, pS, pE);
}

MethodDeclaration d = createSetter(parent, deprecate, fieldNode, name, paramName, booleanFieldToSet, returnType, returnThis, modifier, sourceNode, onMethod, onParam);
MethodDeclaration d = createSetter(parent, deprecate, fieldNode, name, paramName, booleanFieldToSet, returnType, returnThis, modifier, sourceNode, onMethod, onParam, fluent);
return d;
}

static MethodDeclaration createSetter(TypeDeclaration parent, boolean deprecate, EclipseNode fieldNode, String name, char[] paramName, char[] booleanFieldToSet, TypeReference returnType, Statement returnStatement, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam) {
static MethodDeclaration createSetter(TypeDeclaration parent, boolean deprecate, EclipseNode fieldNode, String name, char[] paramName, char[] booleanFieldToSet, TypeReference returnType, Statement returnStatement, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam, boolean fluent) {
FieldDeclaration field = (FieldDeclaration) fieldNode.get();
if (paramName == null) paramName = field.name;
ASTNode source = sourceNode.get();
Expand All @@ -237,7 +231,8 @@ static MethodDeclaration createSetter(TypeDeclaration parent, boolean deprecate,
if (isFieldDeprecated(fieldNode) || deprecate) {
deprecated = new Annotation[] { generateDeprecatedAnnotation(source) };
}
method.annotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated, findCopyableToSetterAnnotations(fieldNode, false));
// Copying Jackson annotations is required for fluent accessors (otherwise Jackson would not find the accessor).
method.annotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated, findCopyableToSetterAnnotations(fieldNode, fluent));
Argument param = new Argument(paramName, p, copyType(field.type, source), Modifier.FINAL);
param.sourceStart = pS; param.sourceEnd = pE;
method.arguments = new Argument[] { param };
Expand Down
2 changes: 1 addition & 1 deletion src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ private void generateSimpleSetterMethodForBuilder(BuilderJob job, boolean deprec
List<Annotation> methodAnnsList = Arrays.asList(EclipseHandlerUtil.findCopyableToSetterAnnotations(originalFieldNode, true));
addCheckerFrameworkReturnsReceiver(returnType, job.source, job.checkerFramework);
MethodDeclaration setter = HandleSetter.createSetter(td, deprecate, fieldNode, setterName, paramName, nameOfSetFlag, returnType, returnStatement, ClassFileConstants.AccPublic,
job.sourceNode, methodAnnsList, annosOnParam != null ? Arrays.asList(copyAnnotations(job.source, annosOnParam)) : Collections.<Annotation>emptyList());
job.sourceNode, methodAnnsList, annosOnParam != null ? Arrays.asList(copyAnnotations(job.source, annosOnParam)) : Collections.<Annotation>emptyList(), false);
if (job.sourceNode.up().getKind() == Kind.METHOD) {
copyJavadocFromParam(originalFieldNode.up(), setter, td, paramName.toString());
} else {
Expand Down
103 changes: 103 additions & 0 deletions test/transform/resource/after-delombok/JacksonJsonProperty2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//CONF: lombok.copyJacksonAnnotationsToAccessors = true
//version 8: Jackson deps are at least Java7+.
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonProperty;

public class JacksonJsonProperty2 {
@JsonProperty("a")
String propertyOne;
@JsonProperty("b")
int propertyTwo;
Map<String, Object> additional = new HashMap<>();

@java.lang.SuppressWarnings("all")
@lombok.Generated
public JacksonJsonProperty2() {
}

@JsonProperty("a")
@java.lang.SuppressWarnings("all")
@lombok.Generated
public String getPropertyOne() {
return this.propertyOne;
}

@JsonProperty("b")
@java.lang.SuppressWarnings("all")
@lombok.Generated
public int getPropertyTwo() {
return this.propertyTwo;
}

@java.lang.SuppressWarnings("all")
@lombok.Generated
public Map<String, Object> getAdditional() {
return this.additional;
}

@JsonProperty("a")
@java.lang.SuppressWarnings("all")
@lombok.Generated
public void setPropertyOne(final String propertyOne) {
this.propertyOne = propertyOne;
}

@JsonProperty("b")
@java.lang.SuppressWarnings("all")
@lombok.Generated
public void setPropertyTwo(final int propertyTwo) {
this.propertyTwo = propertyTwo;
}

@java.lang.SuppressWarnings("all")
@lombok.Generated
public void setAdditional(final Map<String, Object> additional) {
this.additional = additional;
}

@java.lang.Override
@java.lang.SuppressWarnings("all")
@lombok.Generated
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof JacksonJsonProperty2)) return false;
final JacksonJsonProperty2 other = (JacksonJsonProperty2) o;
if (!other.canEqual((java.lang.Object) this)) return false;
if (this.getPropertyTwo() != other.getPropertyTwo()) return false;
final java.lang.Object this$propertyOne = this.getPropertyOne();
final java.lang.Object other$propertyOne = other.getPropertyOne();
if (this$propertyOne == null ? other$propertyOne != null : !this$propertyOne.equals(other$propertyOne)) return false;
final java.lang.Object this$additional = this.getAdditional();
final java.lang.Object other$additional = other.getAdditional();
if (this$additional == null ? other$additional != null : !this$additional.equals(other$additional)) return false;
return true;
}

@java.lang.SuppressWarnings("all")
@lombok.Generated
protected boolean canEqual(final java.lang.Object other) {
return other instanceof JacksonJsonProperty2;
}

@java.lang.Override
@java.lang.SuppressWarnings("all")
@lombok.Generated
public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + this.getPropertyTwo();
final java.lang.Object $propertyOne = this.getPropertyOne();
result = result * PRIME + ($propertyOne == null ? 43 : $propertyOne.hashCode());
final java.lang.Object $additional = this.getAdditional();
result = result * PRIME + ($additional == null ? 43 : $additional.hashCode());
return result;
}

@java.lang.Override
@java.lang.SuppressWarnings("all")
@lombok.Generated
public java.lang.String toString() {
return "JacksonJsonProperty2(propertyOne=" + this.getPropertyOne() + ", propertyTwo=" + this.getPropertyTwo() + ", additional=" + this.getAdditional() + ")";
}
}
66 changes: 66 additions & 0 deletions test/transform/resource/after-ecj/JacksonJsonProperty2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
public @Data class JacksonJsonProperty2 {
@JsonProperty("a") String propertyOne;
@JsonProperty("b") int propertyTwo;
Map<String, Object> additional = new HashMap<>();
public @JsonProperty("a") @java.lang.SuppressWarnings("all") @lombok.Generated String getPropertyOne() {
return this.propertyOne;
}
public @JsonProperty("b") @java.lang.SuppressWarnings("all") @lombok.Generated int getPropertyTwo() {
return this.propertyTwo;
}
public @java.lang.SuppressWarnings("all") @lombok.Generated Map<String, Object> getAdditional() {
return this.additional;
}
public @JsonProperty("a") @java.lang.SuppressWarnings("all") @lombok.Generated void setPropertyOne(final String propertyOne) {
this.propertyOne = propertyOne;
}
public @JsonProperty("b") @java.lang.SuppressWarnings("all") @lombok.Generated void setPropertyTwo(final int propertyTwo) {
this.propertyTwo = propertyTwo;
}
public @java.lang.SuppressWarnings("all") @lombok.Generated void setAdditional(final Map<String, Object> additional) {
this.additional = additional;
}
public @java.lang.Override @java.lang.SuppressWarnings("all") @lombok.Generated boolean equals(final java.lang.Object o) {
if ((o == this))
return true;
if ((! (o instanceof JacksonJsonProperty2)))
return false;
final JacksonJsonProperty2 other = (JacksonJsonProperty2) o;
if ((! other.canEqual((java.lang.Object) this)))
return false;
if ((this.getPropertyTwo() != other.getPropertyTwo()))
return false;
final java.lang.Object this$propertyOne = this.getPropertyOne();
final java.lang.Object other$propertyOne = other.getPropertyOne();
if (((this$propertyOne == null) ? (other$propertyOne != null) : (! this$propertyOne.equals(other$propertyOne))))
return false;
final java.lang.Object this$additional = this.getAdditional();
final java.lang.Object other$additional = other.getAdditional();
if (((this$additional == null) ? (other$additional != null) : (! this$additional.equals(other$additional))))
return false;
return true;
}
protected @java.lang.SuppressWarnings("all") @lombok.Generated boolean canEqual(final java.lang.Object other) {
return (other instanceof JacksonJsonProperty2);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") @lombok.Generated int hashCode() {
final int PRIME = 59;
int result = 1;
result = ((result * PRIME) + this.getPropertyTwo());
final java.lang.Object $propertyOne = this.getPropertyOne();
result = ((result * PRIME) + (($propertyOne == null) ? 43 : $propertyOne.hashCode()));
final java.lang.Object $additional = this.getAdditional();
result = ((result * PRIME) + (($additional == null) ? 43 : $additional.hashCode()));
return result;
}
public @java.lang.Override @java.lang.SuppressWarnings("all") @lombok.Generated java.lang.String toString() {
return (((((("JacksonJsonProperty2(propertyOne=" + this.getPropertyOne()) + ", propertyTwo=") + this.getPropertyTwo()) + ", additional=") + this.getAdditional()) + ")");
}
public @java.lang.SuppressWarnings("all") @lombok.Generated JacksonJsonProperty2() {
super();
}
}
12 changes: 12 additions & 0 deletions test/transform/resource/before/JacksonJsonProperty2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//CONF: lombok.copyJacksonAnnotationsToAccessors = true
//version 8: Jackson deps are at least Java7+.
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

@Data public class JacksonJsonProperty2 {
@JsonProperty("a") String propertyOne;
@JsonProperty("b") int propertyTwo;
Map<String, Object> additional = new HashMap<>();
}
Loading