@Override public int getChildIndex(Object t) { if ( t==null ) return 0; return ((Tree)t).getChildIndex(); }
@Override public int getChildIndex(Object t) { if ( t==null ) return 0; return ((Tree)t).getChildIndex(); }
@Override public int getChildIndex(Object t) { if ( t==null ) return 0; return ((Tree)t).getChildIndex(); }
@Override public int getChildIndex(Object t) { if ( t==null ) return 0; return ((Tree)t).getChildIndex(); }
@Override public int getChildIndex(Object t) { if ( t==null ) return 0; return ((Tree)t).getChildIndex(); }
public int getChildIndex(Object t) { if ( t==null ) return 0; return ((Tree)t).getChildIndex(); }
public boolean deleteChild(org.antlr.runtime.tree.Tree t) { for (int i=0; i<children.size(); i++) { Object c = children.get(i); if ( c == t ) { deleteChild(t.getChildIndex()); return true; } } return false; }
public boolean deleteChild(org.antlr.runtime.tree.Tree t) { for (int i=0; i<children.size(); i++) { Object c = children.get(i); if ( c == t ) { deleteChild(t.getChildIndex()); return true; } } return false; }
public boolean deleteChild(org.antlr.runtime.tree.Tree t) { for (int i=0; i<children.size(); i++) { Object c = children.get(i); if ( c == t ) { deleteChild(t.getChildIndex()); return true; } } return false; }
public boolean deleteChild(org.antlr.runtime.tree.Tree t) { for (int i=0; i<children.size(); i++) { Object c = children.get(i); if ( c == t ) { deleteChild(t.getChildIndex()); return true; } } return false; }
public boolean deleteChild(org.antlr.runtime.tree.Tree t) { for (int i=0; i<children.size(); i++) { Object c = children.get(i); if ( c == t ) { deleteChild(t.getChildIndex()); return true; } } return false; }
private boolean isSimpleStatementNode(Tree node) { int nodeCode = node.getType(); // special case for 'break' statement, since it went to // 'usedKeywordsAsNames' rule and now // it is recognized as TkIdentifier if (nodeCode == LexerMetrics.IDENT.toMetrics() && "break".equalsIgnoreCase(node.getText())) { return true; } else if (nodeCode == LexerMetrics.FOR.toMetrics()) { // special case for "for" statement statementIndex.pop(); statementIndex.push(node.getChildIndex() + 1); lastStatementText = node.getText(); return true; } for (LexerMetrics code : STATEMENT_NODES) { if (code.toMetrics() == nodeCode) { lastStatementText = node.getText(); return true; } } return false; }
private String getArgumentTypes(Tree nameNode) { Tree typeNode = nameNode.getParent().getChild(nameNode.getChildIndex() + 1); if (typeNode.getChildCount() > 0) { return typeNode.getChild(0).getText(); } return UNTYPED_PARAMETER_NAME; }
@SuppressWarnings({ "unchecked", "rawtypes" }) static void replaceNodeWithNodeList(Tree oldNode, CommonTree newTree, String fileName) { int idx = oldNode.getChildIndex(); CommonTree parent = (CommonTree) oldNode.getParent(); int count = parent.getChildCount(); List childList = new ArrayList(parent.getChildren()); List macroList = newTree.getChildren(); while (parent.getChildCount() > 0) { parent.deleteChild(0); } for (int i = 0; i < count; i++) { if (i == idx) { // add only there is something to add if (macroList != null) { parent.addChildren(macroList); } } else { parent.addChild((Tree) childList.get(i)); } } }
public void removeOrderBy() { Tree orderBy = queryTree.getAstTree().getFirstChildWithType(JPA2Lexer.T_ORDER_BY); if (orderBy != null) { queryTree.getAstTree().deleteChild(orderBy.getChildIndex()); } queryTree.getAstTree().freshenParentAndChildIndexes(); }
@Override public CodeNode<Tree> execute(Tree node) { if (node == null) { return new CodeNode<Tree>(null); } Tree parent = node.getParent(); if (parent == null) { return new CodeNode<Tree>(null); } Tree nextNode = parent.getChild(node.getChildIndex() + 1); if (nextNode != null) { return new CodeNode<Tree>(nextNode); } // No child found, trace back again return execute(parent); } }
public boolean verify(Tree node) { CommonTree nextNode = (CommonTree) node.getParent().getChild(node.getChildIndex() + 1); // if we are on a ident token and it is not last if (node.getType() == LexerMetrics.IDENT.toMetrics() && nextNode != null && (nextNode.getType() == LexerMetrics.LPAREN.toMetrics() || nextNode.getType() == LexerMetrics.SEMI.toMetrics())) { String functionName = node.getText().toLowerCase(); List<UnitInterface> unitsToLook = new ArrayList<UnitInterface>(); // first we look in current unit for function reference unitsToLook.add(results.getActiveUnit()); unitsToLook.addAll(results.getActiveUnit().getIncludedUnits(results.getCachedUnits())); for (UnitInterface unit : unitsToLook) { FunctionInterface[] functions = unit.getAllFunctions(); for (FunctionInterface func : functions) { if (func.getShortName().equalsIgnoreCase(functionName)) { calledFunction = func; isUnresolved = false; return true; } } } // create a new unresolved function calledFunction = new DelphiFunction(node.getText().toLowerCase()); // no function found, but this was a function call isUnresolved = true; // so we return true return true; } return false; // not a function call (not like "foo(args);" or "foo;" }
return false; int childIndex = node.getChildIndex(); if (childIndex <= statementIndex.peek()) {
private int extractLine(Tree currentCodeNode) { Tree parent = currentCodeNode.getParent(); for (int i = currentCodeNode.getChildIndex() - 1; i >= 0; i--) { Tree child = parent.getChild(i); if (child.getType() == DelphiLexer.FUNCTION || child.getType() == DelphiLexer.PROCEDURE || child.getType() == DelphiLexer.CONSTRUCTOR || child.getType() == DelphiLexer.DESTRUCTOR || child.getType() == DelphiLexer.OPERATOR) { return child.getLine(); } } return -1; }
public void replaceWithCount(Tree node) { Tree selectedItems = queryTree.getAstSelectedItemsNode(); boolean isDistinct = "distinct".equalsIgnoreCase(selectedItems.getChild(0).getText()); if (!(isDistinct && selectedItems.getChildCount() == 2 || selectedItems.getChildCount() == 1)) throw new IllegalStateException("Cannot replace with count if multiple fields selected"); SelectedItemNode selectedItemNode; if (isDistinct) selectedItems.deleteChild(0); selectedItemNode = (SelectedItemNode) selectedItems.getChild(0); AggregateExpressionNode countNode = createCountNode(node, isDistinct); selectedItemNode.deleteChild(0); selectedItemNode.addChild(countNode); Tree orderBy = queryTree.getAstTree().getFirstChildWithType(JPA2Lexer.T_ORDER_BY); if (orderBy != null) { queryTree.getAstTree().deleteChild(orderBy.getChildIndex()); } queryTree.getAstTree().freshenParentAndChildIndexes(); }