@Override public String translate(ExprCompiler compiler, RexCall call) { String val = compiler.reserveName(); PrintWriter pw = compiler.pw; RexNode op = call.getOperands().get(0); String lhs = op.accept(compiler); pw.print( String.format( "final %1$s %2$s = (%1$s) %3$s;\n", compiler.javaTypeName(call), val, lhs)); return val; }
@Override public String translate(ExprCompiler compiler, RexCall call) { String val = compiler.reserveName(); PrintWriter pw = compiler.pw; RexNode op = call.getOperands().get(0); String lhs = op.accept(compiler); boolean nullable = call.getType().isNullable(); pw.print(String.format("final %s %s;\n", compiler.javaTypeName(call), val)); if (!nullable) { pw.print(String.format("%1$s = !(%2$s);\n", val, lhs)); } else { String s = foldNullExpr(String.format("%1$s == null ? null : !(%1$s)", lhs), "null", op); pw.print(String.format("%1$s = %2$s;\n", val, s)); } return val; }
@Override public String translate(ExprCompiler compiler, RexCall call) { String val = compiler.reserveName(); PrintWriter pw = compiler.pw; pw.print(String.format("final %s %s;\n", compiler.javaTypeName(call), val)); RexNode op0 = call.getOperands().get(0); RexNode op1 = call.getOperands().get(1); boolean lhsNullable = op0.getType().isNullable(); boolean rhsNullable = op1.getType().isNullable(); String lhs = op0.accept(compiler); if (!lhsNullable) { pw.print(String.format("if (%2$s) { %1$s = true; }\n", val, lhs)); pw.print("else {\n"); String rhs = op1.accept(compiler); pw.print(String.format(" %1$s = %2$s;\n}\n", val, rhs)); } else { String foldedLHS = foldNullExpr(String.format("%1$s == null || !(%1$s)", lhs), "true", op0); pw.print(String.format("if (%s) {\n", foldedLHS)); String rhs = op1.accept(compiler); String s; if (rhsNullable) { s = foldNullExpr( String.format( "(%2$s != null && %2$s) ? Boolean.TRUE : ((%1$s == null || %2$s == null) ? null : Boolean.FALSE)", lhs, rhs), "null", op1); } else { s = String.format("%2$s ? Boolean.valueOf(%2$s) : %1$s", lhs, rhs); } pw.print(String.format(" %1$s = %2$s;\n", val, s)); pw.print(String.format("} else { %1$s = true; }\n", val)); } return val; }
private String javaTypeName(RexNode node) { Type ty = typeFactory.getJavaClass(node.getType()); return ((Class<?>) ty).getCanonicalName(); }