/Users/lyon/j4p/src/javassist/CtArray.java

1    /* 
2     * Javassist, a Java-bytecode translator toolkit. 
3     * Copyright (C) 1999-2003 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 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(clazz.getComponentType()); 
49       } 
50    
51       public CtClass getComponentType() throws NotFoundException { 
52           String 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           } catch (NotFoundException e) { 
64               return super.getMethods(); 
65           } 
66       } 
67    
68       public CtMethod getMethod(String name, String desc) 
69               throws NotFoundException { 
70           return getSuperclass().getMethod(name, desc); 
71       } 
72    
73       public CtConstructor[] getConstructors() { 
74           try { 
75               return getSuperclass().getConstructors(); 
76           } catch (NotFoundException e) { 
77               return super.getConstructors(); 
78           } 
79       } 
80   } 
81