Package org.eclipse.handly.model.impl.support

## 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 their `occurrence count`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### StructureHelper

          public StructureHelper()

  - ### 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 (not `null`)
        `child` - the handle for a child element (not `null`)
      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 (not `null`)
      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 their `occurrence count`.
      Parameters:
        `element` - a source construct (not `null`)