1 46 package org.codehaus.groovy.ast.expr; 47 48 import org.codehaus.groovy.ast.GroovyCodeVisitor; 49 import org.codehaus.groovy.classgen.AsmClassGenerator2; 50 51 57 public class ConstantExpression extends Expression { 58 public static final ConstantExpression VOID = new ConstantExpression(Void .class); 59 public static final ConstantExpression NULL = new ConstantExpression(null); 60 public static final ConstantExpression TRUE = new ConstantExpression(Boolean.TRUE); 61 public static final ConstantExpression FALSE = new ConstantExpression(Boolean.FALSE); 62 public static final ConstantExpression EMPTY_STRING = new ConstantExpression(""); 63 65 private Object value; 66 67 public ConstantExpression(Object value) { 68 this.value = value; 69 if (this.value != null) 70 setTypeClass(value.getClass()); 71 } 72 73 public String toString() { 74 return super.toString() +"[value=" + value + "]"; 75 } 76 77 public void visit(GroovyCodeVisitor visitor) { 78 visitor.visitConstantExpression(this); 79 } 80 81 82 public Expression transformExpression(ExpressionTransformer transformer) { 83 return this; 84 } 85 86 protected void resolveType(AsmClassGenerator2 resolver) { 87 } 89 90 93 public Object getValue() { 94 return value; 95 } 96 97 public String getText() { 98 return (value == null) ? "null" : value.toString(); 99 } 100 } 101 | Popular Tags |