KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > bytecode > JavaParameterizedType


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.bytecode;
31
32 import com.caucho.util.CharBuffer;
33
34 /**
35  * Represents an introspected java class.
36  */

37 public class JavaParameterizedType implements JType {
38   private JClassLoader _loader;
39   private JClass _rawClass;
40   private JType []_typeArgs;
41
42   JavaParameterizedType(JClassLoader loader, JClass rawClass, JType []args)
43   {
44     _loader = loader;
45     _rawClass = rawClass;
46     _typeArgs = args;
47   }
48             
49   /**
50    * Returns the type name.
51    */

52   public String JavaDoc getName()
53   {
54     return _rawClass.getName();
55   }
56
57   /**
58    * Returns the print name.
59    */

60   public String JavaDoc getPrintName()
61   {
62     if (_typeArgs.length == 0)
63       return _rawClass.getPrintName();
64
65     CharBuffer cb = new CharBuffer();
66     cb.append(_rawClass.getPrintName());
67     cb.append('<');
68     for (int i = 0; i < _typeArgs.length; i++) {
69       if (i != 0)
70     cb.append(',');
71       
72       cb.append(_typeArgs[i].getPrintName());
73     }
74     
75     cb.append('>');
76
77     return cb.toString();
78   }
79
80   /**
81    * Returns the parameter types.
82    */

83   public JType []getActualTypeArguments()
84   {
85     return _typeArgs;
86   }
87
88   /**
89    * Returns the raw type.
90    */

91   public JClass getRawType()
92   {
93     return _rawClass;
94   }
95   
96   /**
97    * Returns true for a primitive class.
98    */

99   public boolean isPrimitive()
100   {
101     return _rawClass.isPrimitive();
102   }
103   
104   /**
105    * Returns true for a public class.
106    */

107   public boolean isPublic()
108   {
109     return _rawClass.isPublic();
110   }
111   
112   /**
113    * Returns true for an abstract class
114    */

115   public boolean isAbstract()
116   {
117     return _rawClass.isAbstract();
118   }
119   
120   /**
121    * Returns true for a final class
122    */

123   public boolean isFinal()
124   {
125     return _rawClass.isFinal();
126   }
127   
128   /**
129    * Returns true for an interface
130    */

131   public boolean isInterface()
132   {
133     return _rawClass.isAbstract();
134   }
135
136   /**
137    * Returns the superclass.
138    */

139   public JClass getSuperClass()
140   {
141     return _rawClass.getSuperClass();
142   }
143
144   /**
145    * Returns the interfaces.
146    */

147   public JClass []getInterfaces()
148   {
149     return _rawClass.getInterfaces();
150   }
151
152   /**
153    * Returns true for an array class.
154    */

155   public boolean isArray()
156   {
157     return _rawClass.isArray();
158   }
159
160   /**
161    * Returns the component for a class.
162    */

163   public JClass getComponentType()
164   {
165     return null;
166   }
167
168   /**
169    * Returns true if the jClass is assignable to the class.
170    */

171   public boolean isAssignableTo(Class JavaDoc cl)
172   {
173     return _rawClass.isAssignableTo(cl);
174   }
175
176   /**
177    * Returns true if the jClass is assignable to the class.
178    */

179   public boolean isAssignableFrom(Class JavaDoc cl)
180   {
181     return _rawClass.isAssignableFrom(cl);
182   }
183
184   /**
185    * Returns true if the jClass is assignable to the class.
186    */

187   public boolean isAssignableFrom(JClass cl)
188   {
189     return _rawClass.isAssignableFrom(cl);
190   }
191
192   /**
193    * Returns the declared methods
194    */

195   public JMethod []getDeclaredMethods()
196   {
197     return _rawClass.getDeclaredMethods();
198   }
199
200   /**
201    * Returns the public methods
202    */

203   public JMethod []getMethods()
204   {
205     return _rawClass.getMethods();
206   }
207
208   /**
209    * Returns the matching method.
210    */

211   public JMethod getMethod(String JavaDoc name, JClass []param)
212   {
213     return _rawClass.getMethod(name, param);
214   }
215
216   /**
217    * Returns the declared fields
218    */

219   public JField []getDeclaredFields()
220   {
221     return _rawClass.getDeclaredFields();
222   }
223
224   /**
225    * Returns the fields
226    */

227   public JField []getFields()
228   {
229     return _rawClass.getFields();
230   }
231 }
232
Popular Tags