Top Description Fields Constructors Methods
org.antlr.v4.runtime.tree.pattern

public Class ParseTreePattern

extends Object
Class Inheritance
Imports
org.antlr.v4.runtime.tree.ParseTree, org.antlr.v4.runtime.tree.xpath.XPath, java.util.ArrayList, .Collection, .List

A pattern like <ID> = <expr>; converted to a ParseTree by ParseTreePatternMatcher#compile(String, int).

Field Summary

Modifier and TypeField and Description
private final ParseTreePatternMatcher
matcher

This is the backing field for getMatcher().

private final String
pattern

This is the backing field for getPattern().

private final int
patternRuleIndex

This is the backing field for getPatternRuleIndex().

private final ParseTree
patternTree

This is the backing field for getPatternTree().

Constructor Summary

AccessConstructor and Description
public
ParseTreePattern(ParseTreePatternMatcher
The ParseTreePatternMatcher which created this tree pattern.
matcher
,
String
The tree pattern in concrete syntax form.
pattern
,
int
The parser rule which serves as the root of the tree pattern.
patternRuleIndex
,
ParseTree
The tree pattern in ParseTree form.
patternTree
)

Construct a new instance of the ParseTreePattern class.

Method Summary

Modifier and TypeMethod and Description
public List<ParseTreeMatch>

Returns:

A collection of ParseTreeMatch objects describing the successful matches. Unsuccessful matches are omitted from the result, regardless of the reason for the failure.
findAll
(ParseTree
The ParseTree to match against this pattern.
tree
,
String
An expression matching the nodes
xpath
)

Find all nodes using XPath and then try to match those subtrees against this tree pattern.

public ParseTreePatternMatcher

Returns:

The ParseTreePatternMatcher which created this tree pattern.
getMatcher
()

Get the ParseTreePatternMatcher which created this tree pattern.

public String

Returns:

The tree pattern in concrete syntax form.
getPattern
()

Get the tree pattern in concrete syntax form.

public int

Returns:

The parser rule which serves as the outermost rule for the tree pattern.
getPatternRuleIndex
()

Get the parser rule which serves as the outermost rule for the tree pattern.

public ParseTree

Returns:

The tree pattern as a ParseTree.
getPatternTree
()

Get the tree pattern as a ParseTree.

public ParseTreeMatch

Returns:

A ParseTreeMatch object describing the result of the match operation. The ParseTreeMatch#succeeded() method can be used to determine whether or not the match was successful.
match
(ParseTree
The parse tree to match against this tree pattern.
tree
)

Match a specific parse tree against this tree pattern.

public boolean

Returns:

true if tree is a match for the current tree pattern; otherwise, false.
matches
(ParseTree
The parse tree to match against this tree pattern.
tree
)

Determine whether or not a parse tree matches this tree pattern.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

matcherback to summary
private final ParseTreePatternMatcher matcher

This is the backing field for getMatcher().

patternback to summary
private final String pattern

This is the backing field for getPattern().

patternRuleIndexback to summary
private final int patternRuleIndex

This is the backing field for getPatternRuleIndex().

patternTreeback to summary
private final ParseTree patternTree

This is the backing field for getPatternTree().

Constructor Detail

ParseTreePatternback to summary
public ParseTreePattern(ParseTreePatternMatcher matcher, String pattern, int patternRuleIndex, ParseTree patternTree)

Construct a new instance of the ParseTreePattern class.

Parameters
matcher:ParseTreePatternMatcher

The ParseTreePatternMatcher which created this tree pattern.

pattern:String

The tree pattern in concrete syntax form.

patternRuleIndex:int

The parser rule which serves as the root of the tree pattern.

patternTree:ParseTree

The tree pattern in ParseTree form.

Method Detail

findAllback to summary
public List<ParseTreeMatch> findAll(ParseTree tree, String xpath)

Find all nodes using XPath and then try to match those subtrees against this tree pattern.

Parameters
tree:ParseTree

The ParseTree to match against this pattern.

xpath:String

An expression matching the nodes

Returns:List<ParseTreeMatch>

A collection of ParseTreeMatch objects describing the successful matches. Unsuccessful matches are omitted from the result, regardless of the reason for the failure.

getMatcherback to summary
public ParseTreePatternMatcher getMatcher()

Get the ParseTreePatternMatcher which created this tree pattern.

Returns:ParseTreePatternMatcher

The ParseTreePatternMatcher which created this tree pattern.

getPatternback to summary
public String getPattern()

Get the tree pattern in concrete syntax form.

Returns:String

The tree pattern in concrete syntax form.

getPatternRuleIndexback to summary
public int getPatternRuleIndex()

Get the parser rule which serves as the outermost rule for the tree pattern.

Returns:int

The parser rule which serves as the outermost rule for the tree pattern.

getPatternTreeback to summary
public ParseTree getPatternTree()

Get the tree pattern as a ParseTree. The rule and token tags from the pattern are present in the parse tree as terminal nodes with a symbol of type RuleTagToken or TokenTagToken.

Returns:ParseTree

The tree pattern as a ParseTree.

matchback to summary
public ParseTreeMatch match(ParseTree tree)

Match a specific parse tree against this tree pattern.

Parameters
tree:ParseTree

The parse tree to match against this tree pattern.

Returns:ParseTreeMatch

A ParseTreeMatch object describing the result of the match operation. The ParseTreeMatch#succeeded() method can be used to determine whether or not the match was successful.

matchesback to summary
public boolean matches(ParseTree tree)

Determine whether or not a parse tree matches this tree pattern.

Parameters
tree:ParseTree

The parse tree to match against this tree pattern.

Returns:boolean

true if tree is a match for the current tree pattern; otherwise, false.