/**
* JavaGuard -- an obfuscation package for Java classfiles.
*
* Copyright (c) 1999 Mark Welsh (markw@retrologic.com)
* Copyright (c) 2002 Thorsten Heit (theit@gmx.de)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* The author may be contacted at theit@gmx.de.
*
*
* $Id: LocalVariableInfo.java,v 1.2 2002/05/08 11:53:42 glurk Exp $
*/
package net.sf.javaguard.classfile;
import java.io.*;
/** Representation of a local variable table entry.
*
* @author <a href="mailto:theit@gmx.de">Thorsten Heit</a>
* @author <a href="mailto:markw@retrologic.com">Mark Welsh</a>
*/
public class LocalVariableInfo {
/** Start of the Program Counter (PC). */
private int startPc;
/** The length. */
private int length;
/** Name index into the constant pool. */
private int nameIndex;
/** Descriptor index into the constant pool. */
private int descriptorIndex;
/** Index into the constant pool. */
private int index;
/** Creates a new LocalVariableInfo object from the given input stream.
* @param din the input stream
* @return the LocalVariableInfo object created from the input stream
* @throws IOException if an I/O error occurs
*/
public static LocalVariableInfo create(DataInput din)
throws IOException {
LocalVariableInfo lvi = new LocalVariableInfo();
lvi.read(din);
return lvi;
}
/** Private constructor that creates a new LocalVariableInfo object.
*/
private LocalVariableInfo() {
}
/** Sets the address of the program counter.
* @param pc the address of the program counter
* @see #getStartPc
*/
protected void setStartPc(int pc) {
this.startPc = pc;
}
/** Returns the address of the program counter.
* @return address of the program counter
* @see #setStartPc
*/
protected int getStartPc() {
return startPc;
}
/** Sets the length.
* @param len the length
* @see #getLength
*/
protected void setLength(int len) {
this.length = len;
}
/** Returns the length.
* @return length
* @see #setLength
*/
protected int getLength() {
return length;
}
/** Set the name index.
* @param index index into the constant pool
* @see #getNameIndex
*/
protected void setNameIndex(int index) {
nameIndex = index;
}
/** Return the name index into the constant pool.
* @return index into the constant pool
* @see #setNameIndex
*/
protected int getNameIndex() {
return nameIndex;
}
/** Set the descriptor index.
* @param index index into the constant pool
* @see #getDescriptorIndex
*/
protected void setDescriptorIndex(int index) {
descriptorIndex = index;
}
/** Return the descriptor index into constant pool.
* @return index into the constant pool
* @see #setDescriptorIndex
*/
protected int getDescriptorIndex() {
return descriptorIndex;
}
/** Set the index.
* @param index index into the constant pool
* @see #getIndex
*/
protected void setIndex(int index) {
this.index = index;
}
/** Return the index into the constant pool.
* @return index into the constant pool
* @see #setIndex
*/
protected int getIndex() {
return index;
}
/** Check for Utf8 references to constant pool and mark them.
* @param pool the constant pool the element belongs to
*/
protected void markUtf8Refs(ConstantPool pool) {
pool.incRefCount(getNameIndex());
pool.incRefCount(getDescriptorIndex());
}
/** Read the data following the header.
* @param din the input stream
* @throws IOException if an I/O error occurs
*/
private void read(DataInput din)
throws IOException {
setStartPc(din.readUnsignedShort());
setLength(din.readUnsignedShort());
setNameIndex(din.readUnsignedShort());
setDescriptorIndex(din.readUnsignedShort());
setIndex(din.readUnsignedShort());
}
/** Export data following the header to a DataOutput stream.
* @param dout the output stream
* @throws IOException if an I/O error occurs
*/
public void write(DataOutput dout)
throws IOException {
dout.writeShort(getStartPc());
dout.writeShort(getLength());
dout.writeShort(getNameIndex());
dout.writeShort(getDescriptorIndex());
dout.writeShort(getIndex());
}
/** Dump the content of the entry to the specified file (used for debugging).
* @param pw the print writer
* @param cf the class file the element belongs to
*/
public void dump(PrintWriter pw, ClassFile cf) {
pw.print("StartPC: ");
pw.println(getStartPc());
pw.print("Length: ");
pw.println(getLength());
pw.print("Name index: ");
pw.println(getNameIndex());
pw.print("Descriptor index: ");
pw.println(getDescriptorIndex());
pw.print("Index: ");
pw.println(getIndex());
}
}
|