Skip to content

Commit 61dfa7a

Browse files
committed
Merge branch '3.5.x'
Closes gh-46664
2 parents bf76c1e + 31b2ddc commit 61dfa7a

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

configuration-metadata/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/PropertyDescriptorResolver.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ private Stream<PropertyDescriptor> resolveConstructorBoundProperties(TypeElement
8787

8888
private PropertyDescriptor extracted(TypeElement declaringElement, TypeElementMembers members,
8989
VariableElement parameter) {
90-
String name = getPropertyName(parameter);
90+
String parameterName = parameter.getSimpleName().toString();
91+
String name = getPropertyName(parameter, parameterName);
9192
TypeMirror type = parameter.asType();
92-
ExecutableElement getter = members.getPublicGetter(name, type);
93-
ExecutableElement setter = members.getPublicSetter(name, type);
94-
VariableElement field = members.getFields().get(name);
95-
RecordComponentElement recordComponent = members.getRecordComponents().get(name);
93+
ExecutableElement getter = members.getPublicGetter(parameterName, type);
94+
ExecutableElement setter = members.getPublicSetter(parameterName, type);
95+
VariableElement field = members.getFields().get(parameterName);
96+
RecordComponentElement recordComponent = members.getRecordComponents().get(parameterName);
9697
SourceMetadata sourceMetadata = this.environment.resolveSourceMetadata(field, getter);
9798
PropertyDescriptor propertyDescriptor = (recordComponent != null)
9899
? new RecordParameterPropertyDescriptor(name, type, parameter, declaringElement, getter,
@@ -102,10 +103,6 @@ private PropertyDescriptor extracted(TypeElement declaringElement, TypeElementMe
102103
return sourceMetadata.createPropertyDescriptor(name, propertyDescriptor);
103104
}
104105

105-
private String getPropertyName(VariableElement parameter) {
106-
return getPropertyName(parameter, parameter.getSimpleName().toString());
107-
}
108-
109106
private String getPropertyName(VariableElement parameter, String fallback) {
110107
AnnotationMirror nameAnnotation = this.environment.getNameAnnotation(parameter);
111108
if (nameAnnotation != null) {

configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ void deprecatedPropertyOnRecord() {
301301
.fromSource(type)
302302
.withDeprecation("some-reason", null, null));
303303
assertThat(metadata).has(Metadata.withProperty("deprecated-record.bravo", String.class).fromSource(type));
304+
assertThat(metadata).has(Metadata.withProperty("deprecated-record.named.charlie", String.class)
305+
.fromSource(type)
306+
.withDeprecation("another-reason", null, null));
304307
}
305308

306309
@Test
@@ -605,6 +608,8 @@ void recordPropertiesWithDescriptions() {
605608
.withDescription("description without space after asterisk"));
606609
assertThat(metadata).has(Metadata.withProperty("record.descriptions.some-byte", Byte.class)
607610
.withDescription("last description in Javadoc"));
611+
assertThat(metadata).has(Metadata.withProperty("record.descriptions.named.record.component", String.class)
612+
.withDescription("description of a named component"));
608613
}
609614

610615
@Test

configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/record/ExampleRecord.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@
1616

1717
package org.springframework.boot.configurationsample.record;
1818

19-
// @formatter:off
19+
import org.springframework.boot.configurationsample.Name;
2020

2121
/**
2222
* Example Record Javadoc sample
2323
*
24-
* @param someString very long description that
25-
* doesn't fit single line and is indented
24+
* @param someString very long description that doesn't fit single line and is indented
2625
* @param someInteger description with @param and @ pitfalls
2726
* @param someBoolean description with extra spaces
2827
* @param someLong description without space after asterisk
28+
* @param namedComponent description of a named component
2929
* @param someByte last description in Javadoc
3030
* @since 1.0.0
3131
* @author Pavel Anisimov
3232
*/
3333
@org.springframework.boot.configurationsample.ConfigurationProperties("record.descriptions")
34-
public record ExampleRecord(String someString, Integer someInteger, Boolean someBoolean, Long someLong, Byte someByte) {
34+
public record ExampleRecord(String someString, Integer someInteger, Boolean someBoolean, Long someLong,
35+
@Name("named.record.component") String namedComponent, Byte someByte) {
3536
}
36-
37-
//@formatter:on

configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/simple/DeprecatedRecord.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,28 @@
1818

1919
import org.springframework.boot.configurationsample.ConfigurationProperties;
2020
import org.springframework.boot.configurationsample.DeprecatedConfigurationProperty;
21+
import org.springframework.boot.configurationsample.Name;
2122

2223
/**
2324
* Configuration properties as record with deprecated property.
2425
*
2526
* @param alpha alpha property, deprecated
2627
* @param bravo bravo property
28+
* @param charlie charlie property, named, deprecated
2729
* @author Moritz Halbritter
2830
*/
2931
@ConfigurationProperties("deprecated-record")
30-
public record DeprecatedRecord(String alpha, String bravo) {
32+
public record DeprecatedRecord(String alpha, String bravo, @Name("named.charlie") String charlie) {
3133

3234
@Deprecated
3335
@DeprecatedConfigurationProperty(reason = "some-reason")
3436
public String alpha() {
3537
return this.alpha;
3638
}
3739

40+
@Deprecated
41+
@DeprecatedConfigurationProperty(reason = "another-reason")
42+
public String charlie() {
43+
return this.charlie;
44+
}
3845
}

0 commit comments

Comments
 (0)