Package spoon.pattern.internal.parameter
Class AbstractParameterInfo
java.lang.Object
spoon.pattern.internal.parameter.AbstractParameterInfo
- All Implemented Interfaces:
ParameterInfo
- Direct Known Subclasses:
ComputedParameterInfo,ListParameterInfo,MapParameterInfo,SetParameterInfo
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static Objectis used as return value when value cannot be addedFields inherited from interface spoon.pattern.internal.parameter.ParameterInfo
UNLIMITED_OCCURRENCES -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractParameterInfo(ParameterInfo containerItemAccessor) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract ObjectaddValueAs(Object container, Function<Object,Object> merger)takes existing item value from the `container`, sends it as parameter into `merger` and get's new to be stored value stores that value into new `container` and returns itaddValueAs(ImmutableMap parameters, Object value)Matches `value` into `parameters` under the name/structure defined by this ParameterInfo.protected ObjectaddValueToContainer(Object container, Function<Object,Object> merger)protected <T> Tprotected <T> TconvertSingleValue(Factory factory, Object value, Class<T> type)protected <T> voidconvertValue(Factory factory, ResultHolder<T> result, Object rawValue)protected ContainerKindgetContainerKind(Object existingValue, Object value)protected ContainerKindgetContainerKind(ImmutableMap params)protected AbstractParameterInfogetContainerKindAccessor(ContainerKind containerKind)protected Stringprotected abstract <T> TintintgetName()Class<?>protected abstract Stringprotected ObjectgetValue(ImmutableMap parameters)<T> voidgetValueAs(Factory factory, ResultHolder<T> result, ImmutableMap parameters)Takes the value of parameter identified by thisParameterInfofrom the `parameters` and adds that 0, 1 or more values into result (depending on type of result)protected abstract StringgetWrappedName(String containerName)booleanisMandatory(ImmutableMap parameters)booleanbooleanbooleanisTryNextMatch(ImmutableMap parameters)protected booleanChecks whether `value` matches with required type and match condition.protected Objectprotected ObjectmergeSingle(Object existingValue, Object newValue)setContainerKind(ContainerKind containerKind)setMatchCondition(Class<T> requiredType, Predicate<T> matchCondition)voidsetMatchingStrategy(Quantifier matchingStrategy)voidsetMaxOccurrences(int maxOccurrences)setMinOccurrences(int minOccurrences)setParameterValueType(Class<?> parameterValueType)setRepeatable(boolean repeatable)setValueConvertor(ValueConvertor valueConvertor)toString()
-
Field Details
-
NO_MERGE
is used as return value when value cannot be added
-
-
Constructor Details
-
AbstractParameterInfo
-
-
Method Details
-
getContainerName
-
getName
- Specified by:
getNamein interfaceParameterInfo- Returns:
- the full name of the parameter from the root of parameter container to the value represented by this
ParameterInfo
-
getPlainName
-
getWrappedName
-
addValueAs
Description copied from interface:ParameterInfoMatches `value` into `parameters` under the name/structure defined by this ParameterInfo. 1) checks that value matches with optional internal rules of thisParameterInfo2) creates new copy ofImmutableMapwhich contains the new `value` and returns that copy- Specified by:
addValueAsin interfaceParameterInfo- Parameters:
parameters- the existing parametersvalue- the new, to be stored value- Returns:
- copy of `parameters` with new value or existing `parameters` if value is already there or null if value doesn't fit into these parameters
-
addValueToContainer
-
merge
-
getContainerKindAccessor
-
mergeSingle
-
addValueAs
takes existing item value from the `container`, sends it as parameter into `merger` and get's new to be stored value stores that value into new `container` and returns it- Parameters:
container- a container of valuesmerger- a code which merges existing value from container with new value and returns merged value, which has to be stored in the container instead- Returns:
- copy of the container with merged value
-
castTo
-
getEmptyContainer
protected abstract <T> T getEmptyContainer() -
setMatchCondition
public <T> AbstractParameterInfo setMatchCondition(Class<T> requiredType, Predicate<T> matchCondition)- Parameters:
requiredType- a required type of the value which matches as value of this parametermatchCondition- aPredicatewhich selects matching values- Returns:
-
matches
Checks whether `value` matches with required type and match condition.- Parameters:
value-- Returns:
-
getParameterValueType
- Specified by:
getParameterValueTypein interfaceParameterInfo- Returns:
- a type of parameter value - if known Note: Pattern builder needs to know the value type to be able to select substitute node. For example patter: return _expression_.S(); either replaces only `_expression_.S()` if the parameter value is an expression or replaces `return _expression_.S()` if the parameter value is a CtBlock
-
setParameterValueType
- Parameters:
parameterValueType- a type of the value which is acceptable by this parameter- Returns:
- this to support fluent API
-
isMultiple
public boolean isMultiple()- Specified by:
isMultiplein interfaceParameterInfo- Returns:
- true if the value container has to be a List, otherwise the container will be a single value
-
setRepeatable
- Parameters:
repeatable- if this matcher can be applied more than once in the same container of targets Note: even if false, it may be applied again to another container and to match EQUAL value.- Returns:
- this to support fluent API
-
getMinOccurrences
public int getMinOccurrences() -
setMinOccurrences
-
getMaxOccurrences
public int getMaxOccurrences()- Returns:
- maximum number of values in this parameter.
Note: if
isMultiple()==false, then it never returns value > 1
-
setMaxOccurrences
public void setMaxOccurrences(int maxOccurrences) -
getMatchingStrategy
- Specified by:
getMatchingStrategyin interfaceParameterInfo- Returns:
- the strategy used to resolve conflict between two
RootNodes
-
setMatchingStrategy
-
getValueConvertor
- Returns:
- the
ValueConvertorused by reading and writing into parameter values defined by thisParameterInfo
-
setValueConvertor
- Parameters:
valueConvertor- theValueConvertorused by reading and writing into parameter values defined by thisParameterInfo
-
isRepeatable
public boolean isRepeatable()- Specified by:
isRepeatablein interfaceParameterInfo- Returns:
- true if this matcher can be applied more than once in the same container of targets Note: even if false, it may be applied again to another container and to match EQUAL value
-
isMandatory
- Specified by:
isMandatoryin interfaceParameterInfo- Parameters:
parameters- matching parameters- Returns:
- true if the ValueResolver of this parameter MUST match with next target in the state defined by current `parameters`. false if match is optional
-
isTryNextMatch
- Specified by:
isTryNextMatchin interfaceParameterInfo- Parameters:
parameters- matching parameters- Returns:
- true if the ValueResolver of this parameter should be processed again to match next target in the state defined by current `parameters`.
-
getContainerKind
-
setContainerKind
-
getContainerKind
-
getContainerKind
-
getValueAs
Description copied from interface:ParameterInfoTakes the value of parameter identified by thisParameterInfofrom the `parameters` and adds that 0, 1 or more values into result (depending on type of result)- Specified by:
getValueAsin interfaceParameterInfo- Parameters:
factory- the factory used to create new entities if conversion of value is needed before it can be added into `result`result- the receiver of the result value. It defined required type of returned value and multiplicity of returned valueparameters- here are stored all the parameter values
-
getValue
-
convertValue
-
convertSingleValue
-
toString
-