KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > structures > attributes > LocalVariableTableAttribute


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.structures.attributes;
9
10 import org.gjt.jclasslib.structures.InvalidByteCodeException;
11
12 import java.io.DataInput JavaDoc;
13 import java.io.IOException JavaDoc;
14
15 /**
16  * Describes an <tt>LocalVariableTable</tt> attribute structure.
17  *
18  * @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>, <a HREF="mailto:vitor.carreira@gmail.com">Vitor Carreira</a>
19  * @version $Revision: 1.5 $ $Date: 2004/12/28 13:04:32 $
20  */

21 public class LocalVariableTableAttribute extends LocalVariableCommonAttribute {
22
23     /**
24      * Name of the attribute as in the corresponding constant pool entry.
25      */

26     public static final String JavaDoc ATTRIBUTE_NAME = "LocalVariableTable";
27
28     /**
29      * Get the list of local variable associations of the parent <tt>Code</tt>
30      * structure as an array of <tt>LocalVariableTableEntry</tt> structures.
31      *
32      * @return the array
33      */

34     public LocalVariableTableEntry[] getLocalVariableTable() {
35         return (LocalVariableTableEntry[])localVariableTable;
36     }
37
38     /**
39      * Set the list of local variable associations of the parent <tt>Code</tt>
40      * structure as an array of <tt>LocalVariableTableEntry</tt> structures.
41      *
42      * @param localVariableTable the index
43      */

44     public void setLocalVariableTable(LocalVariableTableEntry[] localVariableTable) {
45         this.localVariableTable = localVariableTable;
46     }
47
48     public void read(DataInput JavaDoc in)
49             throws InvalidByteCodeException, IOException JavaDoc {
50         super.read(in);
51
52         int localVariableTableLength = in.readUnsignedShort();
53         localVariableTable = new LocalVariableTableEntry[localVariableTableLength];
54         for (int i = 0; i < localVariableTableLength; i++) {
55             localVariableTable[i] = LocalVariableTableEntry.create(in, classFile);
56         }
57
58         if (debug) debug("read ");
59     }
60
61     public int getAttributeLength() {
62         return INITIAL_LENGTH + getLength(localVariableTable) * LocalVariableTableEntry.LENGTH;
63     }
64
65
66     protected void debug(String JavaDoc message) {
67         super.debug(message + "LocalVariableTable attribute with " + getLength(localVariableTable) + " entries");
68     }
69
70 }
71
Popular Tags