Package spoon.pattern
Class PatternParameterConfigurator
java.lang.Object
spoon.pattern.PatternParameterConfigurator
Used to define pattern parameters.
Main documentation at http://spoon.gforge.inria.fr/pattern.html.
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionbyCondition(Class<T> type, Predicate<T> matchCondition)
Elements will be substituted by parameter valuebyFieldAccessOnVariable(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`All elements matched byFilter
will be substituted by parameter valuebyInvocation(CtMethod<?> method)
each invocation of `method` will be replaces by parameter valuebyLocalType(CtType<?> searchScope, String localTypeSimpleName)
Searches for a type visible in scope `templateType`, whose simple name is equal to `localTypeSimpleName`byNamedElement(String simpleName)
Any named element by it's simple namebyParameterValues(Map<String,Object> parameterValues)
Creates pattern parameter for each key of parameterValuesMap
.byReferenceName(String simpleName)
Any reference identified by it's simple name.Attribute defined by `role` of `element` will be substituted by parameter valueAttribute defined by `role` of all elements matched byFilter
will be substituted by parameter valueAll spoon model string attributes whose value is equal to `stringMarker` are subject for substitution by current parameterbySubstring(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.Creates pattern parameter for each field of typeTemplateParameter
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.byTemplateParameterReference(CtVariable<?> variable)
variable read/write of `variable` of typeTemplateParameter
`type` itself and all the references to the `type` are subject for substitution by current parametertype identified by `typeQualifiedName` itself and all the references (with arbitrary actual type arguments) to that type are subject for substitution by current parameterbyType(CtTypeReference<?> type)
type referred byCtTypeReference
`type` and all the references (with same actual type arguments) to that type are subject for substitution by current parameterbyVariable(String variableName)
variable read/write of `variable`byVariable(CtVariable<?> variable)
variable read/write of `variable`boolean
isSubstituted(String paramName)
marks a CtIf and CtForEach to be matched, even when inlined.Creates a parameter with name `paramName` and assigns it into context, so next calls on builder will be applied to this parametersetConflictResolutionMode(ConflictResolutionMode conflictResolutionMode)
setContainerKind(ContainerKind containerKind)
Defines type of parameter value (List/Set/Map/single).setMatchingStrategy(Quantifier quantifier)
setMaxOccurrence(int maxOccurrence)
setMinOccurrence(int minOccurrence)
setValueType(Class<?> valueType)
Set expected type of Parameter.
-
Method Details
-
getConflictResolutionMode
- Returns:
- current
ConflictResolutionMode
-
setConflictResolutionMode
public PatternParameterConfigurator setConflictResolutionMode(ConflictResolutionMode conflictResolutionMode)- Parameters:
conflictResolutionMode
- to be applied mode- Returns:
- this to support fluent API
-
queryModel
-
parameter
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
-
setMaxOccurrence
-
setMatchingStrategy
-
setValueType
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
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
-
byType
`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
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
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
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
variable read/write of `variable`- Parameters:
variableName
- a variable whose references will be substituted- Returns:
- this to support fluent API
-
byVariable
variable read/write of `variable`- Parameters:
variable
- a variable whose references will be substituted- Returns:
PatternParameterConfigurator
to support fluent API
-
byInvocation
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
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
Creates pattern parameter for each field of typeTemplateParameter
- Returns:
- this to support fluent API
-
byTemplateParameter
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
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
variable read/write of `variable` of typeTemplateParameter
- Parameters:
variable
- a variable whose references will be substituted- Returns:
PatternParameterConfigurator
to support fluent API
-
byString
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
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
Any named element by it's simple name- Parameters:
simpleName
- simple name ofCtNamedElement
- Returns:
PatternParameterConfigurator
to support fluent API
-
byReferenceName
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
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
Elements will be substituted by parameter value- Parameters:
elements
- to be substituted elements- Returns:
PatternParameterConfigurator
to support fluent API
-
byRole
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
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
- 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
marks a CtIf and CtForEach to be matched, even when inlined.- Returns:
- this to support fluent API
-
isSubstituted
-