autoparams.lombok.BuilderCustomizer Maven / Gradle / Ivy
package autoparams.lombok;
import autoparams.customization.Customizer;
import autoparams.generator.ObjectContainer;
import autoparams.generator.ObjectGenerationContext;
import autoparams.generator.ObjectGenerator;
import autoparams.generator.ObjectQuery;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Optional;
public class BuilderCustomizer implements Customizer {
private final String builderMethodName;
private final String buildMethodName;
public BuilderCustomizer() {
this("builder", "build");
}
protected BuilderCustomizer(String builderMethodName, String buildMethodName) {
this.builderMethodName = builderMethodName;
this.buildMethodName = buildMethodName;
}
@Override
public ObjectGenerator customize(ObjectGenerator generator) {
return (query, context) -> getBuilder(query.getType())
.map(builder -> factory(builder, context))
.orElseGet(() -> generator.generate(query, context));
}
private Optional