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

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

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

Node.jjtGetChildIndex介绍

[英]Gets the index of this node in the children of its parent.
[中]获取此节点在其父节点的子节点中的索引。

代码示例

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

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

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

  1. protected Node getPreviousSibling(Node contextNode) {
  2. Node parentNode = contextNode.jjtGetParent();
  3. if (parentNode != null) {
  4. int prevPosition = contextNode.jjtGetChildIndex() - 1;
  5. if (prevPosition >= 0) {
  6. return parentNode.jjtGetChild(prevPosition);
  7. }
  8. }
  9. return null;
  10. }

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

  1. protected Node getNextSibling(Node contextNode) {
  2. Node parentNode = contextNode.jjtGetParent();
  3. if (parentNode != null) {
  4. int nextPosition = contextNode.jjtGetChildIndex() + 1;
  5. if (nextPosition < parentNode.jjtGetNumChildren()) {
  6. return parentNode.jjtGetChild(nextPosition);
  7. }
  8. }
  9. return null;
  10. }

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

  1. /**
  2. * Checks, whether there is a statement after the given if statement, and if
  3. * so, whether this is just a return boolean statement.
  4. *
  5. * @param node
  6. * the if statement
  7. * @return
  8. */
  9. private boolean isJustReturnsBooleanAfter(ASTIfStatement ifNode) {
  10. Node blockStatement = ifNode.jjtGetParent().jjtGetParent();
  11. Node block = blockStatement.jjtGetParent();
  12. if (block.jjtGetNumChildren() != blockStatement.jjtGetChildIndex() + 1 + 1) {
  13. return false;
  14. }
  15. Node nextBlockStatement = block.jjtGetChild(blockStatement.jjtGetChildIndex() + 1);
  16. return terminatesInBooleanLiteral(nextBlockStatement);
  17. }

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

  1. /**
  2. * Returns all the block statements following the given local var declaration.
  3. */
  4. private static List<ASTBlockStatement> statementsAfter(ASTLocalVariableDeclaration node) {
  5. Node blockOrSwitch = node.jjtGetParent().jjtGetParent();
  6. int count = blockOrSwitch.jjtGetNumChildren();
  7. int start = node.jjtGetParent().jjtGetChildIndex() + 1;
  8. List<ASTBlockStatement> nextBlocks = new ArrayList<>(count - start);
  9. for (int i = start; i < count; i++) {
  10. Node maybeBlock = blockOrSwitch.jjtGetChild(i);
  11. if (maybeBlock instanceof ASTBlockStatement) {
  12. nextBlocks.add((ASTBlockStatement) maybeBlock);
  13. }
  14. }
  15. return nextBlocks;
  16. }
  17. }

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

  1. private boolean isMethodCall(Node node) {
  2. // PrimaryExpression
  3. // PrimaryPrefix
  4. // Name
  5. // PrimarySuffix
  6. if (node.jjtGetParent() instanceof ASTPrimaryPrefix && node.getNthParent(2) instanceof ASTPrimaryExpression) {
  7. Node primaryPrefix = node.jjtGetParent();
  8. Node expression = primaryPrefix.jjtGetParent();
  9. boolean hasNextSibling = expression.jjtGetNumChildren() > primaryPrefix.jjtGetChildIndex() + 1;
  10. if (hasNextSibling) {
  11. Node nextSibling = expression.jjtGetChild(primaryPrefix.jjtGetChildIndex() + 1);
  12. if (nextSibling instanceof ASTPrimarySuffix) {
  13. return true;
  14. }
  15. }
  16. }
  17. return false;
  18. }
  19. }

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

  1. private boolean isNoMethodName(Node name) {
  2. if (name instanceof ASTName
  3. && (name.jjtGetParent() instanceof ASTPrimaryPrefix || name.jjtGetParent() instanceof ASTPrimarySuffix)) {
  4. Node prefixOrSuffix = name.jjtGetParent();
  5. if (prefixOrSuffix.jjtGetParent().jjtGetNumChildren() > 1 + prefixOrSuffix.jjtGetChildIndex()) {
  6. // there's one next sibling
  7. Node next = prefixOrSuffix.jjtGetParent().jjtGetChild(prefixOrSuffix.jjtGetChildIndex() + 1);
  8. if (next instanceof ASTPrimarySuffix) {
  9. return !((ASTPrimarySuffix) next).isArguments();
  10. }
  11. }
  12. }
  13. return true;
  14. }
  15. }

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

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

代码示例来源:origin: net.sourceforge.pmd/pmd-core

  1. protected Node getPreviousSibling(Node contextNode) {
  2. Node parentNode = contextNode.jjtGetParent();
  3. if (parentNode != null) {
  4. int prevPosition = contextNode.jjtGetChildIndex() - 1;
  5. if (prevPosition >= 0) {
  6. return parentNode.jjtGetChild(prevPosition);
  7. }
  8. }
  9. return null;
  10. }

代码示例来源:origin: net.sourceforge.pmd/pmd-java

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

代码示例来源:origin: net.sourceforge.pmd/pmd-core

  1. protected Node getNextSibling(Node contextNode) {
  2. Node parentNode = contextNode.jjtGetParent();
  3. if (parentNode != null) {
  4. int nextPosition = contextNode.jjtGetChildIndex() + 1;
  5. if (nextPosition < parentNode.jjtGetNumChildren()) {
  6. return parentNode.jjtGetChild(nextPosition);
  7. }
  8. }
  9. return null;
  10. }

代码示例来源:origin: net.sourceforge.pmd/pmd-java

  1. /**
  2. * Returns all the block statements following the given local var declaration.
  3. */
  4. private static List<ASTBlockStatement> statementsAfter(ASTLocalVariableDeclaration node) {
  5. Node blockOrSwitch = node.jjtGetParent().jjtGetParent();
  6. int count = blockOrSwitch.jjtGetNumChildren();
  7. int start = node.jjtGetParent().jjtGetChildIndex() + 1;
  8. List<ASTBlockStatement> nextBlocks = new ArrayList<>(count - start);
  9. for (int i = start; i < count; i++) {
  10. Node maybeBlock = blockOrSwitch.jjtGetChild(i);
  11. if (maybeBlock instanceof ASTBlockStatement) {
  12. nextBlocks.add((ASTBlockStatement) maybeBlock);
  13. }
  14. }
  15. return nextBlocks;
  16. }
  17. }

代码示例来源:origin: net.sourceforge.pmd/pmd-java

  1. /**
  2. * Checks, whether there is a statement after the given if statement, and if
  3. * so, whether this is just a return boolean statement.
  4. *
  5. * @param node
  6. * the if statement
  7. * @return
  8. */
  9. private boolean isJustReturnsBooleanAfter(ASTIfStatement ifNode) {
  10. Node blockStatement = ifNode.jjtGetParent().jjtGetParent();
  11. Node block = blockStatement.jjtGetParent();
  12. if (block.jjtGetNumChildren() != blockStatement.jjtGetChildIndex() + 1 + 1) {
  13. return false;
  14. }
  15. Node nextBlockStatement = block.jjtGetChild(blockStatement.jjtGetChildIndex() + 1);
  16. return terminatesInBooleanLiteral(nextBlockStatement);
  17. }

代码示例来源:origin: net.sourceforge.pmd/pmd-java

  1. private boolean isMethodCall(Node node) {
  2. // PrimaryExpression
  3. // PrimaryPrefix
  4. // Name
  5. // PrimarySuffix
  6. if (node.jjtGetParent() instanceof ASTPrimaryPrefix && node.getNthParent(2) instanceof ASTPrimaryExpression) {
  7. Node primaryPrefix = node.jjtGetParent();
  8. Node expression = primaryPrefix.jjtGetParent();
  9. boolean hasNextSibling = expression.jjtGetNumChildren() > primaryPrefix.jjtGetChildIndex() + 1;
  10. if (hasNextSibling) {
  11. Node nextSibling = expression.jjtGetChild(primaryPrefix.jjtGetChildIndex() + 1);
  12. if (nextSibling instanceof ASTPrimarySuffix) {
  13. return true;
  14. }
  15. }
  16. }
  17. return false;
  18. }
  19. }

代码示例来源:origin: net.sourceforge.pmd/pmd-java

  1. private boolean isNoMethodName(Node name) {
  2. if (name instanceof ASTName
  3. && (name.jjtGetParent() instanceof ASTPrimaryPrefix || name.jjtGetParent() instanceof ASTPrimarySuffix)) {
  4. Node prefixOrSuffix = name.jjtGetParent();
  5. if (prefixOrSuffix.jjtGetParent().jjtGetNumChildren() > 1 + prefixOrSuffix.jjtGetChildIndex()) {
  6. // there's one next sibling
  7. Node next = prefixOrSuffix.jjtGetParent().jjtGetChild(prefixOrSuffix.jjtGetChildIndex() + 1);
  8. if (next instanceof ASTPrimarySuffix) {
  9. return !((ASTPrimarySuffix) next).isArguments();
  10. }
  11. }
  12. }
  13. return true;
  14. }
  15. }

代码示例来源:origin: net.sourceforge.pmd/pmd-java

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

相关文章