removed Makefile; lifted repo/org.ibex.tool/src/ to src/
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / classfmt / InnerClassInfo.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-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 int[] constantPoolOffsets;
29         private boolean readInnerClassName = false;
30         private boolean readOuterClassName = false;
31         private boolean readInnerName = false;
32 public InnerClassInfo(byte classFileBytes[], int offsets[], int offset) {
33         super(classFileBytes, offset);
34         constantPoolOffsets = offsets;
35         innerClassNameIndex = u2At(0);
36         outerClassNameIndex = u2At(2);
37         this.innerNameIndex = u2At(4);
38 }
39 /**
40  * Answer the resolved name of the enclosing type in the
41  * class file format as specified in section 4.2 of the Java 2 VM spec.
42  *
43  * For example, java.lang.String is java/lang/String.
44  * @return char[]
45  */
46 public char[] getEnclosingTypeName() {
47         if (!readOuterClassName) {
48                 // read outer class name
49                 readOuterClassName = true;
50                 if (outerClassNameIndex != 0) {
51                         int utf8Offset = 
52                                 constantPoolOffsets[u2At(
53                                         constantPoolOffsets[outerClassNameIndex] - structOffset + 1)]
54                                         - structOffset; 
55                         outerClassName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
56                 }
57
58         }
59         return outerClassName;
60 }
61 /**
62  * Answer an int whose bits are set according the access constants
63  * defined by the VM spec.
64  * @return int
65  */
66 public int getModifiers() {
67         if (accessFlags == -1) {
68                 // read access flag
69                 accessFlags = u2At(6);
70         }
71         return accessFlags;
72 }
73 /**
74  * Answer the resolved name of the member type in the
75  * class file format as specified in section 4.2 of the Java 2 VM spec.
76  *
77  * For example, p1.p2.A.M is p1/p2/A$M.
78  * @return char[]
79  */
80 public char[] getName() {
81         if (!readInnerClassName) {
82                 // read the inner class name
83                 readInnerClassName = true;
84                 if (innerClassNameIndex != 0) {
85                         int  classOffset = constantPoolOffsets[innerClassNameIndex] - structOffset;
86                         int utf8Offset = constantPoolOffsets[u2At(classOffset + 1)] - structOffset;
87                         innerClassName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
88                 }
89         }
90         return innerClassName;
91 }
92 /**
93  * Answer the source name of the member type.
94  *
95  * For example, p1.p2.A.M is M.
96  * @return char[]
97  */
98 public char[] getSourceName() {
99         if (!this.readInnerName) {
100                 this.readInnerName = true;
101                 if (innerNameIndex != 0) {
102                         int utf8Offset = constantPoolOffsets[innerNameIndex] - structOffset;
103                         innerName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
104                 }
105         }
106         return innerName;
107 }
108 /**
109  * Answer the string representation of the receiver
110  * @return java.lang.String
111  */
112 public String toString() {
113         StringBuffer buffer = new StringBuffer();
114         if (getName() != null) {
115                 buffer.append(getName());
116         }
117         buffer.append("\n"); //$NON-NLS-1$
118         if (getEnclosingTypeName() != null) {
119                 buffer.append(getEnclosingTypeName());
120         }
121         buffer.append("\n"); //$NON-NLS-1$
122         if (getSourceName() != null) {
123                 buffer.append(getSourceName());
124         }
125         return buffer.toString();   
126 }
127 /**
128  * This method is used to fully initialize the contents of the receiver. All methodinfos, fields infos
129  * will be therefore fully initialized and we can get rid of the bytes.
130  */
131 void initialize() {
132         getModifiers();
133         getName();
134         getSourceName();
135         getEnclosingTypeName();
136         reset();
137 }
138 protected void reset() {
139         this.constantPoolOffsets = null;
140         super.reset();
141 }
142 }