private void compactNodes(T node) { for (int i = 0; i < node.getChildCount(); i++) { MPSTreeNode child = (MPSTreeNode) node.getChildAt(i); if (myBuilder.isNamespaceNode(child)) { compactNodes((T) child); } } if (node.getParent() != null && // skip root node.getChildCount() == 1 && myBuilder.isNamespaceNode((MPSTreeNode) node.getChildAt(0))) { T child = (T) node.getChildAt(0); myBuilder.setName(node, myBuilder.getName(node) + "." + myBuilder.getName(child)); Enumeration children = child.children(); List<MPSTreeNode> oldChildren = new ArrayList<MPSTreeNode>(); while (children.hasMoreElements()) { oldChildren.add((MPSTreeNode) children.nextElement()); } for (MPSTreeNode c : oldChildren) { child.remove(c); node.add(c); } node.remove(child); } }
public static <T extends DomElement> T addElementAfter(@NotNull final T anchor) { final DomElement parent = anchor.getParent(); final DomCollectionChildDescription childDescription = (DomCollectionChildDescription) anchor.getChildDescription(); assert parent != null; final List<? extends DomElement> list = childDescription.getValues(parent); final int i = list.indexOf(anchor); assert i >= 0; return (T) childDescription.addValue(parent, i + 1); }