本文整理了Java中net.sourceforge.pmd.lang.ast.Node.jjtGetChildIndex()
方法的一些代码示例,展示了Node.jjtGetChildIndex()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.jjtGetChildIndex()
方法的具体详情如下:
包路径:net.sourceforge.pmd.lang.ast.Node
类名称:Node
方法名:jjtGetChildIndex
[英]Gets the index of this node in the children of its parent.
[中]获取此节点在其父节点的子节点中的索引。
代码示例来源: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 getPreviousSibling(Node contextNode) {
Node parentNode = contextNode.jjtGetParent();
if (parentNode != null) {
int prevPosition = contextNode.jjtGetChildIndex() - 1;
if (prevPosition >= 0) {
return parentNode.jjtGetChild(prevPosition);
}
}
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
/**
* Checks, whether there is a statement after the given if statement, and if
* so, whether this is just a return boolean statement.
*
* @param node
* the if statement
* @return
*/
private boolean isJustReturnsBooleanAfter(ASTIfStatement ifNode) {
Node blockStatement = ifNode.jjtGetParent().jjtGetParent();
Node block = blockStatement.jjtGetParent();
if (block.jjtGetNumChildren() != blockStatement.jjtGetChildIndex() + 1 + 1) {
return false;
}
Node nextBlockStatement = block.jjtGetChild(blockStatement.jjtGetChildIndex() + 1);
return terminatesInBooleanLiteral(nextBlockStatement);
}
代码示例来源:origin: pmd/pmd
/**
* Returns all the block statements following the given local var declaration.
*/
private static List<ASTBlockStatement> statementsAfter(ASTLocalVariableDeclaration node) {
Node blockOrSwitch = node.jjtGetParent().jjtGetParent();
int count = blockOrSwitch.jjtGetNumChildren();
int start = node.jjtGetParent().jjtGetChildIndex() + 1;
List<ASTBlockStatement> nextBlocks = new ArrayList<>(count - start);
for (int i = start; i < count; i++) {
Node maybeBlock = blockOrSwitch.jjtGetChild(i);
if (maybeBlock instanceof ASTBlockStatement) {
nextBlocks.add((ASTBlockStatement) maybeBlock);
}
}
return nextBlocks;
}
}
代码示例来源:origin: pmd/pmd
private boolean isMethodCall(Node node) {
// PrimaryExpression
// PrimaryPrefix
// Name
// PrimarySuffix
if (node.jjtGetParent() instanceof ASTPrimaryPrefix && node.getNthParent(2) instanceof ASTPrimaryExpression) {
Node primaryPrefix = node.jjtGetParent();
Node expression = primaryPrefix.jjtGetParent();
boolean hasNextSibling = expression.jjtGetNumChildren() > primaryPrefix.jjtGetChildIndex() + 1;
if (hasNextSibling) {
Node nextSibling = expression.jjtGetChild(primaryPrefix.jjtGetChildIndex() + 1);
if (nextSibling instanceof ASTPrimarySuffix) {
return true;
}
}
}
return false;
}
}
代码示例来源:origin: pmd/pmd
private boolean isNoMethodName(Node name) {
if (name instanceof ASTName
&& (name.jjtGetParent() instanceof ASTPrimaryPrefix || name.jjtGetParent() instanceof ASTPrimarySuffix)) {
Node prefixOrSuffix = name.jjtGetParent();
if (prefixOrSuffix.jjtGetParent().jjtGetNumChildren() > 1 + prefixOrSuffix.jjtGetChildIndex()) {
// there's one next sibling
Node next = prefixOrSuffix.jjtGetParent().jjtGetChild(prefixOrSuffix.jjtGetChildIndex() + 1);
if (next instanceof ASTPrimarySuffix) {
return !((ASTPrimarySuffix) next).isArguments();
}
}
}
return true;
}
}
代码示例来源: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: net.sourceforge.pmd/pmd-core
protected Node getPreviousSibling(Node contextNode) {
Node parentNode = contextNode.jjtGetParent();
if (parentNode != null) {
int prevPosition = contextNode.jjtGetChildIndex() - 1;
if (prevPosition >= 0) {
return parentNode.jjtGetChild(prevPosition);
}
}
return null;
}
代码示例来源:origin: net.sourceforge.pmd/pmd-java
private Node getNextSibling(Node current) {
if (current.jjtGetParent().jjtGetNumChildren() > current.jjtGetChildIndex() + 1) {
return current.jjtGetParent().jjtGetChild(current.jjtGetChildIndex() + 1);
}
return null;
}
代码示例来源:origin: net.sourceforge.pmd/pmd-core
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: net.sourceforge.pmd/pmd-java
/**
* Returns all the block statements following the given local var declaration.
*/
private static List<ASTBlockStatement> statementsAfter(ASTLocalVariableDeclaration node) {
Node blockOrSwitch = node.jjtGetParent().jjtGetParent();
int count = blockOrSwitch.jjtGetNumChildren();
int start = node.jjtGetParent().jjtGetChildIndex() + 1;
List<ASTBlockStatement> nextBlocks = new ArrayList<>(count - start);
for (int i = start; i < count; i++) {
Node maybeBlock = blockOrSwitch.jjtGetChild(i);
if (maybeBlock instanceof ASTBlockStatement) {
nextBlocks.add((ASTBlockStatement) maybeBlock);
}
}
return nextBlocks;
}
}
代码示例来源:origin: net.sourceforge.pmd/pmd-java
/**
* Checks, whether there is a statement after the given if statement, and if
* so, whether this is just a return boolean statement.
*
* @param node
* the if statement
* @return
*/
private boolean isJustReturnsBooleanAfter(ASTIfStatement ifNode) {
Node blockStatement = ifNode.jjtGetParent().jjtGetParent();
Node block = blockStatement.jjtGetParent();
if (block.jjtGetNumChildren() != blockStatement.jjtGetChildIndex() + 1 + 1) {
return false;
}
Node nextBlockStatement = block.jjtGetChild(blockStatement.jjtGetChildIndex() + 1);
return terminatesInBooleanLiteral(nextBlockStatement);
}
代码示例来源:origin: net.sourceforge.pmd/pmd-java
private boolean isMethodCall(Node node) {
// PrimaryExpression
// PrimaryPrefix
// Name
// PrimarySuffix
if (node.jjtGetParent() instanceof ASTPrimaryPrefix && node.getNthParent(2) instanceof ASTPrimaryExpression) {
Node primaryPrefix = node.jjtGetParent();
Node expression = primaryPrefix.jjtGetParent();
boolean hasNextSibling = expression.jjtGetNumChildren() > primaryPrefix.jjtGetChildIndex() + 1;
if (hasNextSibling) {
Node nextSibling = expression.jjtGetChild(primaryPrefix.jjtGetChildIndex() + 1);
if (nextSibling instanceof ASTPrimarySuffix) {
return true;
}
}
}
return false;
}
}
代码示例来源:origin: net.sourceforge.pmd/pmd-java
private boolean isNoMethodName(Node name) {
if (name instanceof ASTName
&& (name.jjtGetParent() instanceof ASTPrimaryPrefix || name.jjtGetParent() instanceof ASTPrimarySuffix)) {
Node prefixOrSuffix = name.jjtGetParent();
if (prefixOrSuffix.jjtGetParent().jjtGetNumChildren() > 1 + prefixOrSuffix.jjtGetChildIndex()) {
// there's one next sibling
Node next = prefixOrSuffix.jjtGetParent().jjtGetChild(prefixOrSuffix.jjtGetChildIndex() + 1);
if (next instanceof ASTPrimarySuffix) {
return !((ASTPrimarySuffix) next).isArguments();
}
}
}
return true;
}
}
代码示例来源:origin: net.sourceforge.pmd/pmd-java
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;
}
内容来源于网络,如有侵权,请联系作者删除!