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

LineNumber.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 (PC offset, line number) pair, i.e. a line number in
00008  * the source that corresponds to a relative address in the byte code. This
00009  * is used for debugging purposes.
00010  *
00011  * @version $Id: LineNumber.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     LineNumberTable
00014  */
00015 public final class LineNumber implements Cloneable {
00016   private int start_pc;    // Program Counter (PC) corresponds to line
00017   private int line_number; // number in source file
00018 
00019   /**
00020    * @param start_pc Program Counter (PC) corresponds to
00021    * @param line_number line number in source file
00022    */
00023   public LineNumber(int start_pc, int line_number)
00024   {
00025     this.start_pc    = start_pc;
00026     this.line_number = line_number;
00027   }  
00028   /**
00029    * Initialize from another object.
00030    */
00031   public LineNumber(LineNumber c) {
00032     this(c.getStartPC(), c.getLineNumber());
00033   }  
00034   /**
00035    * Construct object from file stream.
00036    * @param file Input stream
00037    * @throw IOException
00038    */
00039   LineNumber(DataInputStream file) throws IOException
00040   {
00041     this(file.readUnsignedShort(), file.readUnsignedShort());
00042   }  
00043   /**
00044    * Called by objects that are traversing the nodes of the tree implicitely
00045    * defined by the contents of a Java class. I.e., the hierarchy of methods,
00046    * fields, attributes, etc. spawns a tree of objects.
00047    *
00048    * @param v Visitor object
00049    */
00050   public void accept(Visitor v) {
00051     v.visitLineNumber(this);
00052   }  
00053   /**
00054    * @return deep copy of this object
00055    */
00056   public LineNumber copy() {
00057     try {
00058       return (LineNumber)clone();
00059     } catch(CloneNotSupportedException e) {}
00060 
00061     return null;
00062   }  
00063   /**
00064    * Dump line number/pc pair to file stream in binary format.
00065    *
00066    * @param file Output file stream
00067    * @throw IOException
00068    */ 
00069   public final void dump(DataOutputStream file) throws IOException
00070   {
00071     file.writeShort(start_pc);
00072     file.writeShort(line_number);
00073   }  
00074   /**
00075    * @return Corresponding source line
00076    */
00077   public final int getLineNumber() { return line_number; }  
00078   /**
00079    * @return PC in code
00080    */  
00081   public final int getStartPC() { return start_pc; }  
00082   /**
00083    * @param line_number.
00084    */
00085   public final void setLineNumber(int line_number) {
00086     this.line_number = line_number;
00087   }  
00088   /**
00089    * @param start_pc.
00090    */
00091   public final void setStartPC(int start_pc) {
00092     this.start_pc = start_pc;
00093   }  
00094   /**
00095    * @return String representation
00096    */ 
00097   public final String toString()
00098   {
00099     return "LineNumber(" + start_pc + ", " + line_number + ")";
00100   }  
00101 }

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