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.
  • Method Details

    • getConflictResolutionMode

      public ConflictResolutionMode getConflictResolutionMode()
      Returns:
      current ConflictResolutionMode
    • setConflictResolutionMode

      public PatternParameterConfigurator setConflictResolutionMode(ConflictResolutionMode conflictResolutionMode)
      Defines what happens when before explicitly added RootNode has to be replaced by another RootNode
      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. See ValueConvertor, 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 is ContainerKind.SINGLE
      Parameters:
      containerKind - to be used ContainerKind
      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 by CtTypeReference `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 Type
      localTypeSimpleName - 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 type TemplateParameter
      Returns:
      this to support fluent API
    • byTemplateParameter

      public PatternParameterConfigurator byTemplateParameter(Map<String,​Object> parameterValues)
      Creates pattern parameter for each field of type TemplateParameter.
      Note: This method is here for compatibility with obsolete legacy Template 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 parameterValues Map. 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 type TemplateParameter
      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 of CtNamedElement
      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 in getSubstitutedNodeOfElement(ParameterInfo, CtElement)
      Parameters:
      simpleName - simple name of CtReference
      Returns:
      PatternParameterConfigurator to support fluent API
    • byFilter

      public PatternParameterConfigurator byFilter(Filter<?> filter)
      All elements matched by Filter 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 by Filter will be substituted by parameter value
      Parameters:
      role - CtRole, which defines to be substituted elements
      filter - 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 elements
      elements - 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 parameter
      matchCondition - a Predicate 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)