.invoke("getBlock", Block.class, constantInt(sortChannel)); block.append(getStatic(SortOrder.class, sortOrder.name()) .invoke("compareBlockValue", int.class,
body.append(size.set(getStatic(instanceSize)));
.append(thisVariable.setField(sizeField, getStatic(instanceSizeField)));
.cast(Block.class); block.append(getStatic(SortOrder.class, sortOrder.name()) .invoke("compareBlockValue", int.class,
.append(newInstance( PrestoException.class, getStatic(INVALID_FUNCTION_ARGUMENT.getDeclaringClass(), "INVALID_FUNCTION_ARGUMENT").cast(ErrorCodeSupplier.class), constantString("map key cannot be null"))) .throwObject(); .append(newInstance( PrestoException.class, getStatic(INVALID_FUNCTION_ARGUMENT.getDeclaringClass(), "INVALID_FUNCTION_ARGUMENT").cast(ErrorCodeSupplier.class), invokeStatic( String.class,
.append(newInstance( PrestoException.class, getStatic(INVALID_FUNCTION_ARGUMENT.getDeclaringClass(), "INVALID_FUNCTION_ARGUMENT").cast(ErrorCodeSupplier.class), constantString("map key cannot be null"))) .throwObject();
public static BytecodeExpression print(BytecodeExpression variable) { BytecodeExpression out = getStatic(System.class, "out"); return out.invoke("println", void.class, variable); } }
@Test public void testInvalildCast() { // Cast between a boxed primitive and a primitive that are different assertInvalidCast(getStatic(getClass(), "INT_FIELD"), Double.class); assertInvalidCast(getStatic(getClass(), "INT_FIELD").cast(Integer.class), double.class); // Cast between two different boxed primitives assertInvalidCast(getStatic(getClass(), "INT_FIELD").cast(Integer.class), Double.class); // Cast between a primitive and an object (that is not java.lang.Object) assertInvalidCast(getStatic(getClass(), "OBJECT_FIELD").cast(String.class), double.class); assertInvalidCast(getStatic(getClass(), "INT_FIELD"), String.class); }
@Test public void testGetStaticField() throws Exception { assertBytecodeExpression(getStatic(Long.class, "MIN_VALUE"), Long.MIN_VALUE, "Long.MIN_VALUE"); assertBytecodeExpression(getStatic(Long.class.getField("MIN_VALUE")), Long.MIN_VALUE, "Long.MIN_VALUE"); assertBytecodeExpression(getStatic(type(Long.class), "MIN_VALUE", type(long.class)), Long.MIN_VALUE, "Long.MIN_VALUE"); } }
@Test public void testDownCastObject() throws Exception { assertBytecodeExpression(getStatic(getClass(), "OBJECT_FIELD").cast(String.class).invoke("length", int.class), ((String) OBJECT_FIELD).length(), "((String) " + getClass().getSimpleName() + ".OBJECT_FIELD).length()"); }
public void assertPrimitiveCast(String fieldName, Class<?> castToType, Object expected) throws Exception { // simple cast BytecodeExpression baseExpression = getStatic(getClass(), fieldName); assertCast(baseExpression, expected, castToType); // box result baseExpression = baseExpression.cast(castToType); Class<?> boxedType = Primitives.wrap(castToType); assertCast(baseExpression, expected, boxedType); // unbox the boxed result baseExpression = baseExpression.cast(boxedType); assertCast(baseExpression, expected, castToType); }
.invoke("getBlock", Block.class, constantInt(sortChannel)); block.append(getStatic(SortOrder.class, sortOrder.name()) .invoke("compareBlockValue", int.class,
.invoke("getBlock", Block.class, constantInt(sortChannel)); block.append(getStatic(SortOrder.class, sortOrder.name()) .invoke("compareBlockValue", int.class,
body.append(size.set(getStatic(instanceSize)));
body.append(size.set(getStatic(instanceSize)));
.append(thisVariable.setField(sizeField, getStatic(instanceSizeField)));
.append(thisVariable.setField(sizeField, getStatic(instanceSizeField)));
.cast(Block.class); block.append(getStatic(SortOrder.class, sortOrder.name()) .invoke("compareBlockValue", int.class,
.cast(Block.class); block.append(getStatic(SortOrder.class, sortOrder.name()) .invoke("compareBlockValue", int.class,