/** * Gets next sibling of ParseTree node. * @param node ParseTree node * @return next sibling of ParseTree node. */ private static ParseTree getNextSibling(ParseTree node) { ParseTree nextSibling = null; if (node.getParent() != null) { final ParseTree parent = node.getParent(); int index = 0; while (true) { final ParseTree currentNode = parent.getChild(index); if (currentNode.equals(node)) { nextSibling = parent.getChild(index + 1); break; } index++; } } return nextSibling; }
/** * Return node situated on the left of the input node (does not have to be at the same level as the current node). * * @param ctx A node * @return The left node */ public static ParseTree getLeftNode(ParseTree ctx) { while (true) { if (ctx == null) { return null; } ParseTree left = getLeftSibling(ctx); if (left != null) { return left; } ctx = ctx.getParent(); } }
/** * Returns node's index with in its parent's child array. * * @param node A child node * @return Node's index or -1 if node is null or doesn't have a parent */ public static int getNodeIndex(ParseTree node) { if (node == null || node.getParent() == null) { return -1; } ParseTree parent = node.getParent(); for (int i = 0; i < parent.getChildCount(); i++) { if (parent.getChild(i) == node) { return i; } } return -1; }
/** * Return node situated on the right of the input node (does not have to be at the level as the current node). * * @param ctx A node * @return The right node */ public static ParseTree getRightNode(ParseTree ctx) { while (true) { if (ctx == null) { return null; } ParseTree right = getRightSibling(ctx); if (right != null) { return right; } ctx = ctx.getParent(); } }
/** * Gets left sibling of a parse tree node. * * @param ctx A node * @return Left sibling of a node, or null if no sibling is found */ public static ParseTree getLeftSibling(ParseTree ctx) { int index = ParseTreeUtil.getNodeIndex(ctx); if (index < 1) { return null; } return ctx.getParent().getChild(index - 1); }
/** * Gets right sibling of a parse tree node. * * @param ctx A node * @return Right sibling of a node, or null if no sibling is found */ public static ParseTree getRightSibling(ParseTree ctx) { int index = ParseTreeUtil.getNodeIndex(ctx); ParseTree parent = ctx.getParent(); if (index < 0 || index >= parent.getChildCount() - 1) { return null; } return parent.getChild(index + 1); }
addQuery(classUtils.expandExpression(arg0.getParent().getText(), registry, classUtils.DO_NON_STATIC), cursor); } else if (arg0.getParent() instanceof TypeDeclarationContext && arg0.getParent().getParent() != null && arg0.getParent().getParent() instanceof CompilationUnitContext) { AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.TOPLEVEL, arg0.getText()); addQuery(c, cursor); } else if (arg0.getParent() instanceof MemberDeclarationContext && arg0.getParent().getParent() != null && arg0.getParent().getParent() instanceof ClassBodyDeclarationContext && arg0.getParent().getParent().getParent() != null && arg0.getParent().getParent().getParent() instanceof ClassBodyContext && arg0.getParent().getParent().getParent().getText().trim().startsWith("<missing '{'>")) { AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.CLASSLEVEL, arg0.getText()); addQuery(c, cursor); } else if (arg0.getParent() instanceof MemberDeclarationContext && arg0.getParent().getParent() != null && arg0.getParent().getParent() instanceof ClassBodyDeclarationContext && arg0.getParent().getParent().getParent() != null && arg0.getParent().getParent().getParent() instanceof ClassBodyContext) { AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.TYPE, arg0.getText()); addQuery(c, cursor);
(JavadocNodeImpl) currentJavadocParent.getParent(); parseTreeParent = parseTreeParent.getParent();
for (; (null != ctx) && ((ctx instanceof ProgramContext) == false); ctx = ctx.getParent()) { if (ctx instanceof BlockContext) { retval++;
/** Add a parse tree node to this as a child. Works for * internal and leaf nodes. Does not set parent link; * other add methods must do that. Other addChild methods * call this. * * We cannot set the parent pointer of the incoming node * because the existing interfaces do not have a setParent() * method and I don't want to break backward compatibility for this. * * @since 4.7 */ public <T extends ParseTree> T addAnyChild(T t) { assert t.getParent() == null || t.getParent() == this; if ( children==null ) children = new ArrayList<ParseTree>(); children.add(t); return t; }
protected final ParseTree up(ParseTree tree) { ParseTree parent = tree.getParent(); // Needed because of the way the ANTLR rules have been defined. if (parent instanceof UserAgentParser.ProductNameContext || parent instanceof UserAgentParser.ProductVersionContext || parent instanceof UserAgentParser.ProductVersionWithCommasContext ) { return up(parent); } return parent; }
private SymbolScope getScope(ParseTree ctx) { if (ctx != null) { SymbolScope s = scopes.get(ctx); return s != null ? s : getScope(ctx.getParent()); } else { throw new IllegalStateException( "Compiler error: failed to find symbol scope"); } }
protected SymbolScope getScope(ParseTree ctx) { if (ctx != null) { SymbolScope s = scopes.get(ctx); return s != null ? s : getScope(ctx.getParent()); } else { throw new IllegalStateException( "Compiler error: failed to find symbol scope"); } }
private SymbolScope getScope(ParseTree ctx) { if (ctx != null) { SymbolScope s = scopes.get(ctx); return s != null ? s : getScope(ctx.getParent()); } else { throw new IllegalStateException( "Compiler error: failed to find symbol scope"); } }
/** * Gets next sibling of ParseTree node. * @param node ParseTree node * @return next sibling of ParseTree node. */ private static ParseTree getNextSibling(ParseTree node) { ParseTree nextSibling = null; if (node.getParent() != null) { final ParseTree parent = node.getParent(); int index = 0; while (true) { final ParseTree currentNode = parent.getChild(index); if (currentNode.equals(node)) { nextSibling = parent.getChild(index + 1); break; } index++; } } return nextSibling; }
protected SymbolScope getScope(ParseTree ctx) { if (ctx != null) { SymbolScope s = scopes.get(ctx); return s != null ? s : getScope(ctx.getParent()); } else { throw new IllegalStateException( "Compiler error: failed to find symbol scope"); } }
public static int getChildIndex(ParseTree t) { if ( t==null ) return -1; ParseTree parent = t.getParent(); if ( parent==null ) { return -1; } // Figure out which child index t is of parent for (int i = 0; i<parent.getChildCount(); i++) { if ( parent.getChild(i)==t ) { return i; } } return -1; }
/** * Constructor. * * @param node the error node. */ private CQLSyntaxError(ErrorNode node) { this.text = node.getText(); int offset = 0; ParseTree n = node; while (n != null) { offset += n.getSourceInterval().a; n = n.getParent(); } this.interval = new Interval(offset + node.getSourceInterval().a, offset + node.getSourceInterval().b); } }
/** * Constructor. * * @param node the error node. */ private CQLSyntaxError(ErrorNode node) { this.text = node.getText(); int offset = 0; ParseTree n = node; while (n != null) { offset += n.getSourceInterval().a; n = n.getParent(); } this.interval = new Interval(offset + node.getSourceInterval().a, offset + node.getSourceInterval().b); } }