1 package com.sun.org.apache.bcel.internal.classfile; 2 3 56 57 import com.sun.org.apache.bcel.internal.Constants; 58 import java.io.*; 59 60 69 public final class InnerClass implements Cloneable , Node { 70 private int inner_class_index; 71 private int outer_class_index; 72 private int inner_name_index; 73 private int inner_access_flags; 74 75 78 public InnerClass(InnerClass c) { 79 this(c.getInnerClassIndex(), c.getOuterClassIndex(), c.getInnerNameIndex(), 80 c.getInnerAccessFlags()); 81 } 82 83 88 InnerClass(DataInputStream file) throws IOException 89 { 90 this(file.readUnsignedShort(), file.readUnsignedShort(), 91 file.readUnsignedShort(), file.readUnsignedShort()); 92 } 93 94 100 public InnerClass(int inner_class_index, int outer_class_index, 101 int inner_name_index, int inner_access_flags) 102 { 103 this.inner_class_index = inner_class_index; 104 this.outer_class_index = outer_class_index; 105 this.inner_name_index = inner_name_index; 106 this.inner_access_flags = inner_access_flags; 107 } 108 109 116 public void accept(Visitor v) { 117 v.visitInnerClass(this); 118 } 119 125 public final void dump(DataOutputStream file) throws IOException 126 { 127 file.writeShort(inner_class_index); 128 file.writeShort(outer_class_index); 129 file.writeShort(inner_name_index); 130 file.writeShort(inner_access_flags); 131 } 132 135 public final int getInnerAccessFlags() { return inner_access_flags; } 136 139 public final int getInnerClassIndex() { return inner_class_index; } 140 143 public final int getInnerNameIndex() { return inner_name_index; } 144 147 public final int getOuterClassIndex() { return outer_class_index; } 148 151 public final void setInnerAccessFlags(int inner_access_flags) { 152 this.inner_access_flags = inner_access_flags; 153 } 154 157 public final void setInnerClassIndex(int inner_class_index) { 158 this.inner_class_index = inner_class_index; 159 } 160 163 public final void setInnerNameIndex(int inner_name_index) { 164 this.inner_name_index = inner_name_index; 165 } 166 169 public final void setOuterClassIndex(int outer_class_index) { 170 this.outer_class_index = outer_class_index; 171 } 172 175 public final String toString() { 176 return "InnerClass(" + inner_class_index + ", " + outer_class_index + 177 ", " + inner_name_index + ", " + inner_access_flags + ")"; 178 } 179 180 183 public final String toString(ConstantPool constant_pool) { 184 String inner_class_name, outer_class_name, inner_name, access; 185 186 inner_class_name = constant_pool.getConstantString(inner_class_index, 187 Constants.CONSTANT_Class); 188 inner_class_name = Utility.compactClassName(inner_class_name); 189 190 if (outer_class_index != 0) { 191 outer_class_name = constant_pool.getConstantString(outer_class_index, 192 Constants.CONSTANT_Class); 193 outer_class_name = Utility.compactClassName(outer_class_name); 194 } 195 else 196 outer_class_name = "<not a member>"; 197 198 if(inner_name_index != 0) 199 inner_name = ((ConstantUtf8)constant_pool. 200 getConstant(inner_name_index, Constants.CONSTANT_Utf8)).getBytes(); 201 else 202 inner_name = "<anonymous>"; 203 204 access = Utility.accessToString(inner_access_flags, true); 205 access = access.equals("")? "" : (access + " "); 206 207 return "InnerClass:" + access + inner_class_name + 208 "(\"" + outer_class_name + "\", \"" + inner_name + "\")"; 209 } 210 211 214 public InnerClass copy() { 215 try { 216 return (InnerClass)clone(); 217 } catch(CloneNotSupportedException e) {} 218 219 return null; 220 } 221 } 222 | Popular Tags |