1 28 29 package com.caucho.es.parser; 30 31 import com.caucho.es.ESException; 32 33 import java.io.IOException ; 34 35 38 class CastExpr extends Expr { 39 private Expr lhs; 40 private TypeExpr typeExpr; 41 42 private CastExpr(Block block, Expr lhs, TypeExpr typeExpr) 43 throws ESException 44 { 45 super(block); 46 47 this.lhs = lhs; 48 this.typeExpr = typeExpr; 49 } 50 51 static CastExpr create(Block block, Expr lhs, TypeExpr typeExpr) 52 throws ESException 53 { 54 return new CastExpr(block, lhs, typeExpr); 55 } 56 57 60 int getType() 61 { 62 return typeExpr.getType(); 63 } 64 65 68 Expr getTypeExpr() 69 { 70 return typeExpr; 71 } 72 73 76 void printImpl() throws IOException 77 { 78 lhs.print(); 79 } 80 81 84 void printBooleanImpl() throws IOException 85 { 86 lhs.printBoolean(); 87 } 88 89 92 void printInt32Impl() throws IOException 93 { 94 if (! typeExpr.getTypeName().equals("int")) 95 cl.print("(" + typeExpr.getTypeName() + ") "); 96 97 lhs.printInt32(); 98 } 99 100 103 void printNumImpl() throws IOException 104 { 105 if (! typeExpr.getTypeName().equals("double")) 106 cl.print("(" + typeExpr.getTypeName() + ") "); 107 108 lhs.printNum(); 109 } 110 111 114 void printStringImpl() throws IOException 115 { 116 if (lhs.getJavaClass().equals(String .class)) 117 lhs.printStringImpl(); 118 else { 119 cl.print("String.valueOf("); 120 lhs.printString(); 121 cl.print(")"); 122 } 123 } 124 125 128 void printJavaImpl() throws IOException 129 { 130 if (! typeExpr.getJavaClass().isAssignableFrom(lhs.getJavaClass())) { 131 cl.print("("); 132 printJavaClass(typeExpr.getJavaClass()); 133 cl.print(") "); 134 } 135 136 lhs.printJava(); 137 } 138 139 140 143 void setUsed() 144 { 145 lhs.setUsed(); 146 } 147 } 148 | Popular Tags |