001 package serp.bytecode;
002
003 import serp.bytecode.visitor.*;
004 import serp.util.*;
005
006 /**
007 * A local variable contains the name, description, index and scope
008 * of a local used in opcodes.
009 *
010 * @author Abe White
011 */
012 public class LocalVariable extends Local {
013 LocalVariable(LocalVariableTable owner) {
014 super(owner);
015 }
016
017 /**
018 * The owning table.
019 */
020 public LocalVariableTable getLocalVariableTable() {
021 return (LocalVariableTable) getTable();
022 }
023
024 /**
025 * Return the type of this local.
026 * If the type has not been set, this method will return null.
027 */
028 public Class getType() {
029 String type = getTypeName();
030 if (type == null)
031 return null;
032 return Strings.toClass(type, getClassLoader());
033 }
034
035 /**
036 * Return the type of this local.
037 * If the type has not been set, this method will return null.
038 */
039 public BCClass getTypeBC() {
040 String type = getTypeName();
041 if (type == null)
042 return null;
043 return getProject().loadClass(type, getClassLoader());
044 }
045
046 /**
047 * Set the type of this local.
048 */
049 public void setType(Class type) {
050 if (type == null)
051 setType((String) null);
052 else
053 setType(type.getName());
054 }
055
056 /**
057 * Set the type of this local.
058 */
059 public void setType(BCClass type) {
060 if (type == null)
061 setType((String) null);
062 else
063 setType(type.getName());
064 }
065
066 public void acceptVisit(BCVisitor visit) {
067 visit.enterLocalVariable(this);
068 visit.exitLocalVariable(this);
069 }
070 }