001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.bytecode;
031:
032: import com.caucho.util.CharBuffer;
033:
034: /**
035: * Represents an introspected java class.
036: */
037: public class JavaParameterizedType implements JType {
038: private JClassLoader _loader;
039: private JClass _rawClass;
040: private JType[] _typeArgs;
041:
042: JavaParameterizedType(JClassLoader loader, JClass rawClass,
043: JType[] args) {
044: _loader = loader;
045: _rawClass = rawClass;
046: _typeArgs = args;
047: }
048:
049: /**
050: * Returns the type name.
051: */
052: public String getName() {
053: return _rawClass.getName();
054: }
055:
056: /**
057: * Returns the print name.
058: */
059: public String getPrintName() {
060: if (_typeArgs.length == 0)
061: return _rawClass.getPrintName();
062:
063: CharBuffer cb = new CharBuffer();
064: cb.append(_rawClass.getPrintName());
065: cb.append('<');
066: for (int i = 0; i < _typeArgs.length; i++) {
067: if (i != 0)
068: cb.append(',');
069:
070: cb.append(_typeArgs[i].getPrintName());
071: }
072:
073: cb.append('>');
074:
075: return cb.toString();
076: }
077:
078: /**
079: * Returns the parameter types.
080: */
081: public JType[] getActualTypeArguments() {
082: return _typeArgs;
083: }
084:
085: /**
086: * Returns the raw type.
087: */
088: public JClass getRawType() {
089: return _rawClass;
090: }
091:
092: /**
093: * Returns true for a primitive class.
094: */
095: public boolean isPrimitive() {
096: return _rawClass.isPrimitive();
097: }
098:
099: /**
100: * Returns true for a public class.
101: */
102: public boolean isPublic() {
103: return _rawClass.isPublic();
104: }
105:
106: /**
107: * Returns true for an abstract class
108: */
109: public boolean isAbstract() {
110: return _rawClass.isAbstract();
111: }
112:
113: /**
114: * Returns true for a final class
115: */
116: public boolean isFinal() {
117: return _rawClass.isFinal();
118: }
119:
120: /**
121: * Returns true for an interface
122: */
123: public boolean isInterface() {
124: return _rawClass.isAbstract();
125: }
126:
127: /**
128: * Returns the superclass.
129: */
130: public JClass getSuperClass() {
131: return _rawClass.getSuperClass();
132: }
133:
134: /**
135: * Returns the interfaces.
136: */
137: public JClass[] getInterfaces() {
138: return _rawClass.getInterfaces();
139: }
140:
141: /**
142: * Returns true for an array class.
143: */
144: public boolean isArray() {
145: return _rawClass.isArray();
146: }
147:
148: /**
149: * Returns the component for a class.
150: */
151: public JClass getComponentType() {
152: return null;
153: }
154:
155: /**
156: * Returns true if the jClass is assignable to the class.
157: */
158: public boolean isAssignableTo(Class cl) {
159: return _rawClass.isAssignableTo(cl);
160: }
161:
162: /**
163: * Returns true if the jClass is assignable to the class.
164: */
165: public boolean isAssignableFrom(Class cl) {
166: return _rawClass.isAssignableFrom(cl);
167: }
168:
169: /**
170: * Returns true if the jClass is assignable to the class.
171: */
172: public boolean isAssignableFrom(JClass cl) {
173: return _rawClass.isAssignableFrom(cl);
174: }
175:
176: /**
177: * Returns the declared methods
178: */
179: public JMethod[] getDeclaredMethods() {
180: return _rawClass.getDeclaredMethods();
181: }
182:
183: /**
184: * Returns the public methods
185: */
186: public JMethod[] getMethods() {
187: return _rawClass.getMethods();
188: }
189:
190: /**
191: * Returns the matching method.
192: */
193: public JMethod getMethod(String name, JClass[] param) {
194: return _rawClass.getMethod(name, param);
195: }
196:
197: /**
198: * Returns the declared fields
199: */
200: public JField[] getDeclaredFields() {
201: return _rawClass.getDeclaredFields();
202: }
203:
204: /**
205: * Returns the fields
206: */
207: public JField[] getFields() {
208: return _rawClass.getFields();
209: }
210: }
|