View Javadoc

1   package serp.bytecode;
2   
3   import serp.bytecode.visitor.*;
4   
5   /***
6    * Code blocks compiled from source have local variable type tables mapping
7    * generics-using locals used in opcodes to their names and signatures.
8    *
9    * @author Abe White
10   */
11  public class LocalVariableTypeTable extends LocalTable {
12      LocalVariableTypeTable(int nameIndex, Attributes owner) {
13          super(nameIndex, owner);
14      }
15  
16      /***
17       * Return all the locals of this method.
18       */
19      public LocalVariableType[] getLocalVariableTypes() {
20          return (LocalVariableType[]) getLocals();
21      }
22  
23      /***
24       * Return the local with the given locals index, or null if none.
25       */
26      public LocalVariableType getLocalVariableType(int local) {
27          return (LocalVariableType) getLocal(local);
28      }
29  
30      /***
31       * Return the local with the given name, or null if none. If multiple
32       * locals have the given name, which is returned is undefined.
33       */
34      public LocalVariableType getLocalVariableType(String name) {
35          return (LocalVariableType) getLocal(name);
36      }
37  
38      /***
39       * Return all locals with the given name, or empty array if none.
40       */
41      public LocalVariableType[] getLocalVariableTypes(String name) {
42          return (LocalVariableType[]) getLocals(name);
43      }
44  
45      /***
46       * Import a local from another method/class. Note that
47       * the program counter and length from the given local is copied
48       * directly, and thus will be incorrect unless this method is the same
49       * as the one the local is copied from, or the pc and length are reset.
50       */
51      public LocalVariableType addLocalVariableType(LocalVariableType local) {
52          return (LocalVariableType) addLocal(local);
53      }
54  
55      /***
56       * Add a local to this table.
57       */
58      public LocalVariableType addLocalVariableType() {
59          return (LocalVariableType) addLocal();
60      }
61  
62      /***
63       * Add a local to this table.
64       */
65      public LocalVariableType addLocalVariableType(String name, String type) {
66          return (LocalVariableType) addLocal(name, type);
67      }
68  
69      public void acceptVisit(BCVisitor visit) {
70          visit.enterLocalVariableTypeTable(this);
71          LocalVariableType[] locals = (LocalVariableType[]) getLocals();
72          for (int i = 0; i < locals.length; i++)
73              locals[i].acceptVisit(visit);
74          visit.exitLocalVariableTypeTable(this);
75      }
76  
77      protected Local newLocal() {
78          return new LocalVariableType(this);
79      }
80  
81      protected Local[] newLocalArray(int size) {
82          return new LocalVariableType[size];
83      }
84  }