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 70 public final class InnerClasses extends Attribute { 71 private InnerClass[] inner_classes; 72 private int number_of_classes; 73 74 78 public InnerClasses(InnerClasses c) { 79 this(c.getNameIndex(), c.getLength(), c.getInnerClasses(), 80 c.getConstantPool()); 81 } 82 83 90 public InnerClasses(int name_index, int length, 91 InnerClass[] inner_classes, 92 ConstantPool constant_pool) 93 { 94 super(Constants.ATTR_INNER_CLASSES, name_index, length, constant_pool); 95 setInnerClasses(inner_classes); 96 } 97 98 107 InnerClasses(int name_index, int length, DataInputStream file, 108 ConstantPool constant_pool) throws IOException 109 { 110 this(name_index, length, (InnerClass[])null, constant_pool); 111 112 number_of_classes = file.readUnsignedShort(); 113 inner_classes = new InnerClass[number_of_classes]; 114 115 for(int i=0; i < number_of_classes; i++) 116 inner_classes[i] = new InnerClass(file); 117 } 118 125 public void accept(Visitor v) { 126 v.visitInnerClasses(this); 127 } 128 134 public final void dump(DataOutputStream file) throws IOException 135 { 136 super.dump(file); 137 file.writeShort(number_of_classes); 138 139 for(int i=0; i < number_of_classes; i++) 140 inner_classes[i].dump(file); 141 } 142 143 146 public final InnerClass[] getInnerClasses() { return inner_classes; } 147 148 151 public final void setInnerClasses(InnerClass[] inner_classes) { 152 this.inner_classes = inner_classes; 153 number_of_classes = (inner_classes == null)? 0 : inner_classes.length; 154 } 155 156 159 public final String toString() { 160 StringBuffer buf = new StringBuffer (); 161 162 for(int i=0; i < number_of_classes; i++) 163 buf.append(inner_classes[i].toString(constant_pool) + "\n"); 164 165 return buf.toString(); 166 } 167 168 171 public Attribute copy(ConstantPool constant_pool) { 172 InnerClasses c = (InnerClasses)clone(); 173 174 c.inner_classes = new InnerClass[number_of_classes]; 175 for(int i=0; i < number_of_classes; i++) 176 c.inner_classes[i] = inner_classes[i].copy(); 177 178 c.constant_pool = constant_pool; 179 return c; 180 } 181 } 182 | Popular Tags |