1 46 package org.codehaus.groovy.ast.expr; 47 48 import org.codehaus.groovy.ast.GroovyCodeVisitor; 49 import org.codehaus.groovy.classgen.AsmClassGenerator2; 50 import org.codehaus.groovy.classgen.BytecodeHelper; 51 52 53 59 public class VariableExpression extends Expression { 60 61 public static final VariableExpression THIS_EXPRESSION = new VariableExpression("this", null); 62 63 private String variable; 64 65 public VariableExpression(String variable, String type) { 66 this.variable = variable; 67 if (type == null || type.length() == 0) { 68 isDynamic = true; 69 } 70 else { 71 String boxedType = BytecodeHelper.getObjectTypeForPrimitive(type); 72 boxedType = BytecodeHelper.getObjectArrayTypeForPrimitiveArray(boxedType); 73 74 super.setType(boxedType); isDynamic = false; 76 } 77 } 78 79 public VariableExpression(String variable) { 80 this.variable = variable; 81 } 82 83 public void visit(GroovyCodeVisitor visitor) { 84 visitor.visitVariableExpression(this); 85 } 86 87 public Expression transformExpression(ExpressionTransformer transformer) { 88 return this; 89 } 90 91 protected void resolveType(AsmClassGenerator2 resolver) { 92 resolver.resolve(this); 93 } 94 95 public String getVariable() { 96 return variable; 97 } 98 99 public String getText() { 100 return variable; 101 } 102 103 public String getType() { 104 if (type == null) { 105 return "java.lang.Object"; 106 } 107 return type; 108 } 109 110 boolean isDynamic = true; 111 public boolean isDynamic() { 112 return isDynamic; 113 } 114 115 118 119 public String toString() { 120 return super.toString() + "[variable: " + variable + ((isDynamic()) ? "" : " type: " + type) + "]"; 121 } 122 123 public void setDynamic(boolean dynamic) { 124 isDynamic = dynamic; 125 } 126 } 127 | Popular Tags |