Skip to content
Open
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 @@ -182,7 +182,7 @@ ${builderClassModifiers}class ${builderName}${builderFormalTypes} ##
#if ($builderGetter)

@`java.lang.Override`
${p.nullableAnnotation}${builderGetter.access}$builderGetter.type ${builderGetter.name}() {
#if (!$builderGetter.optional)${p.nullableAnnotation}#end${builderGetter.access}$builderGetter.type ${builderGetter.name}() {
#set ($noValueToGetCondition = $builderRequiredProperties.noValueToGet($p))

#if ($builderGetters[$p.name].optional)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,51 @@ public void nullablePrimitiveTypeUseAnnotation() {
.onLineContaining("Baz(@Nullable int thing)");
}

@Test
public void conflictingAnnotationsOnOptionalGetter() {
JavaFileObject javaFileObject =
JavaFileObjects.forSourceLines(
"foo.bar.Baz",
"package foo.bar;",
"",
"import com.google.auto.value.AutoBuilder;",
"import java.lang.annotation.ElementType;",
"import java.lang.annotation.Target;",
"import java.util.Optional;",
"",
"public class Baz {",
" @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})",
" public @interface Nullable {}",
"",
" @Target(ElementType.TYPE_USE)",
" public @interface NotNull {}",
"",
" private final String foo;",
"",
" public Baz(@Nullable String foo) {",
" this.foo = foo;",
" }",
"",
" @AutoBuilder",
" public interface Builder {",
" Builder foo(String foo);",
" @NotNull Optional<String> foo();",
" Baz build();",
" }",
"}");
Compilation compilation =
javac().withProcessors(new AutoBuilderProcessor()).compile(javaFileObject);
assertThat(compilation).succeeded();
assertThat(compilation)
.generatedSourceFile("foo.bar.AutoBuilder_Baz_Builder")
.contentsAsUtf8String()
.doesNotContain("@Baz.Nullable public @Baz.NotNull Optional<String> foo()");
assertThat(compilation)
.generatedSourceFile("foo.bar.AutoBuilder_Baz_Builder")
.contentsAsUtf8String()
.contains("public @Baz.NotNull Optional<String> foo()");
}

private static String sorted(String... imports) {
return stream(imports).sorted().collect(joining("\n"));
}
Expand Down
Loading