Package spoon.pattern

Class PatternParameterConfigurator


  • public class PatternParameterConfigurator
    extends Object
    Used to define pattern parameters. Main documentation at http://spoon.gforge.inria.fr/pattern.html.
    • Method Detail

      • 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
      • 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
      • 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
      • getCurrentParameter

        public ParameterInfo getCurrentParameter()
      • 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
      • 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
      • 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​(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
      • 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
      • 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)