All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
net.zerobuilder.compiler.generate.DtoGoalDetails Maven / Gradle / Ivy
package net.zerobuilder.compiler.generate;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.TypeName;
import javax.lang.model.element.Modifier;
import java.util.List;
import java.util.function.Function;
public final class DtoGoalDetails {
public interface AbstractGoalDetails {
/**
* Returns the goal name.
*
* @return goal name
*/
String name();
Modifier[] access(Modifier... modifiers);
TypeName type();
R acceptAbstract(AbstractGoalDetailsCases cases);
}
interface AbstractGoalDetailsCases {
R regular(AbstractRegularDetails details);
R bean(BeanGoalDetails details);
}
interface RegularGoalDetailsCases {
R method(InstanceMethodGoalDetails details);
R staticMethod(StaticMethodGoalDetails details);
R constructor(ConstructorGoalDetails details);
}
public static Function asFunction(AbstractGoalDetailsCases cases) {
return details -> details.acceptAbstract(cases);
}
public static Function asFunction(RegularGoalDetailsCases cases) {
return details -> details.accept(cases);
}
public interface ProjectableDetails extends AbstractGoalDetails {
R accept(ProjectableDetailsCases cases);
}
interface ProjectableDetailsCases {
R constructor(ConstructorGoalDetails constructor);
R method(StaticMethodGoalDetails method);
}
static Function asFunction(ProjectableDetailsCases cases) {
return details -> details.accept(cases);
}
static Function projectableDetailsCases(
Function constructorFunction,
Function methodFunction) {
return asFunction(new ProjectableDetailsCases() {
@Override
public R constructor(ConstructorGoalDetails constructor) {
return constructorFunction.apply(constructor);
}
@Override
public R method(StaticMethodGoalDetails method) {
return methodFunction.apply(method);
}
});
}
static final Function> parameterNames =
projectableDetailsCases(
constructor -> constructor.parameterNames,
method -> method.parameterNames);
public static abstract class AbstractRegularDetails implements AbstractGoalDetails {
public final String name;
final Access access;
/**
* parameter names in original order
*/
final List parameterNames;
public final String name() {
return name;
}
public final Modifier[] access(Modifier... modifiers) {
return access.modifiers(modifiers);
}
public abstract TypeName type();
/**
* @param name goal name
* @param parameterNames parameter names in original order
* @param access goal options
*/
AbstractRegularDetails(String name, List parameterNames,
Access access) {
this.name = name;
this.access = access;
this.parameterNames = parameterNames;
}
@Override
public final R acceptAbstract(AbstractGoalDetailsCases cases) {
return cases.regular(this);
}
abstract R accept(RegularGoalDetailsCases cases);
}
public static final class ConstructorGoalDetails extends AbstractRegularDetails
implements ProjectableDetails, AbstractGoalDetails {
public final ClassName goalType;
private ConstructorGoalDetails(ClassName goalType, String name, List parameterNames,
Access access) {
super(name, parameterNames, access);
this.goalType = goalType;
}
public static ConstructorGoalDetails create(ClassName goalType, String name, List parameterNames,
Access access) {
return new ConstructorGoalDetails(goalType, name, parameterNames, access);
}
@Override
public TypeName type() {
return goalType;
}
@Override
R accept(RegularGoalDetailsCases cases) {
return cases.constructor(this);
}
@Override
public R accept(ProjectableDetailsCases cases) {
return cases.constructor(this);
}
}
public static final class InstanceMethodGoalDetails extends AbstractRegularDetails {
public final String methodName;
public final TypeName goalType;
private InstanceMethodGoalDetails(TypeName goalType, String name, List parameterNames, String methodName,
Access access) {
super(name, parameterNames, access);
this.goalType = goalType;
this.methodName = methodName;
}
public static InstanceMethodGoalDetails create(TypeName goalType,
String name,
List parameterNames,
String methodName,
Access access) {
return new InstanceMethodGoalDetails(goalType, name, parameterNames, methodName, access);
}
@Override
public TypeName type() {
return goalType;
}
@Override
R accept(RegularGoalDetailsCases cases) {
return cases.method(this);
}
}
public static final class StaticMethodGoalDetails extends AbstractRegularDetails
implements ProjectableDetails, AbstractGoalDetails {
public final String methodName;
public final TypeName goalType;
private StaticMethodGoalDetails(TypeName goalType, String name, List parameterNames, String methodName,
Access access) {
super(name, parameterNames, access);
this.goalType = goalType;
this.methodName = methodName;
}
public static StaticMethodGoalDetails create(TypeName goalType,
String name,
List parameterNames,
String methodName,
Access access) {
return new StaticMethodGoalDetails(goalType, name, parameterNames, methodName, access);
}
@Override
public TypeName type() {
return goalType;
}
@Override
R accept(RegularGoalDetailsCases cases) {
return cases.staticMethod(this);
}
@Override
public R accept(ProjectableDetailsCases cases) {
return cases.method(this);
}
}
public static final class BeanGoalDetails implements AbstractGoalDetails {
public final ClassName goalType;
public final String name;
private final Access access;
public BeanGoalDetails(ClassName goalType, String name, Access access) {
this.name = name;
this.access = access;
this.goalType = goalType;
}
@Override
public String name() {
return name;
}
@Override
public Modifier[] access(Modifier... modifiers) {
return access.modifiers(modifiers);
}
@Override
public TypeName type() {
return goalType;
}
@Override
public R acceptAbstract(AbstractGoalDetailsCases cases) {
return cases.bean(this);
}
}
public static final Function goalType
= asFunction(new AbstractGoalDetailsCases() {
@Override
public TypeName regular(AbstractRegularDetails goal) {
return goal.type();
}
@Override
public TypeName bean(BeanGoalDetails goal) {
return goal.goalType;
}
});
private DtoGoalDetails() {
throw new UnsupportedOperationException("no instances");
}
}