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

io.cucumber.core.runner.DefinitionArgument Maven / Gradle / Ivy

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

import io.cucumber.core.stepexpression.ExpressionArgument;
import io.cucumber.plugin.event.Argument;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

final class DefinitionArgument implements Argument {

    private final ExpressionArgument argument;
    private final io.cucumber.cucumberexpressions.Group group;

    private DefinitionArgument(ExpressionArgument argument) {
        this.argument = argument;
        this.group = argument.getGroup();
    }

    static List createArguments(List match) {
        List args = new ArrayList<>();
        for (io.cucumber.core.stepexpression.Argument argument : match) {
            if (argument instanceof ExpressionArgument) {
                ExpressionArgument expressionArgument = (ExpressionArgument) argument;
                args.add(new DefinitionArgument(expressionArgument));
            }
        }
        return args;
    }

    @Override
    public String getParameterTypeName() {
        return argument.getParameterTypeName();
    }

    @Override
    public String getValue() {
        return group == null ? null : group.getValue();
    }

    @Override
    public int getStart() {
        return group == null ? -1 : group.getStart();
    }

    @Override
    public int getEnd() {
        return group == null ? -1 : group.getEnd();
    }

    @Override
    public io.cucumber.plugin.event.Group getGroup() {
        return group == null ? null : new Group(group);
    }

    private static final class Group implements io.cucumber.plugin.event.Group {

        private final io.cucumber.cucumberexpressions.Group group;
        private final List children;

        private Group(io.cucumber.cucumberexpressions.Group group) {
            this.group = group;
            children = group.getChildren().stream()
                    .map(Group::new)
                    .collect(Collectors.toList());
        }

        @Override
        public Collection getChildren() {
            return children;
        }

        @Override
        public String getValue() {
            return group.getValue();
        }

        @Override
        public int getStart() {
            return group.getStart();
        }

        @Override
        public int getEnd() {
            return group.getEnd();
        }

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy