Variable argument = scope.getVariable("arg" + i); IfStatement ifStatement = new IfStatement() .condition(equal(argument, constantNull(stackTypes.get(i)))) .ifTrue(blockBuilderVariable.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(constantType(binder, elementType).writeValue(blockBuilderVariable, argument.cast(elementType.getJavaType())));
if (!getOnlyElement(fields).isPrimitiveType()) { serializerBody.append(new IfStatement() .condition(equal(fieldValue, constantNull(getter.getReturnType()))) .ifTrue(out.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(sqlType.writeValue(out, fieldValue))); serializerBody.append(fieldValue.set(state.cast(getter.getDeclaringClass()).invoke(getter))); if (!field.isPrimitiveType()) { serializerBody.append(new IfStatement().condition(equal(fieldValue, constantNull(getter.getReturnType()))) .ifTrue(rowBuilder.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(sqlType.writeValue(rowBuilder, fieldValue)));
if (!outputType.equals(UNKNOWN)) { writeOutputElement = new IfStatement() .condition(equal(outputElement, constantNull(outputJavaType))) .ifTrue(blockBuilder.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(constantType(binder, outputType).writeValue(blockBuilder, outputElement.cast(outputType.getJavaType())));
if (!transformedValueType.equals(UNKNOWN)) { writeTransformedValueElement = new IfStatement() .condition(equal(transformedValueElement, constantNull(transformedValueJavaType))) .ifTrue(blockBuilder.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(constantType(binder, transformedValueType).writeValue(blockBuilder, transformedValueElement.cast(transformedValueType.getJavaType())));
.append(transformedKeyElement.set(function.invoke("apply", Object.class, keyElement.cast(Object.class), valueElement.cast(Object.class)).cast(transformedKeyJavaType))) .append(new IfStatement() .condition(equal(transformedKeyElement, constantNull(transformedKeyJavaType))) .ifTrue(throwNullKeyException) .ifFalse(new BytecodeBlock()
public static BytecodeExpression isNull(BytecodeExpression value) { return equal(value, constantNull(value.getType())); }
@SuppressWarnings({"FloatingPointEquality", "ComparisonToNaN", "EqualsNaN", "EqualsWithItself"}) @Test public void testEqual() throws Exception { assertBytecodeExpression(equal(constantInt(7), constantInt(3)), 7 == 3, "(7 == 3)"); assertBytecodeExpression(equal(constantInt(7), constantInt(7)), 7 == 7, "(7 == 7)"); assertBytecodeExpression(equal(constantLong(7L), constantLong(3L)), 7L == 3L, "(7L == 3L)"); assertBytecodeExpression(equal(constantLong(7L), constantLong(7L)), 7L == 7L, "(7L == 7L)"); assertBytecodeExpression(equal(constantFloat(7.7f), constantFloat(3.3f)), 7.7f == 3.3f, "(7.7f == 3.3f)"); assertBytecodeExpression(equal(constantFloat(7.7f), constantFloat(7.7f)), 7.7f == 7.7f, "(7.7f == 7.7f)"); assertBytecodeExpression(equal(constantFloat(Float.NaN), constantFloat(7.7f)), Float.NaN == 7.7f, "(NaNf == 7.7f)"); assertBytecodeExpression(equal(constantFloat(Float.NaN), constantFloat(Float.NaN)), Float.NaN == Float.NaN, "(NaNf == NaNf)"); assertBytecodeExpression(equal(constantDouble(7.7), constantDouble(3.3)), 7.7 == 3.3, "(7.7 == 3.3)"); assertBytecodeExpression(equal(constantDouble(7.7), constantDouble(7.7)), 7.7 == 7.7, "(7.7 == 7.7)"); assertBytecodeExpression(equal(constantDouble(Double.NaN), constantDouble(7.7)), Double.NaN == 7.7, "(NaN == 7.7)"); assertBytecodeExpression(equal(constantDouble(7.7), constantDouble(Double.NaN)), 7.7 == Double.NaN, "(7.7 == NaN)"); assertBytecodeExpression(equal(constantDouble(Double.NaN), constantDouble(Double.NaN)), Double.NaN == Double.NaN, "(NaN == NaN)"); // the byte code is verifying with == but that breaks check style so we use assertBytecodeExpression(equal(constantString("foo"), constantString("bar")), "foo".equals("bar"), "(\"foo\" == \"bar\")"); assertBytecodeExpression(equal(constantString("foo"), constantString("foo")), "foo".equals("foo"), "(\"foo\" == \"foo\")"); }
Variable argument = scope.getVariable("arg" + i); IfStatement ifStatement = new IfStatement() .condition(equal(argument, constantNull(stackTypes.get(i)))) .ifTrue(blockBuilderVariable.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(constantType(binder, elementType).writeValue(blockBuilderVariable, argument.cast(elementType.getJavaType())));
Variable argument = scope.getVariable("arg" + i); IfStatement ifStatement = new IfStatement() .condition(equal(argument, constantNull(stackTypes.get(i)))) .ifTrue(blockBuilderVariable.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(constantType(binder, elementType).writeValue(blockBuilderVariable, argument.cast(elementType.getJavaType())));
if (!getOnlyElement(fields).isPrimitiveType()) { serializerBody.append(new IfStatement() .condition(equal(fieldValue, constantNull(getter.getReturnType()))) .ifTrue(out.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(sqlType.writeValue(out, fieldValue))); serializerBody.append(fieldValue.set(state.cast(getter.getDeclaringClass()).invoke(getter))); if (!field.isPrimitiveType()) { serializerBody.append(new IfStatement().condition(equal(fieldValue, constantNull(getter.getReturnType()))) .ifTrue(rowBuilder.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(sqlType.writeValue(rowBuilder, fieldValue)));
if (!getOnlyElement(fields).isPrimitiveType()) { serializerBody.append(new IfStatement() .condition(equal(fieldValue, constantNull(getter.getReturnType()))) .ifTrue(out.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(sqlType.writeValue(out, fieldValue))); serializerBody.append(fieldValue.set(state.cast(getter.getDeclaringClass()).invoke(getter))); if (!field.isPrimitiveType()) { serializerBody.append(new IfStatement().condition(equal(fieldValue, constantNull(getter.getReturnType()))) .ifTrue(rowBuilder.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(sqlType.writeValue(rowBuilder, fieldValue)));
if (!outputType.equals(UNKNOWN)) { writeOutputElement = new IfStatement() .condition(equal(outputElement, constantNull(outputJavaType))) .ifTrue(blockBuilder.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(constantType(binder, outputType).writeValue(blockBuilder, outputElement.cast(outputType.getJavaType())));
if (!outputType.equals(UNKNOWN)) { writeOutputElement = new IfStatement() .condition(equal(outputElement, constantNull(outputJavaType))) .ifTrue(blockBuilder.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(constantType(binder, outputType).writeValue(blockBuilder, outputElement.cast(outputType.getJavaType())));
if (!transformedValueType.equals(UNKNOWN)) { writeTransformedValueElement = new IfStatement() .condition(equal(transformedValueElement, constantNull(transformedValueJavaType))) .ifTrue(blockBuilder.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(constantType(binder, transformedValueType).writeValue(blockBuilder, transformedValueElement.cast(transformedValueType.getJavaType())));
if (!transformedValueType.equals(UNKNOWN)) { writeTransformedValueElement = new IfStatement() .condition(equal(transformedValueElement, constantNull(transformedValueJavaType))) .ifTrue(blockBuilder.invoke("appendNull", BlockBuilder.class).pop()) .ifFalse(constantType(binder, transformedValueType).writeValue(blockBuilder, transformedValueElement.cast(transformedValueType.getJavaType())));
.append(transformedKeyElement.set(function.invoke("apply", Object.class, keyElement.cast(Object.class), valueElement.cast(Object.class)).cast(transformedKeyJavaType))) .append(new IfStatement() .condition(equal(transformedKeyElement, constantNull(transformedKeyJavaType))) .ifTrue(throwNullKeyException) .ifFalse(new BytecodeBlock()
.append(transformedKeyElement.set(function.invoke("apply", Object.class, keyElement.cast(Object.class), valueElement.cast(Object.class)).cast(transformedKeyJavaType))) .append(new IfStatement() .condition(equal(transformedKeyElement, constantNull(transformedKeyJavaType))) .ifTrue(throwNullKeyException) .ifFalse(new BytecodeBlock()