1 15 16 package javassist.compiler.ast; 17 18 import javassist.compiler.TokenId; 19 import javassist.compiler.CompileError; 20 21 24 public class NewExpr extends ASTList implements TokenId { 25 protected boolean newArray; 26 protected int arrayType; 27 28 public NewExpr(ASTList className, ASTList args) { 29 super(className, new ASTList(args)); 30 newArray = false; 31 arrayType = CLASS; 32 } 33 34 public NewExpr(int type, ASTList arraySize, ASTree init) { 35 super(null, new ASTList(arraySize)); 36 newArray = true; 37 arrayType = type; 38 if (init != null) 39 append(this, init); 40 } 41 42 public static NewExpr makeObjectArray(ASTList className, 43 ASTList arraySize, ASTree init) { 44 NewExpr e = new NewExpr(className, arraySize); 45 e.newArray = true; 46 if (init != null) 47 append(e, init); 48 49 return e; 50 } 51 52 public boolean isArray() { return newArray; } 53 54 56 public int getArrayType() { return arrayType; } 57 58 public ASTList getClassName() { return (ASTList)getLeft(); } 59 60 public ASTList getArguments() { return (ASTList)getRight().getLeft(); } 61 62 public ASTList getArraySize() { return getArguments(); } 63 64 public ASTree getInitializer() { 65 ASTree t = getRight().getRight(); 66 if (t == null) 67 return null; 68 else 69 return t.getLeft(); 70 } 71 72 public void accept(Visitor v) throws CompileError { v.atNewExpr(this); } 73 74 protected String getTag() { 75 return newArray ? "new[]" : "new"; 76 } 77 } 78 | Popular Tags |