/** * Returns the root of the tree containing this node. * @return the {@link AstRoot} at the root of this node's parent * chain, or {@code null} if the topmost parent is not an {@code AstRoot}. */ public AstRoot getAstRoot() { AstNode parent = this; // this node could be the AstRoot while (parent != null && !(parent instanceof AstRoot)) { parent = parent.getParent(); } return (AstRoot)parent; }
/** * Returns the root of the tree containing this node. * @return the {@link AstRoot} at the root of this node's parent * chain, or {@code null} if the topmost parent is not an {@code AstRoot}. */ public AstRoot getAstRoot() { AstNode parent = this; // this node could be the AstRoot while (parent != null && !(parent instanceof AstRoot)) { parent = parent.getParent(); } return (AstRoot)parent; }
/** * Returns the innermost enclosing function, or {@code null} if not in a * function. Begins the search with this node's parent. * @return the {@link FunctionNode} enclosing this node, else {@code null} */ public FunctionNode getEnclosingFunction() { AstNode parent = this.getParent(); while (parent != null && !(parent instanceof FunctionNode)) { parent = parent.getParent(); } return (FunctionNode)parent; }
/** * Returns the root of the tree containing this node. * @return the {@link AstRoot} at the root of this node's parent * chain, or {@code null} if the topmost parent is not an {@code AstRoot}. */ public AstRoot getAstRoot() { AstNode parent = this; // this node could be the AstRoot while (parent != null && !(parent instanceof AstRoot)) { parent = parent.getParent(); } return (AstRoot)parent; }
/** * Returns the innermost enclosing function, or {@code null} if not in a * function. Begins the search with this node's parent. * @return the {@link FunctionNode} enclosing this node, else {@code null} */ public FunctionNode getEnclosingFunction() { AstNode parent = this.getParent(); while (parent != null && !(parent instanceof FunctionNode)) { parent = parent.getParent(); } return (FunctionNode)parent; }
/** * Returns the innermost enclosing function, or {@code null} if not in a * function. Begins the search with this node's parent. * @return the {@link FunctionNode} enclosing this node, else {@code null} */ public FunctionNode getEnclosingFunction() { AstNode parent = this.getParent(); while (parent != null && !(parent instanceof FunctionNode)) { parent = parent.getParent(); } return (FunctionNode)parent; }
/** * Returns the innermost enclosing function, or {@code null} if not in a * function. Begins the search with this node's parent. * @return the {@link FunctionNode} enclosing this node, else {@code null} */ public FunctionNode getEnclosingFunction() { AstNode parent = this.getParent(); while (parent != null && !(parent instanceof FunctionNode)) { parent = parent.getParent(); } return (FunctionNode)parent; }
/** * Returns the root of the tree containing this node. * @return the {@link AstRoot} at the root of this node's parent * chain, or {@code null} if the topmost parent is not an {@code AstRoot}. */ public AstRoot getAstRoot() { AstNode parent = this; // this node could be the AstRoot while (parent != null && !(parent instanceof AstRoot)) { parent = parent.getParent(); } return (AstRoot)parent; }
/** * Returns the innermost enclosing {@link Scope} node, or {@code null} * if we're not nested in a scope. Begins the search with this node's parent. * Note that this is not the same as the defining scope for a {@link Name}. * * @return the {@link Scope} enclosing this node, else {@code null} */ public Scope getEnclosingScope() { AstNode parent = this.getParent(); while (parent != null && !(parent instanceof Scope)) { parent = parent.getParent(); } return (Scope)parent; }
/** * Returns the innermost enclosing {@link Scope} node, or {@code null} * if we're not nested in a scope. Begins the search with this node's parent. * Note that this is not the same as the defining scope for a {@link Name}. * * @return the {@link Scope} enclosing this node, else {@code null} */ public Scope getEnclosingScope() { AstNode parent = this.getParent(); while (parent != null && !(parent instanceof Scope)) { parent = parent.getParent(); } return (Scope)parent; }
/** * Returns the innermost enclosing {@link Scope} node, or {@code null} * if we're not nested in a scope. Begins the search with this node's parent. * Note that this is not the same as the defining scope for a {@link Name}. * * @return the {@link Scope} enclosing this node, else {@code null} */ public Scope getEnclosingScope() { AstNode parent = this.getParent(); while (parent != null && !(parent instanceof Scope)) { parent = parent.getParent(); } return (Scope)parent; }
/** * Returns the innermost enclosing {@link Scope} node, or {@code null} * if we're not nested in a scope. Begins the search with this node's parent. * Note that this is not the same as the defining scope for a {@link Name}. * * @return the {@link Scope} enclosing this node, else {@code null} */ public Scope getEnclosingScope() { AstNode parent = this.getParent(); while (parent != null && !(parent instanceof Scope)) { parent = parent.getParent(); } return (Scope)parent; }
private static List<Label> getLabels(AstNode node) { if (node instanceof LabeledStatement || ((node = node.getParent()) instanceof LabeledStatement)) { return ((LabeledStatement)node).getLabels(); } else { return null; } } private static AstNode makeEmptyLabelStmt(String label) {
/** * Returns the absolute document position of the node. * Computes it by adding the node's relative position * to the relative positions of all its parents. */ public int getAbsolutePosition() { int pos = position; AstNode parent = this.parent; while (parent != null) { pos += parent.getPosition(); parent = parent.getParent(); } return pos; }
/** * Returns the absolute document position of the node. * Computes it by adding the node's relative position * to the relative positions of all its parents. */ public int getAbsolutePosition() { int pos = position; AstNode parent = this.parent; while (parent != null) { pos += parent.getPosition(); parent = parent.getParent(); } return pos; }
public boolean visit(AstNode node) { int type = node.getType(); if (type == Token.SCRIPT) return true; if (node.getParent() == null) throw new IllegalStateException ("No parent for node: " + node + "\n" + node.toSource(0)); return true; } });
public boolean visit(AstNode node) { int type = node.getType(); if (type == Token.SCRIPT) return true; if (node.getParent() == null) throw new IllegalStateException ("No parent for node: " + node + "\n" + node.toSource(0)); return true; } });
public boolean visit(AstNode node) { int type = node.getType(); if (type == Token.SCRIPT) return true; if (node.getParent() == null) throw new IllegalStateException ("No parent for node: " + node + "\n" + node.toSource(0)); return true; } });
public boolean visit(AstNode node) { int type = node.getType(); if (type == Token.SCRIPT) return true; if (node.getParent() == null) throw new IllegalStateException ("No parent for node: " + node + "\n" + node.toSource(0)); return true; } });
private String getParentName(AstNode fn) { for(int i = 5; fn != null && i > 0; i--, fn = fn.getParent()) { if (fn instanceof ObjectProperty) { ObjectProperty prop = (ObjectProperty) fn; AstNode label = prop.getLeft(); if (label instanceof Name) { return (((Name)label).getString()); } } } return null; }