Package spoon.pattern
Class Pattern
java.lang.Object
spoon.pattern.Pattern
Represents a pattern for matching code. A pattern is composed of a list of AST models, where a model is an AST with some nodes being "pattern parameters".
Main documentation at http://spoon.gforge.inria.fr/pattern.html.
Instances can created with
PatternBuilder.
The Pattern can also be used to generate new code where
(Pattern) + (pattern parameters) => (copy of pattern where parameters are replaced by parameter values)
This is done with generator() and it's methods
Differences with TemplateMatcher:
- it can match sequences of elements
- it can match inlined elements-
Method Summary
Modifier and TypeMethodDescriptionvoidforEachMatch(Object input, CtConsumer<Match> consumer)Finds all target program sub-trees that correspond to a template and calls consumer.accept(Match)getMatches(CtElement root)Finds all target program sub-trees that correspond to this pattern and returns them.print(boolean addParameterComments)toString()
-
Method Details
-
getParameterInfos
- Returns:
- Map of parameter names to
ParameterInfofor each parameter of thisPattern
-
generator
-
forEachMatch
Finds all target program sub-trees that correspond to a template and calls consumer.accept(Match)- Parameters:
input- the root of to be searched ASTconsumer- the receiver of matches
-
getMatches
Finds all target program sub-trees that correspond to this pattern and returns them.- Parameters:
root- the root of to be searched AST. It can be a CtElement or List, Set, Map of CtElements- Returns:
- List of
Match
-
print
- Parameters:
addParameterComments- if true then it adds comments with parameter names- Returns:
- pattern printed as java sources
-
toString
-