1 15 16 package javassist.compiler.ast; 17 18 import javassist.compiler.TokenId; 19 import javassist.compiler.CompileError; 20 21 24 public class Declarator extends ASTList implements TokenId { 25 protected int varType; 26 protected int arrayDim; 27 protected int localVar; 28 protected String qualifiedClass; 30 public Declarator(int type, int dim) { 31 super(null); 32 varType = type; 33 arrayDim = dim; 34 localVar = -1; 35 qualifiedClass = null; 36 } 37 38 public Declarator(ASTList className, int dim) { 39 super(null); 40 varType = CLASS; 41 arrayDim = dim; 42 localVar = -1; 43 qualifiedClass = astToClassName(className, '/'); 44 } 45 46 48 public Declarator(int type, String jvmClassName, int dim, 49 int var, Symbol sym) { 50 super(null); 51 varType = type; 52 arrayDim = dim; 53 localVar = var; 54 qualifiedClass = jvmClassName; 55 setLeft(sym); 56 append(this, null); } 58 59 public Declarator make(Symbol sym, int dim, ASTree init) { 60 Declarator d = new Declarator(this.varType, this.arrayDim + dim); 61 d.qualifiedClass = this.qualifiedClass; 62 d.setLeft(sym); 63 append(d, init); 64 return d; 65 } 66 67 70 public int getType() { return varType; } 71 72 public int getArrayDim() { return arrayDim; } 73 74 public void addArrayDim(int d) { arrayDim += d; } 75 76 public String getClassName() { return qualifiedClass; } 77 78 public void setClassName(String s) { qualifiedClass = s; } 79 80 public Symbol getVariable() { return (Symbol)getLeft(); } 81 82 public void setVariable(Symbol sym) { setLeft(sym); } 83 84 public ASTree getInitializer() { 85 ASTList t = tail(); 86 if (t != null) 87 return t.head(); 88 else 89 return null; 90 } 91 92 public void setLocalVar(int n) { localVar = n; } 93 94 public int getLocalVar() { return localVar; } 95 96 public String getTag() { return "decl"; } 97 98 public void accept(Visitor v) throws CompileError { 99 v.atDeclarator(this); 100 } 101 102 public static String astToClassName(ASTList name, char sep) { 103 if (name == null) 104 return null; 105 106 StringBuffer sbuf = new StringBuffer (); 107 astToClassName(sbuf, name, sep); 108 return sbuf.toString(); 109 } 110 111 private static void astToClassName(StringBuffer sbuf, ASTList name, 112 char sep) { 113 for (;;) { 114 ASTree h = name.head(); 115 if (h instanceof Symbol) 116 sbuf.append(((Symbol)h).get()); 117 else if (h instanceof ASTList) 118 astToClassName(sbuf, (ASTList)h, sep); 119 120 name = name.tail(); 121 if (name == null) 122 break; 123 124 sbuf.append(sep); 125 } 126 } 127 } 128 | Popular Tags |