uk.co.badgersinfoil.metaas.dom
Interface ASIfStatement

All Superinterfaces:
ScriptElement, Statement, StatementContainer

public interface ASIfStatement
extends Statement, StatementContainer

An if-statement, such as if (a) { doSomething(); }.

ASIfStatement is a StatementContainer to simplify the common case where the attached statement (as returned by getThenStatement()) is a block (very handy if you are generating code using metaas). If the attached statement is not a block, attempting to call StatementContainer methods directly on this if-statement will fail with an exception, so it is generally required to call getThenStatement() rather than attempting to use StatementContainer methods on the ASIfStatement, or code which was parsed.

e.g. To simply add statements to the 'then' branch (executed when the condition holds true),

 ASIfStatement ifStmt = method.newIf("test()");
 isStmt.addStmt("trace('test succeeded')");

will result in ActionScript code like,

 if (test()) {
        trace('test succeeded');
 }

To add code to both 'then' and 'else' branches,

 ASIfStatement ifStmt = method.newIf("test()");
 ifStmt.addStmt("trace('test succeeded')");
 ifStmt.elseBlock().addStmt("trace('test failed')");

will result in ActionScript code like,

 if (test()) {
        trace('test succeeded');
 } else {
        trace('test failed');
 }

Note that the first call to elseBlock() will cause the else-clause to be created with a block attached to it (even if no statements are subsequently added). Subsequent calls to elseBlock() will return references to the same block, rather than creating further code.

See Also:
StatementContainer.newIf(Expression)

Method Summary
 ASBlock elseBlock()
          Returns a reference to an object which can populate the else-clause of this ActionScript if-statement with new code.
 Expression getCondition()
           
 java.lang.String getConditionString()
          Returns a string representation of the condition-expression for this if-statement.
 ASBlock getElse()
          Deprecated. use elseBlock().
 Statement getElseStatement()
          Returns the statement attached to the else-clause of this if-statement, or null if no else-clause is present.
 Statement getThenStatement()
           
 void setCondition(Expression expr)
           
 void setCondition(java.lang.String expr)
          Changes the condition-expression for this if-statement.
 void setThen(ASBlock thenBlock)
          Deprecated. Use setThenStatement(Statement)
 void setThenStatement(Statement then)
           
 
Methods inherited from interface uk.co.badgersinfoil.metaas.dom.StatementContainer
addComment, addStmt, containsCode, getStatementList, newBreak, newContinue, newDeclaration, newDeclaration, newDefaultXMLNamespace, newDoWhile, newDoWhile, newExprStmt, newExprStmt, newFor, newFor, newForEachIn, newForEachIn, newForIn, newForIn, newIf, newIf, newReturn, newReturn, newReturn, newSuper, newSwitch, newSwitch, newThrow, newTryCatch, newTryFinally, newWhile, newWhile, newWith, newWith
 

Method Detail

getElse

ASBlock getElse()
Deprecated. use elseBlock().


elseBlock

ASBlock elseBlock()
Returns a reference to an object which can populate the else-clause of this ActionScript if-statement with new code. If no else-clause is attached to this if-statement, one will be automatically added as a result of calling this method.

Throws:
SyntaxException - if this if-statement already has an else-clause attached and the statement in the else-clause is something other than a block-statement.

getElseStatement

Statement getElseStatement()
Returns the statement attached to the else-clause of this if-statement, or null if no else-clause is present.


getThenStatement

Statement getThenStatement()

setThenStatement

void setThenStatement(Statement then)

setThen

void setThen(ASBlock thenBlock)
Deprecated. Use setThenStatement(Statement)


getConditionString

java.lang.String getConditionString()
Returns a string representation of the condition-expression for this if-statement. e.g. for the expression if (test()) { }, this method will return the string "test()".


getCondition

Expression getCondition()

setCondition

void setCondition(java.lang.String expr)
Changes the condition-expression for this if-statement.

Throws:
SyntaxException - if the given string is not a valid ActionScript expression.

setCondition

void setCondition(Expression expr)


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