diff --git a/configuration-metadata/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/PropertyDescriptorResolver.java b/configuration-metadata/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/PropertyDescriptorResolver.java index 63f4b8217a8d..a14ef5c80c43 100644 --- a/configuration-metadata/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/PropertyDescriptorResolver.java +++ b/configuration-metadata/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/PropertyDescriptorResolver.java @@ -88,11 +88,12 @@ private Stream resolveConstructorBoundProperties(TypeElement private PropertyDescriptor extracted(TypeElement declaringElement, TypeElementMembers members, VariableElement parameter) { String name = getPropertyName(parameter); + String parameterName = parameter.getSimpleName().toString(); TypeMirror type = parameter.asType(); - ExecutableElement getter = members.getPublicGetter(name, type); - ExecutableElement setter = members.getPublicSetter(name, type); - VariableElement field = members.getFields().get(name); - RecordComponentElement recordComponent = members.getRecordComponents().get(name); + ExecutableElement getter = members.getPublicGetter(parameterName, type); + ExecutableElement setter = members.getPublicSetter(parameterName, type); + VariableElement field = members.getFields().get(parameterName); + RecordComponentElement recordComponent = members.getRecordComponents().get(parameterName); SourceMetadata sourceMetadata = this.environment.resolveSourceMetadata(field, getter); PropertyDescriptor propertyDescriptor = (recordComponent != null) ? new RecordParameterPropertyDescriptor(name, type, parameter, declaringElement, getter, diff --git a/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java b/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java index 3efe53f55ffb..5a1c2f7bffa3 100644 --- a/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java +++ b/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java @@ -301,6 +301,9 @@ void deprecatedPropertyOnRecord() { .fromSource(type) .withDeprecation("some-reason", null, null)); assertThat(metadata).has(Metadata.withProperty("deprecated-record.bravo", String.class).fromSource(type)); + assertThat(metadata).has(Metadata.withProperty("deprecated-record.named.charlie", String.class) + .fromSource(type) + .withDeprecation("another-reason", null, null)); } @Test @@ -605,6 +608,8 @@ void recordPropertiesWithDescriptions() { .withDescription("description without space after asterisk")); assertThat(metadata).has(Metadata.withProperty("record.descriptions.some-byte", Byte.class) .withDescription("last description in Javadoc")); + assertThat(metadata).has(Metadata.withProperty("record.descriptions.named.record.component", String.class) + .withDescription("description of a named component")); } @Test diff --git a/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/record/ExampleRecord.java b/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/record/ExampleRecord.java index 7d861ed09ac6..ce63a3ec7962 100644 --- a/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/record/ExampleRecord.java +++ b/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/record/ExampleRecord.java @@ -16,6 +16,8 @@ package org.springframework.boot.configurationsample.record; +import org.springframework.boot.configurationsample.Name; + // @formatter:off /** @@ -26,12 +28,21 @@ * @param someInteger description with @param and @ pitfalls * @param someBoolean description with extra spaces * @param someLong description without space after asterisk + * @param namedComponent description of a named component * @param someByte last description in Javadoc * @since 1.0.0 * @author Pavel Anisimov */ @org.springframework.boot.configurationsample.ConfigurationProperties("record.descriptions") -public record ExampleRecord(String someString, Integer someInteger, Boolean someBoolean, Long someLong, Byte someByte) { +public record ExampleRecord( + String someString, + Integer someInteger, + Boolean someBoolean, + Long someLong, + @Name("named.record.component") + String namedComponent, + Byte someByte + ) { } //@formatter:on diff --git a/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/simple/DeprecatedRecord.java b/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/simple/DeprecatedRecord.java index 517cab7d6ba3..45405feb9c6e 100644 --- a/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/simple/DeprecatedRecord.java +++ b/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/simple/DeprecatedRecord.java @@ -18,16 +18,18 @@ import org.springframework.boot.configurationsample.ConfigurationProperties; import org.springframework.boot.configurationsample.DeprecatedConfigurationProperty; +import org.springframework.boot.configurationsample.Name; /** * Configuration properties as record with deprecated property. * * @param alpha alpha property, deprecated * @param bravo bravo property + * @param charlie charlie property, named, deprecated * @author Moritz Halbritter */ @ConfigurationProperties("deprecated-record") -public record DeprecatedRecord(String alpha, String bravo) { +public record DeprecatedRecord(String alpha, String bravo, @Name("named.charlie") String charlie) { @Deprecated @DeprecatedConfigurationProperty(reason = "some-reason") @@ -35,4 +37,9 @@ public String alpha() { return this.alpha; } + @Deprecated + @DeprecatedConfigurationProperty(reason = "another-reason") + public String charlie() { + return this.charlie; + } }