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
00016 public final class InnerClasses extends Attribute {
00017 private InnerClass[] inner_classes;
00018 private int number_of_classes;
00019
00020
00021
00022
00023
00024
00025
00026
00027 public InnerClasses(int name_index, int length,
00028 InnerClass[] inner_classes,
00029 ConstantPool constant_pool)
00030 {
00031 super(ATTR_INNER_CLASSES, name_index, length, constant_pool);
00032 setInnerClasses(inner_classes);
00033 }
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 InnerClasses(int name_index, int length, DataInputStream file,
00044 ConstantPool constant_pool) throws IOException
00045 {
00046 this(name_index, length, (InnerClass[])null, constant_pool);
00047
00048 number_of_classes = file.readUnsignedShort();
00049 inner_classes = new InnerClass[number_of_classes];
00050
00051 for(int i=0; i < number_of_classes; i++)
00052 inner_classes[i] = new InnerClass(file);
00053 }
00054
00055
00056
00057
00058 public InnerClasses(InnerClasses c) {
00059 this(c.getNameIndex(), c.getLength(), c.getInnerClasses(),
00060 c.getConstantPool());
00061 }
00062
00063
00064
00065
00066
00067
00068
00069 public void accept(Visitor v) {
00070 v.visitInnerClasses(this);
00071 }
00072
00073
00074
00075 public Attribute copy(ConstantPool constant_pool) {
00076 InnerClasses c = (InnerClasses)clone();
00077
00078 c.inner_classes = new InnerClass[number_of_classes];
00079 for(int i=0; i < number_of_classes; i++)
00080 c.inner_classes[i] = inner_classes[i].copy();
00081
00082 c.constant_pool = constant_pool;
00083 return c;
00084 }
00085
00086
00087
00088
00089
00090
00091 public final void dump(DataOutputStream file) throws IOException
00092 {
00093 super.dump(file);
00094 file.writeShort(number_of_classes);
00095
00096 for(int i=0; i < number_of_classes; i++)
00097 inner_classes[i].dump(file);
00098 }
00099
00100
00101
00102 public final InnerClass[] getInnerClasses() { return inner_classes; }
00103
00104
00105
00106 public final void setInnerClasses(InnerClass[] inner_classes) {
00107 this.inner_classes = inner_classes;
00108 number_of_classes = (inner_classes == null)? 0 : inner_classes.length;
00109 }
00110
00111
00112
00113 public final String toString() {
00114 StringBuffer buf = new StringBuffer();
00115
00116 for(int i=0; i < number_of_classes; i++)
00117 buf.append(inner_classes[i].toString(constant_pool) + "\n");
00118
00119 return buf.toString();
00120 }
00121 }