@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(); } });
@Override public void doBuild(InstructionBuilder builder) { builder.invokeVirtual(plasticClass.className, typeName, methodToInvoke).boxPrimitive(typeName).returnResult(); } });
@Override public void doBuild(InstructionBuilder builder) { builder.invokeVirtual(plasticClass.className, typeName, methodToInvoke).boxPrimitive(typeName).returnResult(); } });
public void invokeGetRootMethod(InstructionBuilder builder) { builder.loadThis().loadArgument(0).invokeVirtual(getRootMethod); }
@Override public void doBuild(InstructionBuilder builder) { // Load the field builder.loadThis(); if (Modifier.isPrivate(providerDescriptor.modifiers)) { builder.invokeSpecial(plasticClass.className, providerDescriptor); } else { builder.invokeVirtual(plasticClass.className, delegateType, providerDescriptor.methodName); } builder.loadArguments(); invokeDelegateAndReturnResult(builder, delegateType); } });
@Override public void doBuild(InstructionBuilder builder) { // Load the field builder.loadThis(); if (Modifier.isPrivate(providerDescriptor.modifiers)) { builder.invokeSpecial(plasticClass.className, providerDescriptor); } else { builder.invokeVirtual(plasticClass.className, delegateType, providerDescriptor.methodName); } builder.loadArguments(); invokeDelegateAndReturnResult(builder, delegateType); } });
private void invokeDelegateAndReturnResult(InstructionBuilder builder, String delegateType) { // The trick is that you have to be careful to use the right opcode based on the field type // (interface vs. ordinary object). final TypeCategory typeCategory = plasticClass.pool.getTypeCategory(delegateType); if (typeCategory == TypeCategory.INTERFACE) builder.invokeInterface(delegateType, description.returnType, description.methodName, description.argumentTypes); else builder.invokeVirtual(delegateType, description.returnType, description.methodName, description.argumentTypes); builder.returnResult(); }
private void invokeDelegateAndReturnResult(InstructionBuilder builder, String delegateType) { // The trick is that you have to be careful to use the right opcode based on the field type // (interface vs. ordinary object). final TypeCategory typeCategory = plasticClass.pool.getTypeCategory(delegateType); if (typeCategory == TypeCategory.INTERFACE) builder.invokeInterface(delegateType, description.returnType, description.methodName, description.argumentTypes); else builder.invokeVirtual(delegateType, description.returnType, description.methodName, description.argumentTypes); builder.returnResult(); }
/** * The first part of any implementation of get() or set(): invoke the navigation method * and if the result is null, return immediately. */ private void invokeNavigateMethod(InstructionBuilder builder) { builder.loadThis().loadArgument(0).invokeVirtual(navMethod); builder.dupe().when(Condition.NULL, RETURN_NULL); }
public void doBuild(InstructionBuilder builder) { builder.loadThis().loadArgument(0).invokeVirtual(getRootMethod); for (InstructionBuilderCallback callback : callbacks) { callback.doBuild(builder); } builder.returnResult(); } });
/** * Convert the original constructor into a private method invoked from the * generated constructor. */ private void convertOriginalConstructorToMethod() { String initializerName = makeUnique(methodNames, "initializeInstance"); int originalAccess = originalConstructor.access; originalConstructor.access = ACC_PRIVATE; originalConstructor.name = initializerName; stripOutSuperConstructorCall(originalConstructor); constructorBuilder.loadThis().invokeVirtual(className, "void", initializerName); // And replace it with a constructor that throws an exception MethodNode replacementConstructor = new MethodNode(originalAccess, CONSTRUCTOR_NAME, NOTHING_TO_VOID, null, null); newBuilder(replacementConstructor).throwException(IllegalStateException.class, invalidConstructorMessage()); classNode.methods.add(replacementConstructor); }
/** * Convert the original constructor into a private method invoked from the * generated constructor. */ private void convertOriginalConstructorToMethod() { String initializerName = makeUnique(methodNames, "initializeInstance"); int originalAccess = originalConstructor.access; originalConstructor.access = ACC_PRIVATE; originalConstructor.name = initializerName; stripOutSuperConstructorCall(originalConstructor); constructorBuilder.loadThis().invokeVirtual(className, "void", initializerName); // And replace it with a constructor that throws an exception MethodNode replacementConstructor = new MethodNode(originalAccess, CONSTRUCTOR_NAME, NOTHING_TO_VOID, null, null); newBuilder(replacementConstructor).throwException(IllegalStateException.class, invalidConstructorMessage()); classNode.methods.add(replacementConstructor); }
private void invokeMethod(InstructionBuilder builder, PlasticMethod method) { // First, tell the Event object what method is being invoked. builder.loadArgument(1); builder.loadConstant( method.getMethodIdentifier()); builder.invoke(Event.class, void.class, "setMethodDescription", String.class); builder.loadThis(); // Methods either take no parameters, or take a MarkupWriter parameter. if (method.getParameters().size() > 0) { builder.loadArgument(0); } builder.invokeVirtual(method); // Non-void methods will pass a value to the event. if (!method.isVoid()) { builder.boxPrimitive(method.getDescription().returnType); builder.loadArgument(1).swap(); builder.invoke(Event.class, boolean.class, "storeResult", Object.class); builder.when(Condition.NON_ZERO, JUST_RETURN); } }
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); } });