View Javadoc

1   /*
2    * ASSwitchStatement.java
3    * 
4    * Copyright (c) 2006-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  import java.util.List;
22  
23  /**
24   * A switch-statement, such as <code>switch (c) {  }</code>.
25   * 
26   * <p>Allows <code>case</code> and <code>default</code> statements to be added
27   * to to the switch-statement body.
28   * 
29   * e.g.
30   * <pre class="eg">
31   * ASSwitchStatement switchStmt = method.newSwitch("c");
32   * switchStmt.newCase("'a'").addStmt("aay()");
33   * switchStmt.newCase("'b'").addStmt("bee()");
34   * switchStmt.newDefault().addStmt("cee()");
35   * </pre>
36   * 
37   * Will result in ActionScript something like,
38   * <pre class="eg">
39   * switch(c) {
40   * 	case 'a':
41   * 		aay();
42   * 	case 'b':
43   * 		bee();
44   * 	default:
45   * 		cee();
46   * }
47   * </pre>
48   * 
49   * <p>To add <code>break</code> statements to either <code>case</code> or
50   * <code>default</code> labels, use <code>switchLabel.newBreak()</code>.</p>
51   * 
52   * @see StatementContainer#newSwitch(String)
53   * @see ASSwitchCase
54   * @see ASSwitchDefault
55   */
56  public interface ASSwitchStatement extends Statement {
57  
58  	/**
59  	 * Creates a <code>case</code>-label in this switch-statement with the given value,
60  	 * to which other statements can be added.
61  	 */
62  	ASSwitchCase newCase(String string);
63  	
64  	// TODO: newCase(ASExpression / ASLiteral)?
65  
66  	/**
67  	 * Creates a <code>default</code>-label in this switch-statement, to
68  	 * which other statements can be added.
69  	 */
70  	ASSwitchDefault newDefault();
71  
72  	Expression getCondition();
73  	public void setCondition(Expression expr);
74  
75  	/**
76  	 * Returns a list of {@link SwitchLabel} elements (i.e. either
77  	 * {@link ASSwitchCase} or {@link ASSwitchDefault}).
78  	 */
79  	public List getLabels();
80  }