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

SourceFile.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 represents a reference
00008  * to the source file of this class.
00009  * It is instantiated from the <em>Attribute.readAttribute()</em> method.
00010  *
00011  * @version $Id: SourceFile.java,v 1.1.1.1 2002/01/24 03:44:00 pserver Exp $
00012  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00013  * @see     Attribute
00014  */
00015 public final class SourceFile extends Attribute {
00016   private int sourcefile_index;
00017 
00018   /**
00019    * @param name_index Index in constant pool to CONSTANT_Utf8
00020    * @param length Content length in bytes
00021    * @param constant_pool Array of constants
00022    * @param sourcefile_index Index in constant pool to CONSTANT_Utf8
00023    */
00024   public SourceFile(int name_index, int length, int sourcefile_index,
00025             ConstantPool constant_pool)
00026   {
00027     super(ATTR_SOURCE_FILE, name_index, length, constant_pool);
00028     this.sourcefile_index = sourcefile_index;
00029   }  
00030   /**
00031    * Construct object from file stream.
00032    * @param name_index Index in constant pool to CONSTANT_Utf8
00033    * @param length Content length in bytes
00034    * @param file Input stream
00035    * @param constant_pool Array of constants
00036    * @throw IOException
00037    */
00038   SourceFile(int name_index, int length, DataInputStream file,
00039          ConstantPool constant_pool) throws IOException
00040   {
00041     this(name_index, length, file.readUnsignedShort(), constant_pool);
00042   }  
00043   /**
00044    * Initialize from another object. Note that both objects use the same
00045    * references (shallow copy). Use clone() for a physical copy.
00046    */
00047   public SourceFile(SourceFile c) {
00048     this(c.getNameIndex(), c.getLength(), c.getSourceFileIndex(),
00049      c.getConstantPool());
00050   }  
00051   /**
00052    * Called by objects that are traversing the nodes of the tree implicitely
00053    * defined by the contents of a Java class. I.e., the hierarchy of methods,
00054    * fields, attributes, etc. spawns a tree of objects.
00055    *
00056    * @param v Visitor object
00057    */
00058   public void accept(Visitor v) {
00059     v.visitSourceFile(this);
00060   }  
00061   /**
00062    * @return deep copy of this attribute
00063    */
00064   public Attribute copy(ConstantPool constant_pool) {
00065     return (SourceFile)clone();
00066   }  
00067   /**
00068    * Dump source file attribute to file stream in binary format.
00069    *
00070    * @param file Output file stream
00071    * @throw IOException
00072    */ 
00073   public final void dump(DataOutputStream file) throws IOException
00074   {
00075     super.dump(file);
00076     file.writeShort(sourcefile_index);
00077   }  
00078   /**
00079    * @return Index in constant pool of source file name.
00080    */  
00081   public final int getSourceFileIndex() { return sourcefile_index; }  
00082   /**
00083    * @return Source file name.
00084    */ 
00085   public final String getSourceFileName() {
00086     ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(sourcefile_index, 
00087                                  CONSTANT_Utf8);
00088     return c.getBytes();
00089   }  
00090   /**
00091    * @param sourcefile_index.
00092    */
00093   public final void setSourceFileIndex(int sourcefile_index) {
00094     this.sourcefile_index = sourcefile_index;
00095   }  
00096   /**
00097    * @return String representation
00098    */ 
00099   public final String toString() {
00100     return "SourceFile(" + getSourceFileName() + ")";
00101   }  
00102 }

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