001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.classreader;
034:
035: import java.io.*;
036:
037: import org.apache.log4j.*;
038:
039: public class LocalVariable implements Visitable {
040: private LocalVariableTable_attribute localVariableTable;
041: private int startPC;
042: private int length;
043: private int nameIndex;
044: private int descriptorIndex;
045: private int index;
046:
047: public LocalVariable(
048: LocalVariableTable_attribute localVariableTable,
049: DataInputStream in) throws IOException {
050: this .localVariableTable = localVariableTable;
051:
052: startPC = in.readUnsignedShort();
053: Logger.getLogger(getClass()).debug("start PC: " + startPC);
054:
055: length = in.readUnsignedShort();
056: Logger.getLogger(getClass()).debug("length: " + length);
057:
058: nameIndex = in.readUnsignedShort();
059: Logger.getLogger(getClass()).debug(
060: "name: " + nameIndex + " (" + getName() + ")");
061:
062: descriptorIndex = in.readUnsignedShort();
063: Logger.getLogger(getClass()).debug(
064: "descriptor: " + descriptorIndex + " ("
065: + getDescriptor() + ")");
066:
067: index = in.readUnsignedShort();
068: Logger.getLogger(getClass()).debug("index: " + index);
069: }
070:
071: public LocalVariableTable_attribute getLocalVariableTable() {
072: return localVariableTable;
073: }
074:
075: public int getStartPC() {
076: return startPC;
077: }
078:
079: public int getLength() {
080: return length;
081: }
082:
083: public int getNameIndex() {
084: return nameIndex;
085: }
086:
087: public UTF8_info getRawName() {
088: return (UTF8_info) getLocalVariableTable().getClassfile()
089: .getConstantPool().get(getNameIndex());
090: }
091:
092: public String getName() {
093: return getRawName().toString();
094: }
095:
096: public int getDescriptorIndex() {
097: return descriptorIndex;
098: }
099:
100: public UTF8_info getRawDescriptor() {
101: return (UTF8_info) getLocalVariableTable().getClassfile()
102: .getConstantPool().get(getDescriptorIndex());
103: }
104:
105: public String getDescriptor() {
106: return getRawDescriptor().toString();
107: }
108:
109: public int getIndex() {
110: return index;
111: }
112:
113: public String toString() {
114: return "Local variable " + getDescriptor() + " " + getName();
115: }
116:
117: public void accept(Visitor visitor) {
118: visitor.visitLocalVariable(this);
119: }
120: }
|