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

io.cucumber.core.stepexpression.StepExpression Maven / Gradle / Ivy

There is a newer version: 7.20.1
Show newest version
package io.cucumber.core.stepexpression;

import io.cucumber.cucumberexpressions.Expression;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import static java.util.Objects.requireNonNull;

public final class StepExpression {

    private final Expression expression;
    private final DocStringTransformer docStringType;
    private final RawTableTransformer tableType;

    StepExpression(Expression expression, DocStringTransformer docStringType, RawTableTransformer tableType) {
        this.expression = requireNonNull(expression);
        this.docStringType = requireNonNull(docStringType);
        this.tableType = requireNonNull(tableType);
    }

    public Class getExpressionType() {
        return expression.getClass();
    }

    public String getSource() {
        return expression.getSource();
    }

    public List match(String text, List> cells, Type... types) {
        List list = match(text, types);

        if (list == null) {
            return null;
        }

        list.add(new DataTableArgument(tableType, cells));

        return list;

    }

    public List match(String text, Type... types) {
        List> match = expression.match(text, types);
        if (match == null) {
            return null;
        }
        return wrapPlusOne(match);
    }

    private static List wrapPlusOne(List> match) {
        List copy = new ArrayList<>(match.size() + 1);
        for (io.cucumber.cucumberexpressions.Argument argument : match) {
            copy.add(new ExpressionArgument(argument));
        }
        return copy;
    }

    public List match(String text, String content, String contentType, Type... types) {
        List list = match(text, types);
        if (list == null) {
            return null;
        }

        list.add(new DocStringArgument(this.docStringType, content, contentType));

        return list;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy