private ASPrefixExpression newPrefixExpression(LinkedListToken op, Expression sub) { LinkedListTree ast = ASTUtils.newAST(op); LinkedListTree subExpr = ast(sub); ASTBuilder.assertNoParent("sub-expression", subExpr); ast.addChildWithTokens(subExpr); return new ASTASPrefixExpression(ast); }
/** @throws SyntaxException if the given string is not a vaild ActionScript 3 expression. */ public Expression newExpression(String expr) { LinkedListTree ast = AS3FragmentParser.parseExpr(expr); // ANTLR creates a 'nil' parent node (in case the result is a // list). We break the link to that parent because we assert // the parent is null when child nodes are attached elsewhere // in the tree. ast.setParent(null); return ExpressionBuilder.build(ast); }
public String getTypeName() { LinkedListTree type = ASTUtils.findChildByType(ast, AS3Parser.TYPE_SPEC); if (type == null) { return null; } final LinkedListTree typeAST = type.getFirstChild(); if (typeAST.getType() == AS3Parser.STAR) { return "*"; } return ASTUtils.identText(typeAST); }
private void setExpr(LinkedListTree expression) { if (hasExpr()) { LinkedListToken after = ast.getStopToken(); LinkedListToken before = after.getPrev(); ast.addChild(expression); before.setNext(expression.getStartToken()); after.setPrev(expression.getStopToken()); before.afterInsert(TokenBuilder.newSpace()); } else { ast.setChildWithTokens(0, expression); } }
public List<ASNamespaceDeclaration> getOutOfPackageNamespaces() { List<ASNamespaceDeclaration> namespaces = new ArrayList<ASNamespaceDeclaration>(); List<LinkedListTree> namespacesAST = ASTUtils.findChildrenByType(ast, AS3Parser.NAMESPACE_DEF); for (LinkedListTree namespaceAST : namespacesAST) { final LinkedListTree child = namespaceAST.getFirstChild(); if (child != null) { namespaces.add(new ASTASNamespaceDeclaration(namespaceAST)); } } return namespaces; }
/** * @param argumentNode the ARGUMENTS AST node * @param args list of ASExpression objects to be used as the new argument list */ public static void overwriteArgsWithExpressionList(LinkedListTree argumentNode, List args) { // get rid of any old arguments, ASTUtils.deleteAllChildren(argumentNode); // add the new arguments, for (Iterator i = args.iterator(); i.hasNext(); ) { ASTExpression arg = (ASTExpression) i.next(); argumentNode.addChildWithTokens(arg.getAST()); if (i.hasNext()) { argumentNode.appendToken(TokenBuilder.newComma()); argumentNode.appendToken(TokenBuilder.newSpace()); } } }
public List<Statement> getOutOfPackageStatements() { List<Statement> statements = new ArrayList<Statement>(); List<LinkedListTree> statementsAST = ASTUtils.findChildrenByType(ast, AS3Parser.OUT_OF_FUNCTION_STMT); for (LinkedListTree statementAST : statementsAST) { final LinkedListTree child = statementAST.getFirstChild(); if (child != null) { statements.add(StatementBuilder.build(child)); } } return statements; }
public ASArrayAccessExpression newArrayAccessExpression(Expression target, Expression subscript) { LinkedListTree ast = ASTUtils.newImaginaryAST(AS3Parser.ARRAY_ACC); LinkedListTree targetExpr = ast(target); ASTBuilder.assertNoParent("target expression", targetExpr); // TODO: recursively check the given subexpression ast.addChildWithTokens(targetExpr); ast.appendToken(TokenBuilder.newLBrack()); LinkedListTree subscriptExpr = ast(subscript); ASTBuilder.assertNoParent("subscript expression", subscriptExpr); ast.addChildWithTokens(subscriptExpr); ast.appendToken(TokenBuilder.newRBrack()); ASTASArrayAccessExpression result = new ASTASArrayAccessExpression(ast); return result; }
public ASInvocationExpression newInvocationExpression(Expression sub, List args) { LinkedListTree ast = ASTUtils.newImaginaryAST(AS3Parser.METHOD_CALL); LinkedListTree subExpr = ast(sub); ASTBuilder.assertNoParent("sub-expression", subExpr); // TODO: recursively check the given subexpression ast.addChildWithTokens(subExpr); LinkedListTree arguments = ASTUtils.newParentheticAST( AS3Parser.ARGUMENTS, AS3Parser.LPAREN, "(", AS3Parser.RPAREN, ")"); ast.addChildWithTokens(arguments); ASTASInvocationExpression result = new ASTASInvocationExpression(ast); result.setArguments(args); return result; }
public ASNewExpression newNewExpression(Expression subexpression, List args) { LinkedListTree ast = ASTUtils.newAST(AS3Parser.NEW, "new"); ast.appendToken(TokenBuilder.newSpace()); LinkedListTree subExpr = ast(subexpression); ASTBuilder.assertNoParent("sub-expression", subExpr); // TODO: recursively check the given subexpression ast.addChildWithTokens(subExpr); LinkedListTree arguments = ASTUtils.newParentheticAST( AS3Parser.ARGUMENTS, AS3Parser.LPAREN, "(", AS3Parser.RPAREN, ")"); ast.addChildWithTokens(arguments); ASTASNewExpression result = new ASTASNewExpression(ast); result.setArguments(args); return result; }
/** * @param args the ARGUMENTS AST node * @return a list of ASExpression */ public static List astToExpressionList(LinkedListTree args) { ASTIterator i = new ASTIterator(args); List result = new ArrayList(args.getChildCount()); while (i.hasNext()) { result.add(ExpressionBuilder.build(i.next())); } return Collections.unmodifiableList(result); }
private ASPostfixExpression newPostfixExpression(LinkedListToken op, Expression sub) { LinkedListTree ast = ASTUtils.newAST(op); LinkedListTree subExpr = ast(sub); ASTBuilder.assertNoParent("sub-expression", subExpr); ast.addChild(subExpr); ast.setStartToken(subExpr.getStartToken()); subExpr.getStopToken().setNext(op); return new ASTASPostfixExpression(ast); }
private String importText(LinkedListTree imp) { return ASTUtils.identStarText(imp.getFirstChild()); }