private MethodDeclaration findMethodDeclaration(final AstNode node) { for (AstNode current = node; current != null; current = current.getParent()) { if (current instanceof MethodDeclaration) { return (MethodDeclaration) current; } } return null; }
private MethodDeclaration findMethodDeclaration(final AstNode node) { for (AstNode current = node; current != null; current = current.getParent()) { if (current instanceof MethodDeclaration) { return (MethodDeclaration) current; } } return null; }
private PackageReference getCurrentPackageReference() { final AstNode node = nodeStack.peek(); PackageReference pkg = node.getUserData(Keys.PACKAGE_REFERENCE); if (pkg == null && node.getParent() instanceof ImportDeclaration) { pkg = node.getParent().getUserData(Keys.PACKAGE_REFERENCE); } return pkg; }
private MemberReference getCurrentMemberReference() { final AstNode node = nodeStack.peek(); MemberReference member = node.getUserData(Keys.MEMBER_REFERENCE); if (member == null && node.getRole() == Roles.TARGET_EXPRESSION && (node.getParent() instanceof InvocationExpression || node.getParent() instanceof ObjectCreationExpression)) { member = node.getParent().getUserData(Keys.MEMBER_REFERENCE); } return member; }
@Nullable public static AstNode skipParenthesesUp(final AstNode e) { AstNode result = e; while (result instanceof ParenthesizedExpression) { result = result.getParent(); } return result; }
private MemberReference getCurrentMemberReference() { final AstNode node = nodeStack.peek(); MemberReference member = node.getUserData(Keys.MEMBER_REFERENCE); if (member == null && node.getRole() == Roles.TARGET_EXPRESSION && (node.getParent() instanceof InvocationExpression || node.getParent() instanceof ObjectCreationExpression)) { member = node.getParent().getUserData(Keys.MEMBER_REFERENCE); } return member; }
@Override public boolean contains(final Object o) { return o instanceof AstNode && ((AstNode) o).getParent() == _node && ((AstNode) o).getRole() == _role; }
@Nullable private static AstNode skipParenthesesUp(final AstNode e) { AstNode result = e; while (result instanceof ParenthesizedExpression) { result = result.getParent(); } return result; }
private MemberReference getCurrentMemberReference() { final AstNode node = nodeStack.peek(); MemberReference member = node.getUserData(Keys.MEMBER_REFERENCE); if (member == null && node.getRole() == Roles.TARGET_EXPRESSION && (node.getParent() instanceof InvocationExpression || node.getParent() instanceof ObjectCreationExpression)) { member = node.getParent().getUserData(Keys.MEMBER_REFERENCE); } return member; }
@Override public boolean contains(final Object o) { return o instanceof AstNode && ((AstNode) o).getParent() == _node && ((AstNode) o).getRole() == _role; }
void endNode(final AstNode node) { assert node == containerStack.peek(); final AstNode position = positionStack.pop(); assert position == null || position.getParent() == node; writeSpecials(position, null); containerStack.pop(); formatter.endNode(node); }
private void recurse(final AstNode replacement) { final AstNode parent = replacement.getParent(); if (parent != null) { parent.acceptVisitor(this, null); } else { replacement.acceptVisitor(this, null); } } }
public final AstNode getPreviousNode() { final AstNode previousSibling = getPreviousSibling(); if (previousSibling != null) { return previousSibling; } final AstNode parent = getParent(); if (parent != null) { return parent.getPreviousNode(); } return null; }
public final AstNode getNextNode() { final AstNode nextSibling = getNextSibling(); if (nextSibling != null) { return nextSibling; } final AstNode parent = getParent(); if (parent != null) { return parent.getNextNode(); } return null; }
private void recurse(final AstNode replacement) { final AstNode parent = replacement.getParent(); if (parent != null) { parent.acceptVisitor(this, null); } else { replacement.acceptVisitor(this, null); } } }
public final AstNode getPreviousNode() { final AstNode previousSibling = getPreviousSibling(); if (previousSibling != null) { return previousSibling; } final AstNode parent = getParent(); if (parent != null) { return parent.getPreviousNode(); } return null; }
public void acceptVisitor(final IAstVisitor<? super T, ?> visitor) { AstNode next; for (AstNode current = _node.getFirstChild(); current != null; current = next) { assert current.getParent() == _node; next = current.getNextSibling(); if (current.getRole() == _role) { current.acceptVisitor(visitor, null); } } }
public static void replaceAll(final AstNode tree) { for (final AstNode node : tree.getDescendants()) { if (node instanceof CommentStatement) { node.getParent().insertChildBefore( node, new Comment(((CommentStatement) node).getComment()), Roles.COMMENT ); node.remove(); } } }
public static boolean isCastRedundant(final Function<AstNode, ResolveResult> resolver, final CastExpression cast) { AstNode parent = skipParenthesesUp(cast.getParent()); if (parent == null) { return false; } if (parent.getRole() == Roles.ARGUMENT || parent.isReference()) { parent = parent.getParent(); } final IsRedundantVisitor visitor = new IsRedundantVisitor(resolver, false); parent.acceptVisitor(visitor, null); return visitor.isRedundant(); }