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; }
protected ClassNode[] interfaces(AST node) { List<ClassNode> interfaceList = new ArrayList<ClassNode>(); for (AST implementNode = node.getFirstChild(); implementNode != null; implementNode = implementNode.getNextSibling()) { interfaceList.add(makeTypeWithArguments(implementNode)); } ClassNode[] interfaces = ClassNode.EMPTY_ARRAY; if (!interfaceList.isEmpty()) { interfaces = new ClassNode[interfaceList.size()]; interfaceList.toArray(interfaces); } return interfaces; }
public List<GroovySourceAST> childrenOfType(int type) { List<GroovySourceAST> result = new ArrayList<GroovySourceAST>(); AST child = this.getFirstChild(); while (child != null) { if (child.getType() == type) { result.add((GroovySourceAST) child); } child = child.getNextSibling(); } return result; }
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); } }
protected Expression enumArguments(AST elist) { List<Expression> expressionList = new ArrayList<Expression>(); for (AST node = elist; node != null; node = node.getNextSibling()) { Expression expression = expression(node); expressionList.add(expression); } ArgumentListExpression argumentListExpression = new ArgumentListExpression(expressionList); configureAST(argumentListExpression, elist); return argumentListExpression; }
private void processAnnotations(List<AnnotationNode> annotations, AST node) { AST child = node.getFirstChild(); while (child != null) { if (isType(ANNOTATION, child)) annotations.add(annotation(child)); child = child.getNextSibling(); } }
private List<GenericsType> getTypeArgumentsList(AST node) { assertNodeType(TYPE_ARGUMENTS, node); List<GenericsType> typeArgumentList = new LinkedList<GenericsType>(); AST typeArgument = node.getFirstChild(); while (typeArgument != null) { assertNodeType(TYPE_ARGUMENT, typeArgument); GenericsType gt = makeGenericsArgumentType(typeArgument); typeArgumentList.add(gt); typeArgument = typeArgument.getNextSibling(); } return typeArgumentList; }
private void dumpTree(AST ast, String offset) { dump(ast, offset); for (AST node = ast.getFirstChild(); node != null; node = node.getNextSibling()) { dumpTree(node, offset+"\t"); } }
private BlockStatement siblingsToBlockStatement(AST firstSiblingNode) { BlockStatement block = new BlockStatement(); for (AST node = firstSiblingNode; node != null; node = node.getNextSibling()) { block.addStatement(statement(node)); } return block; }
protected Expression asExpression(AST node) { AST leftNode = node.getFirstChild(); Expression leftExpression = expression(leftNode); AST rightNode = leftNode.getNextSibling(); ClassNode type = makeTypeWithArguments(rightNode); return CastExpression.asExpression(type, leftExpression); }
protected Statement labelledStatement(AST labelNode) { AST node = labelNode.getFirstChild(); String label = identifier(node); Statement statement = statement(node.getNextSibling()); statement.addStatementLabel(label); return statement; }
protected void packageDef(AST packageDef) { List<AnnotationNode> annotations = new ArrayList<AnnotationNode>(); AST node = packageDef.getFirstChild(); if (isType(ANNOTATIONS, node)) { processAnnotations(annotations, node); node = node.getNextSibling(); } String name = qualifiedName(node); // TODO should we check package node doesn't already exist? conflict? PackageNode packageNode = setPackage(name, annotations); configureAST(packageNode, packageDef); }
protected Expression rangeExpression(AST rangeNode, boolean inclusive) { AST node = rangeNode.getFirstChild(); Expression left = expression(node); Expression right = expression(node.getNextSibling()); RangeExpression rangeExpression = new RangeExpression(left, right, inclusive); configureAST(rangeExpression, rangeNode); return rangeExpression; }
@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 Statement synchronizedStatement(AST syncNode) { AST node = syncNode.getFirstChild(); Expression expression = expression(node); Statement code = statement(node.getNextSibling()); SynchronizedStatement synchronizedStatement = new SynchronizedStatement(expression, code); configureAST(synchronizedStatement, syncNode); return synchronizedStatement; }
protected Statement throwStatement(AST node) { AST expressionNode = node.getFirstChild(); if (expressionNode == null) { expressionNode = node.getNextSibling(); } if (expressionNode == null) { throw new ASTRuntimeException(node, "No expression available"); } ThrowStatement throwStatement = new ThrowStatement(expression(expressionNode)); configureAST(throwStatement, node); return throwStatement; }
protected Expression castExpression(AST castNode) { AST node = castNode.getFirstChild(); ClassNode type = makeTypeWithArguments(node); assertTypeNotNull(type, node); AST expressionNode = node.getNextSibling(); Expression expression = expression(expressionNode); CastExpression castExpression = new CastExpression(type, expression); configureAST(castExpression, castNode); return castExpression; }
protected ClosureExpression closureExpression(AST node) { AST paramNode = node.getFirstChild(); Parameter[] parameters = null; AST codeNode = paramNode; if (isType(PARAMETERS, paramNode) || isType(IMPLICIT_PARAMETERS, paramNode)) { parameters = parameters(paramNode); codeNode = paramNode.getNextSibling(); } Statement code = statementListNoChild(codeNode, node); ClosureExpression closureExpression = new ClosureExpression(parameters, code); configureAST(closureExpression, node); return closureExpression; }
protected Expression instanceofExpression(AST node) { AST leftNode = node.getFirstChild(); Expression leftExpression = expression(leftNode); AST rightNode = leftNode.getNextSibling(); ClassNode type = buildName(rightNode); assertTypeNotNull(type, rightNode); Expression rightExpression = new ClassExpression(type); configureAST(rightExpression, rightNode); BinaryExpression binaryExpression = new BinaryExpression(leftExpression, makeToken(Types.KEYWORD_INSTANCEOF, node), rightExpression); configureAST(binaryExpression, node); return binaryExpression; }