001: /**
002: * JavaGuard -- an obfuscation package for Java classfiles.
003: *
004: * Copyright (c) 1999 Mark Welsh (markw@retrologic.com)
005: * Copyright (c) 2002 Thorsten Heit (theit@gmx.de)
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * The author may be contacted at theit@gmx.de.
022: *
023: *
024: * $Id: LocalVariableInfo.java,v 1.2 2002/05/08 11:53:42 glurk Exp $
025: */package net.sf.javaguard.classfile;
026:
027: import java.io.*;
028:
029: /** Representation of a local variable table entry.
030: *
031: * @author <a href="mailto:theit@gmx.de">Thorsten Heit</a>
032: * @author <a href="mailto:markw@retrologic.com">Mark Welsh</a>
033: */
034: public class LocalVariableInfo {
035: /** Start of the Program Counter (PC). */
036: private int startPc;
037: /** The length. */
038: private int length;
039: /** Name index into the constant pool. */
040: private int nameIndex;
041: /** Descriptor index into the constant pool. */
042: private int descriptorIndex;
043: /** Index into the constant pool. */
044: private int index;
045:
046: /** Creates a new LocalVariableInfo object from the given input stream.
047: * @param din the input stream
048: * @return the LocalVariableInfo object created from the input stream
049: * @throws IOException if an I/O error occurs
050: */
051: public static LocalVariableInfo create(DataInput din)
052: throws IOException {
053: LocalVariableInfo lvi = new LocalVariableInfo();
054: lvi.read(din);
055: return lvi;
056: }
057:
058: /** Private constructor that creates a new LocalVariableInfo object.
059: */
060: private LocalVariableInfo() {
061: }
062:
063: /** Sets the address of the program counter.
064: * @param pc the address of the program counter
065: * @see #getStartPc
066: */
067: protected void setStartPc(int pc) {
068: this .startPc = pc;
069: }
070:
071: /** Returns the address of the program counter.
072: * @return address of the program counter
073: * @see #setStartPc
074: */
075: protected int getStartPc() {
076: return startPc;
077: }
078:
079: /** Sets the length.
080: * @param len the length
081: * @see #getLength
082: */
083: protected void setLength(int len) {
084: this .length = len;
085: }
086:
087: /** Returns the length.
088: * @return length
089: * @see #setLength
090: */
091: protected int getLength() {
092: return length;
093: }
094:
095: /** Set the name index.
096: * @param index index into the constant pool
097: * @see #getNameIndex
098: */
099: protected void setNameIndex(int index) {
100: nameIndex = index;
101: }
102:
103: /** Return the name index into the constant pool.
104: * @return index into the constant pool
105: * @see #setNameIndex
106: */
107: protected int getNameIndex() {
108: return nameIndex;
109: }
110:
111: /** Set the descriptor index.
112: * @param index index into the constant pool
113: * @see #getDescriptorIndex
114: */
115: protected void setDescriptorIndex(int index) {
116: descriptorIndex = index;
117: }
118:
119: /** Return the descriptor index into constant pool.
120: * @return index into the constant pool
121: * @see #setDescriptorIndex
122: */
123: protected int getDescriptorIndex() {
124: return descriptorIndex;
125: }
126:
127: /** Set the index.
128: * @param index index into the constant pool
129: * @see #getIndex
130: */
131: protected void setIndex(int index) {
132: this .index = index;
133: }
134:
135: /** Return the index into the constant pool.
136: * @return index into the constant pool
137: * @see #setIndex
138: */
139: protected int getIndex() {
140: return index;
141: }
142:
143: /** Check for Utf8 references to constant pool and mark them.
144: * @param pool the constant pool the element belongs to
145: */
146: protected void markUtf8Refs(ConstantPool pool) {
147: pool.incRefCount(getNameIndex());
148: pool.incRefCount(getDescriptorIndex());
149: }
150:
151: /** Read the data following the header.
152: * @param din the input stream
153: * @throws IOException if an I/O error occurs
154: */
155: private void read(DataInput din) throws IOException {
156: setStartPc(din.readUnsignedShort());
157: setLength(din.readUnsignedShort());
158: setNameIndex(din.readUnsignedShort());
159: setDescriptorIndex(din.readUnsignedShort());
160: setIndex(din.readUnsignedShort());
161: }
162:
163: /** Export data following the header to a DataOutput stream.
164: * @param dout the output stream
165: * @throws IOException if an I/O error occurs
166: */
167: public void write(DataOutput dout) throws IOException {
168: dout.writeShort(getStartPc());
169: dout.writeShort(getLength());
170: dout.writeShort(getNameIndex());
171: dout.writeShort(getDescriptorIndex());
172: dout.writeShort(getIndex());
173: }
174:
175: /** Dump the content of the entry to the specified file (used for debugging).
176: * @param pw the print writer
177: * @param cf the class file the element belongs to
178: */
179: public void dump(PrintWriter pw, ClassFile cf) {
180: pw.print("StartPC: ");
181: pw.println(getStartPc());
182: pw.print("Length: ");
183: pw.println(getLength());
184: pw.print("Name index: ");
185: pw.println(getNameIndex());
186: pw.print("Descriptor index: ");
187: pw.println(getDescriptorIndex());
188: pw.print("Index: ");
189: pw.println(getIndex());
190: }
191: }
|