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

ConstantNameAndType.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 the abstract 
00008  * <A HREF="de.fub.bytecode.classfile.Constant.html">Constant</A> class 
00009  * and represents a reference to the name and signature
00010  * of a field or method.
00011  *
00012  * @version $Id: ConstantNameAndType.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     Constant
00015  */
00016 public final class ConstantNameAndType extends Constant {
00017   private int name_index;      // Name of field/method
00018   private int signature_index; // and its signature.
00019 
00020   /**
00021    * @param name_index Name of field/method
00022    * @param signature_index and its signature
00023    */
00024   public ConstantNameAndType(int name_index,
00025                  int signature_index)
00026   {
00027     super(CONSTANT_NameAndType);
00028     this.name_index      = name_index;
00029     this.signature_index = signature_index;
00030   }  
00031   /**
00032    * Initialize from another object.
00033    */
00034   public ConstantNameAndType(ConstantNameAndType c) {
00035     this(c.getNameIndex(), c.getSignatureIndex());
00036   }  
00037   /**
00038    * Initialize instance from file data.
00039    *
00040    * @param file Input stream
00041    * @throw IOException
00042    */
00043   ConstantNameAndType(DataInputStream file) throws IOException
00044   {    
00045     this((int)file.readUnsignedShort(), (int)file.readUnsignedShort());
00046   }  
00047   /**
00048    * Called by objects that are traversing the nodes of the tree implicitely
00049    * defined by the contents of a Java class. I.e., the hierarchy of methods,
00050    * fields, attributes, etc. spawns a tree of objects.
00051    *
00052    * @param v Visitor object
00053    */
00054   public void accept(Visitor v) {
00055     v.visitConstantNameAndType(this);
00056   }  
00057   /**
00058    * Dump name and signature index to file stream in binary format.
00059    *
00060    * @param file Output file stream
00061    * @throw IOException
00062    */ 
00063   public final void dump(DataOutputStream file) throws IOException
00064   {
00065     file.writeByte(tag);
00066     file.writeShort(name_index);
00067     file.writeShort(signature_index);
00068   }  
00069   /**
00070    * @return Name index in constant pool of field/method name.
00071    */  
00072   public final int getNameIndex()      { return name_index; }  
00073   /**
00074    * @return Index in constant pool of field/method signature.
00075    */  
00076   public final int getSignatureIndex() { return signature_index; }  
00077   /**
00078    * @param name_index.
00079    */
00080   public final void setNameIndex(int name_index) {
00081     this.name_index = name_index;
00082   }  
00083   /**
00084    * @param signature_index.
00085    */
00086   public final void setSignatureIndex(int signature_index) {
00087     this.signature_index = signature_index;
00088   }  
00089   /**
00090    * @return String representation
00091    */
00092   public final String toString() {
00093     return super.toString() + "(name_index = " + name_index + 
00094       ", signature_index = " + signature_index + ")";
00095   }  
00096 }

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