KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javassist > CtArray


1 /*
2  * Javassist, a Java-bytecode translator toolkit.
3  * Copyright (C) 1999-2005 Shigeru Chiba. All Rights Reserved.
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. Alternatively, the contents of this file may be used under
8  * the terms of the GNU Lesser General Public License Version 2.1 or later.
9  *
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 JavaDoc 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 JavaDoc 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(clazz.getComponentType());
49     }
50
51     public CtClass getComponentType() throws NotFoundException {
52         String JavaDoc name = getName();
53         return pool.get(name.substring(0, name.length() - 2));
54     }
55
56     public CtClass getSuperclass() throws NotFoundException {
57         return pool.get(javaLangObject);
58     }
59
60     public CtMethod[] getMethods() {
61         try {
62             return getSuperclass().getMethods();
63         }
64         catch (NotFoundException e) {
65             return super.getMethods();
66         }
67     }
68
69     public CtMethod getMethod(String JavaDoc name, String JavaDoc desc)
70         throws NotFoundException
71     {
72         return getSuperclass().getMethod(name, desc);
73     }
74
75     public CtConstructor[] getConstructors() {
76         try {
77             return getSuperclass().getConstructors();
78         }
79         catch (NotFoundException e) {
80             return super.getConstructors();
81         }
82     }
83 }
84
Popular Tags