001: /*
002: * @(#)InnerClassEntry.java 1.7 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package components;
029:
030: import java.io.DataOutput;
031: import java.io.IOException;
032:
033: /*
034: * This class is used to represent information contained in the innerclass
035: * attribute of a class file which contains one or more inner classes. The
036: * innerclass attribute is new in 1.2 and is documented in the 1.2 JVM Spec.
037: */
038: public class InnerClassEntry {
039: //__________ CLASS CONSTANTS
040: public static final int SIZE = 8; //bytes in .class files
041:
042: //__________ INSTANCE VARIABLES
043: ClassConstant innerInfo;
044: ClassConstant outerInfo;
045: UnicodeConstant innerName;
046: int accessFlags;
047:
048: //__________ CONSTRUCTORS
049: InnerClassEntry(ClassConstant inner_info, ClassConstant outer_info,
050: UnicodeConstant inner_name, int flags) {
051: innerInfo = inner_info;
052: outerInfo = outer_info;
053: innerName = inner_name;
054: accessFlags = flags;
055: /*
056: if (innerName.toString().equals("")) {
057: if (outerInfo != null) {
058: System.err.println("1) "+outerInfo.name.toString()+" has blank innerclass name because compiled w/javac V1.1");
059: } else if (innerInfo != null) {
060: System.err.println("2) "+innerInfo.name.toString()+" has blank innerclass name because compiled w/javac V1.1");
061: }
062: }
063: */
064: }
065:
066: //__________ INSTANCE METHODS
067: /*
068: * Given an output stream, write the indexes and access flag to that stream.
069: */
070: public void write(DataOutput o) throws IOException {
071: if (innerInfo != null) {
072: o.writeShort(innerInfo.index);
073: } else {
074: o.writeShort(0);
075: }
076:
077: if (outerInfo != null) {
078: o.writeShort(outerInfo.index);
079: } else {
080: o.writeShort(0);
081: }
082:
083: if (innerName != null) {
084: o.writeShort(innerName.index);
085: } else {
086: o.writeShort(0);
087: }
088:
089: o.writeShort(accessFlags);
090: }
091:
092: /*
093: * The following four methods return information about this
094: * particular inner class. If the attribute index is null,
095: * the method returns 0.
096: */
097:
098: public int getInnerInfoIndex() {
099: if (innerInfo != null) {
100: return innerInfo.index;
101: }
102:
103: return 0;
104: }
105:
106: public int getOuterInfoIndex() {
107: if (outerInfo != null) {
108: return outerInfo.index;
109: }
110:
111: return 0;
112: }
113:
114: public int getInnerNameIndex() {
115: if (innerName != null) {
116: return innerName.index;
117: }
118:
119: return 0;
120: }
121:
122: public int getAccessFlags() {
123: return accessFlags;
124: }
125:
126: /*
127: * Return the name of this inner class. If this inner class does not
128: * have a name, then it is an anonymous inner class, so return the
129: * string "anonymous".
130: */
131: public String getName() {
132: if (innerName != null) {
133: return innerName.toString();
134: } else {
135: return "";
136: }
137: }
138:
139: public String getFullName() {
140: if (outerInfo != null) {
141: if (getName().equals("")) {
142: return "Old-Style-InnerClass";
143: } else {
144: return outerInfo.name.string + "$" + getName();
145: }
146: } else {
147: return "ICA-ReferingToSelf";
148: }
149: }
150: }
|