当前位置: 首页>>代码示例>>Java>>正文


Java Node.hasMoreThanOneChild方法代码示例

本文整理汇总了Java中com.google.javascript.rhino.Node.hasMoreThanOneChild方法的典型用法代码示例。如果您正苦于以下问题:Java Node.hasMoreThanOneChild方法的具体用法?Java Node.hasMoreThanOneChild怎么用?Java Node.hasMoreThanOneChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.javascript.rhino.Node的用法示例。


在下文中一共展示了Node.hasMoreThanOneChild方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeChild

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/** Safely remove children while maintaining a valid node structure. */
static void removeChild(Node parent, Node node) {
  // Node parent = node.getParent();
  if (isStatementBlock(parent)
      || isSwitchCase(node)
      || isTryFinallyNode(parent, node)) {
    // A statement in a block can simply be removed.
    parent.removeChild(node);
  } else if (parent.getType() == Token.VAR) {
    if (parent.hasMoreThanOneChild()) {
      parent.removeChild(node);
    } else {
      // Remove the node from the parent, so it can be reused.
      parent.removeChild(node);
      // This would leave an empty VAR, remove the VAR itself.
      removeChild(parent.getParent(), parent);
    }
  } else if (node.getType() == Token.BLOCK) {
    // Simply empty the block.  This maintains source location and
    // "synthetic"-ness.
    node.detachChildren();
  } else if (parent.getType() == Token.LABEL
      && node == parent.getLastChild()) {
    // Remove the node from the parent, so it can be reused.
    parent.removeChild(node);
    // A LABEL without children can not be referred to, remove it.
    removeChild(parent.getParent(), parent);
  } else if (parent.getType() == Token.FOR
      && parent.getChildCount() == 4) {
    // Only Token.FOR can have an Token.EMPTY other control structure
    // need something for the condition. Others need to be replaced
    // or the structure removed.
    parent.replaceChild(node, new Node(Token.EMPTY));
  } else {
    throw new IllegalStateException("Invalid attempt to remove node: " +
        node.toString() + " of "+ parent.toString());
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:39,代码来源:NodeUtil.java


注:本文中的com.google.javascript.rhino.Node.hasMoreThanOneChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。