View Javadoc

1   /*
2    * FunctionCommon.java
3    * 
4    * Copyright (c) 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   * Common interface for {@link ASMethod} and {@link ASFunctionExpression}.
25   */
26  public interface FunctionCommon {
27  
28  	/**
29  	 * Returns a list of the formal arguments accepted by this ActionScript
30  	 * method.  Note that the resulting list is not modifiable.
31  	 * 
32  	 * @see #addParam(String, String)
33  	 */
34  	public List getArgs();
35  
36  	/**
37  	 * Returns the name of the return type of this ActionScript
38  	 * method, or null if it is untyped.
39  	 */
40  	public String getType();
41  
42  	/**
43  	 * Defines the name of the type of object returned by this ActionScript
44  	 * method.  May be set to null, denoting that the return value is
45  	 * untyped.
46  	 */
47  	public void setType(String string);
48  
49  	/**
50  	 * Adds a formal parameter to the list of parameters supported by this
51  	 * ActionScript method.
52  	 * 
53  	 * @param name The name for the parameter
54  	 * @param type The type for the parameter, or null if the parameter is
55  	 *        to be untyped
56  	 * @return the newly created parameter
57  	 * 
58  	 * @see #addRestParam(String)
59  	 */
60  	public ASArg addParam(String name, String type);
61  
62  	/**
63  	 * Adds a 'rest' parameter to the list of parameters supported by this
64  	 * ActionScript method.
65  	 * 
66  	 * <p>e.g. The java code,</p>
67  	 * <pre class="eg">ASMethod meth = class.newMethod("test", Visibility.PUBLIC, "void");
68  	 *meth.addRestParam("foo");</pre>
69  	 * <p>will result in ActionScript code like,</p>
70  	 * <pre class="eg">public function test(...foo):void {
71  	 *}</pre>
72  	 * 
73  	 * <p>To create an anonymous 'rest' parameter, pass the name "..."
74  	 * (this name can also be passed to removeParam() to remove an
75  	 * anonymous rest parameter).</p>
76  	 * 
77  	 * @return the newly created parameter
78  	 * 
79  	 * @see #addParam(String,String)
80  	 */
81  	public ASArg addRestParam(String name);
82  
83  	/**
84  	 * Removes the named parameter from this ActionScript methods formal
85  	 * parameter list.  In the case of a 'rest' parameter, give the name
86  	 * of the parameter without the ellipsis prefix (i.e. if the parameter
87  	 * is declared as "...foo", pass the name "foo" to this method).
88  	 * To remove an anonymous 'rest' parameter, pass the string "..." as
89  	 * the argument to this method.
90  	 * 
91  	 * @return the removed parameter, if found, or null otherwise.
92  	 */
93  	public ASArg removeParam(String string);
94  }