mirror of
https://github.com/tiennm99/lombok.git
synced 2026-06-05 20:13:24 +00:00
[fixes #3315] Copy annotations on record components
This commit is contained in:
@@ -809,12 +809,12 @@ public class EclipseHandlerUtil {
|
||||
* Searches the given field node for annotations and returns each one that is 'copyable' (either via configuration or from the base list).
|
||||
*/
|
||||
public static Annotation[] findCopyableAnnotations(EclipseNode node) {
|
||||
AbstractVariableDeclaration avd = (AbstractVariableDeclaration) node.get();
|
||||
if (avd.annotations == null) return EMPTY_ANNOTATIONS_ARRAY;
|
||||
List<Annotation> result = new ArrayList<Annotation>();
|
||||
List<TypeName> configuredCopyable = node.getAst().readConfiguration(ConfigurationKeys.COPYABLE_ANNOTATIONS);
|
||||
|
||||
for (Annotation annotation : avd.annotations) {
|
||||
for (EclipseNode child : node.down()) {
|
||||
if (child.getKind() != Kind.ANNOTATION) continue;
|
||||
|
||||
Annotation annotation = (Annotation) child.get();
|
||||
TypeReference typeRef = annotation.type;
|
||||
boolean match = false;
|
||||
if (typeRef != null && typeRef.getTypeName() != null) {
|
||||
@@ -850,11 +850,11 @@ public class EclipseHandlerUtil {
|
||||
* Searches the given field node for annotations that are in the given list, and returns those.
|
||||
*/
|
||||
private static Annotation[] findAnnotationsInList(EclipseNode node, java.util.List<String> annotationsToFind) {
|
||||
AbstractVariableDeclaration avd = (AbstractVariableDeclaration) node.get();
|
||||
if (avd.annotations == null) return EMPTY_ANNOTATIONS_ARRAY;
|
||||
List<Annotation> result = new ArrayList<Annotation>();
|
||||
|
||||
for (Annotation annotation : avd.annotations) {
|
||||
for (EclipseNode child : node.down()) {
|
||||
if (child.getKind() != Kind.ANNOTATION) continue;
|
||||
|
||||
Annotation annotation = (Annotation) child.get();
|
||||
TypeReference typeRef = annotation.type;
|
||||
if (typeRef != null && typeRef.getTypeName() != null) {
|
||||
for (String bn : annotationsToFind) if (typeMatches(bn, node, typeRef)) {
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
//version 14:
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonIgnoreProperties
|
||||
@com.fasterxml.jackson.databind.annotation.JsonDeserialize(builder = JacksonizedOnRecord.JacksonizedOnRecordBuilder.class)
|
||||
public record JacksonizedOnRecord(@JsonProperty("test") @Nullable String string, @JsonAnySetter List<String> values) {
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
@JsonIgnoreProperties
|
||||
@com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder(withPrefix = "", buildMethodName = "build")
|
||||
public static class JacksonizedOnRecordBuilder {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private String string;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private java.util.ArrayList<String> values;
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
JacksonizedOnRecordBuilder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code this}.
|
||||
*/
|
||||
@JsonProperty("test")
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public JacksonizedOnRecord.JacksonizedOnRecordBuilder string(@Nullable final String string) {
|
||||
this.string = string;
|
||||
return this;
|
||||
}
|
||||
|
||||
@JsonAnySetter
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public JacksonizedOnRecord.JacksonizedOnRecordBuilder value(final String value) {
|
||||
if (this.values == null) this.values = new java.util.ArrayList<String>();
|
||||
this.values.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public JacksonizedOnRecord.JacksonizedOnRecordBuilder values(final java.util.Collection<? extends String> values) {
|
||||
if (values == null) {
|
||||
throw new java.lang.NullPointerException("values cannot be null");
|
||||
}
|
||||
if (this.values == null) this.values = new java.util.ArrayList<String>();
|
||||
this.values.addAll(values);
|
||||
return this;
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public JacksonizedOnRecord.JacksonizedOnRecordBuilder clearValues() {
|
||||
if (this.values != null) this.values.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public JacksonizedOnRecord build() {
|
||||
java.util.List<String> values;
|
||||
switch (this.values == null ? 0 : this.values.size()) {
|
||||
case 0:
|
||||
values = java.util.Collections.emptyList();
|
||||
break;
|
||||
case 1:
|
||||
values = java.util.Collections.singletonList(this.values.get(0));
|
||||
break;
|
||||
default:
|
||||
values = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(this.values));
|
||||
}
|
||||
return new JacksonizedOnRecord(this.string, values);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "JacksonizedOnRecord.JacksonizedOnRecordBuilder(string=" + this.string + ", values=" + this.values + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public static JacksonizedOnRecord.JacksonizedOnRecordBuilder builder() {
|
||||
return new JacksonizedOnRecord.JacksonizedOnRecordBuilder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
public @lombok.extern.jackson.Jacksonized @lombok.Builder @JsonIgnoreProperties @com.fasterxml.jackson.databind.annotation.JsonDeserialize(builder = JacksonizedOnRecord.JacksonizedOnRecordBuilder.class) record JacksonizedOnRecord(String string, List values) {
|
||||
public static @java.lang.SuppressWarnings("all") @JsonIgnoreProperties @com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder(withPrefix = "",buildMethodName = "build") class JacksonizedOnRecordBuilder {
|
||||
private @java.lang.SuppressWarnings("all") String string;
|
||||
private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> values;
|
||||
@java.lang.SuppressWarnings("all") JacksonizedOnRecordBuilder() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* @return {@code this}.
|
||||
*/
|
||||
public @JsonProperty("test") @java.lang.SuppressWarnings("all") JacksonizedOnRecord.JacksonizedOnRecordBuilder string(final @Nullable String string) {
|
||||
this.string = string;
|
||||
return this;
|
||||
}
|
||||
public @JsonAnySetter @java.lang.SuppressWarnings("all") JacksonizedOnRecord.JacksonizedOnRecordBuilder value(final String value) {
|
||||
if ((this.values == null))
|
||||
this.values = new java.util.ArrayList<String>();
|
||||
this.values.add(value);
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") JacksonizedOnRecord.JacksonizedOnRecordBuilder values(final java.util.Collection<? extends String> values) {
|
||||
if ((values == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("values cannot be null");
|
||||
}
|
||||
if ((this.values == null))
|
||||
this.values = new java.util.ArrayList<String>();
|
||||
this.values.addAll(values);
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") JacksonizedOnRecord.JacksonizedOnRecordBuilder clearValues() {
|
||||
if ((this.values != null))
|
||||
this.values.clear();
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") JacksonizedOnRecord build() {
|
||||
java.util.List<String> values;
|
||||
switch (((this.values == null) ? 0 : this.values.size())) {
|
||||
case 0 :
|
||||
values = java.util.Collections.emptyList();
|
||||
break;
|
||||
case 1 :
|
||||
values = java.util.Collections.singletonList(this.values.get(0));
|
||||
break;
|
||||
default :
|
||||
values = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(this.values));
|
||||
}
|
||||
return new JacksonizedOnRecord(this.string, values);
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
|
||||
return (((("JacksonizedOnRecord.JacksonizedOnRecordBuilder(string=" + this.string) + ", values=") + this.values) + ")");
|
||||
}
|
||||
}
|
||||
/* Implicit */ private final String string;
|
||||
/* Implicit */ private final List<String> values;
|
||||
public JacksonizedOnRecord(@JsonProperty("test") @Nullable String string, @lombok.Singular List<String> values) {
|
||||
super();
|
||||
.string = string;
|
||||
.values = values;
|
||||
}
|
||||
public static @java.lang.SuppressWarnings("all") JacksonizedOnRecord.JacksonizedOnRecordBuilder builder() {
|
||||
return new JacksonizedOnRecord.JacksonizedOnRecordBuilder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
//version 14:
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@lombok.extern.jackson.Jacksonized
|
||||
@lombok.Builder
|
||||
@JsonIgnoreProperties
|
||||
public record JacksonizedOnRecord(@JsonProperty("test") @Nullable String string, @JsonAnySetter @lombok.Singular List<String> values) {
|
||||
}
|
||||
Reference in New Issue
Block a user