@Override public void doBuild(InstructionBuilder builder) { builder.castOrUnbox(typeName); builder.invokeVirtual(plasticClass.className, "void", methodToInvoke, typeName); // Should not be necessary, as its always a void method, and we can // drop to the bottom of the method. // builder.returnResult(); } });
@Override public void doBuild(InstructionBuilder builder) { builder.castOrUnbox(typeName); builder.invokeVirtual(plasticClass.className, "void", methodToInvoke, typeName); // Should not be necessary, as its always a void method, and we can // drop to the bottom of the method. // builder.returnResult(); } });
public void doBuild(InstructionBuilder builder) { builder.loadArgument(1).castOrUnbox(PlasticUtils.toTypeName(field.getType())); builder.putStaticField(field.getDeclaringClass().getName(), field.getName(), field.getType()); builder.returnResult(); } });
public void doBuild(InstructionBuilder builder) { invokeNavigateMethod(builder); builder.loadArgument(1).castOrUnbox(PlasticUtils.toTypeName(field.getType())); builder.putField(field.getDeclaringClass().getName(), field.getName(), field.getType()); builder.returnResult(); } });
public void doBuild(InstructionBuilder builder) { invokeNavigateMethod(builder); Class propertyType = writeMethod.getParameterTypes()[0]; String propertyTypeName = PlasticUtils.toTypeName(propertyType); builder.loadArgument(1).castOrUnbox(propertyTypeName); builder.invoke(writeMethod); builder.returnResult(); } });
private void bridgeToClojure(InstructionBuilder builder, MethodDescription description, PlasticField ifnField) { builder.loadThis().getField(ifnField); int count = description.argumentTypes.length; Class[] invokeParameterTypes = new Class[count]; for (int i = 0; i < count; i++) { invokeParameterTypes[i] = Object.class; builder.loadArgument(i).boxPrimitive(description.argumentTypes[i]); } Method ifnMethod = null; try { ifnMethod = IFn.class.getMethod("invoke", invokeParameterTypes); } catch (NoSuchMethodException ex) { throw new RuntimeException(String.format("Unable to find correct IFn.invoke() method: %s", ExceptionUtils.toMessage(ex)), ex); } builder.invoke(ifnMethod); builder.castOrUnbox(description.returnType); builder.returnResult(); } });
private void invokeCallback(ConstructorCallback callback) { int index = staticContext.store(callback); // First, load the callback constructorBuilder.loadArgument(0).loadConstant(index).invoke(STATIC_CONTEXT_GET_METHOD).castOrUnbox(ConstructorCallback.class.getName()); // Load this and the InstanceContext constructorBuilder.loadThis().loadArgument(1); constructorBuilder.invoke(CONSTRUCTOR_CALLBACK_METHOD); }
private void invokeCallback(ConstructorCallback callback) { int index = staticContext.store(callback); // First, load the callback constructorBuilder.loadArgument(0).loadConstant(index).invoke(STATIC_CONTEXT_GET_METHOD).castOrUnbox(ConstructorCallback.class.getName()); // Load this and the InstanceContext constructorBuilder.loadThis().loadArgument(1); constructorBuilder.invoke(CONSTRUCTOR_CALLBACK_METHOD); }
builder.castOrUnbox(parameterType.getName()); } else
/** * Initializes a field from the static context. The injected value is added to the static * context and the class constructor updated to assign the value from the context (which includes casting and * possibly unboxing). */ void initializeFieldFromStaticContext(String fieldName, String fieldType, Object injectedFieldValue) { int index = staticContext.store(injectedFieldValue); // Although it feels nicer to do the loadThis() later and then swap(), that breaks // on primitive longs and doubles, so its just easier to do the loadThis() first // so its at the right place on the stack for the putField(). constructorBuilder.loadThis(); constructorBuilder.loadArgument(0).loadConstant(index); constructorBuilder.invoke(STATIC_CONTEXT_GET_METHOD); constructorBuilder.castOrUnbox(fieldType); constructorBuilder.putField(className, fieldName, fieldType); }
/** * Initializes a field from the static context. The injected value is added to the static * context and the class constructor updated to assign the value from the context (which includes casting and * possibly unboxing). */ void initializeFieldFromStaticContext(String fieldName, String fieldType, Object injectedFieldValue) { int index = staticContext.store(injectedFieldValue); // Although it feels nicer to do the loadThis() later and then swap(), that breaks // on primitive longs and doubles, so its just easier to do the loadThis() first // so its at the right place on the stack for the putField(). constructorBuilder.loadThis(); constructorBuilder.loadArgument(0).loadConstant(index); constructorBuilder.invoke(STATIC_CONTEXT_GET_METHOD); constructorBuilder.castOrUnbox(fieldType); constructorBuilder.putField(className, fieldName, fieldType); }
private void addReturnValueSetter() { InstructionBuilder builder = newMethod("setReturnValue", MethodInvocation.class, Object.class); if (isVoid) { builder.throwException(IllegalArgumentException.class, String .format("Method %s of class %s is void, setting a return value is not allowed.", description, plasticClass.className)); } else { builder.loadThis().loadArgument(0); builder.castOrUnbox(description.returnType); builder.putField(invocationClassName, RETURN_VALUE, description.returnType); builder.loadThis().invoke(AbstractMethodInvocation.class, void.class, "clearCheckedException"); builder.loadThis().returnResult(); } }
private void addReturnValueSetter() { InstructionBuilder builder = newMethod("setReturnValue", MethodInvocation.class, Object.class); if (isVoid) { builder.throwException(IllegalArgumentException.class, String .format("Method %s of class %s is void, setting a return value is not allowed.", description, plasticClass.className)); } else { builder.loadThis().loadArgument(0); builder.castOrUnbox(description.returnType); builder.putField(invocationClassName, RETURN_VALUE, description.returnType); builder.loadThis().invoke(AbstractMethodInvocation.class, void.class, "clearCheckedException"); builder.loadThis().returnResult(); } }
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); }
@Override public PlasticField injectFromInstanceContext() { plasticClass.check(); verifyInitialState("inject instance context value into"); // Easiest to load this, for the putField(), early, in case the field is // wide (long or double primitive) plasticClass.constructorBuilder.loadThis(); // Add the InstanceContext to the stack plasticClass.constructorBuilder.loadArgument(1); plasticClass.constructorBuilder.loadConstant(typeName); plasticClass.constructorBuilder.invokeStatic(PlasticInternalUtils.class, Object.class, "getFromInstanceContext", InstanceContext.class, String.class).castOrUnbox(typeName); plasticClass.constructorBuilder.putField(plasticClass.className, node.name, typeName); makeReadOnly(); state = FieldState.INJECTED; return this; }
@Override public PlasticField injectFromInstanceContext() { plasticClass.check(); verifyInitialState("inject instance context value into"); // Easiest to load this, for the putField(), early, in case the field is // wide (long or double primitive) plasticClass.constructorBuilder.loadThis(); // Add the InstanceContext to the stack plasticClass.constructorBuilder.loadArgument(1); plasticClass.constructorBuilder.loadConstant(typeName); plasticClass.constructorBuilder.invokeStatic(PlasticInternalUtils.class, Object.class, "getFromInstanceContext", InstanceContext.class, String.class).castOrUnbox(typeName); plasticClass.constructorBuilder.putField(plasticClass.className, node.name, typeName); makeReadOnly(); state = FieldState.INJECTED; return this; }
public void doBuild(InstructionBuilder builder) { builder.loadArgument(0).loadConstant(method.getMethodIdentifier()).invoke(Event.class, void.class, "setMethodDescription", String.class); builder.loadThis(); int count = description.argumentTypes.length; for (int i = 0; i < count; i++) { builder.loadThis().getField(sourceField).loadArgument(0).loadConstant(i); builder.invoke(EventHandlerMethodParameterSource.class, Object.class, "get", ComponentEvent.class, int.class); builder.castOrUnbox(description.argumentTypes[i]); } builder.invokeVirtual(method); if (!method.isVoid()) { builder.boxPrimitive(description.returnType); builder.loadArgument(0).swap(); builder.invoke(Event.class, boolean.class, "storeResult", Object.class); // storeResult() returns true if the method is aborted. Return true since, certainly, // a method was invoked. builder.when(Condition.NON_ZERO, RETURN_TRUE); } // Set the result to true, to indicate that some method was invoked. builder.loadConstant(true).storeVariable(resultVariable); } });
builder.invoke(FieldConduit.class, Object.class, "get", Object.class, InstanceContext.class).castOrUnbox( typeName);
builder.invoke(FieldConduit.class, Object.class, "get", Object.class, InstanceContext.class).castOrUnbox( typeName);