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

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

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

import io.cucumber.cucumberexpressions.Expression;

import java.util.ArrayList;
import java.util.List;

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 = expression;
        this.docStringType = docStringType;
        this.tableType = tableType;
    }

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

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

    public List match(String text, List> tableArgument) {
        List list = match(text);

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

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

        return list;

    }

    public List match(String text, String docStringArgument) {
        List list = match(text);
        if (list == null) {
            return null;
        }

        list.add(new DocStringArgument(docStringType, docStringArgument));

        return list;
    }


    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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy