/** * Casts the results of a field read or method invocation based on generic information. * * @param builder * used to add instructions * @param rawType * the simple type (often Object) of the field (or method return type) * @param genericType * the generic Type, from which parameterizations can be determined */ private void castToGenericType(InstructionBuilder builder, Class rawType, final Type genericType) { if (!genericType.equals(rawType)) { Class castType = GenericsUtils.asClass(genericType); builder.checkcast(castType); } }
@Override public void doBuild(InstructionBuilder builder) { builder.loadThis().getField(delegateField); builder.checkcast(delegateType).returnResult(); } });
@Override public void doBuild(InstructionBuilder builder) { builder.loadThis().getField(delegateField); builder.checkcast(delegateType).returnResult(); } });
public void doBuild(InstructionBuilder builder) { builder.loadArgument(0).dupe().when(Condition.NULL, new InstructionBuilderCallback() { public void doBuild(InstructionBuilder builder) { builder.throwException(NullPointerException.class, String.format("Root object of property expression '%s' is null.", expression)); } }); builder.checkcast(rootType).returnResult(); } });
private void implementShimGet(ClassNode shimClassNode) { MethodNode mn = new MethodNode(ACC_PUBLIC, "get", OBJECT_INT_TO_OBJECT, null, null); InstructionBuilder builder = newBuilder(mn); // Arg 0 is the target instance // Arg 1 is the index builder.loadArgument(0).checkcast(className); builder.loadArgument(1); builder.startSwitch(0, nextFieldIndex - 1, new SwitchCallback() { @Override public void doSwitch(SwitchBlock block) { for (PlasticFieldImpl f : shimFields) { f.extendShimGet(block); } } }); shimClassNode.methods.add(mn); }
private void implementShimGet(ClassNode shimClassNode) { MethodNode mn = new MethodNode(ACC_PUBLIC, "get", OBJECT_INT_TO_OBJECT, null, null); InstructionBuilder builder = newBuilder(mn); // Arg 0 is the target instance // Arg 1 is the index builder.loadArgument(0).checkcast(className); builder.loadArgument(1); builder.startSwitch(0, nextFieldIndex - 1, new SwitchCallback() { @Override public void doSwitch(SwitchBlock block) { for (PlasticFieldImpl f : shimFields) { f.extendShimGet(block); } } }); shimClassNode.methods.add(mn); }
private void implementShimInvoke(ClassNode shimClassNode) { MethodNode mn = new MethodNode(ACC_PUBLIC, "invoke", OBJECT_INT_OBJECT_ARRAY_TO_METHOD_INVOCATION_RESULT, null, null); InstructionBuilder builder = newBuilder(mn); // Arg 0 is the target instance // Arg 1 is the index // Arg 2 is the object array of parameters builder.loadArgument(0).checkcast(className); builder.loadArgument(1); builder.startSwitch(0, nextMethodIndex - 1, new SwitchCallback() { @Override public void doSwitch(SwitchBlock block) { for (PlasticMethodImpl m : shimMethods) { m.extendShimInvoke(block); } } }); shimClassNode.methods.add(mn); }
private void implementShimInvoke(ClassNode shimClassNode) { MethodNode mn = new MethodNode(ACC_PUBLIC, "invoke", OBJECT_INT_OBJECT_ARRAY_TO_METHOD_INVOCATION_RESULT, null, null); InstructionBuilder builder = newBuilder(mn); // Arg 0 is the target instance // Arg 1 is the index // Arg 2 is the object array of parameters builder.loadArgument(0).checkcast(className); builder.loadArgument(1); builder.startSwitch(0, nextMethodIndex - 1, new SwitchCallback() { @Override public void doSwitch(SwitchBlock block) { for (PlasticMethodImpl m : shimMethods) { m.extendShimInvoke(block); } } }); shimClassNode.methods.add(mn); }
} else builder.checkcast(parameterType);
private void implementShimSet(ClassNode shimClassNode) { MethodNode mn = new MethodNode(ACC_PUBLIC, "set", OBJECT_INT_OBJECT_TO_VOID, null, null); InstructionBuilder builder = newBuilder(mn); // Arg 0 is the target instance // Arg 1 is the index // Arg 2 is the new value builder.loadArgument(0).checkcast(className); builder.loadArgument(2); builder.loadArgument(1); builder.startSwitch(0, nextFieldIndex - 1, new SwitchCallback() { @Override public void doSwitch(SwitchBlock block) { for (PlasticFieldImpl f : shimFields) { f.extendShimSet(block); } } }); builder.returnResult(); shimClassNode.methods.add(mn); }
private void implementShimSet(ClassNode shimClassNode) { MethodNode mn = new MethodNode(ACC_PUBLIC, "set", OBJECT_INT_OBJECT_TO_VOID, null, null); InstructionBuilder builder = newBuilder(mn); // Arg 0 is the target instance // Arg 1 is the index // Arg 2 is the new value builder.loadArgument(0).checkcast(className); builder.loadArgument(2); builder.loadArgument(1); builder.startSwitch(0, nextFieldIndex - 1, new SwitchCallback() { @Override public void doSwitch(SwitchBlock block) { for (PlasticFieldImpl f : shimFields) { f.extendShimSet(block); } } }); builder.returnResult(); shimClassNode.methods.add(mn); }
private void initializeComputedField(ComputedValue<?> computedValue) { int index = plasticClass.staticContext.store(computedValue); plasticClass.constructorBuilder.loadThis(); // for the putField() // Get the ComputedValue out of the StaticContext and onto the stack plasticClass.constructorBuilder.loadArgument(0).loadConstant(index); plasticClass.constructorBuilder.invoke(PlasticClassImpl.STATIC_CONTEXT_GET_METHOD).checkcast(ComputedValue.class); // Add the InstanceContext to the stack plasticClass.constructorBuilder.loadArgument(1); plasticClass.constructorBuilder.invoke(PlasticClassImpl.COMPUTED_VALUE_GET_METHOD).castOrUnbox(typeName); plasticClass.constructorBuilder.putField(plasticClass.className, node.name, typeName); }
private void initializeComputedField(ComputedValue<?> computedValue) { int index = plasticClass.staticContext.store(computedValue); plasticClass.constructorBuilder.loadThis(); // for the putField() // Get the ComputedValue out of the StaticContext and onto the stack plasticClass.constructorBuilder.loadArgument(0).loadConstant(index); plasticClass.constructorBuilder.invoke(PlasticClassImpl.STATIC_CONTEXT_GET_METHOD).checkcast(ComputedValue.class); // Add the InstanceContext to the stack plasticClass.constructorBuilder.loadArgument(1); plasticClass.constructorBuilder.invoke(PlasticClassImpl.COMPUTED_VALUE_GET_METHOD).castOrUnbox(typeName); plasticClass.constructorBuilder.putField(plasticClass.className, node.name, typeName); }
builder.loadThis(); builder.loadThis().invoke(AbstractMethodInvocation.class, Object.class, "getInstance").checkcast(plasticClass.className);
builder.loadThis(); builder.loadThis().invoke(AbstractMethodInvocation.class, Object.class, "getInstance").checkcast(plasticClass.className);