Package spoon.pattern.internal.node
Class ForEachNode
java.lang.Object
spoon.pattern.internal.node.AbstractNode
spoon.pattern.internal.node.ForEachNode
- All Implemented Interfaces:
Matchers
,InlineNode
,RepeatableMatcher
,RootNode
Pattern node of multiple occurrences of the same model, just with different parameters.
Example with three occurrences of model `System.out.println(_x_)`, with parameter `_x_`
System.out.println("a")
System.out.println("b")
System.out.println(getStringOf(p1, p2))
where parameter values are _x_ = ["a", "b", getStringOf(p1, p2)]-
Field Summary
Fields inherited from interface spoon.pattern.internal.node.RootNode
MATCH_ALL, MATCH_PART
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
forEachParameterInfo(BiConsumer<ParameterInfo,RootNode> consumer)
Calls consumer for each pair of parameter definition (ParameterInfo
) andRootNode
, which uses it<T> void
generateInlineTargets(DefaultGenerator generator, ResultHolder<T> result, ImmutableMap parameters)
Generates inline statements of this inlineRootNode
.<T> void
generateTargets(DefaultGenerator generator, ResultHolder<T> result, ImmutableMap parameters)
Generates zero, one or more target depending on kind of thisRootNode
, expected `result` and input `parameters`If twoRepeatableMatcher
s in a list are matching the same element, then returnedQuantifier
defines how resolve this conflictboolean
isMandatory(ImmutableMap parameters)
boolean
boolean
isTryNextMatch(ImmutableMap parameters)
matchAllWith(TobeMatched tobeMatched)
Matches all matchers of thisMatchers
instance with `targets`matchTargets(TobeMatched targets, Matchers next)
boolean
replaceNode(RootNode oldNode, RootNode newNode)
Call it to modify Pattern structure.void
setIterableParameter(PrimitiveMatcher substRequestOfIterable)
void
setLocalParameter(ParameterInfo parameterInfo)
void
setNestedModel(RootNode valueResolver)
Methods inherited from class spoon.pattern.internal.node.AbstractNode
isSimplifyGenerated, setSimplifyGenerated, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface spoon.pattern.internal.node.RootNode
isSimplifyGenerated, matchTargets, setSimplifyGenerated
-
Constructor Details
-
ForEachNode
public ForEachNode()
-
-
Method Details
-
replaceNode
Description copied from interface:RootNode
Call it to modify Pattern structure. It is actually called mainly by PatternBuilder. TODO: May be we can move this method into some internal interface?- Specified by:
replaceNode
in interfaceRootNode
- Parameters:
oldNode
- oldRootNode
newNode
- newRootNode
- Returns:
- a true if `oldNode` was found in this
RootNode
or it's children and replaced by `newNode` false if `oldNode` was not found
-
generateTargets
public <T> void generateTargets(DefaultGenerator generator, ResultHolder<T> result, ImmutableMap parameters)Description copied from interface:RootNode
Generates zero, one or more target depending on kind of thisRootNode
, expected `result` and input `parameters`- Specified by:
generateTargets
in interfaceRootNode
- Parameters:
generator
-Generator
which drives generation processresult
- holder for the generated objectsparameters
- aImmutableMap
holding parameters
-
getMatchingStrategy
Description copied from interface:RepeatableMatcher
If twoRepeatableMatcher
s in a list are matching the same element, then returnedQuantifier
defines how resolve this conflict- Specified by:
getMatchingStrategy
in interfaceRepeatableMatcher
- Returns:
Quantifier
-
matchAllWith
Description copied from interface:Matchers
Matches all matchers of thisMatchers
instance with `targets`- Specified by:
matchAllWith
in interfaceMatchers
- Specified by:
matchAllWith
in interfaceRootNode
- Parameters:
tobeMatched
- to be matched target nodes and input parameters- Returns:
TobeMatched
with targets which remained after allRootNode
s were matched + matched parameters
-
forEachParameterInfo
Description copied from interface:RootNode
Calls consumer for each pair of parameter definition (ParameterInfo
) andRootNode
, which uses it- Specified by:
forEachParameterInfo
in interfaceRootNode
- Parameters:
consumer
- the receiver of pairs ofParameterInfo
andRootNode
-
setNestedModel
-
setIterableParameter
-
setLocalParameter
-
isRepeatable
public boolean isRepeatable()- Specified by:
isRepeatable
in interfaceRepeatableMatcher
- Returns:
- true if this matcher can be applied more then 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:
isMandatory
in interfaceRepeatableMatcher
- Parameters:
parameters
- matching parameters- Returns:
- true if this ValueResolver MUST match with next target in the state defined by current `parameters`. false if match is optional
-
isTryNextMatch
- Specified by:
isTryNextMatch
in interfaceRepeatableMatcher
- Parameters:
parameters
- matching parameters- Returns:
- true if this ValueResolver should be processed again to match next target in the state defined by current `parameters`.
-
generateInlineTargets
public <T> void generateInlineTargets(DefaultGenerator generator, ResultHolder<T> result, ImmutableMap parameters)Description copied from interface:InlineNode
Generates inline statements of this inlineRootNode
. This method is used when sources of pattern have to be printed- Specified by:
generateInlineTargets
in interfaceInlineNode
- Parameters:
generator
- a to be usedGenerator
result
- holder of the resultparameters
- aImmutableMap
with current parameters
-
matchTargets
- Specified by:
matchTargets
in interfaceRootNode
- Parameters:
targets
- to be matched target nodes and input parametersnext
- Chain of matchers which has to be processed after thisRootNode
- Returns:
- new parameters and container with remaining targets
-