01: /*
02: * Javassist, a Java-bytecode translator toolkit.
03: * Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.
04: *
05: * The contents of this file are subject to the Mozilla Public License Version
06: * 1.1 (the "License"); you may not use this file except in compliance with
07: * the License. Alternatively, the contents of this file may be used under
08: * the terms of the GNU Lesser General Public License Version 2.1 or later.
09: *
10: * Software distributed under the License is distributed on an "AS IS" basis,
11: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12: * for the specific language governing rights and limitations under the
13: * License.
14: */
15:
16: package javassist;
17:
18: /**
19: * Array types.
20: */
21: final class CtArray extends CtClass {
22: protected ClassPool pool;
23:
24: // the name of array type ends with "[]".
25: CtArray(String name, ClassPool cp) {
26: super (name);
27: pool = cp;
28: }
29:
30: public ClassPool getClassPool() {
31: return pool;
32: }
33:
34: public boolean isArray() {
35: return true;
36: }
37:
38: public boolean subtypeOf(CtClass clazz) throws NotFoundException {
39: if (super .subtypeOf(clazz))
40: return true;
41:
42: String cname = clazz.getName();
43: if (cname.equals(javaLangObject)
44: || cname.equals("java.lang.Cloneable"))
45: return true;
46:
47: return clazz.isArray()
48: && getComponentType().subtypeOf(
49: clazz.getComponentType());
50: }
51:
52: public CtClass getComponentType() throws NotFoundException {
53: String name = getName();
54: return pool.get(name.substring(0, name.length() - 2));
55: }
56:
57: public CtClass getSuperclass() throws NotFoundException {
58: return pool.get(javaLangObject);
59: }
60:
61: public CtMethod[] getMethods() {
62: try {
63: return getSuperclass().getMethods();
64: } catch (NotFoundException e) {
65: return super .getMethods();
66: }
67: }
68:
69: public CtMethod getMethod(String name, String desc)
70: throws NotFoundException {
71: return getSuperclass().getMethod(name, desc);
72: }
73:
74: public CtConstructor[] getConstructors() {
75: try {
76: return getSuperclass().getConstructors();
77: } catch (NotFoundException e) {
78: return super.getConstructors();
79: }
80: }
81: }
|