Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 7b8bc49

Browse files
authored
Merge pull request #189 from google/issue/183.generic.subbuilder
Fix bug with generic buildable properties
2 parents 188a73d + e31f066 commit 7b8bc49

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/main/java/org/inferred/freebuilder/processor/BuildablePropertyFactory.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ private void addSetterTakingBuilder(SourceBuilder code, Metadata metadata) {
207207
.addLine(" * @return this {@code %s} object", metadata.getBuilder().getSimpleName())
208208
.addLine(" * @throws NullPointerException if {@code builder} is null")
209209
.addLine(" */")
210-
.addLine("public %s %s(%s.Builder builder) {",
210+
.addLine("public %s %s(%s builder) {",
211211
metadata.getBuilder(),
212212
setter(property),
213-
property.getType())
213+
builderType)
214214
.addLine(" return %s(builder.build());", setter(property))
215215
.addLine("}");
216216
}
@@ -232,11 +232,11 @@ private void addMutate(SourceBuilder code, Metadata metadata) {
232232
.addLine(" * @return this {@code %s} object", metadata.getBuilder().getSimpleName())
233233
.addLine(" * @throws NullPointerException if {@code mutator} is null")
234234
.addLine(" */")
235-
.addLine("public %s %s(%s<%s.Builder> mutator) {",
235+
.addLine("public %s %s(%s<%s> mutator) {",
236236
metadata.getBuilder(),
237237
mutator(property),
238238
consumer.getQualifiedName(),
239-
property.getType())
239+
builderType)
240240
.addLine(" mutator.accept(%s);", property.getName())
241241
.addLine(" return (%s) this;", metadata.getBuilder())
242242
.addLine("}");

src/test/java/org/inferred/freebuilder/processor/BuildablePropertyFactoryTest.java

+25
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,31 @@ public void testBuilderClear_freebuilderlike() {
796796
.runTest();
797797
}
798798

799+
@Test
800+
public void testGenericChildProperty() {
801+
// Raised in issue #183
802+
behaviorTester
803+
.with(new Processor())
804+
.with(new SourceBuilder()
805+
.addLine("package com.example;")
806+
.addLine("@%s", FreeBuilder.class)
807+
.addLine("public interface PIdentityDefinition<T, U> {")
808+
.addLine(" class Builder<T, U> extends PIdentityDefinition_Builder<T, U> {}")
809+
.addLine("}")
810+
.build())
811+
.with(new SourceBuilder()
812+
.addLine("package com.example;")
813+
.addLine("@%s", FreeBuilder.class)
814+
.addLine("public interface PAccess<T, U> {")
815+
.addLine(" class Builder<T, U> extends PAccess_Builder<T, U> {}")
816+
.addLine("")
817+
.addLine(" PIdentityDefinition<T, U> getIdentity();")
818+
.addLine("}")
819+
.build())
820+
.compiles()
821+
.withNoWarnings();
822+
}
823+
799824
@Test
800825
public void testIssue68_nameCollisionForValue() {
801826
// mergeFrom(DataType value) must resolve the name collision on "value"

0 commit comments

Comments
 (0)