1 17 package org.apache.bcel.classfile; 18 19 import java.io.DataInputStream ; 20 import java.io.DataOutputStream ; 21 import java.io.IOException ; 22 import java.io.Serializable ; 23 import org.apache.bcel.Constants; 24 25 33 public final class LocalVariable implements Constants, Cloneable , Node, Serializable { 34 35 private int start_pc; private int length; 37 private int name_index; private int signature_index; private int index; 42 private ConstantPool constant_pool; 43 44 45 49 public LocalVariable(LocalVariable c) { 50 this(c.getStartPC(), c.getLength(), c.getNameIndex(), c.getSignatureIndex(), c.getIndex(), 51 c.getConstantPool()); 52 } 53 54 55 60 LocalVariable(DataInputStream file, ConstantPool constant_pool) throws IOException { 61 this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file 62 .readUnsignedShort(), file.readUnsignedShort(), constant_pool); 63 } 64 65 66 74 public LocalVariable(int start_pc, int length, int name_index, int signature_index, int index, 75 ConstantPool constant_pool) { 76 this.start_pc = start_pc; 77 this.length = length; 78 this.name_index = name_index; 79 this.signature_index = signature_index; 80 this.index = index; 81 this.constant_pool = constant_pool; 82 } 83 84 85 92 public void accept( Visitor v ) { 93 v.visitLocalVariable(this); 94 } 95 96 97 103 public final void dump( DataOutputStream file ) throws IOException { 104 file.writeShort(start_pc); 105 file.writeShort(length); 106 file.writeShort(name_index); 107 file.writeShort(signature_index); 108 file.writeShort(index); 109 } 110 111 112 115 public final ConstantPool getConstantPool() { 116 return constant_pool; 117 } 118 119 120 123 public final int getLength() { 124 return length; 125 } 126 127 128 131 public final String getName() { 132 ConstantUtf8 c; 133 c = (ConstantUtf8) constant_pool.getConstant(name_index, CONSTANT_Utf8); 134 return c.getBytes(); 135 } 136 137 138 141 public final int getNameIndex() { 142 return name_index; 143 } 144 145 146 149 public final String getSignature() { 150 ConstantUtf8 c; 151 c = (ConstantUtf8) constant_pool.getConstant(signature_index, CONSTANT_Utf8); 152 return c.getBytes(); 153 } 154 155 156 159 public final int getSignatureIndex() { 160 return signature_index; 161 } 162 163 164 167 public final int getIndex() { 168 return index; 169 } 170 171 172 175 public final int getStartPC() { 176 return start_pc; 177 } 178 179 180 183 public final void setConstantPool( ConstantPool constant_pool ) { 184 this.constant_pool = constant_pool; 185 } 186 187 188 191 public final void setLength( int length ) { 192 this.length = length; 193 } 194 195 196 199 public final void setNameIndex( int name_index ) { 200 this.name_index = name_index; 201 } 202 203 204 207 public final void setSignatureIndex( int signature_index ) { 208 this.signature_index = signature_index; 209 } 210 211 212 215 public final void setIndex( int index ) { 216 this.index = index; 217 } 218 219 220 223 public final void setStartPC( int start_pc ) { 224 this.start_pc = start_pc; 225 } 226 227 228 231 public final String toString() { 232 String name = getName(), signature = Utility.signatureToString(getSignature()); 233 return "LocalVariable(start_pc = " + start_pc + ", length = " + length + ", index = " 234 + index + ":" + signature + " " + name + ")"; 235 } 236 237 238 241 public LocalVariable copy() { 242 try { 243 return (LocalVariable) clone(); 244 } catch (CloneNotSupportedException e) { 245 } 246 return null; 247 } 248 } 249 | Popular Tags |