Package io.cucumber.plugin.event
Interface Node
- All Known Subinterfaces:
Node.Container<T>
,Node.Example
,Node.Examples
,Node.Feature
,Node.Rule
,Node.Scenario
,Node.ScenarioOutline
@API(status=EXPERIMENTAL)
public interface Node
A node in a source file.
A node has a location, a keyword and name. The keyword and name are both
optional (e.g. Node.Example
and blank scenario names).
Nodes are organized in a tree like structure where Node.Container
nodes
contain yet more nodes.
A node can be linked to a TestCase
by getLocation()
. The
findPathTo(Predicate)
method can be used to find a path from the
root node to a node with the same location as a test case.
Location location = testCase.getLocation();
Predicate<Node> withLocation = candidate -> location.equals(candidate.getLocation());
Optional<List<Node>> path = node.findPathTo(withLocation);
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Node.Container<T extends Node>
static interface
An example has no keyword but always a name.static interface
An examples section has a keyword and optionally a name.static interface
A feature has a keyword and optionally a name.static interface
A rule has a keyword and optionally a name.static interface
A scenario has a keyword and optionally a name.static interface
A scenario outline has a keyword and optionally a name. -
Method Summary
Modifier and TypeMethodDescriptionfindPathTo
(Predicate<Node> predicate) Finds a path down tree starting at this node to the first node that matches the predicate using depth first search.getName()
default <T> T
map
(T parent, BiFunction<Node.Feature, T, T> mapFeature, BiFunction<Node.Rule, T, T> mapRule, BiFunction<Node.Scenario, T, T> mapScenario, BiFunction<Node.ScenarioOutline, T, T> mapScenarioOutline, BiFunction<Node.Examples, T, T> mapExamples, BiFunction<Node.Example, T, T> mapExample) Recursively maps a node into another tree-like structure.
-
Method Details
-
getLocation
Location getLocation() -
getKeyword
-
getName
-
getParent
-
map
default <T> T map(T parent, BiFunction<Node.Feature, T, T> mapFeature, BiFunction<Node.Rule, T, T> mapRule, BiFunction<Node.Scenario, T, T> mapScenario, BiFunction<Node.ScenarioOutline, T, T> mapScenarioOutline, BiFunction<Node.Examples, T, T> mapExamples, BiFunction<Node.Example, T, T> mapExample) Recursively maps a node into another tree-like structure.- Type Parameters:
T
- the type of the target structure- Parameters:
parent
- the parent node of the target structuremapFeature
- a function that takes a feature and a parent node and returns a mapped featuremapRule
- a function that takes a rule and a parent node and returns a mapped rulemapScenario
- a function that takes a scenario and a parent node and returns a mapped scenariomapScenarioOutline
- a function that takes a scenario outline and a parent node and returns a mapped scenario outlinemapExamples
- a function that takes an examples and a parent node and returns a mapped examplesmapExample
- a function that takes an example and a parent node and returns a mapped example- Returns:
- the mapped version of this instance
-
findPathTo
Finds a path down tree starting at this node to the first node that matches the predicate using depth first search.- Parameters:
predicate
- to match the target node.- Returns:
- a path to the first node or an empty optional if none was found.
-