KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > classfmt > InnerClassInfo


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.compiler.classfmt;
12
13 import org.eclipse.jdt.internal.compiler.env.IBinaryNestedType;
14
15 /**
16  * Describes one entry in the classes table of the InnerClasses attribute.
17  * See the inner class specification (The class file attribute "InnerClasses").
18  */

19
20 public class InnerClassInfo extends ClassFileStruct implements IBinaryNestedType {
21     int innerClassNameIndex = -1;
22     int outerClassNameIndex = -1;
23     int innerNameIndex = -1;
24     private char[] innerClassName;
25     private char[] outerClassName;
26     private char[] innerName;
27     private int accessFlags = -1;
28     private boolean readInnerClassName = false;
29     private boolean readOuterClassName = false;
30     private boolean readInnerName = false;
31
32 public InnerClassInfo(byte classFileBytes[], int offsets[], int offset) {
33     super(classFileBytes, offsets, offset);
34     this.innerClassNameIndex = u2At(0);
35     this.outerClassNameIndex = u2At(2);
36     this.innerNameIndex = u2At(4);
37 }
38 /**
39  * Answer the resolved name of the enclosing type in the
40  * class file format as specified in section 4.2 of the Java 2 VM spec.
41  *
42  * For example, java.lang.String is java/lang/String.
43  * @return char[]
44  */

45 public char[] getEnclosingTypeName() {
46     if (!readOuterClassName) {
47         // read outer class name
48
readOuterClassName = true;
49         if (outerClassNameIndex != 0) {
50             int utf8Offset =
51                 constantPoolOffsets[u2At(
52                     constantPoolOffsets[outerClassNameIndex] - structOffset + 1)]
53                     - structOffset;
54             outerClassName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
55         }
56
57     }
58     return outerClassName;
59 }
60 /**
61  * Answer an int whose bits are set according the access constants
62  * defined by the VM spec.
63  * @return int
64  */

65 public int getModifiers() {
66     if (accessFlags == -1) {
67         // read access flag
68
accessFlags = u2At(6);
69     }
70     return accessFlags;
71 }
72 /**
73  * Answer the resolved name of the member type in the
74  * class file format as specified in section 4.2 of the Java 2 VM spec.
75  *
76  * For example, p1.p2.A.M is p1/p2/A$M.
77  * @return char[]
78  */

79 public char[] getName() {
80     if (!readInnerClassName) {
81         // read the inner class name
82
readInnerClassName = true;
83         if (innerClassNameIndex != 0) {
84             int classOffset = constantPoolOffsets[innerClassNameIndex] - structOffset;
85             int utf8Offset = constantPoolOffsets[u2At(classOffset + 1)] - structOffset;
86             innerClassName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
87         }
88     }
89     return innerClassName;
90 }
91 /**
92  * Answer the source name of the member type.
93  *
94  * For example, p1.p2.A.M is M.
95  * @return char[]
96  */

97 public char[] getSourceName() {
98     if (!this.readInnerName) {
99         this.readInnerName = true;
100         if (innerNameIndex != 0) {
101             int utf8Offset = constantPoolOffsets[innerNameIndex] - structOffset;
102             innerName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
103         }
104     }
105     return innerName;
106 }
107 /**
108  * Answer the string representation of the receiver
109  * @return java.lang.String
110  */

111 public String JavaDoc toString() {
112     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
113     if (getName() != null) {
114         buffer.append(getName());
115     }
116     buffer.append("\n"); //$NON-NLS-1$
117
if (getEnclosingTypeName() != null) {
118         buffer.append(getEnclosingTypeName());
119     }
120     buffer.append("\n"); //$NON-NLS-1$
121
if (getSourceName() != null) {
122         buffer.append(getSourceName());
123     }
124     return buffer.toString();
125 }
126 /**
127  * This method is used to fully initialize the contents of the receiver. All methodinfos, fields infos
128  * will be therefore fully initialized and we can get rid of the bytes.
129  */

130 void initialize() {
131     getModifiers();
132     getName();
133     getSourceName();
134     getEnclosingTypeName();
135     reset();
136 }
137 }
138
Popular Tags