View Javadoc

1   /*
2    * ASForStatement.java
3    * 
4    * Copyright (c) 2007-2008 David Holroyd
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package uk.co.badgersinfoil.metaas.dom;
20  
21  /**
22   * A <code>for</code> statement, such as <code>for (; ; ) { }</code>.
23   * 
24   * <p>e.g. The Java code</p>
25   * <pre class="eg">ASForStatement forStmt = method.newFor("var i=0", "i<10", "i++");
26   *forStmt.addStmt("trace(i)");</pre>
27   *
28   * <p>Will create ActionScript code like,</p>
29   * <pre class="eg">for (var i=0; i<10; i++) {
30   *	trace(i);
31   *}</pre>
32   *
33   * @see StatementContainer#newFor(Expression, Expression, Expression)
34   */
35  public interface ASForStatement extends Statement, StatementContainer {
36  
37  	/**
38  	 * Returns a string representation of the loop initialisation
39  	 * expression.
40  	 * 
41  	 * e.g. given the loop <code>for (var i=0; i<10; i++)</code>, this
42  	 * method will return the string <code>"var i=0"</code>.
43  	 */
44  	public String getInitString();
45  
46  	/**
47  	 * Returns a script element representing the initialisation part of
48  	 * this for-statement.
49  	 * 
50  	 * <p>The return value depends on the kind of initialiser present:</p>
51  	 * 
52  	 * <dl>
53  	 * <dt>No initialiser: <code>for (; ; )</code></dt>
54  	 * <dd>Returns <code>null</code></dd>
55  	 * 
56  	 * <dt>Expression initialiser: <code>for (v=1; ; )</code></dt>
57  	 * <dd>Returns an {@link Expression}</dd>
58  	 * 
59  	 * <dt>Declaration initialiser: <code>for (var v=1; ; )</code></dt>
60  	 * <dd>Returns an {@link ASDeclarationStatement}</dd>
61  	 * </dl>
62  	 */
63  	public ScriptElement getInit();
64  
65  	/**
66  	 * Returns a string representation of the loop termination condition
67  	 * expression.
68  	 * 
69  	 * e.g. given the loop <code>for (var i=0; i<10; i++)</code>, this
70  	 * method will return the string <code>"i<10"</code>.
71  	 */
72  	public String getConditionString();
73  
74  	public Expression getCondition();
75  
76  	/**
77  	 * Returns a string representation of the loop update expression.
78  	 * 
79  	 * e.g. given the loop <code>for (var i=0; i<10; i++)</code>, this
80  	 * method will return the string <code>"i++"</code>.
81  	 */
82  	public String getUpdateString();
83  
84  	public Expression getUpdate();
85  
86  	/**
87  	 * Changes the initialisation expression for this loop.
88  	 * 
89  	 * @throws uk.co.badgersinfoil.metaas.SyntaxException if the given
90  	 * string is not a valid ActionScript expression.
91  	 */
92  	public void setInit(String expr);
93  
94  	/**
95  	 * Changes the termination condition expression for this loop.
96  	 * 
97  	 * @throws uk.co.badgersinfoil.metaas.SyntaxException if the given
98  	 * string is not a valid ActionScript expression.
99  	 */
100 	public void setCondition(String expr);
101 
102 	public void setCondition(Expression expr);
103 
104 	/**
105 	 * Changes the update expression for this loop.
106 	 * 
107 	 * @throws uk.co.badgersinfoil.metaas.SyntaxException if the given
108 	 * string is not a valid ActionScript expression.
109 	 */
110 	public void setUpdate(String expr);
111 
112 	public void setUpdate(Expression expr);
113 }