Package spoon.pattern.internal.node
Class ElementNode
java.lang.Object
spoon.pattern.internal.node.AbstractNode
spoon.pattern.internal.node.ElementNode
- All Implemented Interfaces:
Matchers
,PrimitiveMatcher
,RepeatableMatcher
,RootNode
Generates/Matches a copy of a single CtElement AST node with all it's children (whole AST tree of the root CtElement)
-
Field Summary
Fields inherited from interface spoon.pattern.internal.node.RootNode
MATCH_ALL, MATCH_PART
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ListOfNodes
Same likecreate(CtElement, Map)
but withList
of elements or primitive objectsstatic ListOfNodes
Same likecreate(CtElement, Map)
but withMap
of String to elements or primitive objectsstatic ListOfNodes
Same likecreate(CtElement, Map)
but withSet
of elements or primitive objectsstatic ElementNode
Creates an implicitElementNode
, which contains all non derived attributes of `element` and all it's childrenvoid
forEachParameterInfo(BiConsumer<ParameterInfo,RootNode> consumer)
Calls consumer for each pair of parameter definition (ParameterInfo
) andRootNode
, which uses itprotected void
generateSingleNodeAttributes(DefaultGenerator generator, CtElement clone, ImmutableMap parameters)
<U> void
generateTargets(DefaultGenerator generator, ResultHolder<U> 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 conflictgetNodeOfRole(CtRole attributeRole)
getOrCreateNodeOfRole(CtRole role, Map<CtElement,RootNode> patternElementToSubstRequests)
<T> @Nullable T
getValueOfRole(CtRole role, Class<T> type)
boolean
isTryNextMatch(ImmutableMap parameters)
matchAllWith(TobeMatched tobeMatched)
Matches all matchers of thisMatchers
instance with `targets`protected ImmutableMap
matchesRole(ImmutableMap parameters, CtElement target, MetamodelProperty mmField, RootNode attrNode)
matchTarget(Object target, ImmutableMap parameters)
matchTargets(TobeMatched targets, Matchers next)
boolean
replaceNode(RootNode oldNode, RootNode newNode)
Call it to modify Pattern structure.void
setElementType(MetamodelConcept elementType)
setNodeOfRole(CtRole role, RootNode newAttrNode)
toString()
Methods inherited from class spoon.pattern.internal.node.AbstractNode
isSimplifyGenerated, setSimplifyGenerated
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.RepeatableMatcher
isMandatory, isRepeatable
Methods inherited from interface spoon.pattern.internal.node.RootNode
isSimplifyGenerated, matchTargets, setSimplifyGenerated
-
Constructor Details
-
ElementNode
- Parameters:
elementType
- The type of Spoon node which has to be generated/matched by thisElementNode
templateElement
- - optional ref to template element which was used to created thisElementNode
. It is used e.g. to generate generatedBy comment
-
-
Method Details
-
create
public static ElementNode create(CtElement element, Map<CtElement,RootNode> patternElementToSubstRequests)Creates an implicitElementNode
, which contains all non derived attributes of `element` and all it's children- Parameters:
element
- source element, which is used to initializeElementNode
patternElementToSubstRequests
- theMap
, which will receive mapping between `element` and it's children and newly created tree ofElementNode
s- Returns:
- a tree of
ElementNode
s, which reflects tree of `element`
-
create
public static ListOfNodes create(List<?> objects, Map<CtElement,RootNode> patternElementToSubstRequests)Same likecreate(CtElement, Map)
but withList
of elements or primitive objects- Parameters:
objects
- List of objects which has to be transformed to nodespatternElementToSubstRequests
- mapping betweenCtElement
from `objects` to created `node`- Returns:
- a list of trees of nodes, which reflects list of `objects`
-
create
public static ListOfNodes create(Set<?> templates, Map<CtElement,RootNode> patternElementToSubstRequests)Same likecreate(CtElement, Map)
but withSet
of elements or primitive objects- Parameters:
templates
- Set of objects which has to be transformed to nodespatternElementToSubstRequests
- mapping betweenCtElement
from `templates` to created `node`- Returns:
- a list of trees of nodes, which reflects Set of `templates`
-
create
public static ListOfNodes create(Map<String,?> map, Map<CtElement,RootNode> patternElementToSubstRequests)Same likecreate(CtElement, Map)
but withMap
of String to elements or primitive objects- Parameters:
map
- Map of objects which has to be transformed to nodespatternElementToSubstRequests
- mapping betweenCtElement
from `map` to created `node`- Returns:
- a list of
MapEntryNode
s, which reflects `map`
-
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? -
getRoleToNode
-
getNodeOfRole
-
setNodeOfRole
-
getOrCreateNodeOfRole
public RootNode getOrCreateNodeOfRole(CtRole role, Map<CtElement,RootNode> patternElementToSubstRequests)- Parameters:
role
-- Returns:
- a
RootNode
, which exists on the `role` or creates implicit container for that role
-
getValueOfRole
- Parameters:
role
- to be returnedCtRole
type
- required type of returned value- Returns:
- value of
ConstantNode
on the `role` attribute of thisElementNode
or null if there is none or has different type
-
forEachParameterInfo
Description copied from interface:RootNode
Calls consumer for each pair of parameter definition (ParameterInfo
) andRootNode
, which uses it- Parameters:
consumer
- the receiver of pairs ofParameterInfo
andRootNode
-
generateTargets
public <U> void generateTargets(DefaultGenerator generator, ResultHolder<U> result, ImmutableMap parameters)Description copied from interface:RootNode
Generates zero, one or more target depending on kind of thisRootNode
, expected `result` and input `parameters`- Parameters:
generator
-Generator
which drives generation processresult
- holder for the generated objectsparameters
- aImmutableMap
holding parameters
-
generateSingleNodeAttributes
protected void generateSingleNodeAttributes(DefaultGenerator generator, CtElement clone, ImmutableMap parameters) -
matchTarget
- Parameters:
target
- - to be matched elementparameters
- will receive the matching parameter values- Returns:
- true if `element` matches with pattern of this matcher
-
matchesRole
protected ImmutableMap matchesRole(ImmutableMap parameters, CtElement target, MetamodelProperty mmField, RootNode attrNode) -
toString
- Overrides:
toString
in classAbstractNode
-
getElementType
-
setElementType
-
getMatchingStrategy
Description copied from interface:RepeatableMatcher
If twoRepeatableMatcher
s in a list are matching the same element, then returnedQuantifier
defines how resolve this conflict- Returns:
Quantifier
-
isTryNextMatch
- Parameters:
parameters
- matching parameters- Returns:
- true if this ValueResolver should be processed again to match next target in the state defined by current `parameters`.
-
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
-
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
-