00001 package de.fub.bytecode.classfile;
00002
00003 import de.fub.bytecode.Constants;
00004 import java.io.*;
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 public final class InnerClass implements Constants, Cloneable
00016 {
00017 private int inner_class_index;
00018 private int outer_class_index;
00019 private int inner_name_index;
00020 private int inner_access_flags;
00021
00022
00023
00024
00025
00026
00027
00028 public InnerClass(int inner_class_index, int outer_class_index,
00029 int inner_name_index, int inner_access_flags)
00030 {
00031 this.inner_class_index = inner_class_index;
00032 this.outer_class_index = outer_class_index;
00033 this.inner_name_index = inner_name_index;
00034 this.inner_access_flags = inner_access_flags;
00035 }
00036
00037
00038
00039 public InnerClass(InnerClass c) {
00040 this(c.getInnerClassIndex(), c.getOuterClassIndex(), c.getInnerNameIndex(),
00041 c.getInnerAccessFlags());
00042 }
00043
00044
00045
00046
00047
00048 InnerClass(DataInputStream file) throws IOException
00049 {
00050 this(file.readUnsignedShort(), file.readUnsignedShort(),
00051 file.readUnsignedShort(), file.readUnsignedShort());
00052 }
00053
00054
00055
00056
00057
00058
00059
00060 public void accept(Visitor v) {
00061 v.visitInnerClass(this);
00062 }
00063
00064
00065
00066 public InnerClass copy() {
00067 try {
00068 return (InnerClass)clone();
00069 } catch(CloneNotSupportedException e) {}
00070
00071 return null;
00072 }
00073
00074
00075
00076
00077
00078
00079 public final void dump(DataOutputStream file) throws IOException
00080 {
00081 file.writeShort(inner_class_index);
00082 file.writeShort(outer_class_index);
00083 file.writeShort(inner_name_index);
00084 file.writeShort(inner_access_flags);
00085 }
00086
00087
00088
00089 public final int getInnerAccessFlags() { return inner_access_flags; }
00090
00091
00092
00093 public final int getInnerClassIndex() { return inner_class_index; }
00094
00095
00096
00097 public final int getInnerNameIndex() { return inner_name_index; }
00098
00099
00100
00101 public final int getOuterClassIndex() { return outer_class_index; }
00102
00103
00104
00105 public final void setInnerAccessFlags(int inner_access_flags) {
00106 this.inner_access_flags = inner_access_flags;
00107 }
00108
00109
00110
00111 public final void setInnerClassIndex(int inner_class_index) {
00112 this.inner_class_index = inner_class_index;
00113 }
00114
00115
00116
00117 public final void setInnerNameIndex(int inner_name_index) {
00118 this.inner_name_index = inner_name_index;
00119 }
00120
00121
00122
00123 public final void setOuterClassIndex(int outer_class_index) {
00124 this.outer_class_index = outer_class_index;
00125 }
00126
00127
00128
00129 public final String toString() {
00130 return "InnerClass(" + inner_class_index + ", " + outer_class_index +
00131 ", " + inner_name_index + ", " + inner_access_flags;
00132 }
00133
00134
00135
00136 public final String toString(ConstantPool constant_pool) {
00137 String inner_class_name, outer_class_name, inner_name, access;
00138
00139 inner_class_name = constant_pool.getConstantString(inner_class_index,
00140 CONSTANT_Class);
00141 inner_class_name = Utility.compactClassName(inner_class_name);
00142
00143 if (outer_class_index != 0) {
00144 outer_class_name = constant_pool.getConstantString(outer_class_index,
00145 CONSTANT_Class);
00146 outer_class_name = Utility.compactClassName(outer_class_name);
00147 }
00148 else
00149 outer_class_name = "<not a member>";
00150
00151 if(inner_name_index != 0)
00152 inner_name = ((ConstantUtf8)constant_pool.getConstant(inner_name_index,
00153 CONSTANT_Utf8)).getBytes();
00154 else
00155 inner_name = "<anonymous>";
00156
00157 access = Utility.accessToString(inner_access_flags, true);
00158 access = access.equals("")? "" : (access + " ");
00159
00160 return "InnerClass:" + access + inner_class_name +
00161 "(\"" + outer_class_name + "\", \"" + inner_name + "\")";
00162 }
00163 }