Class StructureHelper
java.lang.Object
org.eclipse.handly.model.impl.support.StructureHelper
A helper class that is typically used when building the inner structure of a
source file. A typical usage pattern is as follows:
Body parentBody = new ...; // for each child element SourceConstruct element = new ...; helper.resolveDuplicates(element); Body body = new ...; // create and initialize the body newElements.put(element, body); helper.pushChild(parentBody, element); parentBody.setChildren(helper.popChildren(parentBody).toArray(...));
Note that calling parentBody.addChild(element)
for each child
element would generally be less efficient than using the pattern shown above.
Clients can use this class as it stands or subclass it as circumstances warrant.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionpopChildren
(Object body) Retrieves and forgets the child elements previously remembered for the given body.final void
Remembers the given element as a child for the given parent body.void
Resolves duplicate source constructs by incrementing theiroccurrence count
.
-
Constructor Details
-
StructureHelper
public StructureHelper()
-
-
Method Details
-
pushChild
Remembers the given element as a child for the given parent body. If the given element has already been remembered as a child for a body, the behavior is unspecified.- Parameters:
parentBody
- the body of a parent element (notnull
)child
- the handle for a child element (notnull
)- See Also:
-
popChildren
Retrieves and forgets the child elements previously remembered for the given body. The returned children are in the order in which they were remembered.- Parameters:
body
- a body (notnull
)- Returns:
- a list of child elements for the given body, possibly empty
(never
null
) - See Also:
-
resolveDuplicates
Resolves duplicate source constructs by incrementing theiroccurrence count
.- Parameters:
element
- a source construct (notnull
)
-