コード例 #1
0
  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);
    }
  }
コード例 #2
0
  private T getSubnamespace(T sourceNode, List<String> pathElements, IOperationContext context) {
    if (pathElements.size() == 0) return sourceNode;

    String first = pathElements.get(0);
    List<String> otherElements = pathElements.subList(1, pathElements.size());

    for (int i = 0; i < sourceNode.getChildCount(); i++) {
      if (myBuilder.isNamespaceNode((MPSTreeNode) sourceNode.getChildAt(i))) {
        T child = (T) sourceNode.getChildAt(i);
        if (first.equals(myBuilder.getName(child))) {
          return getSubnamespace(child, otherElements, context);
        }
      }
    }

    IModule module = (context != null) ? context.getModule() : null;
    T newChild =
        myBuilder.createNamespaceNode(first, new ModuleChangingOperationContext(module, context));

    sourceNode.add(newChild);

    return getSubnamespace(newChild, otherElements, context);
  }