1 17 package org.apache.bcel.classfile; 18 19 import java.io.DataInputStream ; 20 import java.io.DataOutputStream ; 21 import java.io.IOException ; 22 import java.io.Serializable ; 23 import org.apache.bcel.Constants; 24 25 34 public final class InnerClass implements Cloneable , Node, Serializable { 35 36 private int inner_class_index; 37 private int outer_class_index; 38 private int inner_name_index; 39 private int inner_access_flags; 40 41 42 45 public InnerClass(InnerClass c) { 46 this(c.getInnerClassIndex(), c.getOuterClassIndex(), c.getInnerNameIndex(), c 47 .getInnerAccessFlags()); 48 } 49 50 51 56 InnerClass(DataInputStream file) throws IOException { 57 this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file 58 .readUnsignedShort()); 59 } 60 61 62 68 public InnerClass(int inner_class_index, int outer_class_index, int inner_name_index, 69 int inner_access_flags) { 70 this.inner_class_index = inner_class_index; 71 this.outer_class_index = outer_class_index; 72 this.inner_name_index = inner_name_index; 73 this.inner_access_flags = inner_access_flags; 74 } 75 76 77 84 public void accept( Visitor v ) { 85 v.visitInnerClass(this); 86 } 87 88 89 95 public final void dump( DataOutputStream file ) throws IOException { 96 file.writeShort(inner_class_index); 97 file.writeShort(outer_class_index); 98 file.writeShort(inner_name_index); 99 file.writeShort(inner_access_flags); 100 } 101 102 103 106 public final int getInnerAccessFlags() { 107 return inner_access_flags; 108 } 109 110 111 114 public final int getInnerClassIndex() { 115 return inner_class_index; 116 } 117 118 119 122 public final int getInnerNameIndex() { 123 return inner_name_index; 124 } 125 126 127 130 public final int getOuterClassIndex() { 131 return outer_class_index; 132 } 133 134 135 138 public final void setInnerAccessFlags( int inner_access_flags ) { 139 this.inner_access_flags = inner_access_flags; 140 } 141 142 143 146 public final void setInnerClassIndex( int inner_class_index ) { 147 this.inner_class_index = inner_class_index; 148 } 149 150 151 154 public final void setInnerNameIndex( int inner_name_index ) { 155 this.inner_name_index = inner_name_index; 156 } 157 158 159 162 public final void setOuterClassIndex( int outer_class_index ) { 163 this.outer_class_index = outer_class_index; 164 } 165 166 167 170 public final String toString() { 171 return "InnerClass(" + inner_class_index + ", " + outer_class_index + ", " 172 + inner_name_index + ", " + inner_access_flags + ")"; 173 } 174 175 176 179 public final String toString( ConstantPool constant_pool ) { 180 String inner_class_name, outer_class_name, inner_name, access; 181 inner_class_name = constant_pool.getConstantString(inner_class_index, 182 Constants.CONSTANT_Class); 183 inner_class_name = Utility.compactClassName(inner_class_name); 184 if (outer_class_index != 0) { 185 outer_class_name = constant_pool.getConstantString(outer_class_index, 186 Constants.CONSTANT_Class); 187 outer_class_name = Utility.compactClassName(outer_class_name); 188 } else { 189 outer_class_name = "<not a member>"; 190 } 191 if (inner_name_index != 0) { 192 inner_name = ((ConstantUtf8) constant_pool.getConstant(inner_name_index, 193 Constants.CONSTANT_Utf8)).getBytes(); 194 } else { 195 inner_name = "<anonymous>"; 196 } 197 access = Utility.accessToString(inner_access_flags, true); 198 access = access.equals("") ? "" : (access + " "); 199 return "InnerClass:" + access + inner_class_name + "(\"" + outer_class_name + "\", \"" 200 + inner_name + "\")"; 201 } 202 203 204 207 public InnerClass copy() { 208 try { 209 return (InnerClass) clone(); 210 } catch (CloneNotSupportedException e) { 211 } 212 return null; 213 } 214 } 215 | Popular Tags |