diff --git a/src/main/java/org/inferred/freebuilder/processor/BuildablePropertyFactory.java b/src/main/java/org/inferred/freebuilder/processor/BuildablePropertyFactory.java index 1ef49f013..0f01f3e44 100644 --- a/src/main/java/org/inferred/freebuilder/processor/BuildablePropertyFactory.java +++ b/src/main/java/org/inferred/freebuilder/processor/BuildablePropertyFactory.java @@ -207,10 +207,10 @@ private void addSetterTakingBuilder(SourceBuilder code, Metadata metadata) { .addLine(" * @return this {@code %s} object", metadata.getBuilder().getSimpleName()) .addLine(" * @throws NullPointerException if {@code builder} is null") .addLine(" */") - .addLine("public %s %s(%s.Builder builder) {", + .addLine("public %s %s(%s builder) {", metadata.getBuilder(), setter(property), - property.getType()) + builderType) .addLine(" return %s(builder.build());", setter(property)) .addLine("}"); } @@ -232,11 +232,11 @@ private void addMutate(SourceBuilder code, Metadata metadata) { .addLine(" * @return this {@code %s} object", metadata.getBuilder().getSimpleName()) .addLine(" * @throws NullPointerException if {@code mutator} is null") .addLine(" */") - .addLine("public %s %s(%s<%s.Builder> mutator) {", + .addLine("public %s %s(%s<%s> mutator) {", metadata.getBuilder(), mutator(property), consumer.getQualifiedName(), - property.getType()) + builderType) .addLine(" mutator.accept(%s);", property.getName()) .addLine(" return (%s) this;", metadata.getBuilder()) .addLine("}"); diff --git a/src/test/java/org/inferred/freebuilder/processor/BuildablePropertyFactoryTest.java b/src/test/java/org/inferred/freebuilder/processor/BuildablePropertyFactoryTest.java index ed88756ab..855da464f 100644 --- a/src/test/java/org/inferred/freebuilder/processor/BuildablePropertyFactoryTest.java +++ b/src/test/java/org/inferred/freebuilder/processor/BuildablePropertyFactoryTest.java @@ -796,6 +796,31 @@ public void testBuilderClear_freebuilderlike() { .runTest(); } + @Test + public void testGenericChildProperty() { + // Raised in issue #183 + behaviorTester + .with(new Processor()) + .with(new SourceBuilder() + .addLine("package com.example;") + .addLine("@%s", FreeBuilder.class) + .addLine("public interface PIdentityDefinition {") + .addLine(" class Builder extends PIdentityDefinition_Builder {}") + .addLine("}") + .build()) + .with(new SourceBuilder() + .addLine("package com.example;") + .addLine("@%s", FreeBuilder.class) + .addLine("public interface PAccess {") + .addLine(" class Builder extends PAccess_Builder {}") + .addLine("") + .addLine(" PIdentityDefinition getIdentity();") + .addLine("}") + .build()) + .compiles() + .withNoWarnings(); + } + @Test public void testIssue68_nameCollisionForValue() { // mergeFrom(DataType value) must resolve the name collision on "value"