private boolean isParent(Node possibleParent, Node node) { Node checkNode = node; while (checkNode.jjtGetParent() != null) { if (checkNode.jjtGetParent().equals(possibleParent)) { return true; } checkNode = checkNode.jjtGetParent(); } return false; }
ASTTreeNode(Node theNode) { node = theNode; Node parent = node.jjtGetParent(); if (parent != null) { this.parent = new ASTTreeNode(parent); } }
/** * This method can be called on a prefix */ private ASTArguments getSuffixMethodArgs(Node node) { Node prefix = node.jjtGetParent(); if (prefix instanceof ASTPrimaryPrefix && prefix.jjtGetParent().jjtGetNumChildren() >= 2) { return prefix.jjtGetParent().jjtGetChild(1).getFirstChildOfType(ASTArguments.class); } return null; }
private boolean insideLoop(ASTSoqlExpression node) { Node n = node.jjtGetParent(); while (n != null) { if (n instanceof ASTDoLoopStatement || n instanceof ASTWhileLoopStatement || n instanceof ASTForLoopStatement || n instanceof ASTForEachStatement) { return true; } n = n.jjtGetParent(); } return false; } }
/** * Returns true if this nodes declares an exception parameter in * a {@code catch} statement. */ public boolean isExceptionBlockParameter() { return jjtGetParent().jjtGetParent() instanceof ASTCatchStatement; }
@Override public Object getParentNode(Object arg0) { if (arg0 instanceof Node) { return ((Node) arg0).jjtGetParent(); } if (arg0 instanceof Attribute) { return ((Attribute) arg0).getParent(); } // can't navigate to parent node... return null; }
private boolean insideLoop(ASTSoslExpression node) { Node n = node.jjtGetParent(); while (n != null) { if (n instanceof ASTDoLoopStatement || n instanceof ASTWhileLoopStatement || n instanceof ASTForLoopStatement || n instanceof ASTForEachStatement) { return true; } n = n.jjtGetParent(); } return false; } }
@Override public <T> List<T> getParentsOfType(Class<T> parentType) { List<T> parents = new ArrayList<>(); Node parentNode = jjtGetParent(); while (parentNode != null) { if (parentType.isInstance(parentNode)) { parents.add(parentType.cast(parentNode)); } parentNode = parentNode.jjtGetParent(); } return parents; }
@Override public Object visit(final ASTConstructorDeclaration node, final Object data) { if (node.isPrivate()) { final String className = node.jjtGetParent().jjtGetParent().jjtGetParent().getImage(); if (!privateConstructors.containsKey(className)) { privateConstructors.put(className, new ArrayList<ASTConstructorDeclaration>()); } privateConstructors.get(className).add(node); } return data; }
private void checkDeclarationInInterfaceType(Object data, Node fieldOrMethod, Set<Modifier> unnecessary) { // third ancestor could be an AllocationExpression // if this is a method in an anonymous inner class Node parent = fieldOrMethod.jjtGetParent().jjtGetParent().jjtGetParent(); if (parent instanceof ASTAnnotationTypeDeclaration || parent instanceof ASTClassOrInterfaceDeclaration && ((ASTClassOrInterfaceDeclaration) parent).isInterface()) { reportUnnecessaryModifiers(data, fieldOrMethod, unnecessary, "the " + getPrintableNodeKind(fieldOrMethod) + " is declared in an " + getPrintableNodeKind(parent) + " type"); } }
@Override public Object visit(ASTStatementExpression node, Object data) { if (!(node.jjtGetParent().jjtGetParent() instanceof ASTForUpdate)) { ((MutableInt) data).increment(); } return data; }
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; }
public Node getTypeNameNode() { if (jjtGetParent() instanceof ASTFormalParameter) { return findTypeNameNode(jjtGetParent()); } else if (jjtGetParent().jjtGetParent() instanceof ASTVariableOrConstantDeclaration || jjtGetParent().jjtGetParent() instanceof ASTFieldDeclaration) { return findTypeNameNode(jjtGetParent().jjtGetParent()); } throw new RuntimeException( "Don't know how to get the type for anything other than ASTLocalVariableDeclaration/ASTFormalParameter/ASTFieldDeclaration"); }
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; }
/** * 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; }
public ASTDatatype getTypeNode() { if (jjtGetParent() instanceof ASTFormalParameter) { return ((ASTFormalParameter) jjtGetParent()).getTypeNode(); } else { Node n = jjtGetParent().jjtGetParent(); if (n instanceof ASTVariableOrConstantDeclaration || n instanceof ASTFieldDeclaration) { return n.getFirstChildOfType(ASTDatatype.class); } } throw new RuntimeException( "Don't know how to get the type for anything other than ASTLocalVariableDeclaration/ASTFormalParameter/ASTFieldDeclaration"); }
public AccessNode getAccessNodeParent() { if (node.jjtGetParent() instanceof ASTFormalParameter || node.jjtGetParent() instanceof ASTLambdaExpression) { return (AccessNode) node.jjtGetParent(); } return (AccessNode) node.jjtGetParent().jjtGetParent(); }
private boolean isStandAlonePostfix(Node primaryExpression) { if (!(primaryExpression instanceof ASTPostfixExpression) || !(primaryExpression.jjtGetParent() instanceof ASTStatementExpression)) { return false; } ASTPrimaryPrefix pf = (ASTPrimaryPrefix) ((ASTPrimaryExpression) primaryExpression.jjtGetChild(0)) .jjtGetChild(0); if (pf.usesThisModifier()) { return true; } return thirdChildHasDottedName(primaryExpression); }
@Override public boolean isTargetMethod(JavaNameOccurrence occ) { if (occ.getNameForWhichThisIsAQualifier() != null && occ.getNameForWhichThisIsAQualifier().getImage().indexOf("trim") != -1) { Node pExpression = occ.getLocation().jjtGetParent().jjtGetParent(); if (pExpression.jjtGetNumChildren() > 2 && "length".equals(pExpression.jjtGetChild(2).getImage())) { return true; } } return false; }