KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > js > ast > JsFunction


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.dev.js.ast;
17
18 /**
19  * Represents a JavaScript function expression.
20  */

21 public class JsFunction extends JsExpression implements HasName {
22
23   protected JsBlock body;
24   protected final JsParameters params = new JsParameters();
25   protected final JsScope scope;
26   private JsName name;
27
28   /**
29    * Creates an anonymous function.
30    */

31   public JsFunction(JsScope parent) {
32     this(parent, null);
33   }
34
35   /**
36    * Creates an named function.
37    */

38   public JsFunction(JsScope parent, JsName name) {
39     assert (parent != null);
40     this.name = name;
41     String JavaDoc scopeName = (name == null) ? "<anonymous>" : name.getIdent();
42     scopeName = "function " + scopeName;
43     this.scope = new JsScope(parent, scopeName);
44   }
45
46   public JsBlock getBody() {
47     return body;
48   }
49
50   public JsName getName() {
51     return name;
52   }
53
54   public JsParameters getParameters() {
55     return params;
56   }
57
58   public JsScope getScope() {
59     return scope;
60   }
61
62   public void setBody(JsBlock body) {
63     this.body = body;
64   }
65
66   public void setName(JsName name) {
67     this.name = name;
68   }
69
70   public void traverse(JsVisitor v, JsContext ctx) {
71     if (v.visit(this, ctx)) {
72       v.acceptWithInsertRemove(params);
73       body = (JsBlock) v.accept(body);
74     }
75     v.endVisit(this, ctx);
76   }
77 }
78
Popular Tags