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

InnerClass.java

00001 package de.fub.bytecode.classfile;
00002 
00003 import  de.fub.bytecode.Constants;
00004 import  java.io.*;
00005 
00006 /** 
00007  * This class represents a inner class attribute, i.e., the class
00008  * indices of the inner and outer classes, the name and the attributes
00009  * of the inner class.
00010  *
00011  * @version $Id: InnerClass.java,v 1.1.1.1 2002/01/24 03:41:37 pserver Exp $
00012  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00013  * @see InnerClasses
00014  */
00015 public final class InnerClass implements Cloneable
00016 {
00017   private int inner_class_index;
00018   private int outer_class_index;
00019   private int inner_name_index;
00020   private int inner_access_flags;
00021 
00022   /**
00023    * @param inner_class_index Class index in constant pool of inner class
00024    * @param outer_class_index Class index in constant pool of outer class
00025    * @param inner_name_index  Name index in constant pool of inner class
00026    * @param inner_access_flags Access flags of inner class
00027    */
00028   public InnerClass(int inner_class_index, int outer_class_index,
00029             int inner_name_index, int inner_access_flags)
00030   {
00031     this.inner_class_index  = inner_class_index; 
00032     this.outer_class_index  = outer_class_index;
00033     this.inner_name_index   = inner_name_index; 
00034     this.inner_access_flags = inner_access_flags;
00035   }  
00036   /**
00037    * Initialize from another object.
00038    */
00039   public InnerClass(InnerClass c) {
00040     this(c.getInnerClassIndex(), c.getOuterClassIndex(), c.getInnerNameIndex(),
00041      c.getInnerAccessFlags());
00042   }  
00043   /**
00044    * Construct object from file stream.
00045    * @param file Input stream
00046    * @throw IOException
00047    */  
00048   InnerClass(DataInputStream file) throws IOException
00049   {
00050     this(file.readUnsignedShort(), file.readUnsignedShort(),
00051      file.readUnsignedShort(), file.readUnsignedShort());
00052   }  
00053   /**
00054    * Called by objects that are traversing the nodes of the tree implicitely
00055    * defined by the contents of a Java class. I.e., the hierarchy of methods,
00056    * fields, attributes, etc. spawns a tree of objects.
00057    *
00058    * @param v Visitor object
00059    */
00060   public void accept(Visitor v) {
00061     v.visitInnerClass(this);
00062   }  
00063   /**
00064    * @return deep copy of this object
00065    */
00066   public InnerClass copy() {
00067     try {
00068       return (InnerClass)clone();
00069     } catch(CloneNotSupportedException e) {}
00070 
00071     return null;
00072   }  
00073   /**
00074    * Dump inner class attribute to file stream in binary format.
00075    *
00076    * @param file Output file stream
00077    * @throw IOException
00078    */ 
00079   public final void dump(DataOutputStream file) throws IOException
00080   {
00081     file.writeShort(inner_class_index);
00082     file.writeShort(outer_class_index);
00083     file.writeShort(inner_name_index);
00084     file.writeShort(inner_access_flags);
00085   }  
00086   /**
00087    * @return access flags of inner class.
00088    */  
00089   public final int getInnerAccessFlags() { return inner_access_flags; }  
00090   /**
00091    * @return class index of inner class.
00092    */  
00093   public final int getInnerClassIndex() { return inner_class_index; }  
00094   /**
00095    * @return name index of inner class.
00096    */  
00097   public final int getInnerNameIndex() { return inner_name_index; }  
00098   /**
00099    * @return class index of outer class.
00100    */  
00101   public final int getOuterClassIndex() { return outer_class_index; }  
00102   /**
00103    * @param inner_access_flags.
00104    */
00105   public final void setInnerAccessFlags(int inner_access_flags) {
00106     this.inner_access_flags = inner_access_flags;
00107   }  
00108   /**
00109    * @param inner_class_index.
00110    */
00111   public final void setInnerClassIndex(int inner_class_index) {
00112     this.inner_class_index = inner_class_index;
00113   }  
00114   /**
00115    * @param inner_name_index.
00116    */
00117   public final void setInnerNameIndex(int inner_name_index) {
00118     this.inner_name_index = inner_name_index;
00119   }  
00120   /**
00121    * @param outer_class_index.
00122    */
00123   public final void setOuterClassIndex(int outer_class_index) {
00124     this.outer_class_index = outer_class_index;
00125   }  
00126   /**
00127    * @return String representation.
00128    */ 
00129   public final String toString() {
00130     return "InnerClass(" + inner_class_index + ", " + outer_class_index +
00131       ", " + inner_name_index + ", " + inner_access_flags + ")";
00132   }  
00133   /**
00134    * @return Resolved string representation
00135    */ 
00136   public final String toString(ConstantPool constant_pool) { 
00137     String inner_class_name, outer_class_name, inner_name, access;
00138  
00139     inner_class_name = constant_pool.getConstantString(inner_class_index,
00140                                Constants.CONSTANT_Class);
00141     inner_class_name = Utility.compactClassName(inner_class_name);
00142 
00143     if (outer_class_index != 0) {
00144       outer_class_name = constant_pool.getConstantString(outer_class_index, 
00145                                                          Constants.CONSTANT_Class);
00146       outer_class_name = Utility.compactClassName(outer_class_name);
00147     }
00148     else
00149       outer_class_name = "<not a member>";
00150     
00151     if(inner_name_index != 0)
00152       inner_name = ((ConstantUtf8)constant_pool.
00153             getConstant(inner_name_index, Constants.CONSTANT_Utf8)).getBytes();
00154     else
00155       inner_name = "<anonymous>";
00156 
00157     access = Utility.accessToString(inner_access_flags, true);
00158     access = access.equals("")? "" : (access + " ");
00159 
00160     return "InnerClass:" + access + inner_class_name + 
00161       "(\"" + outer_class_name + "\", \"" + inner_name + "\")";
00162   }  
00163 }

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