KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > jjs > ast > JMethod


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.jjs.ast;
17
18 import com.google.gwt.dev.jjs.InternalCompilerException;
19 import com.google.gwt.dev.jjs.SourceInfo;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23
24 /**
25  * A Java method implementation.
26  */

27 public class JMethod extends JNode implements HasEnclosingType, HasName,
28     HasType, HasSettableType, CanBeAbstract, CanBeFinal, CanBeSetFinal,
29     CanBeNative, CanBeStatic {
30
31   public final JBlock body;
32   public final ArrayList JavaDoc/* <JLocal> */locals = new ArrayList JavaDoc/* <JLocal> */();
33   /**
34    * References to any methods which this method overrides. This should be an
35    * EXHAUSTIVE list, that is, if C overrides B overrides A, then C's overrides
36    * list will contain both A and B.
37    */

38   public final List JavaDoc/* <JMethod> */overrides = new ArrayList JavaDoc/* <JMethod> */();
39   public final ArrayList JavaDoc/* <JParameter> */params = new ArrayList JavaDoc/* <JParameter> */();
40   public final ArrayList JavaDoc/* <JClassType> */thrownExceptions = new ArrayList JavaDoc/* <JClassType> */();
41   private final JReferenceType enclosingType;
42   private final boolean isAbstract;
43   private boolean isFinal;
44   private final boolean isPrivate;
45   private final boolean isStatic;
46   private final String JavaDoc name;
47   private ArrayList JavaDoc/* <JType> */originalParamTypes;
48   private JType returnType;
49
50   /**
51    * These are only supposed to be constructed by JProgram.
52    */

53   public JMethod(JProgram program, SourceInfo info, String JavaDoc name,
54       JReferenceType enclosingType, JType returnType, boolean isAbstract,
55       boolean isStatic, boolean isFinal, boolean isPrivate) {
56     super(program, info);
57     this.name = name;
58     this.enclosingType = enclosingType;
59     this.returnType = returnType;
60     this.body = new JBlock(program, info);
61     this.isAbstract = isAbstract;
62     this.isStatic = isStatic;
63     this.isFinal = isFinal;
64     this.isPrivate = isPrivate;
65   }
66
67   public void freezeParamTypes() {
68     if (originalParamTypes != null) {
69       throw new InternalCompilerException("Param types already frozen");
70     }
71     originalParamTypes = new ArrayList JavaDoc/* <JType> */();
72     for (int i = 0; i < params.size(); ++i) {
73       JParameter param = (JParameter) params.get(i);
74       originalParamTypes.add(param.getType());
75     }
76   }
77
78   public JReferenceType getEnclosingType() {
79     return enclosingType;
80   }
81
82   public String JavaDoc getName() {
83     return name;
84   }
85
86   public List JavaDoc/* <JType> */getOriginalParamTypes() {
87     if (originalParamTypes == null) {
88       return null;
89     }
90     return originalParamTypes;
91   }
92
93   public JType getType() {
94     return returnType;
95   }
96
97   public boolean isAbstract() {
98     return isAbstract;
99   }
100
101   public boolean isFinal() {
102     return isFinal;
103   }
104
105   public boolean isNative() {
106     return false;
107   }
108
109   public boolean isPrivate() {
110     return isPrivate;
111   }
112
113   public boolean isStatic() {
114     return isStatic;
115   }
116
117   public void setFinal(boolean b) {
118     isFinal = b;
119   }
120
121   public void setType(JType newType) {
122     returnType = newType;
123   }
124
125   public void traverse(JVisitor visitor, Context ctx) {
126     if (visitor.visit(this, ctx)) {
127       visitor.accept(params);
128       visitor.accept(locals);
129       visitor.accept(body);
130     }
131     visitor.endVisit(this, ctx);
132   }
133
134 }
135
Popular Tags