1 28 29 package com.caucho.ejb.ql; 30 31 import com.caucho.config.ConfigException; 32 import com.caucho.util.CharBuffer; 33 34 37 class UnaryExpr extends Expr { 38 private int _op; 40 private Expr _expr; 42 43 49 UnaryExpr(int op, Expr expr) 50 throws ConfigException 51 { 52 _op = op; 53 _expr = expr; 54 55 evalTypes(); 56 } 57 58 61 void evalTypes() 62 throws ConfigException 63 { 64 if (getJavaType() != null) 65 return; 66 67 switch (_op) { 68 case '+': 69 if (! _expr.isNumeric()) 70 throw error(L.l("`+' expects numeric expression at `{0}'", _expr)); 71 setJavaType(_expr.getJavaType()); 72 break; 73 case '-': 74 if (! _expr.isNumeric()) 75 throw error(L.l("`-' expects numeric expression at `{0}'", _expr)); 76 setJavaType(_expr.getJavaType()); 77 break; 78 case Query.NOT: 79 if (! _expr.isBoolean()) 80 throw error(L.l("NOT expects boolean expression at `{0}'", _expr)); 81 setJavaType(boolean.class); 82 break; 83 84 default: 85 throw new RuntimeException (); 86 } 87 } 88 89 90 95 void generateWhere(CharBuffer cb) 96 { 97 switch (_op) { 98 case '+': 99 cb.append("+"); 100 break; 101 case '-': 102 cb.append("-"); 103 break; 104 case Query.NOT: 105 cb.append("NOT "); 106 break; 107 } 108 109 _expr.generateWhereSubExpr(cb); 110 } 111 } 112 | Popular Tags |