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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.compiler.classfmt;
13 import org.eclipse.jdt.internal.compiler.env.IBinaryNestedType;
16 * Describes one entry in the classes table of the InnerClasses attribute.
17 * See the inner class specification (The class file attribute "InnerClasses").
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);
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.
43 * For example, java.lang.String is java/lang/String.
46 public char[] getEnclosingTypeName() {
47 if (!readOuterClassName) {
48 // read outer class name
49 readOuterClassName = true;
50 if (outerClassNameIndex != 0) {
52 constantPoolOffsets[u2At(
53 constantPoolOffsets[outerClassNameIndex] - structOffset + 1)]
55 outerClassName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
59 return outerClassName;
62 * Answer an int whose bits are set according the access constants
63 * defined by the VM spec.
66 public int getModifiers() {
67 if (accessFlags == -1) {
69 accessFlags = u2At(6);
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.
77 * For example, p1.p2.A.M is p1/p2/A$M.
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));
90 return innerClassName;
93 * Answer the source name of the member type.
95 * For example, p1.p2.A.M is M.
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));
109 * Answer the string representation of the receiver
110 * @return java.lang.String
112 public String toString() {
113 StringBuffer buffer = new StringBuffer();
114 if (getName() != null) {
115 buffer.append(getName());
117 buffer.append("\n"); //$NON-NLS-1$
118 if (getEnclosingTypeName() != null) {
119 buffer.append(getEnclosingTypeName());
121 buffer.append("\n"); //$NON-NLS-1$
122 if (getSourceName() != null) {
123 buffer.append(getSourceName());
125 return buffer.toString();
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.
135 getEnclosingTypeName();
138 protected void reset() {
139 this.constantPoolOffsets = null;