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 TernaryExpression extends Expression { 58 59 private BooleanExpression booleanExpression; 60 private Expression trueExpression; 61 private Expression falseExpression; 62 63 public TernaryExpression( 64 BooleanExpression booleanExpression, 65 Expression trueExpression, 66 Expression falseExpression) { 67 this.booleanExpression = booleanExpression; 68 this.trueExpression = trueExpression; 69 this.falseExpression = falseExpression; 70 } 71 public void visit(GroovyCodeVisitor visitor) { 72 visitor.visitTernaryExpression(this); 73 } 74 75 public Expression transformExpression(ExpressionTransformer transformer) { 76 return new TernaryExpression( 77 (BooleanExpression) transformer.transform(booleanExpression), 78 transformer.transform(trueExpression), 79 transformer.transform(falseExpression)); 80 } 81 82 protected void resolveType(AsmClassGenerator2 resolver) { 83 trueExpression.resolve(resolver); 84 falseExpression.resolve(resolver); 85 setTypeClass(trueExpression.getTypeClass()); 86 } 87 88 public String toString() { 89 return super.toString() +"[" + booleanExpression + " ? " + trueExpression + " : " + falseExpression + "]"; 90 } 91 92 public BooleanExpression getBooleanExpression() { 93 return booleanExpression; 94 } 95 96 public Expression getFalseExpression() { 97 return falseExpression; 98 } 99 100 public Expression getTrueExpression() { 101 return trueExpression; 102 } 103 104 public String getText() { 105 return "(" 106 + booleanExpression.getText() 107 + ") ? " 108 + trueExpression.getText() 109 + " : " 110 + falseExpression.getText(); 111 } 112 public Class getTypeClass() { 113 return trueExpression.getTypeClass(); } 115 116 public String getType() { 117 return trueExpression.getType(); 118 } 119 } 120 | Popular Tags |