|  |  | 
|  |  | 
|  |  */ | 
|  | /* | 
|  |  * Licensed to the Apache Software Foundation (ASF) under one or more | 
|  |  * contributor license agreements.  See the NOTICE file distributed with | 
|  |  * this work for additional information regarding copyright ownership. | 
|  |  * The ASF licenses this file to You under the Apache License, Version 2.0 | 
|  |  * (the "License"); you may not use this file except in compliance with | 
|  |  * the License.  You may obtain a copy of the License at | 
|  |  * | 
|  |  *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  |  * | 
|  |  * Unless required by applicable law or agreed to in writing, software | 
|  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
|  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  |  * See the License for the specific language governing permissions and | 
|  |  * limitations under the License. | 
|  |  */ | 
|  |  | 
|  | package com.sun.org.apache.bcel.internal.classfile; | 
|  |  | 
|  | import java.io.DataInput; | 
|  | import java.io.DataOutputStream; | 
|  | import java.io.IOException; | 
|  |  | 
|  | import com.sun.org.apache.bcel.internal.Const; | 
|  |  | 
|  |  | 
|  |  | 
|  |  | 
|  |  | 
|  |  | 
|  |  | 
|  |  */ | 
|  | public final class LocalVariable implements Cloneable, Node { | 
|  |  | 
|  |     private int start_pc;  | 
|  |     private int length; | 
|  |     private int name_index;  | 
|  |     private int signature_index;  | 
|  |     private int index;  | 
|  |  | 
|  |      */ | 
|  |     private ConstantPool constant_pool; | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |  | 
|  |      */ | 
|  |     public LocalVariable(final LocalVariable c) { | 
|  |         this(c.getStartPC(), c.getLength(), c.getNameIndex(), c.getSignatureIndex(), c.getIndex(), | 
|  |                 c.getConstantPool()); | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |  | 
|  |  | 
|  |      */ | 
|  |     LocalVariable(final DataInput file, final ConstantPool constant_pool) throws IOException { | 
|  |         this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file | 
|  |                 .readUnsignedShort(), file.readUnsignedShort(), constant_pool); | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |  | 
|  |  | 
|  |  | 
|  |  | 
|  |  | 
|  |      */ | 
|  |     public LocalVariable(final int start_pc, final int length, final int name_index, final int signature_index, final int index, | 
|  |             final ConstantPool constant_pool) { | 
|  |         this.start_pc = start_pc; | 
|  |         this.length = length; | 
|  |         this.name_index = name_index; | 
|  |         this.signature_index = signature_index; | 
|  |         this.index = index; | 
|  |         this.constant_pool = constant_pool; | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |  | 
|  |  | 
|  |  | 
|  |  | 
|  |      */ | 
|  |     @Override | 
|  |     public void accept( final Visitor v ) { | 
|  |         v.visitLocalVariable(this); | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |  | 
|  |  | 
|  |  | 
|  |      */ | 
|  |     public final void dump( final DataOutputStream file ) throws IOException { | 
|  |         file.writeShort(start_pc); | 
|  |         file.writeShort(length); | 
|  |         file.writeShort(name_index); | 
|  |         file.writeShort(signature_index); | 
|  |         file.writeShort(index); | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     public final ConstantPool getConstantPool() { | 
|  |         return constant_pool; | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     public final int getLength() { | 
|  |         return length; | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     public final String getName() { | 
|  |         ConstantUtf8 c; | 
|  |         c = (ConstantUtf8) constant_pool.getConstant(name_index, Const.CONSTANT_Utf8); | 
|  |         return c.getBytes(); | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     public final int getNameIndex() { | 
|  |         return name_index; | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     public final String getSignature() { | 
|  |         ConstantUtf8 c; | 
|  |         c = (ConstantUtf8) constant_pool.getConstant(signature_index, Const.CONSTANT_Utf8); | 
|  |         return c.getBytes(); | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     public final int getSignatureIndex() { | 
|  |         return signature_index; | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     public final int getIndex() { | 
|  |         return index; | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     public final int getStartPC() { | 
|  |         return start_pc; | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     final String toStringShared( final boolean typeTable ) { | 
|  |         final String name = getName(); | 
|  |         final String signature = Utility.signatureToString(getSignature(), false); | 
|  |         final String label = "LocalVariable" + (typeTable ? "Types" : "" ); | 
|  |         return label + "(start_pc = " + start_pc + ", length = " + length + ", index = " | 
|  |                 + index + ":" + signature + " " + name + ")"; | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     public final void setConstantPool( final ConstantPool constant_pool ) { | 
|  |         this.constant_pool = constant_pool; | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     public final void setLength( final int length ) { | 
|  |         this.length = length; | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     public final void setNameIndex( final int name_index ) {  | 
|  |         this.name_index = name_index; | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     public final void setSignatureIndex( final int signature_index ) {  | 
|  |         this.signature_index = signature_index; | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     public final void setIndex( final int index ) {  | 
|  |         this.index = index; | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     public final void setStartPC( final int start_pc ) {  | 
|  |         this.start_pc = start_pc; | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     @Override | 
|  |     public final String toString() { | 
|  |         return toStringShared(false); | 
|  |     } | 
|  |  | 
|  |  | 
|  |      | 
|  |  | 
|  |      */ | 
|  |     public LocalVariable copy() { | 
|  |         try { | 
|  |             return (LocalVariable) clone(); | 
|  |         } catch (final CloneNotSupportedException e) { | 
|  |             // TODO should this throw? | 
|  |         } | 
|  |         return null; | 
|  |     } | 
|  | } |