/** Get the pointer to the parent node */ public Operand getParent() { return ( Operand ) super.getParent(); }
private void findTableNames(final Object obj, final Set<TableName> tableNames) { if (!(obj instanceof CommonTree)) { return; } final CommonTree tree = (CommonTree) obj; final int childCount = tree.getChildCount(); if ("TOK_TABNAME".equals(tree.getText())) { final TableName tableName; final boolean isInput = "TOK_TABREF".equals(tree.getParent().getText()); switch (childCount) { case 1 : tableName = new TableName(null, tree.getChild(0).getText(), isInput); break; case 2: tableName = new TableName(tree.getChild(0).getText(), tree.getChild(1).getText(), isInput); break; default: throw new IllegalStateException("TOK_TABNAME does not have expected children, childCount=" + childCount); } // If parent is TOK_TABREF, then it is an input table. tableNames.add(tableName); return; } for (int i = 0; i < childCount; i++) { findTableNames(tree.getChild(i), tableNames); } }
private void findTableNames(final Object obj, final Set<TableName> tableNames) { if (!(obj instanceof CommonTree)) { return; } final CommonTree tree = (CommonTree) obj; final int childCount = tree.getChildCount(); if ("TOK_TABNAME".equals(tree.getText())) { final TableName tableName; final boolean isInput = "TOK_TABREF".equals(tree.getParent().getText()); switch (childCount) { case 1 : tableName = new TableName(null, tree.getChild(0).getText(), isInput); break; case 2: tableName = new TableName(tree.getChild(0).getText(), tree.getChild(1).getText(), isInput); break; default: throw new IllegalStateException("TOK_TABNAME does not have expected children, childCount=" + childCount); } // If parent is TOK_TABREF, then it is an input table. tableNames.add(tableName); return; } for (int i = 0; i < childCount; i++) { findTableNames(tree.getChild(i), tableNames); } }
public static CommonTree getModuleParent(CommonTree ct) { return (CommonTree) ct.getParent(); } }
public static CommonTree getModuleParent(CommonTree ct) { return (CommonTree) ct.getParent(); } }
@Override public HiddenTokenAwareTree getParent() { return (HiddenTokenAwareTree) super.getParent(); }
@Override public Object post(Object t) { if (!(t instanceof CommonTree)) return t; if (t instanceof CommonErrorNode) { return t; } CommonTree node = (CommonTree) t; if (node.token == null) return t; if ((node instanceof QueryNode) && node.getParent() != null && "T_CONDITION".equals(((CommonTree) node.getParent()).token.getText())) { stack.peekLast().setPropagateVariablesUp(false); return t; } if (node instanceof IdentificationVariableNode) { IdentificationVariableNode vnode = (IdentificationVariableNode) node; vnode.identifyVariableEntity(model, stack, invalidIdVarNodes); return t; } if (node instanceof JoinVariableNode) { JoinVariableNode vnode = (JoinVariableNode) node; vnode.identifyVariableEntity(model, stack, invalidIdVarNodes); return t; } return t; }
/** * C-tor, used in DelphiPMD to safely cast from CommonTree to DelphiPMDNode * * @param node CommonTree node */ public DelphiPMDNode(CommonTree node) { super(node.getToken()); this.children = node.getChildren(); this.parent = (CommonTree) node.getParent(); this.childIndex = node.getChildIndex(); }
public void visit(Object t) { CommonTree a = (CommonTree)t; if ( a.getParent().getType()==ANTLRv3Parser.RULE_REF ) { tokens.delete(a.getTokenStartIndex(), a.getTokenStopIndex()); } } });
@Override public void visit(Object t) { CommonTree a = (CommonTree)t; if ( a.getParent().getType()==ANTLRv3Parser.RULE_REF ) { tokens.delete(a.getTokenStartIndex(), a.getTokenStopIndex()); } } });
public void visit(Object t) { CommonTree a = (CommonTree)t; if ( a.getParent().getType()==ANTLRv3Parser.RULE_REF ) { tokens.delete(a.getTokenStartIndex(), a.getTokenStopIndex()); } } });
@Override public void visit(Object t) { CommonTree a = (CommonTree)t; if ( a.getParent().getType()==ANTLRv3Parser.RULE_REF ) { tokens.delete(a.getTokenStartIndex(), a.getTokenStopIndex()); } } });
public static void ACTION(TokenRewriteStream tokens, CommonTree t) { CommonTree parent = (CommonTree)t.getParent(); int ptype = parent.getType(); if ( ptype==ANTLRv3Parser.SCOPE || // we have special rules for these ptype==ANTLRv3Parser.AT ) { return; } //System.out.println("ACTION: "+t.getText()); CommonTree root = (CommonTree)t.getAncestor(ANTLRv3Parser.RULE); if ( root!=null ) { CommonTree rule = (CommonTree)root.getChild(0); //System.out.println("rule: "+rule); if ( !Character.isUpperCase(rule.getText().charAt(0)) ) { tokens.delete(t.getTokenStartIndex(),t.getTokenStopIndex()); killTrailingNewline(tokens, t.token.getTokenIndex()); } } }
public static void ACTION(TokenRewriteStream tokens, CommonTree t) { CommonTree parent = (CommonTree)t.getParent(); int ptype = parent.getType(); if ( ptype==ANTLRv3Parser.SCOPE || // we have special rules for these ptype==ANTLRv3Parser.AT ) { return; } //System.out.println("ACTION: "+t.getText()); CommonTree root = (CommonTree)t.getAncestor(ANTLRv3Parser.RULE); if ( root!=null ) { CommonTree rule = (CommonTree)root.getChild(0); //System.out.println("rule: "+rule); if ( !Character.isUpperCase(rule.getText().charAt(0)) ) { tokens.delete(t.getTokenStartIndex(),t.getTokenStopIndex()); killTrailingNewline(tokens, t.token.getTokenIndex()); } } }
public static void ACTION(TokenRewriteStream tokens, CommonTree t) { CommonTree parent = (CommonTree)t.getParent(); int ptype = parent.getType(); if ( ptype==ANTLRv3Parser.SCOPE || // we have special rules for these ptype==ANTLRv3Parser.AT ) { return; } //System.out.println("ACTION: "+t.getText()); CommonTree root = (CommonTree)t.getAncestor(ANTLRv3Parser.RULE); if ( root!=null ) { CommonTree rule = (CommonTree)root.getChild(0); //System.out.println("rule: "+rule); if ( !Character.isUpperCase(rule.getText().charAt(0)) ) { tokens.delete(t.getTokenStartIndex(),t.getTokenStopIndex()); killTrailingNewline(tokens, t.token.getTokenIndex()); } } }
public static void ACTION(TokenRewriteStream tokens, CommonTree t) { CommonTree parent = (CommonTree)t.getParent(); int ptype = parent.getType(); if ( ptype==ANTLRv3Parser.SCOPE || // we have special rules for these ptype==ANTLRv3Parser.AT ) { return; } //System.out.println("ACTION: "+t.getText()); CommonTree root = (CommonTree)t.getAncestor(ANTLRv3Parser.RULE); if ( root!=null ) { CommonTree rule = (CommonTree)root.getChild(0); //System.out.println("rule: "+rule); if ( !Character.isUpperCase(rule.getText().charAt(0)) ) { tokens.delete(t.getTokenStartIndex(),t.getTokenStopIndex()); killTrailingNewline(tokens, t.token.getTokenIndex()); } } }
private void findTableNames(final Object obj, final Set<TableName> tableNames) { if (!(obj instanceof CommonTree)) { return; } final CommonTree tree = (CommonTree) obj; final int childCount = tree.getChildCount(); if ("TOK_TABNAME".equals(tree.getText())) { final TableName tableName; final boolean isInput = "TOK_TABREF".equals(tree.getParent().getText()); switch (childCount) { case 1 : tableName = new TableName(null, tree.getChild(0).getText(), isInput); break; case 2: tableName = new TableName(tree.getChild(0).getText(), tree.getChild(1).getText(), isInput); break; default: throw new IllegalStateException("TOK_TABNAME does not have expected children, childCount=" + childCount); } // If parent is TOK_TABREF, then it is an input table. tableNames.add(tableName); return; } for (int i = 0; i < childCount; i++) { findTableNames(tree.getChild(i), tableNames); } }
Tree defineNode = t.getParent(); Tree stmtNode = defineNode.getParent(); stmtNode.deleteChild(defineNode.getChildIndex());
getPreviousTokenInHiddenChannel(retval, input); public String getPreviousTokenInHiddenChannel(TreeRuleReturnScope retval, TreeNodeStream input) { try { TokenStream tstream = input.getTokenStream(); CommonTree node = (CommonTree) retval.start; int boundary = node.getTokenStopIndex(); if (boundary <= 0) { // fix for antlr 3.3 bug, from 3.5 getTokenStartIndex should itself resolve parent's boundaries if <= 0 while (node.getTokenStartIndex() == -1) { // if node is imaginary node = (CommonTree) node.getParent(); if (node == null) return ""; // means we are root boundary = node.getTokenStopIndex(); if (boundary > 0) break; } } int i = boundary; while (true) { i--; Token tok = tstream.get(i); if (tok.getChannel() == HIDDEN) { // do what you want to do https://www.youtube.com/watch?v=JgRBkjgXHro } } } catch (Exception e) { // handle e } }