Package spoon.pattern
Class PatternParameterConfigurator
- java.lang.Object
-
- spoon.pattern.PatternParameterConfigurator
-
public class PatternParameterConfigurator extends Object
Used to define pattern parameters. Main documentation at http://spoon.gforge.inria.fr/pattern.html.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PatternParameterConfigurator.ParameterElementPair
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> PatternParameterConfigurator
byCondition(Class<T> type, Predicate<T> matchCondition)
PatternParameterConfigurator
byElement(CtElement... elements)
Elements will be substituted by parameter valuePatternParameterConfigurator
byFieldAccessOnVariable(String varName)
Add parameters for each field reference to variable named `variableName` For example this pattern model class Params { int paramA; int paramB; } void matcher(Params p) { return p.paramA + p.paramB; } called with `byFieldRefOfVariable("p")` will create pattern parameters: `paramA` and `paramB`PatternParameterConfigurator
byFilter(Filter<?> filter)
All elements matched byFilter
will be substituted by parameter valuePatternParameterConfigurator
byInvocation(CtMethod<?> method)
each invocation of `method` will be replaces by parameter valuePatternParameterConfigurator
byLocalType(CtType<?> searchScope, String localTypeSimpleName)
Searches for a type visible in scope `templateType`, whose simple name is equal to `localTypeSimpleName`PatternParameterConfigurator
byNamedElement(String simpleName)
Any named element by it's simple namePatternParameterConfigurator
byParameterValues(Map<String,Object> parameterValues)
Creates pattern parameter for each key of parameterValuesMap
.PatternParameterConfigurator
byReferenceName(String simpleName)
Any reference identified by it's simple name.PatternParameterConfigurator
byRole(CtRole role, CtElement... elements)
Attribute defined by `role` of `element` will be substituted by parameter valuePatternParameterConfigurator
byRole(CtRole role, Filter<?> filter)
Attribute defined by `role` of all elements matched byFilter
will be substituted by parameter valuePatternParameterConfigurator
byString(String stringMarker)
All spoon model string attributes whose value is equal to `stringMarker` are subject for substitution by current parameterPatternParameterConfigurator
bySubstring(String stringMarker)
All spoon model string attributes whose value contains whole string or a substring equal to `stringMarker` are subject for substitution by current parameter.PatternParameterConfigurator
byTemplateParameter()
Creates pattern parameter for each field of typeTemplateParameter
PatternParameterConfigurator
byTemplateParameter(Map<String,Object> parameterValues)
Creates pattern parameter for each field of typeTemplateParameter
.
Note: This method is here for compatibility with obsolete legacyTemplate
based concept.PatternParameterConfigurator
byTemplateParameterReference(CtVariable<?> variable)
variable read/write of `variable` of typeTemplateParameter
PatternParameterConfigurator
byType(Class<?> type)
`type` itself and all the references to the `type` are subject for substitution by current parameterPatternParameterConfigurator
byType(String typeQualifiedName)
type identified by `typeQualifiedName` itself and all the references (with arbitrary actual type arguments) to that type are subject for substitution by current parameterPatternParameterConfigurator
byType(CtTypeReference<?> type)
type referred byCtTypeReference
`type` and all the references (with same actual type arguments) to that type are subject for substitution by current parameterPatternParameterConfigurator
byVariable(String variableName)
variable read/write of `variable`PatternParameterConfigurator
byVariable(CtVariable<?> variable)
variable read/write of `variable`ConflictResolutionMode
getConflictResolutionMode()
ParameterInfo
getCurrentParameter()
boolean
isSubstituted(String paramName)
PatternParameterConfigurator
matchInlinedStatements()
marks a CtIf and CtForEach to be matched, even when inlined.PatternParameterConfigurator
parameter(String paramName)
Creates a parameter with name `paramName` and assigns it into context, so next calls on builder will be applied to this parameterCtQueryable
queryModel()
PatternParameterConfigurator
setConflictResolutionMode(ConflictResolutionMode conflictResolutionMode)
PatternParameterConfigurator
setContainerKind(ContainerKind containerKind)
Defines type of parameter value (List/Set/Map/single).PatternParameterConfigurator
setMatchingStrategy(Quantifier quantifier)
PatternParameterConfigurator
setMaxOccurrence(int maxOccurrence)
PatternParameterConfigurator
setMinOccurrence(int minOccurrence)
PatternParameterConfigurator
setValueType(Class<?> valueType)
Set expected type of Parameter.
-
-
-
Method Detail
-
getConflictResolutionMode
public ConflictResolutionMode getConflictResolutionMode()
- Returns:
- current
ConflictResolutionMode
-
setConflictResolutionMode
public PatternParameterConfigurator setConflictResolutionMode(ConflictResolutionMode conflictResolutionMode)
- Parameters:
conflictResolutionMode
- to be applied mode- Returns:
- this to support fluent API
-
queryModel
public CtQueryable queryModel()
-
parameter
public PatternParameterConfigurator parameter(String paramName)
Creates a parameter with name `paramName` and assigns it into context, so next calls on builder will be applied to this parameter- Parameters:
paramName
- to be build parameter name- Returns:
- this
PatternParameterConfigurator
to support fluent API
-
setMinOccurrence
public PatternParameterConfigurator setMinOccurrence(int minOccurrence)
-
setMaxOccurrence
public PatternParameterConfigurator setMaxOccurrence(int maxOccurrence)
-
setMatchingStrategy
public PatternParameterConfigurator setMatchingStrategy(Quantifier quantifier)
-
setValueType
public PatternParameterConfigurator setValueType(Class<?> valueType)
Set expected type of Parameter. In some cases legacy Template needs to know the type of parameter value to select substituted element. SeeValueConvertor
, which provides conversion between matched element and expected parameter type- Parameters:
valueType
- a expected type of parameter value- Returns:
- this
PatternParameterConfigurator
to support fluent API
-
setContainerKind
public PatternParameterConfigurator setContainerKind(ContainerKind containerKind)
Defines type of parameter value (List/Set/Map/single). If not defined then real value type of property is used. If null, then default isContainerKind.SINGLE
- Parameters:
containerKind
- to be usedContainerKind
- Returns:
- this
PatternParameterConfigurator
to support fluent API
-
getCurrentParameter
public ParameterInfo getCurrentParameter()
-
byType
public PatternParameterConfigurator byType(Class<?> type)
`type` itself and all the references to the `type` are subject for substitution by current parameter- Parameters:
type
- to be substituted Class- Returns:
PatternParameterConfigurator
to support fluent API
-
byType
public PatternParameterConfigurator byType(String typeQualifiedName)
type identified by `typeQualifiedName` itself and all the references (with arbitrary actual type arguments) to that type are subject for substitution by current parameter- Parameters:
typeQualifiedName
- a fully qualified name of to be substituted Class- Returns:
PatternParameterConfigurator
to support fluent API
-
byType
public PatternParameterConfigurator byType(CtTypeReference<?> type)
type referred byCtTypeReference
`type` and all the references (with same actual type arguments) to that type are subject for substitution by current parameter- Parameters:
type
- a fully qualified name of to be substituted Class- Returns:
PatternParameterConfigurator
to support fluent API
-
byLocalType
public PatternParameterConfigurator byLocalType(CtType<?> searchScope, String localTypeSimpleName)
Searches for a type visible in scope `templateType`, whose simple name is equal to `localTypeSimpleName`- Parameters:
searchScope
- the Type which is searched for local TypelocalTypeSimpleName
- the simple name of to be returned Type- Returns:
PatternParameterConfigurator
to support fluent API
-
byVariable
public PatternParameterConfigurator byVariable(String variableName)
variable read/write of `variable`- Parameters:
variableName
- a variable whose references will be substituted- Returns:
- this to support fluent API
-
byVariable
public PatternParameterConfigurator byVariable(CtVariable<?> variable)
variable read/write of `variable`- Parameters:
variable
- a variable whose references will be substituted- Returns:
PatternParameterConfigurator
to support fluent API
-
byInvocation
public PatternParameterConfigurator byInvocation(CtMethod<?> method)
each invocation of `method` will be replaces by parameter value- Parameters:
method
- the method whose invocation has to be substituted- Returns:
PatternParameterConfigurator
to support fluent API
-
byFieldAccessOnVariable
public PatternParameterConfigurator byFieldAccessOnVariable(String varName)
Add parameters for each field reference to variable named `variableName` For example this pattern model class Params { int paramA; int paramB; } void matcher(Params p) { return p.paramA + p.paramB; } called with `byFieldRefOfVariable("p")` will create pattern parameters: `paramA` and `paramB`- Parameters:
varName
- the name of the variable reference- Returns:
PatternParameterConfigurator
to support fluent API
-
byTemplateParameter
public PatternParameterConfigurator byTemplateParameter()
Creates pattern parameter for each field of typeTemplateParameter
- Returns:
- this to support fluent API
-
byTemplateParameter
public PatternParameterConfigurator byTemplateParameter(Map<String,Object> parameterValues)
Creates pattern parameter for each field of typeTemplateParameter
.
Note: This method is here for compatibility with obsolete legacyTemplate
based concept. We suggest to define each parameter individually using `byXxxx(...)` methods of this class instead.- Parameters:
parameterValues
- pattern parameter values. Note these values may influence the way how pattern parameters are created. This unclear and ambiguous technique was used in legacy templates- Returns:
- this to support fluent API
-
byParameterValues
public PatternParameterConfigurator byParameterValues(Map<String,Object> parameterValues)
Creates pattern parameter for each key of parameterValuesMap
. The parameter is created only if doesn't exist yet. If the parameter value is a CtTypeReference, then all local types whose simple name equals to parameter name are substituted Then any name in source code which contains a parameter name will be converted to parameter Note: This unclear and ambiguous technique was used in legacy templates We suggest to define each parameter individually using `byXxxx(...)` methods of this class instead.- Parameters:
parameterValues
- pattern parameter values or null if not known- Returns:
- this to support fluent API
-
byTemplateParameterReference
public PatternParameterConfigurator byTemplateParameterReference(CtVariable<?> variable)
variable read/write of `variable` of typeTemplateParameter
- Parameters:
variable
- a variable whose references will be substituted- Returns:
PatternParameterConfigurator
to support fluent API
-
byString
public PatternParameterConfigurator byString(String stringMarker)
All spoon model string attributes whose value is equal to `stringMarker` are subject for substitution by current parameter- Parameters:
stringMarker
- a string value which has to be substituted- Returns:
PatternParameterConfigurator
to support fluent API
-
bySubstring
public PatternParameterConfigurator bySubstring(String stringMarker)
All spoon model string attributes whose value contains whole string or a substring equal to `stringMarker` are subject for substitution by current parameter. Only the `stringMarker` substring of the string value is substituted!- Parameters:
stringMarker
- a string value which has to be substituted- Returns:
PatternParameterConfigurator
to support fluent API
-
byNamedElement
public PatternParameterConfigurator byNamedElement(String simpleName)
Any named element by it's simple name- Parameters:
simpleName
- simple name ofCtNamedElement
- Returns:
PatternParameterConfigurator
to support fluent API
-
byReferenceName
public PatternParameterConfigurator byReferenceName(String simpleName)
Any reference identified by it's simple name. Can be used to match any method call for instance. In some cases, the selected object is actually the parent of the reference (eg the invocation). This is implemented ingetSubstitutedNodeOfElement(ParameterInfo, CtElement)
- Parameters:
simpleName
- simple name ofCtReference
- Returns:
PatternParameterConfigurator
to support fluent API
-
byFilter
public PatternParameterConfigurator byFilter(Filter<?> filter)
All elements matched byFilter
will be substituted by parameter value- Parameters:
filter
-Filter
, which defines to be substituted elements- Returns:
PatternParameterConfigurator
to support fluent API
-
byElement
public PatternParameterConfigurator byElement(CtElement... elements)
Elements will be substituted by parameter value- Parameters:
elements
- to be substituted elements- Returns:
PatternParameterConfigurator
to support fluent API
-
byRole
public PatternParameterConfigurator byRole(CtRole role, Filter<?> filter)
Attribute defined by `role` of all elements matched byFilter
will be substituted by parameter value- Parameters:
role
-CtRole
, which defines to be substituted elementsfilter
-Filter
, which defines to be substituted elements- Returns:
PatternParameterConfigurator
to support fluent API
-
byRole
public PatternParameterConfigurator byRole(CtRole role, CtElement... elements)
Attribute defined by `role` of `element` will be substituted by parameter value- Parameters:
role
-CtRole
, which defines to be substituted elementselements
- to be substituted element- Returns:
PatternParameterConfigurator
to support fluent API
-
byCondition
public <T> PatternParameterConfigurator byCondition(Class<T> type, Predicate<T> matchCondition)
- Parameters:
type
- a required type of the value which matches as value of this parametermatchCondition
- aPredicate
which selects matching values- Returns:
- this to support fluent API
-
matchInlinedStatements
public PatternParameterConfigurator matchInlinedStatements()
marks a CtIf and CtForEach to be matched, even when inlined.- Returns:
- this to support fluent API
-
isSubstituted
public boolean isSubstituted(String paramName)
-
-