protected Expression listExpression(AST listNode) { List<Expression> expressions = new ArrayList<Expression>(); AST elist = listNode.getFirstChild(); assertNodeType(ELIST, elist); for (AST node = elist.getFirstChild(); node != null; node = node.getNextSibling()) { // check for stray labeled arguments: switch (node.getType()) { case LABELED_ARG: assertNodeType(COMMA, node); break; // helpful error? case SPREAD_MAP_ARG: assertNodeType(SPREAD_ARG, node); break; // helpful error } expressions.add(expression(node)); } ListExpression listExpression = new ListExpression(expressions); configureAST(listExpression, listNode); return listExpression; }
@Override public void visitMultiCatch(final GroovySourceAST t, final int visit) { if (visit == CLOSING_VISIT) { final AST child = t.getFirstChild(); if ("MULTICATCH_TYPES".equals(child.getText())) { print(t, visit, null, null, " "+child.getNextSibling().getText()); } else { print(t, visit, null, null, " "+child.getFirstChild().getText()); } } }
protected String getFirstChildText(AST node) { AST child = node.getFirstChild(); return child != null ? child.getText() : null; }
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 void dumpTree(AST ast) { for (AST node = ast.getFirstChild(); node != null; node = node.getNextSibling()) { dump(node); } }
Token first = cloneToken(LT(1)); if (modifiers != null) { first.setLine(modifiers.getLine()); first.setColumn(modifiers.getColumn()); annotationDefinition_AST = (AST)astFactory.make( (new ASTArray(4)).add(create(ANNOTATION_DEF,"ANNOTATION_DEF",first,LT(1))).add(modifiers).add(tmp38_AST).add(ab_AST)); currentAST.root = annotationDefinition_AST; currentAST.child = annotationDefinition_AST!=null &&annotationDefinition_AST.getFirstChild()!=null ? annotationDefinition_AST.getFirstChild() : annotationDefinition_AST; currentAST.advanceChildToEnd();
for (AST node = gstringNode.getFirstChild(); node != null; node = node.getNextSibling()) { int type = node.getType(); String text = null; switch (type) { if (isPrevString) assertNodeType(IDENT, node); // parser bug isPrevString = true; text = node.getText(); ConstantExpression constantExpression = new ConstantExpression(text); configureAST(constantExpression, node);
protected Expression unaryMinusExpression(AST unaryMinusExpr) { AST node = unaryMinusExpr.getFirstChild(); // if we are a number literal then let's just parse it // as the negation operator on MIN_INT causes rounding to a long String text = node.getText(); switch (node.getType()) { case NUM_DOUBLE: case NUM_FLOAT: case NUM_BIG_DECIMAL: ConstantExpression constantExpression = new ConstantExpression(Numbers.parseDecimal("-" + text)); configureAST(constantExpression, unaryMinusExpr); return constantExpression; case NUM_BIG_INT: case NUM_INT: case NUM_LONG: ConstantExpression constantLongExpression = new ConstantExpression(Numbers.parseInteger(unaryMinusExpr,"-" + text)); configureAST(constantLongExpression, unaryMinusExpr); return constantLongExpression; default: UnaryMinusExpression unaryMinusExpression = new UnaryMinusExpression(expression(node)); configureAST(unaryMinusExpression, unaryMinusExpr); return unaryMinusExpression; } }
boolean isStatic = importNode.getType() == STATIC_IMPORT; List<AnnotationNode> annotations = new ArrayList<AnnotationNode>(); AST node = importNode.getFirstChild(); if (isType(ANNOTATIONS, node)) { processAnnotations(annotations, node); node = node.getNextSibling(); if (isType(LITERAL_as, node)) { node = node.getFirstChild(); AST aliasNode = node.getNextSibling(); alias = identifier(aliasNode); if (node.getNumberOfChildren() == 0) { String name = identifier(node); AST packageNode = node.getFirstChild(); String packageName = qualifiedName(packageNode); AST nameNode = packageNode.getNextSibling(); if (isType(STAR, nameNode)) { if (isStatic) {
/** * Extracts an identifier from the Antlr AST */ protected String identifier(AST node) { assertNodeType(IDENT, node); return node.getText(); }
protected boolean addArgumentExpression(AST node, List<Expression> expressionList) { if (node.getType() == SPREAD_MAP_ARG) { AST rightNode = node.getFirstChild(); Expression keyExpression = spreadMapExpression(node); Expression rightExpression = expression(rightNode); MapEntryExpression mapEntryExpression = new MapEntryExpression(keyExpression, rightExpression); expressionList.add(mapEntryExpression); return true; } else { Expression expression = expression(node); expressionList.add(expression); return expression instanceof MapEntryExpression; } }
Token first = cloneToken(LT(1)); if (mods != null) { first.setLine(mods.getLine()); first.setColumn(mods.getColumn()); } else if (t != null) { first.setLine(t.getLine()); first.setColumn(t.getColumn()); match(STRING_LITERAL); if ( inputState.guessing==0 ) { qid_AST.setType(IDENT); currentAST.child = variableDefinitions_AST!=null &&variableDefinitions_AST.getFirstChild()!=null ? variableDefinitions_AST.getFirstChild() : variableDefinitions_AST; currentAST.advanceChildToEnd();
protected String label(AST labelNode) { AST node = labelNode.getFirstChild(); if (node == null) { return null; } return identifier(node); }
private void dumpTree(AST ast, String indent) { dump(ast); for (AST node = ast.getFirstChild(); node != null; node = node.getNextSibling()) { if (node.getNumberOfChildren() > 0) { dumpTree(node, indent + " "); } else { dump(node, indent + " "); } } }
public static boolean isType(int typeCode, AST node) { return node != null && node.getType() == typeCode; }
private boolean isConstructorIdent(Token x) { if (currentClass == null) return false; if (currentClass.getType() != IDENT) return false; // cannot happen? String cname = currentClass.getText(); if (x == null || x.getType() != IDENT) return false; // cannot happen? return cname.equals(x.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 getColumn() { return ast != null ? ast.getColumn() : -1; }
public int getLine() { return ast != null ? ast.getLine() : -1; }