diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/JavaBeanPropertyDescriptor.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/JavaBeanPropertyDescriptor.java index ab876524b5..35e9758a19 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/JavaBeanPropertyDescriptor.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/JavaBeanPropertyDescriptor.java @@ -21,8 +21,6 @@ import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeMirror; -import org.springframework.boot.configurationprocessor.metadata.ItemDeprecation; - /** * A {@link PropertyDescriptor} for a standard JavaBean property. * @@ -30,17 +28,10 @@ import org.springframework.boot.configurationprocessor.metadata.ItemDeprecation; */ class JavaBeanPropertyDescriptor extends PropertyDescriptor { - private final ExecutableElement setter; - JavaBeanPropertyDescriptor(TypeElement ownerElement, ExecutableElement factoryMethod, ExecutableElement getter, String name, TypeMirror type, VariableElement field, ExecutableElement setter) { - super(ownerElement, factoryMethod, getter, name, type, field, getter); - this.setter = setter; - } - - public ExecutableElement getSetter() { - return this.setter; + super(ownerElement, factoryMethod, getter, name, type, field, getter, setter); } @Override @@ -50,13 +41,4 @@ class JavaBeanPropertyDescriptor extends PropertyDescriptor { && (getSetter() != null || isCollection); } - @Override - protected ItemDeprecation resolveItemDeprecation( - MetadataGenerationEnvironment environment) { - boolean deprecated = environment.isDeprecated(getGetter()) - || environment.isDeprecated(getSetter()) - || environment.isDeprecated(getFactoryMethod()); - return deprecated ? environment.resolveItemDeprecation(getGetter()) : null; - } - } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/LombokPropertyDescriptor.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/LombokPropertyDescriptor.java index 93848ba4fa..0513d33b6f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/LombokPropertyDescriptor.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/LombokPropertyDescriptor.java @@ -43,9 +43,9 @@ class LombokPropertyDescriptor extends PropertyDescriptor { private static final String LOMBOK_ACCESS_LEVEL_PUBLIC = "PUBLIC"; LombokPropertyDescriptor(TypeElement typeElement, ExecutableElement factoryMethod, - VariableElement field, String name, TypeMirror type, - ExecutableElement getter) { - super(typeElement, factoryMethod, field, name, type, field, getter); + VariableElement field, String name, TypeMirror type, ExecutableElement getter, + ExecutableElement setter) { + super(typeElement, factoryMethod, field, name, type, field, getter, setter); } @Override @@ -69,14 +69,15 @@ class LombokPropertyDescriptor extends PropertyDescriptor { protected ItemDeprecation resolveItemDeprecation( MetadataGenerationEnvironment environment) { boolean deprecated = environment.isDeprecated(getField()) + || environment.isDeprecated(getGetter()) || environment.isDeprecated(getFactoryMethod()); - return deprecated ? new ItemDeprecation() : null; - + return deprecated ? environment.resolveItemDeprecation(getGetter()) : null; } private boolean hasSetter(MetadataGenerationEnvironment env) { - return !getField().getModifiers().contains(Modifier.FINAL) + boolean nonFinalPublicField = !getField().getModifiers().contains(Modifier.FINAL) && hasLombokPublicAccessor(env, false); + return getSetter() != null || nonFinalPublicField; } /** diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/PropertyDescriptor.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/PropertyDescriptor.java index 8607220570..9973906a35 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/PropertyDescriptor.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/PropertyDescriptor.java @@ -49,9 +49,11 @@ abstract class PropertyDescriptor { private final ExecutableElement getter; + private final ExecutableElement setter; + protected PropertyDescriptor(TypeElement ownerElement, ExecutableElement factoryMethod, S source, String name, TypeMirror type, - VariableElement field, ExecutableElement getter) { + VariableElement field, ExecutableElement getter, ExecutableElement setter) { this.ownerElement = ownerElement; this.factoryMethod = factoryMethod; this.source = source; @@ -59,6 +61,7 @@ abstract class PropertyDescriptor { this.type = type; this.field = field; this.getter = getter; + this.setter = setter; } public TypeElement getOwnerElement() { @@ -89,11 +92,20 @@ abstract class PropertyDescriptor { return this.getter; } - protected abstract ItemDeprecation resolveItemDeprecation( - MetadataGenerationEnvironment environment); + public ExecutableElement getSetter() { + return this.setter; + } protected abstract boolean isProperty(MetadataGenerationEnvironment environment); + protected ItemDeprecation resolveItemDeprecation( + MetadataGenerationEnvironment environment) { + boolean deprecated = environment.isDeprecated(getGetter()) + || environment.isDeprecated(getSetter()) + || environment.isDeprecated(getFactoryMethod()); + return deprecated ? environment.resolveItemDeprecation(getGetter()) : null; + } + protected boolean isNested(MetadataGenerationEnvironment environment) { Element typeElement = environment.getTypeUtils().asElement(getType()); if (!(typeElement instanceof TypeElement) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/PropertyDescriptorResolver.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/PropertyDescriptorResolver.java index c5f81fc909..4b5e9be6d3 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/PropertyDescriptorResolver.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/PropertyDescriptorResolver.java @@ -61,8 +61,9 @@ class PropertyDescriptorResolver { members.getFields().forEach((name, field) -> { TypeMirror returnType = field.asType(); ExecutableElement getter = members.getPublicGetter(name, returnType); + ExecutableElement setter = members.getPublicSetter(name, returnType); candidates.add(new LombokPropertyDescriptor(type, factoryMethod, field, name, - returnType, getter)); + returnType, getter, setter)); }); return candidates.stream().filter(this::isCandidate); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/LombokPropertyDescriptorTests.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/LombokPropertyDescriptorTests.java index 538906638a..1abc06e430 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/LombokPropertyDescriptorTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/LombokPropertyDescriptorTests.java @@ -191,7 +191,7 @@ public class LombokPropertyDescriptorTests extends PropertyDescriptorTests { VariableElement field = getField(ownerElement, "third"); ExecutableElement getter = getMethod(ownerElement, "getThird"); LombokPropertyDescriptor property = new LombokPropertyDescriptor(ownerElement, - null, field, "third", field.asType(), getter); + null, field, "third", field.asType(), getter, null); assertItemMetadata(metadataEnv, property).isGroup().hasName("test.third") .hasType( "org.springframework.boot.configurationsample.lombok.SimpleLombokPojo") @@ -303,8 +303,10 @@ public class LombokPropertyDescriptorTests extends PropertyDescriptorTests { VariableElement field = getField(ownerElement, name); ExecutableElement getter = getMethod(ownerElement, createAccessorMethodName("get", name)); + ExecutableElement setter = getMethod(ownerElement, + createAccessorMethodName("set", name)); return new LombokPropertyDescriptor(ownerElement, null, field, name, - field.asType(), getter); + field.asType(), getter, setter); } }