ch.powerunit.extensions.matchers.provideprocessor.extension.AbstractDSLExtensionSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powerunit-extensions-matchers-factory Show documentation
Show all versions of powerunit-extensions-matchers-factory Show documentation
This is a test framework for the JDK 1.8 - Extension to provide matchers based on annotation. - Factory Support
package ch.powerunit.extensions.matchers.provideprocessor.extension;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.joining;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.function.Supplier;
import ch.powerunit.extensions.matchers.provideprocessor.DSLMethod;
public abstract class AbstractDSLExtensionSupplier {
protected final String targetName;
protected final String returnType;
protected final String methodName;
protected final String targetMethodName;
public AbstractDSLExtensionSupplier(String targetName, String returnType, String methodName,
String targetMethodName) {
this.targetName = targetName;
this.returnType = returnType;
this.methodName = methodName;
this.targetMethodName = targetMethodName;
}
public abstract Collection> asSuppliers();
public String[][] getSeveralParameter(boolean lastIsVarargs, String... name) {
List tmp = Arrays.stream(name).map(this::getOneParameter).collect(toList());
if (lastIsVarargs) {
tmp.get(name.length - 1)[0] += "...";
}
return tmp.toArray(new String[0][0]);
}
public String[] getOneParameter(String name) {
return new String[] { targetName, name };
}
public String getSeveralWith(String... name) {
return Arrays.stream(name).map(this::getOneWith).collect(joining(","));
}
public String getOneWith(String name) {
return targetMethodName + "(" + name + ")";
}
public DSLMethod generateSimpleDSLMethodFor(String javadoc[], String containerMatcher, String... parameters) {
return new DSLMethod(javadoc, returnType + " " + methodName, getSeveralParameter(false, parameters),
"return " + containerMatcher + "(" + getSeveralWith(parameters) + ");");
}
}