1 package serp.bytecode;
2
3 import serp.bytecode.visitor.*;
4 import serp.util.*;
5
6 /***
7 * A local variable contains the name, description, index and scope
8 * of a local used in opcodes.
9 *
10 * @author Abe White
11 */
12 public class LocalVariable extends Local {
13 LocalVariable(LocalVariableTable owner) {
14 super(owner);
15 }
16
17 /***
18 * The owning table.
19 */
20 public LocalVariableTable getLocalVariableTable() {
21 return (LocalVariableTable) getTable();
22 }
23
24 /***
25 * Return the type of this local.
26 * If the type has not been set, this method will return null.
27 */
28 public Class getType() {
29 String type = getTypeName();
30 if (type == null)
31 return null;
32 return Strings.toClass(type, getClassLoader());
33 }
34
35 /***
36 * Return the type of this local.
37 * If the type has not been set, this method will return null.
38 */
39 public BCClass getTypeBC() {
40 String type = getTypeName();
41 if (type == null)
42 return null;
43 return getProject().loadClass(type, getClassLoader());
44 }
45
46 /***
47 * Set the type of this local.
48 */
49 public void setType(Class type) {
50 if (type == null)
51 setType((String) null);
52 else
53 setType(type.getName());
54 }
55
56 /***
57 * Set the type of this local.
58 */
59 public void setType(BCClass type) {
60 if (type == null)
61 setType((String) null);
62 else
63 setType(type.getName());
64 }
65
66 public void acceptVisit(BCVisitor visit) {
67 visit.enterLocalVariable(this);
68 visit.exitLocalVariable(this);
69 }
70 }