KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > logicalcobwebs > 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  * Contact: Eric.Bruneton@rd.francetelecom.com
31  *
32  * Author: Eric Bruneton
33  */

34
35 package org.logicalcobwebs.asm.tree;
36
37 import org.logicalcobwebs.asm.ClassVisitor;
38 import org.logicalcobwebs.asm.Attribute;
39
40 import java.util.List JavaDoc;
41 import java.util.ArrayList JavaDoc;
42 import java.util.Arrays JavaDoc;
43
44 /**
45  * A node that represents a class.
46  */

47
48 public class ClassNode {
49
50   /**
51    * The class's access flags (see {@link org.logicalcobwebs.asm.Constants}). This
52    * field also indicates if the class is deprecated.
53    */

54
55   public int access;
56
57   /**
58    * The internal name of the class (see {@link
59    * org.logicalcobwebs.asm.Type#getInternalName getInternalName}).
60    */

61
62   public String JavaDoc name;
63
64   /**
65    * The internal of name of the super class (see {@link
66    * org.logicalcobwebs.asm.Type#getInternalName getInternalName}). For interfaces,
67    * the super class is {@link Object}. May be <tt>null</tt>, but only for the
68    * {@link Object java.lang.Object} class.
69    */

70
71   public String JavaDoc superName;
72
73   /**
74    * The internal names of the class's interfaces (see {@link
75    * org.logicalcobwebs.asm.Type#getInternalName getInternalName}). This list is a
76    * list of {@link String} objects.
77    */

78
79   public final List JavaDoc interfaces;
80
81   /**
82    * The name of the source file from which this class was compiled. May be
83    * <tt>null</tt>.
84    */

85
86   public String JavaDoc sourceFile;
87
88   /**
89    * Informations about the inner classes of this class. This list is a list of
90    * {@link InnerClassNode InnerClassNode} objects.
91    */

92
93   public final List JavaDoc innerClasses;
94
95   /**
96    * The fields of this class. This list is a list of {@link FieldNode
97    * FieldNode} objects.
98    */

99
100   public final List JavaDoc fields;
101
102   /**
103    * The methods of this class. This list is a list of {@link MethodNode
104    * MethodNode} objects.
105    */

106
107   public final List JavaDoc methods;
108
109   /**
110    * The non standard attributes of the class.
111    */

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

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

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