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

ConstantCP.java

00001 package de.fub.bytecode.classfile;
00002 
00003 import java.io.*;
00004 
00005 /** 
00006  * Abstract super class for Fieldref and Methodref constants.
00007  *
00008  * @version $Id: ConstantCP.java,v 1.1.1.1 2002/01/24 03:44:00 pserver Exp $
00009  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00010  * @see     ConstantFieldref
00011  * @see     ConstantMethodref
00012  * @see     ConstantInterfaceMethodref
00013  */
00014 public abstract class ConstantCP extends Constant {
00015   /** References to the constants containing the class and the field signature
00016    */
00017   protected int class_index, name_and_type_index; 
00018 
00019   /**
00020    * @param class_index Reference to the class containing the field
00021    * @param name_and_type_index and the field signature
00022    */
00023   protected ConstantCP(byte tag, int class_index, 
00024                int name_and_type_index) {
00025     super(tag);
00026     this.class_index         = class_index;
00027     this.name_and_type_index = name_and_type_index;
00028   }  
00029   /**
00030    * Initialize instance from file data.
00031    *
00032    * @param tag  Constant type tag
00033    * @param file Input stream
00034    * @throw IOException
00035    */
00036   ConstantCP(byte tag, DataInputStream file) throws IOException
00037   {
00038     this(tag, file.readUnsignedShort(), file.readUnsignedShort());
00039   }  
00040   /**
00041    * Initialize from another object.
00042    */
00043   public ConstantCP(ConstantCP c) {
00044     this(c.getTag(), c.getClassIndex(), c.getNameAndTypeIndex());
00045   }  
00046   /** 
00047    * Dump constant field reference to file stream in binary format.
00048    *
00049    * @param file Output file stream
00050    * @throw IOException
00051    */ 
00052   public final void dump(DataOutputStream file) throws IOException
00053   {
00054     file.writeByte(tag);
00055     file.writeShort(class_index);
00056     file.writeShort(name_and_type_index);
00057   }  
00058   /**
00059    * @return Reference (index) to class this field belongs to.
00060    */  
00061   public final int getClassIndex()       { return class_index; }  
00062   /**
00063    * @return Reference (index) to signature of the field.
00064    */  
00065   public final int getNameAndTypeIndex() { return name_and_type_index; }  
00066   /**
00067    * @param class_index points to Constant_class 
00068    */
00069   public final void setClassIndex(int class_index) {
00070     this.class_index = class_index;
00071   }  
00072   /**
00073    * @param name_and_type_index points to Constant_NameAndType
00074    */
00075   public final void setNameAndTypeIndex(int name_and_type_index) {
00076     this.name_and_type_index = name_and_type_index;
00077   }  
00078   /**
00079    * @return String representation.
00080    */
00081   public final String toString() {
00082     return super.toString() + "(class_index = " + class_index +
00083       ", name_and_type_index = " + name_and_type_index + ")";
00084   }  
00085 }

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