KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > classfile > InnerClass


1 /*
2  * InnerClass.java
3  *
4  * The contents of this file are subject to the terms of the Common Development
5  * and Distribution License (the License). You may not use this file except in
6  * compliance with the License.
7  *
8  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
9  * or http://www.netbeans.org/cddl.txt.
10  *
11  * When distributing Covered Code, include this CDDL Header Notice in each file
12  * and include the License file at http://www.netbeans.org/cddl.txt.
13  * If applicable, add the following below the CDDL Header, with the fields
14  * enclosed by brackets [] replaced by your own identifying information:
15  * "Portions Copyrighted [year] [name of copyright owner]"
16  *
17  * The Original Software is NetBeans. The Initial Developer of the Original
18  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
19  * Microsystems, Inc. All Rights Reserved.
20  *
21  * Contributor(s): Thomas Ball
22  *
23  * Version: $Revision: 1.4 $
24  */

25
26 package org.netbeans.modules.classfile;
27
28 import java.io.DataInputStream JavaDoc;
29 import java.io.IOException JavaDoc;
30
31 /**
32  * An InnerClass attribute of a classfile.
33  *
34  * @author Thomas Ball
35  */

36 public final class InnerClass {
37
38     ClassName name;
39     ClassName outerClassName;
40     String JavaDoc simpleName;
41     int access;
42
43     static InnerClass[] loadInnerClasses(DataInputStream JavaDoc in, ConstantPool pool)
44       throws IOException JavaDoc {
45         int n = in.readUnsignedShort();
46         InnerClass[] innerClasses = new InnerClass[n];
47         for (int i = 0; i < n; i++)
48             innerClasses[i] = new InnerClass(in, pool);
49         return innerClasses;
50     }
51
52     InnerClass(DataInputStream JavaDoc in, ConstantPool pool)
53       throws IOException JavaDoc {
54         loadInnerClass(in, pool);
55     }
56
57     private void loadInnerClass(DataInputStream JavaDoc in, ConstantPool pool)
58       throws IOException JavaDoc {
59         int index = in.readUnsignedShort();
60         name = (index > 0) ? pool.getClass(index).getClassName() : null;
61         index = in.readUnsignedShort();
62     outerClassName = (index > 0) ? pool.getClass(index).getClassName() : null;
63         index = in.readUnsignedShort();
64         if (index > 0) {
65             CPUTF8Info entry = (CPUTF8Info)pool.get(index);
66             simpleName = entry.getName();
67         }
68         access = in.readUnsignedShort();
69     }
70
71     /** Returns the name of this class, including its package (if any).
72      * If the compiler didn't define this value, the string
73      * "<not defined>" is returned.
74      * @return the name of this class.
75      */

76     public final ClassName getName() {
77         return name;
78     }
79     
80     /** Returns the name of the enclosing outer class, including
81      * its package (if any).
82      * @return the name of this class, or null if not available.
83      */

84     public final ClassName getOuterClassName() {
85         return outerClassName;
86     }
87
88     /**
89      * Returns the original simple name as given in the source code.
90      * If this is an anonymous class, null is returned instead.
91      * @return the simple name of this class, or null if anonymous.
92      */

93     public final String JavaDoc getSimpleName() {
94         return simpleName;
95     }
96
97     /**
98      * Returns the access flags of this class.
99      */

100     public final int getAccess() {
101         return access;
102     }
103
104     public String JavaDoc toString() {
105         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
106         sb.append("innerclass=");
107         sb.append(name);
108         if (simpleName != null) {
109             sb.append(" (");
110             sb.append(simpleName);
111             sb.append(')');
112         }
113         sb.append(", outerclass=");
114         sb.append(outerClassName);
115         return sb.toString();
116     }
117 }
118
Popular Tags