net.sourceforge.pmd.lang.ast.Node.jjtGetChild()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中net.sourceforge.pmd.lang.ast.Node.jjtGetChild()方法的一些代码示例,展示了Node.jjtGetChild()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.jjtGetChild()方法的具体详情如下:
包路径:net.sourceforge.pmd.lang.ast.Node
类名称:Node
方法名:jjtGetChild

Node.jjtGetChild介绍

[英]This method returns a child node. The children are numbered from zero, left to right.
[中]此方法返回一个子节点。孩子们从零开始编号,从左到右。

代码示例

代码示例来源:origin: pmd/pmd

private ASTCatchStatement getCatch(Node n) {
    for (int i = 0; i < n.jjtGetNumChildren(); i++) {
      if (n.jjtGetChild(i) instanceof ASTCatchStatement) {
        return (ASTCatchStatement) n.jjtGetChild(i);
      }
    }
    return null;
  }
}

代码示例来源:origin: pmd/pmd

protected Node getNextSibling(Node contextNode) {
  Node parentNode = contextNode.jjtGetParent();
  if (parentNode != null) {
    int nextPosition = contextNode.jjtGetChildIndex() + 1;
    if (nextPosition < parentNode.jjtGetNumChildren()) {
      return parentNode.jjtGetChild(nextPosition);
    }
  }
  return null;
}

代码示例来源:origin: pmd/pmd

private Node skipAnnotations(Node p) {
    int index = 0;
    Node n = p.jjtGetChild(index++);
    while (n instanceof ASTAnnotation && index < p.jjtGetNumChildren()) {
      n = p.jjtGetChild(index++);
    }
    return n;
  }
}

代码示例来源:origin: pmd/pmd

private Node getNextSibling(Node current) {
  if (current.jjtGetParent().jjtGetNumChildren() > current.jjtGetChildIndex() + 1) {
    return current.jjtGetParent().jjtGetChild(current.jjtGetChildIndex() + 1);
  }
  return null;
}

代码示例来源:origin: pmd/pmd

private boolean hasAssignmentOperator(Node node) {
  if (node instanceof ASTStatementExpression || node instanceof ASTExpression) {
    if (node.jjtGetNumChildren() >= 2 && node.jjtGetChild(1) instanceof ASTAssignmentOperator) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: pmd/pmd

private boolean couldBeMethodCall(JavaNode node) {
  if (node.getNthParent(2) instanceof ASTPrimaryExpression && node.getNthParent(1) instanceof ASTPrimaryPrefix) {
    int nextSibling = node.jjtGetParent().jjtGetChildIndex() + 1;
    if (node.getNthParent(2).jjtGetNumChildren() > nextSibling) {
      return node.getNthParent(2).jjtGetChild(nextSibling) instanceof ASTPrimarySuffix;
    }
  }
  return false;
}

代码示例来源:origin: pmd/pmd

protected Node getFirstChild(Node contextNode) {
  if (contextNode.jjtGetNumChildren() > 0) {
    return contextNode.jjtGetChild(0);
  } else {
    return null;
  }
}

代码示例来源:origin: pmd/pmd

private boolean isAppendingStringLiteral(Node node) {
  Node n = node;
  while (n.jjtGetNumChildren() != 0 && !(n instanceof ASTLiteral)) {
    n = n.jjtGetChild(0);
  }
  return n instanceof ASTLiteral;
}

代码示例来源:origin: pmd/pmd

private Node getFirstChildOrThis(Node node) {
  if (node.jjtGetNumChildren() > 0) {
    return node.jjtGetChild(0);
  }
  return node;
}

代码示例来源:origin: pmd/pmd

private boolean hasOneBlockStmt(Node node) {
  return node.jjtGetChild(0) instanceof ASTBlock && node.jjtGetChild(0).jjtGetNumChildren() == 1
      && terminatesInBooleanLiteral(node.jjtGetChild(0).jjtGetChild(0));
}

代码示例来源:origin: pmd/pmd

/**
 * Returns the first child node going down 'level' levels or null if level
 * is invalid
 */
private Node getDescendant(Node node, int level) {
  Node n = node;
  for (int i = 0; i < level; i++) {
    if (n.jjtGetNumChildren() == 0) {
      return null;
    }
    n = n.jjtGetChild(0);
  }
  return n;
}

代码示例来源:origin: pmd/pmd

private boolean hasName(Node n) {
  return n.jjtGetNumChildren() > 0 && n.jjtGetChild(0) instanceof ASTName;
}

代码示例来源:origin: pmd/pmd

protected Node getLastChild(Node contextNode) {
    if (contextNode.jjtGetNumChildren() > 0) {
      return contextNode.jjtGetChild(contextNode.jjtGetNumChildren() - 1);
    } else {
      return null;
    }
  }
}

代码示例来源:origin: pmd/pmd

private void moveToNext() {
  while (i < parent.jjtGetNumChildren() && !(targetChildType.isInstance(parent.jjtGetChild(i)))) {
    i++;
  }
}

代码示例来源:origin: pmd/pmd

private boolean hasNameAsChild(Node node) {
  if (node.jjtGetNumChildren() > 0) {
    if (node.jjtGetChild(0) instanceof ASTName) {
      return true;
    } else {
      return hasNameAsChild(node.jjtGetChild(0));
    }
  }
  return false;
}

代码示例来源:origin: pmd/pmd

/**
 * @see javax.swing.tree.TreeModel#getIndexOfChild(java.lang.Object,java.lang.Object)
 */
@Override
public int getIndexOfChild(Object parent, Object child) {
  Node node = (Node) parent;
  for (int i = 0; i < node.jjtGetNumChildren(); i++) {
    if (node.jjtGetChild(i).equals(child)) {
      return i;
    }
  }
  return -1;
}

代码示例来源:origin: pmd/pmd

private boolean isFirstChild(Node node, Class<?> clazz) {
    return node.jjtGetNumChildren() == 1 && clazz.isAssignableFrom(node.jjtGetChild(0).getClass());
  }
}

代码示例来源:origin: pmd/pmd

private String getName(Node node) {
    if (node.jjtGetNumChildren() > 0) {
      if (node.jjtGetChild(0) instanceof ASTName) {
        return ((ASTName) node.jjtGetChild(0)).getImage();
      } else {
        return getName(node.jjtGetChild(0));
      }
    }
    throw new IllegalArgumentException("Check with hasNameAsChild() first!");
  }
}

代码示例来源:origin: pmd/pmd

private Node getLastChild(Node node) {
  if (node.jjtGetNumChildren() == 0) {
    return node;
  }
  return getLastChild(node.jjtGetChild(0));
}

代码示例来源:origin: pmd/pmd

/**
 * Indicate whether this node is allocating a new object.
 *
 * @param n
 *            node that might be allocating a new object
 * @return true if child 0 is an AllocationExpression
 */
private boolean isAllocation(Node n) {
  return n.jjtGetNumChildren() > 0 && n.jjtGetChild(0) instanceof ASTAllocationExpression
      && n.jjtGetParent().jjtGetNumChildren() == 1;
}

相关文章