KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > libraries > asm > tree > ClassNode


1 /***
2  * ASM: a very small and fast Java bytecode manipulation framework
3  * Copyright (c) 2000,2002,2003 INRIA, France Telecom
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package oracle.toplink.libraries.asm.tree;
32
33 import oracle.toplink.libraries.asm.ClassVisitor;
34 import oracle.toplink.libraries.asm.Attribute;
35
36 import java.util.List JavaDoc;
37 import java.util.ArrayList JavaDoc;
38 import java.util.Arrays JavaDoc;
39
40 /**
41  * A node that represents a class.
42  *
43  * @author Eric Bruneton
44  */

45
46 public class ClassNode {
47
48   /**
49    * The class version.
50    */

51   
52   public int version;
53   
54   /**
55    * The class's access flags (see {@link oracle.toplink.libraries.asm.Constants}). This
56    * field also indicates if the class is deprecated.
57    */

58
59   public int access;
60
61   /**
62    * The internal name of the class (see {@link
63    * oracle.toplink.libraries.asm.Type#getInternalName() getInternalName}).
64    */

65
66   public String JavaDoc name;
67
68   /**
69    * The internal of name of the super class (see {@link
70    * oracle.toplink.libraries.asm.Type#getInternalName() getInternalName}). For interfaces,
71    * the super class is {@link Object}. May be <tt>null</tt>, but only for the
72    * {@link Object java.lang.Object} class.
73    */

74
75   public String JavaDoc superName;
76
77   /**
78    * The internal names of the class's interfaces (see {@link
79    * oracle.toplink.libraries.asm.Type#getInternalName() getInternalName}). This list is a
80    * list of {@link String} objects.
81    */

82
83   public final List JavaDoc interfaces;
84
85   /**
86    * The name of the source file from which this class was compiled. May be
87    * <tt>null</tt>.
88    */

89
90   public String JavaDoc sourceFile;
91
92   /**
93    * Informations about the inner classes of this class. This list is a list of
94    * {@link InnerClassNode InnerClassNode} objects.
95    */

96
97   public final List JavaDoc innerClasses;
98
99   /**
100    * The fields of this class. This list is a list of {@link FieldNode
101    * FieldNode} objects.
102    */

103
104   public final List JavaDoc fields;
105
106   /**
107    * The methods of this class. This list is a list of {@link MethodNode
108    * MethodNode} objects.
109    */

110
111   public final List JavaDoc methods;
112
113   /**
114    * The non standard attributes of the class.
115    */

116
117   public Attribute attrs;
118
119   /**
120    * Constructs a new {@link ClassNode ClassNode} object.
121    *
122    * @param version the class version.
123    * @param access the class's access flags (see {@link
124    * oracle.toplink.libraries.asm.Constants}). This parameter also indicates if the
125    * class is deprecated.
126    * @param name the internal name of the class (see {@link
127    * oracle.toplink.libraries.asm.Type#getInternalName() getInternalName}).
128    * @param superName the internal of name of the super class (see {@link
129    * oracle.toplink.libraries.asm.Type#getInternalName() getInternalName}). For
130    * interfaces, the super class is {@link Object}.
131    * @param interfaces the internal names of the class's interfaces (see {@link
132    * oracle.toplink.libraries.asm.Type#getInternalName() getInternalName}). May be
133    * <tt>null</tt>.
134    * @param sourceFile the name of the source file from which this class was
135    * compiled. May be <tt>null</tt>.
136    */

137
138   public ClassNode (
139     final int version,
140     final int access,
141     final String JavaDoc name,
142     final String JavaDoc superName,
143     final String JavaDoc[] interfaces,
144     final String JavaDoc sourceFile)
145   {
146     this.version = version;
147     this.access = access;
148     this.name = name;
149     this.superName = superName;
150     this.interfaces = new ArrayList JavaDoc();
151     this.sourceFile = sourceFile;
152     this.innerClasses = new ArrayList JavaDoc();
153     this.fields = new ArrayList JavaDoc();
154     this.methods = new ArrayList JavaDoc();
155     if (interfaces != null) {
156       this.interfaces.addAll(Arrays.asList(interfaces));
157     }
158   }
159
160   /**
161    * Makes the given class visitor visit this class.
162    *
163    * @param cv a class visitor.
164    */

165
166   public void accept (final ClassVisitor cv) {
167     // visits header
168
String JavaDoc[] interfaces = new String JavaDoc[this.interfaces.size()];
169     this.interfaces.toArray(interfaces);
170     cv.visit(version, access, name, superName, interfaces, sourceFile);
171     // visits inner classes
172
int i;
173     for (i = 0; i < innerClasses.size(); ++i) {
174       ((InnerClassNode)innerClasses.get(i)).accept(cv);
175     }
176     // visits fields
177
for (i = 0; i < fields.size(); ++i) {
178       ((FieldNode)fields.get(i)).accept(cv);
179     }
180     // visits methods
181
for (i = 0; i < methods.size(); ++i) {
182       ((MethodNode)methods.get(i)).accept(cv);
183     }
184     // visits attributes
185
Attribute attrs = this.attrs;
186     while (attrs != null) {
187       cv.visitAttribute(attrs);
188       attrs = attrs.next;
189     }
190     // visits end
191
cv.visitEnd();
192   }
193 }
194
Popular Tags