<html>
<head>
<style><!--
body {background-color:#ffffff;}
.file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
.pathname {font-family:monospace; float:right;}
.fileheader {margin-bottom:.5em;}
.diff {margin:0;}
.tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
.tasklist ul {margin-top:0;margin-bottom:0;}
tr.alt {background-color:#eeeeee}
#added {background-color:#ddffdd;}
#addedchars {background-color:#99ff99;font-weight:bolder;}
tr.alt #added {background-color:#ccf7cc;}
#removed {background-color:#ffdddd;}
#removedchars {background-color:#ff9999;font-weight:bolder;}
tr.alt #removed {background-color:#f7cccc;}
#copied {background-color:#ccccff;}
tr.alt #copied {background-color:#bbbbf7;}
#info {color:#888888;}
#context {background-color:#eeeeee;}
td {padding-left:.3em;padding-right:.3em;}
tr.head {border-bottom-width:1px;border-bottom-style:solid;}
tr.head td {padding:0;padding-top:.2em;}
.task {background-color:#ffff00;}
.comment {white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;padding:4px;border:1px dashed #000000;background-color:#ffffdd}
.error {color:red;}
hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="5">Commit in <b><tt>metaas/trunk/src</tt></b></td></tr>
<tr><td><tt>main/java/uk/co/badgersinfoil/metaas/dom/<a href="#file1">ASIfStatement.java</a></tt> </td><td></td><td align="right" id="added">+35</td><td align="right" id="removed">-18</td><td nowrap="nowrap" align="center">573 -> 574</td></tr>
<tr class="alt"><td><tt>main/java/uk/co/badgersinfoil/metaas/impl/<a href="#file2">ASTASIfStatement.java</a></tt> </td><td></td><td align="right" id="added">+33</td><td align="right" id="removed">-7</td><td nowrap="nowrap" align="center">573 -> 574</td></tr>
<tr><td><tt>test/java/uk/co/badgersinfoil/metaas/<a href="#file3">StatementTests.java</a></tt> </td><td></td><td align="right" id="added">+14</td><td align="right" id="removed">-1</td><td nowrap="nowrap" align="center">573 -> 574</td></tr>
<tr><td></td><td></td><td align="right" id="added">+82</td><td align="right" id="removed">-26</td><td></td></tr>
</table>
<small id="info">3 modified files</small><br />
<div class="tasklist"><ul>
<li><a href="#task1">TODO: 'Statement' parameter instead</a></li>
</ul></div>
<pre class="comment">
Do a better job of supporting the statement within else-clauses
per conversation with Matthew Tretter.
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname">metaas/trunk/src/main/java/uk/co/badgersinfoil/metaas/dom</span><br />
<div class="fileheader"><big><b>ASIfStatement.java</b></big> <small id="info">573 -> 574</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/metaas/dom/ASIfStatement.java        2007-12-14 23:09:13 UTC (rev 573)
+++ trunk/src/main/java/uk/co/badgersinfoil/metaas/dom/ASIfStatement.java        2007-12-15 01:20:29 UTC (rev 574)
@@ -6,50 +6,67 @@
</small></pre><pre class="diff" id="context">
package uk.co.badgersinfoil.metaas.dom;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.metaas.SyntaxException;
+
</pre><pre class="diff" id="context"> /**
* Obtained from {@link StatementContainer#newIf(String)}, an ASIfStatement
* allows statements to be added to the 'then' and else' branches.
*
* <p>e.g. To simply add statements to the 'then' branch (executed when
* the condition holds true),</p>
</pre><pre class="diff" id="removed">- * <pre>
</pre><pre class="diff" id="added">+ * <pre class="eg">
</pre><pre class="diff" id="context"> * ASIfStatement ifStmt = method.newIf("test()");
</pre><pre class="diff" id="removed">- * isStmt.addStmt("trace('test succeeded')");
- * </pre>
</pre><pre class="diff" id="added">+ * isStmt.addStmt("trace('test succeeded')");</pre>
</pre><pre class="diff" id="context"> * <p>will result in ActionScript code like,</p>
</pre><pre class="diff" id="removed">- * <pre>
</pre><pre class="diff" id="added">+ * <pre class="eg">
</pre><pre class="diff" id="context"> * if (test()) {
*         trace('test succeeded');
</pre><pre class="diff" id="removed">- * }
- * </pre>
</pre><pre class="diff" id="added">+ * }</pre>
</pre><pre class="diff" id="context"> *
* <p>To add code to both 'then' and 'else' branches,</p>
</pre><pre class="diff" id="removed">- * <pre>
</pre><pre class="diff" id="added">+ * <pre class="eg">
</pre><pre class="diff" id="context"> * ASIfStatement ifStmt = method.newIf("test()");
</pre><pre class="diff" id="removed">- * isStmt.addStmt("trace('test succeeded')");
- * ifStmt.getElse().addStmt("trace('test failed')");
- * </pre>
</pre><pre class="diff" id="added">+ * ifStmt.addStmt("trace('test succeeded')");
+ * ifStmt.elseBlock().addStmt("trace('test failed')");</pre>
</pre><pre class="diff" id="context"> * <p>will result in ActionScript code like,</p>
</pre><pre class="diff" id="removed">- * <pre>
</pre><pre class="diff" id="added">+ * <pre class="eg">
</pre><pre class="diff" id="context"> * if (test()) {
*         trace('test succeeded');
* } else {
*         trace('test failed');
</pre><pre class="diff" id="removed">- * }
- * </pre>
</pre><pre class="diff" id="added">+ * }</pre>
</pre><pre class="diff" id="context"> *
</pre><pre class="diff" id="removed">- * <p>Note that the first call to getElse() will cause the else-block to be
- * created (even if no statements are subsequently added to it). Subsequent
- * calls to getElse() will return references to the same else-block.</p>
</pre><pre class="diff" id="added">+ * <p>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.</p>
</pre><pre class="diff" id="context"> */
public interface ASIfStatement extends Statement, StatementContainer {
        /**
</pre><pre class="diff" id="removed">-         * Returns a reference to an object which can populate the else-clause
-         * of this ActionScript if-statement with new code.
</pre><pre class="diff" id="added">+         * @deprecated use {@link #elseBlock()}.
</pre><pre class="diff" id="context">          */
        public ASBlock getElse();
</pre><pre class="diff" id="added">+        /**
+         * 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.
+         */
+        public ASBlock elseBlock();
+
+        /**
+         * Returns the statement attached to the else-clause of this
+         * if-statement, or null if no else-clause is present.
+         */
+        public Statement getElseStatement();
+
<a name="task1" />+        // <span class="task">TODO</span>: 'Statement' parameter instead
</pre><pre class="diff" id="context">         public void setThen(ASBlock thenBlock);
        /**
</pre></div>
<hr /><a name="file2" /><div class="file">
<span class="pathname">metaas/trunk/src/main/java/uk/co/badgersinfoil/metaas/impl</span><br />
<div class="fileheader"><big><b>ASTASIfStatement.java</b></big> <small id="info">573 -> 574</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/metaas/impl/ASTASIfStatement.java        2007-12-14 23:09:13 UTC (rev 573)
+++ trunk/src/main/java/uk/co/badgersinfoil/metaas/impl/ASTASIfStatement.java        2007-12-15 01:20:29 UTC (rev 574)
@@ -7,15 +7,18 @@
</small></pre><pre class="diff" id="context"> package uk.co.badgersinfoil.metaas.impl;
import org.asdt.core.internal.antlr.AS3Parser;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.metaas.SyntaxException;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.dom.ASBlock;
import uk.co.badgersinfoil.metaas.dom.ASExpression;
import uk.co.badgersinfoil.metaas.dom.ASIfStatement;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.metaas.dom.Statement;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.dom.StatementContainer;
import uk.co.badgersinfoil.metaas.impl.antlr.LinkedListTree;
public class ASTASIfStatement extends ContainerDelegate implements ASIfStatement {
</pre><pre class="diff" id="added">+        private static final int ELSE_INDEX = 2;
</pre><pre class="diff" id="context">         private LinkedListTree ast;
        public ASTASIfStatement(LinkedListTree ast) {
</pre><pre class="diff"><small id="info">@@ -27,21 +30,44 @@
</small></pre><pre class="diff" id="context">                 return new ASTStatementList((LinkedListTree)ast.getChild(1));
        }
</pre><pre class="diff" id="added">+        
</pre><pre class="diff" id="context">         public ASBlock getElse() {
</pre><pre class="diff" id="removed">-                LinkedListTree elseStmt = (LinkedListTree)ast.getChild(2);
-                if (elseStmt == null) {
</pre><pre class="diff" id="added">+                return elseBlock();
+        }
+
+        private LinkedListTree elseClause() {
+                return (LinkedListTree)ast.getChild(ELSE_INDEX);
+        }
+
+        public ASBlock elseBlock() {
+                LinkedListTree elseClause = elseClause();
+                if (elseClause == null) {
</pre><pre class="diff" id="context">                         String indent = ASTUtils.findIndent(ast);
</pre><pre class="diff" id="removed">-                        else<span id="removedchars">Stmt</span> = ASTUtils.newAST(AS3Parser.ELSE, "else");
</pre><pre class="diff" id="added">+                        else<span id="addedchars">Clause</span> = ASTUtils.newAST(AS3Parser.ELSE, "else");
</pre><pre class="diff" id="context">                         ast.appendToken(TokenBuilder.newSpace());
</pre><pre class="diff" id="removed">-                        ast.addChildWithTokens(elseStmt);
-                        elseStmt.appendToken(TokenBuilder.newSpace());
</pre><pre class="diff" id="added">+                        ast.addChildWithTokens(elseClause);
+                        elseClause.appendToken(TokenBuilder.newSpace());
</pre><pre class="diff" id="context">                         LinkedListTree block = ASTBuilder.newBlock();
</pre><pre class="diff" id="removed">-                        else<span id="removedchars">Stmt</span>.addChildWithTokens(block);
</pre><pre class="diff" id="added">+                        else<span id="addedchars">Clause</span>.addChildWithTokens(block);
</pre><pre class="diff" id="context">                         ASTUtils.increaseIndentAfterFirstLine(block, indent);
</pre><pre class="diff" id="added">+                        return new ASTStatementList(block);
</pre><pre class="diff" id="context">                 }
</pre><pre class="diff" id="removed">-                return new ASTStatementList(elseStmt.getFirstChild());
</pre><pre class="diff" id="added">+                Statement stmt = StatementBuilder.build(elseClause.getFirstChild());
+                if (!(stmt instanceof ASBlock)) {
+                        throw new SyntaxException("Expected a block, got "+ASTUtils.tokenName(elseClause.getFirstChild()));
+                }
+                return (ASBlock)stmt;
</pre><pre class="diff" id="context">         }
</pre><pre class="diff" id="added">+        public Statement getElseStatement() {
+                LinkedListTree elseClause = elseClause();
+                if (elseClause == null) {
+                        return null;
+                }
+                return StatementBuilder.build(elseClause.getFirstChild());
+        }
+
+
</pre><pre class="diff" id="context">         public void setThen(ASBlock block) {
                LinkedListTree theBlock = ((ASTStatementList)block).getAST();
                ASTIterator i = new ASTIterator(ast);
</pre></div>
<hr /><a name="file3" /><div class="file">
<span class="pathname">metaas/trunk/src/test/java/uk/co/badgersinfoil/metaas</span><br />
<div class="fileheader"><big><b>StatementTests.java</b></big> <small id="info">573 -> 574</small></div>
<pre class="diff"><small id="info">--- trunk/src/test/java/uk/co/badgersinfoil/metaas/StatementTests.java        2007-12-14 23:09:13 UTC (rev 573)
+++ trunk/src/test/java/uk/co/badgersinfoil/metaas/StatementTests.java        2007-12-15 01:20:29 UTC (rev 574)
@@ -83,7 +83,8 @@
</small></pre><pre class="diff" id="context">         public void testIfStatement() {
                ASIfStatement ifStmt = meth.newIf("a == b");
                ifStmt.addStmt("trace('then true!')");
</pre><pre class="diff" id="removed">-                ifStmt.getElse().addStmt("trace('else false!')");
</pre><pre class="diff" id="added">+                assertNull(ifStmt.getElseStatement());
+                ifStmt.elseBlock().addStmt("trace('else false!')");
</pre><pre class="diff" id="context">                 assertEquals("a == b", ifStmt.getConditionString());
                ifStmt.setCondition("b == a");
                assertEquals("b == a", ifStmt.getConditionString());
</pre><pre class="diff"><small id="info">@@ -92,6 +93,18 @@
</small></pre><pre class="diff" id="context">                 ifStmt.setCondition(fact.newBooleanLiteral(true));
                assertTrue(((ASBooleanLiteral)ifStmt.getCondition()).getValue());
        }
</pre><pre class="diff" id="added">+        
+        public void testParseIf() {
+                ASIfStatement ifStmt = (ASIfStatement)meth.addStmt("if (foo) {blah();} else if (bar) {other();}");
+                assertNotNull(ifStmt.getElseStatement());
+                ExtraAssertions.assertInstanceof(ifStmt.getElseStatement(), ASIfStatement.class);
+                try {
+                        ifStmt.elseBlock();
+                        fail("should not allow access to block from else-clause when else-cluase contains other stmt type");
+                } catch (SyntaxException e) {
+                        // expected
+                }
+        }
</pre><pre class="diff" id="context">
        public void testFor() {
                ASForStatement forStmt = meth.newFor((String)null, null, null);
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -> email">CVSspam</a> 0.2.12</small></center>
</body></html>