uk.co.badgersinfoil.metaas.dom
Interface StatementContainer

All Known Subinterfaces:
ASBlock, ASDoWhileStatement, ASForEachInStatement, ASForInStatement, ASForStatement, ASIfStatement, ASMethod, ASSwitchCase, ASSwitchDefault, ASWhileStatement, ASWithStatement

public interface StatementContainer

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


Method Summary
 void addComment(java.lang.String text)
          Adds a single-line comment to list of statements being generated
 void 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 statements held in the containing element.
 ASDeclarationStatement newDeclaration(java.lang.String assignment)
          Adds a new variable declaration to the code, and returns a reference to it.
 ASDoWhileStatement newDoWhile(java.lang.String condition)
          Adds a do-while-loop to the code.
 ASExpressionStatement newExprStmt(java.lang.String expr)
          Adds a new expression-statement to the code, and returns a reference to it.
 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(java.lang.String init, java.lang.String list)
           
 ASForInStatement newForIn(java.lang.String init, java.lang.String list)
          Adds a for-in-loop to the code.
 ASIfStatement newIf(java.lang.String condition)
          Adds an if-statement to the code.
 ASReturnStatement newReturn(java.lang.String expr)
          Adds a new return-statement to the code (with optional return expression), and returns a reference to it.
 ASSwitchStatement newSwitch(java.lang.String condition)
          Adds a switch-statement to the code.
 ASWhileStatement newWhile(java.lang.String condition)
          Adds a while-loop to the code.
 ASWithStatement newWith(java.lang.String string)
          Adds a new with-statement to the code, and returns a reference to it.
 

Method Detail

addStmt

void 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).


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');
 }


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);
 }


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);
 }


newForEachIn

ASForEachInStatement newForEachIn(java.lang.String init,
                                  java.lang.String 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');
 }


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());


newSwitch

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


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);
 }


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;


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();


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 statements 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-2007 David Holroyd. All Rights Reserved.