All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.zerobuilder.compiler.generate.DtoBeanGoalContext Maven / Gradle / Ivy

There is a newer version: 1.603
Show newest version
package net.zerobuilder.compiler.generate;

import com.squareup.javapoet.FieldSpec;
import net.zerobuilder.compiler.generate.DtoGoal.BeanGoalDetails;
import net.zerobuilder.compiler.generate.DtoBeanStep.AbstractBeanStep;
import net.zerobuilder.compiler.generate.DtoBuildersContext.BuildersContext;
import net.zerobuilder.compiler.generate.DtoGoalContext.AbstractGoalContext;
import net.zerobuilder.compiler.generate.DtoGoalContext.GoalCases;
import net.zerobuilder.compiler.generate.DtoGoalContext.IGoal;

import java.util.List;

import static javax.lang.model.element.Modifier.PRIVATE;
import static net.zerobuilder.compiler.generate.Utilities.downcase;
import static net.zerobuilder.compiler.generate.Utilities.fieldSpec;

final class DtoBeanGoalContext {

  static final class BeanGoal implements IGoal {

    final List steps;
    final BeanGoalDetails details;
    final FieldSpec field;

    private BeanGoal(BeanGoalDetails details,
                     List steps, FieldSpec field) {
      this.steps = steps;
      this.details = details;
      this.field = field;
    }

    static BeanGoal create(BeanGoalDetails goal,
                           List steps) {
      FieldSpec field = fieldSpec(goal.goalType,
          downcase(goal.goalType.simpleName()), PRIVATE);
      return new BeanGoal(goal, steps, field);

    }

    @Override
    public AbstractGoalContext withContext(BuildersContext context) {
      return new BeanGoalContext(this, context);
    }
  }

  static final class BeanGoalContext implements AbstractGoalContext {

    final BuildersContext builders;
    final BeanGoal goal;

    BeanGoalContext(BeanGoal goal,
                    BuildersContext builders) {
      this.goal = goal;
      this.builders = builders;
    }

    public  R accept(GoalCases cases) {
      return cases.beanGoal(this);
    }
  }

  private DtoBeanGoalContext() {
    throw new UnsupportedOperationException("no instances");
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy