Skip to content

Commit c81f874

Browse files
cushonGoogle Java Core Libraries
authored andcommitted
Internal change
RELNOTES=n/a PiperOrigin-RevId: 960184417
1 parent 50985f1 commit c81f874

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

value/src/test/java/com/google/auto/value/processor/AutoBuilderCompilationTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,47 @@ public void nullablePrimitiveTypeUseAnnotation() {
11801180
.onLineContaining("Baz(@Nullable int thing)");
11811181
}
11821182

1183+
@Test
1184+
public void conflictingAnnotationsOnOptionalGetter() {
1185+
JavaFileObject javaFileObject =
1186+
JavaFileObjects.forSourceLines(
1187+
"foo.bar.Baz",
1188+
"package foo.bar;",
1189+
"",
1190+
"import com.google.auto.value.AutoBuilder;",
1191+
"import java.lang.annotation.ElementType;",
1192+
"import java.lang.annotation.Target;",
1193+
"import java.util.Optional;",
1194+
"",
1195+
"public class Baz {",
1196+
" @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})",
1197+
" public @interface Nullable {}",
1198+
"",
1199+
" @Target(ElementType.TYPE_USE)",
1200+
" public @interface NotNull {}",
1201+
"",
1202+
" private final String foo;",
1203+
"",
1204+
" public Baz(@Nullable String foo) {",
1205+
" this.foo = foo;",
1206+
" }",
1207+
"",
1208+
" @AutoBuilder",
1209+
" public interface Builder {",
1210+
" Builder foo(String foo);",
1211+
" @NotNull Optional<String> foo();",
1212+
" Baz build();",
1213+
" }",
1214+
"}");
1215+
Compilation compilation =
1216+
javac().withProcessors(new AutoBuilderProcessor()).compile(javaFileObject);
1217+
assertThat(compilation).succeeded();
1218+
assertThat(compilation)
1219+
.generatedSourceFile("foo.bar.AutoBuilder_Baz_Builder")
1220+
.contentsAsUtf8String()
1221+
.contains("@Baz.Nullable public @Baz.NotNull Optional<String> foo()");
1222+
}
1223+
11831224
private static String sorted(String... imports) {
11841225
return stream(imports).sorted().collect(joining("\n"));
11851226
}

0 commit comments

Comments
 (0)