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

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

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

import com.squareup.javapoet.TypeName;
import net.zerobuilder.NullPolicy;
import net.zerobuilder.compiler.generate.DtoBeanParameter.AbstractBeanParameter;
import net.zerobuilder.compiler.generate.DtoRegularParameter.AbstractRegularParameter;

import java.util.function.Function;

public final class DtoParameter {

  interface ParameterCases {
    R regularParameter(AbstractRegularParameter parameter);
    R beanParameter(AbstractBeanParameter parameter);
  }

  static  Function asFunction(ParameterCases cases) {
    return parameter -> parameter.acceptParameter(cases);
  }

  static  Function parameterCases(
      Function regularParameter,
      Function beanParameter) {
    return asFunction(new ParameterCases() {
      @Override
      public R regularParameter(AbstractRegularParameter parameter) {
        return regularParameter.apply(parameter);
      }
      @Override
      public R beanParameter(AbstractBeanParameter parameter) {
        return beanParameter.apply(parameter);
      }
    });
  }

  public abstract static class AbstractParameter {

    /**
     * 

for beans, this is the type that's returned by the getter, * or equivalently the type of the setter parameter

*

for regular goals, it is the original parameter type

*/ public final TypeName type; /** * true if null checks should be added */ public final NullPolicy nullPolicy; /** * For regular parameters, this is just the parameter name. * For bean goals, it's the truncated, lower case getter name. * * @return parameter name */ public abstract String name(); AbstractParameter(TypeName type, NullPolicy nullPolicy) { this.type = type; this.nullPolicy = nullPolicy; } public abstract R acceptParameter(ParameterCases cases); } static final Function parameterName = parameterCases( parameter -> parameter.name, parameter -> parameter.name()); private DtoParameter() { throw new UnsupportedOperationException("no instances"); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy