uk.co.badgersinfoil.metaas.dom
Interface StatementContainer

All Known Subinterfaces:
ASBlock, ASCatchClause, ASDoWhileStatement, ASFinallyClause, ASForEachInStatement, ASForInStatement, ASForStatement, ASFunctionExpression, ASIfStatement, ASMethod, ASSwitchCase, ASSwitchDefault, ASTryStatement, ASWhileStatement, ASWithStatement, SwitchLabel

public interface StatementContainer

Defines the common services provided by structures which can contain ActionScript 'statements'.

Some elements in the metaas DOM extend StatementContainer while they are not strictly containers for multiple statements. This is a convinience for the common case where the element in question usually appears with an attached block-statement. So, for example, rather than writing...

List stmts = ((ASBlock)ifStmt.getThenStatement()).getStatementList();

...we can instead write...

List stmts = ifStmt.getStatementList();
If, in the above example, the 'then-clause' of the ASIfStatement was not actually a block, a SyntaxException would be raised.


Method Summary
 void addComment(java.lang.String text)
          Adds a single-line comment to list of statements being generated
 Statement addStmt(java.lang.String statement)
          Checks the syntax of the given code, and then adds the statement to the end of the current block.
 boolean containsCode()
          Returns true if if this container currently contains at least one statement, and false if it is empty, or contains only comments and whitespace.
 java.util.List getStatementList()
          Returns a list of the Statement objects held in the containing element.
 ASBreakStatement newBreak()
          Creates a new break statement.
 ASContinueStatement newContinue()
           
 ASDeclarationStatement newDeclaration(Expression assignment)
           
 ASDeclarationStatement newDeclaration(java.lang.String assignment)
          Adds a new variable declaration to the code, and returns a reference to it.
 ASDefaultXMLNamespaceStatement newDefaultXMLNamespace(java.lang.String namespace)
           
 ASDoWhileStatement newDoWhile(Expression condition)
           
 ASDoWhileStatement newDoWhile(java.lang.String condition)
          Adds a do-while-loop to the code.
 ASExpressionStatement newExprStmt(Expression expr)
           
 ASExpressionStatement newExprStmt(java.lang.String expr)
          Adds a new expression-statement to the code, and returns a reference to it.
 ASForStatement newFor(Expression init, Expression condition, Expression update)
           
 ASForStatement newFor(java.lang.String init, java.lang.String condition, java.lang.String update)
          Adds a C-style for-loop to the code.
 ASForEachInStatement newForEachIn(Expression init, Expression list)
           
 ASForEachInStatement newForEachIn(java.lang.String init, java.lang.String list)
           
 ASForInStatement newForIn(Expression init, Expression list)
           
 ASForInStatement newForIn(java.lang.String init, java.lang.String list)
          Adds a for-in-loop to the code.
 ASIfStatement newIf(Expression condition)
           
 ASIfStatement newIf(java.lang.String condition)
          Adds an if-statement to the code.
 ASReturnStatement newReturn()
           
 ASReturnStatement newReturn(Expression expr)
           
 ASReturnStatement newReturn(java.lang.String expr)
          Adds a new return-statement to the code (with optional return expression), and returns a reference to it.
 ASSuperStatement newSuper(java.util.List arguments)
          Adds a call to the superclass constructor (assuming that this is itself a constructor).
 ASSwitchStatement newSwitch(Expression condition)
           
 ASSwitchStatement newSwitch(java.lang.String condition)
          Adds a switch-statement to the code.
 ASThrowStatement newThrow(Expression t)
           
 ASTryStatement newTryCatch(java.lang.String var, java.lang.String type)
           
 ASTryStatement newTryFinally()
           
 ASWhileStatement newWhile(Expression condition)
           
 ASWhileStatement newWhile(java.lang.String condition)
          Adds a while-loop to the code.
 ASWithStatement newWith(Expression string)
           
 ASWithStatement newWith(java.lang.String string)
          Adds a new with-statement to the code, and returns a reference to it.
 

Method Detail

addStmt

Statement addStmt(java.lang.String statement)
Checks the syntax of the given code, and then adds the statement to the end of the current block.

Throws:
SyntaxException - if the syntax of the given code fragment is incorrect.

newExprStmt

ASExpressionStatement newExprStmt(java.lang.String expr)
Adds a new expression-statement to the code, and returns a reference to it. An 'expression-statement' is a statement that just contains an expression (followed in normal ActionScript by a semicolon, though that should be omitted from the supplied string).


newExprStmt

ASExpressionStatement newExprStmt(Expression expr)

addComment

void addComment(java.lang.String text)
Adds a single-line comment to list of statements being generated

Parameters:
text - the text of the comment (minus the initial '//') which must not include any newline characters.

newIf

ASIfStatement newIf(java.lang.String condition)
Adds an if-statement to the code. e.g.
block.newIf("test()").addStmt("trace('success')")
results in
 if (test()) {
        trace('success');
 }


newIf

ASIfStatement newIf(Expression condition)

newFor

ASForStatement newFor(java.lang.String init,
                      java.lang.String condition,
                      java.lang.String update)
Adds a C-style for-loop to the code. e.g.
block.newFor("var i=0", "i<10", "i++").addStmt("trace(i)")
results in
 for (var i=0; i<10; i++) {
        trace(i);
 }


newFor

ASForStatement newFor(Expression init,
                      Expression condition,
                      Expression update)

newForIn

ASForInStatement newForIn(java.lang.String init,
                          java.lang.String list)
Adds a for-in-loop to the code. e.g.
block.newForIn("var i", "myArray").addStmt("trace(i)")
results in
 for (var i in myArray) {
        trace(i);
 }


newForIn

ASForInStatement newForIn(Expression init,
                          Expression list)

newForEachIn

ASForEachInStatement newForEachIn(java.lang.String init,
                                  java.lang.String list)

newForEachIn

ASForEachInStatement newForEachIn(Expression init,
                                  Expression list)

newWhile

ASWhileStatement newWhile(java.lang.String condition)
Adds a while-loop to the code. e.g.
block.newWhile("test()").addStmt("trace('hi there')")
results in
 while (test()) {
        trace('hi there');
 }


newWhile

ASWhileStatement newWhile(Expression condition)

newDoWhile

ASDoWhileStatement newDoWhile(java.lang.String condition)
Adds a do-while-loop to the code. e.g.
block.newDoWhile("test()").addStmt("trace('hi there')")
results in
 do {
        trace('hi there');
 } while (test());


newDoWhile

ASDoWhileStatement newDoWhile(Expression condition)

newSwitch

ASSwitchStatement newSwitch(java.lang.String condition)
Adds a switch-statement to the code. See ASSwitchStatement for more information.


newSwitch

ASSwitchStatement newSwitch(Expression condition)

newWith

ASWithStatement newWith(java.lang.String string)
Adds a new with-statement to the code, and returns a reference to it. e.g.
method.newWith("value").addStmt("trace(test)");

results in,

with (value) {
        trace(test);
 }


newWith

ASWithStatement newWith(Expression string)

newDeclaration

ASDeclarationStatement newDeclaration(java.lang.String assignment)
Adds a new variable declaration to the code, and returns a reference to it. e.g.
method.newDeclaration("a=1");

results in,

var a=1;


newDeclaration

ASDeclarationStatement newDeclaration(Expression assignment)

newReturn

ASReturnStatement newReturn(java.lang.String expr)
Adds a new return-statement to the code (with optional return expression), and returns a reference to it. e.g.
method.newReturn(null);

results in a plain return statement,

return;

Whereas passing an expression,

method.newReturn("theVal()");

results will cause that expression to be returned,

return theVal();


newReturn

ASReturnStatement newReturn(Expression expr)

newReturn

ASReturnStatement newReturn()

newSuper

ASSuperStatement newSuper(java.util.List arguments)
Adds a call to the superclass constructor (assuming that this is itself a constructor).


newBreak

ASBreakStatement newBreak()
Creates a new break statement.


newTryCatch

ASTryStatement newTryCatch(java.lang.String var,
                           java.lang.String type)

newTryFinally

ASTryStatement newTryFinally()

newContinue

ASContinueStatement newContinue()

newThrow

ASThrowStatement newThrow(Expression t)

newDefaultXMLNamespace

ASDefaultXMLNamespaceStatement newDefaultXMLNamespace(java.lang.String namespace)

containsCode

boolean containsCode()
Returns true if if this container currently contains at least one statement, and false if it is empty, or contains only comments and whitespace.


getStatementList

java.util.List getStatementList()
Returns a list of the Statement objects held in the containing element. The list is immutable (entries cannnot be added, removed or replaced) but the objects obtained from the list my be modified via the methods they provide.



Copyright © 2006-2008 David Holroyd. All Rights Reserved.