Package spoon.pattern.internal.node
Class SwitchNode
java.lang.Object
spoon.pattern.internal.node.AbstractNode
spoon.pattern.internal.node.SwitchNode
- All Implemented Interfaces:
Matchers
,InlineNode
,RootNode
List of conditional cases
{code}
if (a) {
... someStatements if a == true..
} else if (b) {
... someStatements if b == true..
} else {
... someStatements in other cases ...
}
-
Field Summary
Fields inherited from interface spoon.pattern.internal.node.RootNode
MATCH_ALL, MATCH_PART
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCase(PrimitiveMatcher vrOfExpression, RootNode statement)
Adds another case into this switch statementvoid
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`matchTargets(TobeMatched targets, Matchers nextMatchers)
boolean
replaceNode(RootNode oldNode, RootNode newNode)
Call it to modify Pattern structure.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, matchAllWith, setSimplifyGenerated
-
Constructor Details
-
SwitchNode
public SwitchNode()
-
-
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
-
addCase
Adds another case into this switch statement- Parameters:
vrOfExpression
- if value of this parameter is true then statement has to be used. If vrOfExpression is null, then statement is always usedstatement
- optional statement
-
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
-
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
-
matchTargets
- Specified by:
matchTargets
in interfaceRootNode
- Parameters:
targets
- to be matched target nodes and input parametersnextMatchers
- Chain of matchers which has to be processed after thisRootNode
- Returns:
- new parameters and container with remaining targets
-
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
-