Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that type annotations appear in AutoBuilder property types. #1858

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private Property newProperty(
return new Property(
name,
identifier,
TypeEncoder.encode(type),
TypeEncoder.encodeWithAnnotations(type),
new AnnotatedTypeMirror(type),
nullableAnnotation,
nullables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ${builderClassModifiers}class ${builderName}${builderFormalTypes} ##
private ${builderPropertyBuilders[$p.name].nullableBuilderType} ##
${builderPropertyBuilders[$p.name].name};

#end
#end

private $p.builderFieldType $p $p.builderInitializer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,42 @@ public void simpleRecord() {
.hasSourceEquivalentTo(EXPECTED_SIMPLE_OUTPUT);
}

@Test
public void recordWithNullableNestedComponentType() {
double version = Double.parseDouble(JAVA_SPECIFICATION_VERSION.value());
assume().that(version).isAtLeast(16.0);
JavaFileObject javaFileObject =
JavaFileObjects.forSourceLines(
"foo.bar.Baz",
"package foo.bar;",
"",
"import com.google.auto.value.AutoBuilder;",
"import org.checkerframework.checker.nullness.qual.Nullable;",
"",
"public record Baz(@Nullable Nested nested) {",
" public static Builder builder() {",
" return new AutoBuilder_Baz_Builder();",
" }",
"",
" @AutoBuilder",
" public interface Builder {",
" Builder setNested(Nested nested);",
" Baz build();",
" }",
"",
" public record Nested() {}",
"}");
Compilation compilation =
javac()
.withProcessors(new AutoBuilderProcessor())
.withOptions("-A" + Nullables.NULLABLE_OPTION + "=org.checkerframework.checker.nullness.qual.Nullable")
.compile(javaFileObject);
assertThat(compilation)
.generatedSourceFile("foo.bar.AutoBuilder_Baz_Builder")
.contentsAsUtf8String()
.contains("private Baz.@Nullable Nested nested;");
}

@Test
public void buildOtherPackage() {
JavaFileObject built =
Expand Down