public abstract class Rule extends Object
| Modifier | Constructor and Description |
|---|---|
protected |
Rule() |
| Modifier and Type | Method and Description |
|---|---|
abstract Node |
apply(Node node)
Applies the rule to the node using the following criteria
- if rule does not match returns an ErrorNode and stops processing
- if rule matches, applies rules to children
- if rule contains a NodeFactory, returns the result of it
- else returns node
Only structure rules (
ObjectRule, ArrayRule, KeyValueRule) replace child nodes. |
Rule |
cleanFactory() |
protected Node |
createNodeUsingFactory(Node currentNode,
Object... args) |
List<? extends Rule> |
getChildren() |
abstract String |
getDescription()
Returns a description of this rule
|
NodeFactory |
getFactory() |
List<Suggestion> |
getSuggestions(List<Node> pathToRoot,
ParsingContext context)
Returns the list of suggestions after navigating through the path
|
abstract List<Suggestion> |
getSuggestions(Node node,
ParsingContext context)
Returns the suggestions of this specific rule
|
abstract boolean |
matches(Node node)
Check if the current rule matches the specified node
|
Rule |
named(String ruleName) |
String |
ruleName() |
Rule |
then(Class<? extends Node> clazz)
Sets the clazz of the node that is going to be created to replaced the matched node of this rule.
|
Rule |
then(NodeFactory factory)
Sets the factory of the node that is going to be created to replaced the matched node of this rule.
|
String |
toString() |
public String ruleName()
public abstract boolean matches(@Nonnull Node node)
node - The node to check with@Nonnull public abstract Node apply(@Nonnull Node node)
ObjectRule, ArrayRule, KeyValueRule) replace child nodes.node - The current nodepublic abstract String getDescription()
@Nullable public NodeFactory getFactory()
@Nonnull protected Node createNodeUsingFactory(@Nonnull Node currentNode, Object... args)
public Rule then(Class<? extends Node> clazz)
clazz - The class of the nodepublic Rule then(NodeFactory factory)
factory - The class of the nodepublic Rule cleanFactory()
public List<Suggestion> getSuggestions(List<Node> pathToRoot, ParsingContext context)
pathToRoot - The path of nodes to get of the node from where we want the suggestionscontext - The parse context@Nonnull public abstract List<Suggestion> getSuggestions(Node node, ParsingContext context)
node - The nodecontext - The parse contextCopyright © 2017. All rights reserved.