1 16 package com.google.gwt.dev.jjs.ast; 17 18 import com.google.gwt.dev.jjs.SourceInfo; 19 20 23 public class JConditional extends JExpression { 24 25 private JExpression elseExpr; 26 private JExpression ifTest; 27 private JExpression thenExpr; 28 private final JType type; 29 30 public JConditional(JProgram program, SourceInfo info, JType type, 31 JExpression ifTest, JExpression thenExpr, JExpression elseExpr) { 32 super(program, info); 33 this.type = type; 34 this.ifTest = ifTest; 35 this.thenExpr = thenExpr; 36 this.elseExpr = elseExpr; 37 } 38 39 public JExpression getElseExpr() { 40 return elseExpr; 41 } 42 43 public JExpression getIfTest() { 44 return ifTest; 45 } 46 47 public JExpression getThenExpr() { 48 return thenExpr; 49 } 50 51 public JType getType() { 52 if (type instanceof JReferenceType) { 54 return program.generalizeTypes((JReferenceType) thenExpr.getType(), 55 (JReferenceType) elseExpr.getType()); 56 } else { 57 return type; 58 } 59 } 60 61 public boolean hasSideEffects() { 62 return ifTest.hasSideEffects() || thenExpr.hasSideEffects() 63 || elseExpr.hasSideEffects(); 64 } 65 66 public void traverse(JVisitor visitor, Context ctx) { 67 if (visitor.visit(this, ctx)) { 68 ifTest = visitor.accept(ifTest); 69 thenExpr = visitor.accept(thenExpr); 70 elseExpr = visitor.accept(elseExpr); 71 } 72 visitor.endVisit(this, ctx); 73 } 74 75 } 76 | Popular Tags |