diff options
author | Éamonn McManus <emcmanus@google.com> | 2021-04-30 08:56:40 -0700 |
---|---|---|
committer | Google Java Core Libraries <java-libraries-firehose+copybara@google.com> | 2021-04-30 08:57:23 -0700 |
commit | aaf39f6c211fc34e4fa4abc5954c1e3a6db22cdc (patch) | |
tree | b15403b1e0472ceac7de02aa3e585e3310618fe4 /value/src/test/java/com/google | |
parent | 8cb93ed1b00f21d05286ae0fe9a6b4c9a8c5f0fe (diff) | |
download | auto-aaf39f6c211fc34e4fa4abc5954c1e3a6db22cdc.tar.gz |
Use the correct `package` in the generated `AutoBuilder_Foo` class.
Previously it was erroneously using the package from the `ofClass` class. That's often the same package, but when it isn't the generated code was wrong.
RELNOTES=n/a
PiperOrigin-RevId: 371342620
Diffstat (limited to 'value/src/test/java/com/google')
-rw-r--r-- | value/src/test/java/com/google/auto/value/processor/AutoBuilderCompilationTest.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/value/src/test/java/com/google/auto/value/processor/AutoBuilderCompilationTest.java b/value/src/test/java/com/google/auto/value/processor/AutoBuilderCompilationTest.java index aabdbc71..ddf12ff3 100644 --- a/value/src/test/java/com/google/auto/value/processor/AutoBuilderCompilationTest.java +++ b/value/src/test/java/com/google/auto/value/processor/AutoBuilderCompilationTest.java @@ -155,6 +155,49 @@ public final class AutoBuilderCompilationTest { } @Test + public void buildOtherPackage() { + JavaFileObject built = + JavaFileObjects.forSourceLines( + "com.example.Built", + "package com.example;", + "", + "public class Built {", + " private final int anInt;", + " private final String aString;", + "", + " public Built(int anInt, String aString) {", + " this.anInt = anInt;", + " this.aString = aString;", + " }", + "}"); + JavaFileObject builder = + JavaFileObjects.forSourceLines( + "foo.bar.Builder", + "package foo.bar;", + "", + "import com.example.Built;", + "import com.google.auto.value.AutoBuilder;", + "", + "@AutoBuilder(ofClass = Built.class)", + "public interface Builder {", + " public static Builder builder() {", + " return new AutoBuilder_Builder();", + " }", + "", + " Builder setAnInt(int x);", + " Builder setAString(String x);", + " Built build();", + "}"); + Compilation compilation = + javac() + .withProcessors(new AutoBuilderProcessor()) + .withOptions("-Acom.google.auto.value.AutoBuilderIsUnstable") + .compile(built, builder); + assertThat(compilation).succeededWithoutWarnings(); + assertThat(compilation).generatedSourceFile("foo.bar.AutoBuilder_Builder"); + } + + @Test public void autoBuilderOnEnum() { JavaFileObject javaFileObject = JavaFileObjects.forSourceLines( |