io.cucumber.cucumberexpressions.Argument Maven / Gradle / Ivy
package io.cucumber.cucumberexpressions;
import java.util.ArrayList;
import java.util.List;
public class Argument {
private final ParameterType parameterType;
private final Group group;
static List> build(TreeRegexp treeRegexp, List> parameterTypes, String text) {
Group group = treeRegexp.match(text);
if (group == null) return null;
List argGroups = group.getChildren();
if (argGroups.size() != parameterTypes.size()) {
throw new CucumberExpressionException(String.format("Expression /%s/ has %s capture groups (%s), but there were %s parameter types (%s)",
treeRegexp.pattern().pattern(),
argGroups.size(),
getGroupValues(argGroups),
parameterTypes.size(),
getParameterTypeNames(parameterTypes)
));
}
List> args = new ArrayList<>(argGroups.size());
for (int i = 0; i < parameterTypes.size(); i++) {
Group argGroup = argGroups.get(i);
ParameterType> parameterType = parameterTypes.get(i);
args.add(new Argument<>(argGroup, parameterType));
}
return args;
}
private static List getParameterTypeNames(List> parameterTypes) {
List list = new ArrayList<>();
for (ParameterType> type : parameterTypes) {
String name = type.getName();
list.add(name);
}
return list;
}
private static List