本文整理了Java中net.sourceforge.pmd.lang.ast.Node.jjtGetNumChildren()
方法的一些代码示例,展示了Node.jjtGetNumChildren()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.jjtGetNumChildren()
方法的具体详情如下:
包路径:net.sourceforge.pmd.lang.ast.Node
类名称:Node
方法名:jjtGetNumChildren
[英]Returns the number of children the node has.
[中]返回节点的子节点数。
代码示例来源:origin: pmd/pmd
protected Node getLastChild(Node contextNode) {
if (contextNode.jjtGetNumChildren() > 0) {
return contextNode.jjtGetChild(contextNode.jjtGetNumChildren() - 1);
} else {
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 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 Node getNextSibling(Node current) {
if (current.jjtGetParent().jjtGetNumChildren() > current.jjtGetChildIndex() + 1) {
return current.jjtGetParent().jjtGetChild(current.jjtGetChildIndex() + 1);
}
return null;
}
代码示例来源:origin: pmd/pmd
protected Node getFirstChild(Node contextNode) {
if (contextNode.jjtGetNumChildren() > 0) {
return contextNode.jjtGetChild(0);
} else {
return null;
}
}
代码示例来源: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
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
/**
* 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
private void moveToNext() {
while (i < parent.jjtGetNumChildren() && !(targetChildType.isInstance(parent.jjtGetChild(i)))) {
i++;
}
}
代码示例来源: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
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
/**
* 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;
}
代码示例来源: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 eachNodeHasOneChild(Node node) {
if (node.jjtGetNumChildren() > 1) {
return false;
}
if (node.jjtGetNumChildren() == 0) {
return true;
}
return eachNodeHasOneChild(node.jjtGetChild(0));
}
代码示例来源:origin: pmd/pmd
private boolean isFirstChild(Node node, Class<?> clazz) {
return node.jjtGetNumChildren() == 1 && clazz.isAssignableFrom(node.jjtGetChild(0).getClass());
}
}
代码示例来源:origin: pmd/pmd
/**
* checks the children and creates them if neccessary
*/
private void checkChildren() {
if (children == null) {
children = new ArrayList<>(node.jjtGetNumChildren());
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
children.add(new SimpleNodeTreeNodeAdapter(this, node.jjtGetChild(i)));
}
}
}
代码示例来源:origin: pmd/pmd
private Node getLastChild(Node node) {
if (node.jjtGetNumChildren() == 0) {
return node;
}
return getLastChild(node.jjtGetChild(0));
}
代码示例来源: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;
}
内容来源于网络,如有侵权,请联系作者删除!