public static boolean isType(int typeCode, AST node) { return node != null && node.getType() == typeCode; }
protected String getFirstChildText(AST node) { AST child = node.getFirstChild(); return child != null ? child.getText() : null; }
protected void dumpTree(AST ast) { for (AST node = ast.getFirstChild(); node != null; node = node.getNextSibling()) { dump(node); } }
public GroovySourceAST childOfType(int type) { AST child = this.getFirstChild(); while (child != null) { if (child.getType() == type) { return (GroovySourceAST)child; } child = child.getNextSibling(); } return null; }
protected String label(AST labelNode) { AST node = labelNode.getFirstChild(); if (node == null) { return null; } return identifier(node); }
/** * Extracts an identifier from the Antlr AST */ protected String identifier(AST node) { assertNodeType(IDENT, node); return node.getText(); }
public GroovySourceAST childAt(int position) { int cur = 0; AST child = this.getFirstChild(); while (child != null && cur <= position) { if (cur == position) { return (GroovySourceAST) child; } cur++; child = child.getNextSibling(); } return null; }
public int getLine() { return ast != null ? ast.getLine() : -1; }
public int getColumn() { return ast != null ? ast.getColumn() : -1; }
public void traceOut(String rname) throws TokenStreamException { if (!GroovyRecognizer.tracing) return; if (returnAST != null) rname += returnAST.toStringList(); super.traceOut(rname); }
private void dumpTree(AST ast, String offset) { dump(ast, offset); for (AST node = ast.getFirstChild(); node != null; node = node.getNextSibling()) { dumpTree(node, offset+"\t"); } }
protected ClassNode type(AST typeNode) { // TODO intern types? // TODO configureAST(...) return buildName(typeNode.getFirstChild()); }
protected boolean isPrimitiveTypeLiteral(AST node) { int type = node.getType(); switch (type) { case LITERAL_boolean: case LITERAL_byte: case LITERAL_char: case LITERAL_double: case LITERAL_float: case LITERAL_int: case LITERAL_long: case LITERAL_short: return true; default: return false; } }
protected boolean setAccessTrue(AST node, boolean access) { if (!access) { return true; } else { throw new ASTRuntimeException(node, "Cannot specify modifier: " + node.getText() + " when access scope has already been defined"); } }
protected Expression dynamicMemberExpression(AST dynamicMemberNode) { AST node = dynamicMemberNode.getFirstChild(); return expression(node); }
private String getTokenName(AST node) { if (node == null) return "null"; return getTokenName(node.getType()); }
protected int setModifierBit(AST node, int answer, int bit) { if ((answer & bit) != 0) { throw new ASTRuntimeException(node, "Cannot repeat modifier: " + node.getText()); } return answer | bit; }
protected Statement statementList(AST code) { BlockStatement block = siblingsToBlockStatement(code.getFirstChild()); configureAST(block, code); return block; }