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
public class SwitchNode extends AbstractNode implements InlineNode
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
Constructors Constructor Description SwitchNode()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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`TobeMatched
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
-
-
-
-
Method Detail
-
replaceNode
public boolean replaceNode(RootNode oldNode, RootNode newNode)
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
public void addCase(PrimitiveMatcher vrOfExpression, RootNode statement)
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
public void forEachParameterInfo(BiConsumer<ParameterInfo,RootNode> consumer)
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
public TobeMatched matchTargets(TobeMatched targets, Matchers nextMatchers)
- 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
-
-