Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
@@ -0,0 +1,12 @@
package org.immutables.fixture.builder;

import org.immutables.fixture.builder.attribute_builders.FirstPartyImmutable;
import org.immutables.fixture.builder.attribute_builders.ThirdPartyImmutable;
import org.immutables.value.Value;

@Value.Immutable
@Value.Style(attributeBuilderDetection = true)
public interface ForLambdaBuilder {
FirstPartyImmutable firstPartyImmutable();
ThirdPartyImmutable thirdPartyImmutable();
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ public void toBuilderSandwich() {
check(instance.a()).is(2);
}

@Test
public void lambdaBuilder() {
ForLambdaBuilder l = ImmutableForLambdaBuilder.builder()
.firstPartyImmutable(b -> b.value("X"))
.thirdPartyImmutable(b -> b.setValue("Y"))
.build();

check(l.firstPartyImmutable().value()).is("X");
check(l.thirdPartyImmutable().getValue()).is("Y");
}

@Test
public void basicApiForVanillaParent() {
assertBasicApi(ImmutableVanillaAttributeBuilderParent.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,24 @@ checkNotIsSet([v.names.isSet](), "[v.names.raw]");
}
[if v.isAttributeBuilder]

/**
* Initialized [sourceDocRef v] using lambda (consumer) which receives builder instance for the attribute value.
*
* Once called, the attribute builder field is set to a new instance of the builder.
* If called more than once, returns the same builder instance.
*/
[eachLine v.builderAttributeAnnotation]
[deprecation v]
[builderInitAccess v]final [builderReturnType type] [v.names.init](java.util.function.Consumer<[attributeBuilderBuilderType v.getAttributeBuilderDescriptor]> consumer) {
if (this.[v.name] == null) {
this.[v.name] = [createAttributeBuilder v.getAttributeBuilderDescriptor];
}
[nondefaultSetInBuilder v]
[mandatorySetInBuilder v]
consumer.accept(this.[v.name]);
return [builderReturnThis type];
}

/**
* Returns a builder for [sourceDocRef v].
*
Expand Down Expand Up @@ -2101,6 +2119,24 @@ checkNotIsSet([v.names.isSet](), "[v.names.raw]");
}
[if v.isAttributeBuilder]

/**
* Initialized [sourceDocRef v] using lambda (consumer) which receives builder instance for the attribute value.
*
* Once called, the attribute builder field is set to a new instance of the builder.
* If called more than once, returns the same builder instance.
*/
[eachLine v.builderAttributeAnnotation]
[deprecation v]
[builderInitAccess v]final [builderReturnType type] [v.names.init](java.util.function.Consumer<[attributeBuilderBuilderType v.getAttributeBuilderDescriptor]> consumer) {
if (this.[v.name] == null) {
this.[v.name] = [createAttributeBuilder v.getAttributeBuilderDescriptor];
}
[nondefaultSetInBuilder v]
[mandatorySetInBuilder v]
consumer.accept(this.[v.name]);
return [builderReturnThis type];
}

/**
* Returns a builder for [sourceDocRef v].
*
Expand Down
Loading