net.zerobuilder.compiler.generate.DtoGeneratorInput Maven / Gradle / Ivy
package net.zerobuilder.compiler.generate;
import net.zerobuilder.compiler.generate.DtoContext.BuildersContext;
import net.zerobuilder.compiler.generate.DtoDescriptionInput.DescriptionInput;
import net.zerobuilder.compiler.generate.DtoModule.Module;
import net.zerobuilder.compiler.generate.DtoProjectedGoal.ProjectedGoal;
import net.zerobuilder.compiler.generate.DtoProjectedModule.ProjectedModule;
import net.zerobuilder.compiler.generate.DtoSimpleGoal.SimpleGoal;
import java.util.List;
import java.util.function.Function;
public final class DtoGeneratorInput {
interface GoalInputCases {
R simple(GoalInput simple);
R projected(ProjectedGoalInput projected);
}
static abstract class AbstractGoalInput {
abstract R accept(GoalInputCases cases);
}
static Function asFunction(GoalInputCases cases) {
return input -> input.accept(cases);
}
static Function goalInputCases(
Function simpleFunction,
Function projectedFunction) {
return asFunction(new GoalInputCases() {
@Override
public R simple(GoalInput simple) {
return simpleFunction.apply(simple);
}
@Override
public R projected(ProjectedGoalInput projected) {
return projectedFunction.apply(projected);
}
});
}
static final class GoalInput extends AbstractGoalInput {
final Module module;
final SimpleGoal goal;
GoalInput(Module module, SimpleGoal goal) {
this.module = module;
this.goal = goal;
}
@Override
R accept(GoalInputCases cases) {
return cases.simple(this);
}
}
static final class ProjectedGoalInput extends AbstractGoalInput {
final ProjectedModule module;
final ProjectedGoal goal;
ProjectedGoalInput(ProjectedModule module, ProjectedGoal goal) {
this.module = module;
this.goal = goal;
}
@Override
R accept(GoalInputCases cases) {
return cases.projected(this);
}
}
public static final class GeneratorInput {
public final List goals;
public final BuildersContext context;
private GeneratorInput(BuildersContext context, List goals) {
this.goals = goals;
this.context = context;
}
public static GeneratorInput create(BuildersContext context, List goals) {
return new GeneratorInput(context, goals);
}
}
private DtoGeneratorInput() {
throw new UnsupportedOperationException("no instances");
}
}