|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ASIfStatement
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.
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 |
---|
ASBlock getElse()
elseBlock()
.
ASBlock elseBlock()
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.Statement getElseStatement()
Statement getThenStatement()
void setThenStatement(Statement then)
void setThen(ASBlock thenBlock)
setThenStatement(Statement)
java.lang.String getConditionString()
if (test()) { }
, this method will return the string
"test()"
.
Expression getCondition()
void setCondition(java.lang.String expr)
SyntaxException
- if the given
string is not a valid ActionScript expression.void setCondition(Expression expr)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |