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
bygetLocation()
. ThefindPathTo(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 Classes Modifier and Type Interface Description static interface
Node.Container<T extends Node>
static interface
Node.Example
An example has no keyword but always a name.static interface
Node.Examples
An examples section has a keyword and optionally a name.static interface
Node.Feature
A feature has a keyword and optionally a name.static interface
Node.Rule
A rule has a keyword and optionally a name.static interface
Node.Scenario
A scenario has a keyword and optionally a name.static interface
Node.ScenarioOutline
A scenario outline has a keyword and optionally a name.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Optional<List<Node>>
findPathTo(Predicate<Node> predicate)
Finds a path down tree starting at this node to the first node that matches the predicate using depth first search.Optional<String>
getKeyword()
Location
getLocation()
Optional<String>
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 Detail
-
getLocation
Location getLocation()
-
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
default Optional<List<Node>> findPathTo(Predicate<Node> predicate)
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.
-
-