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 org.apache.bcel.Constants; 23 24 34 public final class InnerClasses extends Attribute { 35 36 private InnerClass[] inner_classes; 37 private int number_of_classes; 38 39 40 44 public InnerClasses(InnerClasses c) { 45 this(c.getNameIndex(), c.getLength(), c.getInnerClasses(), c.getConstantPool()); 46 } 47 48 49 55 public InnerClasses(int name_index, int length, InnerClass[] inner_classes, 56 ConstantPool constant_pool) { 57 super(Constants.ATTR_INNER_CLASSES, name_index, length, constant_pool); 58 setInnerClasses(inner_classes); 59 } 60 61 62 71 InnerClasses(int name_index, int length, DataInputStream file, ConstantPool constant_pool) 72 throws IOException { 73 this(name_index, length, (InnerClass[]) null, constant_pool); 74 number_of_classes = file.readUnsignedShort(); 75 inner_classes = new InnerClass[number_of_classes]; 76 for (int i = 0; i < number_of_classes; i++) { 77 inner_classes[i] = new InnerClass(file); 78 } 79 } 80 81 82 89 public void accept( Visitor v ) { 90 v.visitInnerClasses(this); 91 } 92 93 94 100 public final void dump( DataOutputStream file ) throws IOException { 101 super.dump(file); 102 file.writeShort(number_of_classes); 103 for (int i = 0; i < number_of_classes; i++) { 104 inner_classes[i].dump(file); 105 } 106 } 107 108 109 112 public final InnerClass[] getInnerClasses() { 113 return inner_classes; 114 } 115 116 117 120 public final void setInnerClasses( InnerClass[] inner_classes ) { 121 this.inner_classes = inner_classes; 122 number_of_classes = (inner_classes == null) ? 0 : inner_classes.length; 123 } 124 125 126 129 public final String toString() { 130 StringBuffer buf = new StringBuffer (); 131 for (int i = 0; i < number_of_classes; i++) { 132 buf.append(inner_classes[i].toString(constant_pool)).append("\n"); 133 } 134 return buf.toString(); 135 } 136 137 138 141 public Attribute copy( ConstantPool _constant_pool ) { 142 InnerClasses c = (InnerClasses) clone(); 143 c.inner_classes = new InnerClass[number_of_classes]; 144 for (int i = 0; i < number_of_classes; i++) { 145 c.inner_classes[i] = inner_classes[i].copy(); 146 } 147 c.constant_pool = _constant_pool; 148 return c; 149 } 150 } 151 | Popular Tags |