Refine SourceFile record to class conversion

Update conversion logic to deal with annotations.

See gh-29236
This commit is contained in:
Phillip Webb
2022-09-30 11:58:14 -07:00
parent 7fd8e081bb
commit afac8dd8af
2 changed files with 39 additions and 1 deletions

View File

@@ -146,6 +146,19 @@ class SourceFileTests {
assertThat(sourceFile.getClassName()).isEqualTo("com.example.helloworld.HelloWorld");
}
@Test
void getClassNameFromAnnotatedRecord() {
SourceFile sourceFile = SourceFile.of("""
package com.example;
public record RecordProperties(
@org.springframework.boot.context.properties.bind.DefaultValue("default-value-1") String property1,
@org.springframework.boot.context.properties.bind.DefaultValue("default-value-2") String property2) {
}
""");
assertThat(sourceFile.getClassName()).isEqualTo("com.example.RecordProperties");
}
/**
* JavaPoet style API with a {@code writeTo} method.
*/