KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gcc > generator > JMethod


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

19 package gcc.generator;
20
21 import gcc.generator.JBlockStatement;
22 import gcc.generator.JEntity;
23 import gcc.generator.JExpression;
24 import gcc.generator.JLocalVariable;
25
26 import java.util.Vector;
27 import java.lang.reflect.Modifier;
28
29 public class JMethod extends JEntity
30 {
31     protected JReturnType _rt;
32     protected JParameter _parms[];
33     protected Class _thrown[];
34
35     protected Vector _statements;
36     protected JBlockStatement _bodyBlockStatement;
37
38     protected String _body; // Yuck
39

40     protected JMethod( String name )
41     {
42         super( name, Modifier.PUBLIC );
43
44         _statements = new Vector();
45         _bodyBlockStatement = new JBlockStatement();
46     }
47
48     protected JMethod( JReturnType rt, String name, JParameter parms[], Class thrown[] )
49     {
50         this( name );
51
52         setRT( rt );
53         setParms( parms );
54         setThrown( thrown );
55     }
56
57     public void setRT( JReturnType jt )
58     {
59         _rt = jt;
60     }
61
62     public JReturnType getRT()
63     {
64         return _rt;
65     }
66
67     public void setParms( JParameter parms[] )
68     {
69         _parms = parms;
70     }
71
72     public JParameter[] getParms()
73     {
74         return _parms;
75     }
76
77     public void setThrown( Class thrown[] )
78     {
79         _thrown = thrown;
80
81         /*
82         if (_thrown != null)
83         {
84             _thrownType = new String[_thrown.length];
85             int i;
86             for( i=0; i<_thrown.length; i++ )
87             {
88                 _thrownType[i] = _thrown[i].getName();
89             }
90         }
91         else
92         {
93             _thrownType = null;
94         }
95         */

96     }
97
98     public Class[] getThrown()
99     {
100         return _thrown;
101     }
102
103     /*
104     public void setThrownType( String thrownType[] )
105     {
106         _thrownType = thrownType;
107         _thrown = null;
108     }
109
110     public String[] getThrownType()
111     {
112         return _thrownType;
113     }
114     */

115
116     public void setBody( String body )
117     {
118         _body = body;
119     }
120
121     public String getBody()
122     {
123         return _body;
124     }
125
126     public JLocalVariable newLocalVariable( Class type, String name )
127     {
128         return _bodyBlockStatement.newLocalVariable( type, name );
129     }
130
131     public JLocalVariable newLocalVariable( Class type, String name, JExpression initExpr )
132     {
133         return _bodyBlockStatement.newLocalVariable( type, name, initExpr );
134     }
135
136     public void deleteLocalVariable( JLocalVariable f )
137     {
138         _bodyBlockStatement.deleteLocalVariable( f );
139     }
140
141     public Vector getLocalVariables()
142     {
143         return _bodyBlockStatement.getLocalVariables();
144     }
145
146     public void addStatement( JStatement s )
147     {
148         _statements.add( s );
149     }
150
151     public Vector getStatements()
152     {
153         return _statements;
154     }
155 }
156
Popular Tags