Class StructureHelper
- java.lang.Object
-
- org.eclipse.handly.model.impl.support.StructureHelper
-
public class StructureHelper extends java.lang.Object
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
Constructors Constructor Description StructureHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<IElement>
popChildren(java.lang.Object body)
Retrieves and forgets the child elements previously remembered for the given body.void
pushChild(java.lang.Object parentBody, IElement child)
Remembers the given element as a child for the given parent body.void
resolveDuplicates(ISourceConstructImplExtension element)
Resolves duplicate source constructs by incrementing theiroccurrence count
.
-
-
-
Method Detail
-
pushChild
public final void pushChild(java.lang.Object parentBody, IElement child)
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(Object)
-
popChildren
public final java.util.List<IElement> popChildren(java.lang.Object body)
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:
pushChild(Object, IElement)
-
resolveDuplicates
public void resolveDuplicates(ISourceConstructImplExtension element)
Resolves duplicate source constructs by incrementing theiroccurrence count
.- Parameters:
element
- a source construct (notnull
)
-
-