private Node getNextSibling(Node current) { if (current.jjtGetParent().jjtGetNumChildren() > current.jjtGetChildIndex() + 1) { return current.jjtGetParent().jjtGetChild(current.jjtGetChildIndex() + 1); } return null; }
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; }
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; }
/** * 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); }
/** * 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; } }
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; } }
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; } }
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; }
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; }
private Node getNextSibling(Node current) { if (current.jjtGetParent().jjtGetNumChildren() > current.jjtGetChildIndex() + 1) { return current.jjtGetParent().jjtGetChild(current.jjtGetChildIndex() + 1); } return null; }
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; }
/** * 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; } }
/** * 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); }
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; } }
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; } }
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; }