Package spoon.template
Class TemplateMatcher
java.lang.Object
spoon.template.TemplateMatcher
This class defines an engine for matching a template to pieces of code.
-
Constructor Summary
ConstructorDescriptionTemplateMatcher(CtElement templateRoot)
Constructs a matcher for a given template.TemplateMatcher(CtElement templateRoot, CtClass<?> templateType)
Constructs a matcher for a given template. -
Method Summary
Modifier and TypeMethodDescriptionFinds all target program sub-trees that correspond to a template.void
forEachMatch(CtElement rootElement, CtConsumer<Match> consumer)
Finds all target program sub-trees that correspond to a template and calls consumer.accept(matchingElement, )Returns all the matches where the keys are the corresponding template parameters.boolean
Tells if the given element matches.
-
Constructor Details
-
TemplateMatcher
Constructs a matcher for a given template.- Parameters:
templateRoot
- the template to match against
-
TemplateMatcher
Constructs a matcher for a given template. All parameters must be declared using Template fields.- Parameters:
templateRoot
- the template model to match against. It must be a child of `templateType`templateType
- the class of the template, which contains all the template parameters
-
-
Method Details
-
matches
Description copied from interface:Filter
Tells if the given element matches. -
getMatches
Returns all the matches where the keys are the corresponding template parameters. Thematches(CtElement)
method must have been called before and must return true. Otherwise it returns null. -
find
Finds all target program sub-trees that correspond to a template.- Parameters:
targetRoot
- the target to be tested for match- Returns:
- the matched elements
-
forEachMatch
Finds all target program sub-trees that correspond to a template and calls consumer.accept(matchingElement, )- Parameters:
rootElement
- the root of to be searched ASTconsumer
- the receiver of matches
-