Package spoon.pattern
Class Pattern
- java.lang.Object
-
- spoon.pattern.Pattern
-
public class Pattern extends Object
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 withPatternBuilder
. ThePattern
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 withgenerator()
and it's methods Differences withTemplateMatcher
: - it can match sequences of elements - it can match inlined elements
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
forEachMatch(Object input, CtConsumer<Match> consumer)
Finds all target program sub-trees that correspond to a template and calls consumer.accept(Match)Generator
generator()
List<Match>
getMatches(CtElement root)
Finds all target program sub-trees that correspond to this pattern and returns them.Map<String,ParameterInfo>
getParameterInfos()
String
print(boolean addParameterComments)
String
toString()
-
-
-
Method Detail
-
getParameterInfos
public Map<String,ParameterInfo> getParameterInfos()
- Returns:
- Map of parameter names to
ParameterInfo
for each parameter of thisPattern
-
generator
public Generator generator()
-
forEachMatch
public void forEachMatch(Object input, CtConsumer<Match> consumer)
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
public List<Match> getMatches(CtElement root)
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
public String print(boolean addParameterComments)
- Parameters:
addParameterComments
- if true then it adds comments with parameter names- Returns:
- pattern printed as java sources
-
-