Package spoon.pattern
Class PatternBuilder
java.lang.Object
spoon.pattern.PatternBuilder
The master class to create a
Pattern
instance.
Main documentation at http://spoon.gforge.inria.fr/pattern.html.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds a Pattern and returns itConfigures inlined statements For example if the `for` statement in this pattern modelAll the variable references, whose variables are out of the template model are automatically marked as pattern parametersconfigurePatternParameters(Consumer<PatternParameterConfigurator> parametersBuilder)
Configure pattern parameters with aPatternParameterConfigurator
static PatternBuilder
Creates aPatternBuilder
from the List of template elementsstatic PatternBuilder
protected Factory
boolean
setAddGeneratedBy(boolean addGeneratedBy)
setAutoSimplifySubstitutions(boolean autoSimplifySubstitutions)
-
Field Details
-
TARGET_TYPE
- See Also:
- Constant Field Values
-
patternNodes
-
-
Constructor Details
-
PatternBuilder
-
-
Method Details
-
create
Creates aPatternBuilder
from the List of template elements- Parameters:
patternModel
- a List of Spoon AST nodes, which represents a template of to be generated or to be matched code- Returns:
- new instance of
PatternBuilder
-
create
-
build
Builds a Pattern and returns it- Returns:
- the built pattern
- Throws:
SpoonException
- if the pattern has been built already
-
configurePatternParameters
All the variable references, whose variables are out of the template model are automatically marked as pattern parameters- Returns:
- this to support fluent API
-
configurePatternParameters
public PatternBuilder configurePatternParameters(Consumer<PatternParameterConfigurator> parametersBuilder)Configure pattern parameters with aPatternParameterConfigurator
- Returns:
- this
-
configureInlineStatements
Configures inlined statements For example if the `for` statement in this pattern model
is configured as inline statement and a Pattern is substituted using parameterfor(Object x : $iterable$) { System.out.println(x); }
$iterable$ = new String[]{"A", "B", "C"}
then pattern generated this code
because inline statements are executed during substitution process and are not included in generated result. The inline statements may be used in PatternMatching process (opposite to Pattern substitution) too.System.out.println("A"); System.out.println("B"); System.out.println("C");
- Parameters:
consumer
-- Returns:
- this to support fluent API
-
getFactory
-
setAddGeneratedBy
- Parameters:
addGeneratedBy
- true when generated by comments have to be appended to each generated type member- Returns:
- this to support fluent API
-
isAutoSimplifySubstitutions
public boolean isAutoSimplifySubstitutions()- Returns:
- true if generated result has to be evaluated to apply simplifications.
-
setAutoSimplifySubstitutions
- Parameters:
autoSimplifySubstitutions
- true if generated result of each substituted has to be evaluated to apply simplifications. The rule is applied only to substitutions defined after this call- Returns:
- this to support fluent API
-