Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

InnerClasses.java

00001 package de.fub.bytecode.classfile;
00002 
00003 import  de.fub.bytecode.Constants;
00004 import  java.io.*;
00005 
00006 /**
00007  * This class is derived from <em>Attribute</em> and denotes that this class
00008  * is an Inner class of another.
00009  * to the source file of this class.
00010  * It is instantiated from the <em>Attribute.readAttribute()</em> method.
00011  *
00012  * @version $Id: InnerClasses.java,v 1.1.1.1 2002/01/24 03:44:00 pserver Exp $
00013  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00014  * @see     Attribute
00015  */
00016 public final class InnerClasses extends Attribute {
00017   private InnerClass[] inner_classes;
00018   private int          number_of_classes;
00019 
00020   /**
00021    * @param name_index Index in constant pool to CONSTANT_Utf8
00022    * @param length Content length in bytes
00023    * @param inner_classes array of inner classes attributes
00024    * @param constant_pool Array of constants
00025    * @param sourcefile_index Index in constant pool to CONSTANT_Utf8
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    * Construct object from file stream.
00036    *
00037    * @param name_index Index in constant pool to CONSTANT_Utf8
00038    * @param length Content length in bytes
00039    * @param file Input stream
00040    * @param constant_pool Array of constants
00041    * @throw IOException
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    * Initialize from another object. Note that both objects use the same
00056    * references (shallow copy). Use clone() for a physical copy.
00057    */
00058   public InnerClasses(InnerClasses c) {
00059     this(c.getNameIndex(), c.getLength(), c.getInnerClasses(),
00060      c.getConstantPool());
00061   }  
00062   /**
00063    * Called by objects that are traversing the nodes of the tree implicitely
00064    * defined by the contents of a Java class. I.e., the hierarchy of methods,
00065    * fields, attributes, etc. spawns a tree of objects.
00066    *
00067    * @param v Visitor object
00068    */
00069   public void accept(Visitor v) {
00070     v.visitInnerClasses(this);
00071   }  
00072   /**
00073    * @return deep copy of this attribute
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    * Dump source file attribute to file stream in binary format.
00087    *
00088    * @param file Output file stream
00089    * @throw IOException
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    * @return Index in constant pool of source file name.
00101    */  
00102   public final InnerClass[] getInnerClasses() { return inner_classes; }  
00103   /**
00104    * @param inner_classes.
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    * @return String representation.
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 }

Generated at Thu Feb 7 06:46:43 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001