Examples of InstructionBuilder


Examples of org.jplastic.core.InstructionBuilder

    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()
        {
            public void doSwitch(SwitchBlock block)
            {
                for (PlasticFieldImpl f : shimFields)
                {
                    f.extendShimSet(block);
                }
            }
        });

        builder.returnResult();

        shimClassNode.methods.add(mn);
    }
View Full Code Here

Examples of org.jplastic.core.InstructionBuilder

    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()
        {
            public void doSwitch(SwitchBlock block)
            {
                for (PlasticMethodImpl m : shimMethods)
                {
View Full Code Here

Examples of org.jplastic.core.InstructionBuilder

            // Kind of awkward that exceptions are specified as String[] when what we have handy is List<String>
            MethodNode mn = new MethodNode(ACC_SYNTHETIC | ACC_FINAL, name, node.desc, node.signature, null);
            // But it is safe enough for the two nodes to share
            mn.exceptions = node.exceptions;

            InstructionBuilder builder = newBuilder(mn);

            builder.loadThis();
            builder.loadArguments();
            builder.invokeSpecial(className, description);
            builder.returnResult();

            classNode.methods.add(mn);

            return name;
        }
View Full Code Here

Examples of org.jplastic.core.InstructionBuilder

        {
            setAccessName = makeUnique(methodNames, "set_" + node.name);

            MethodNode mn = new MethodNode(ACC_SYNTHETIC | ACC_FINAL, setAccessName, "(" + node.desc + ")V", null, null);

            InstructionBuilder builder = newBuilder(mn);

            pushFieldConduitOntoStack(conduitFieldName, builder);
            pushInstanceContextFieldOntoStack(builder);

            // Take the value passed to this method and push it onto the stack.

            builder.loadArgument(0);
            builder.boxPrimitive(typeName);

            builder.invoke(FieldConduit.class, void.class, "set", InstanceContext.class, Object.class);

            builder.returnResult();

            addMethod(mn);

            fieldToWriteMethod.put(node.name, setAccessName);
        }
View Full Code Here

Examples of org.jplastic.core.InstructionBuilder

        {
            getAccessName = makeUnique(methodNames, "getfieldvalue_" + node.name);

            MethodNode mn = new MethodNode(ACC_SYNTHETIC | ACC_FINAL, getAccessName, "()" + node.desc, null, null);

            InstructionBuilder builder = newBuilder(mn);

            // Get the correct FieldConduit object on the stack

            pushFieldConduitOntoStack(conduitFieldName, builder);

            // Now push the instance context on the stack

            pushInstanceContextFieldOntoStack(builder);

            builder.invoke(FieldConduit.class, Object.class, "get", InstanceContext.class).castOrUnbox(typeName);

            builder.returnResult();

            addMethod(mn);

            fieldToReadMethod.put(node.name, getAccessName);
        }
View Full Code Here

Examples of org.jplastic.core.InstructionBuilder

            // Takes two Object parameters (instance, and value) and returns void.

            MethodNode mn = new MethodNode(ACC_SYNTHETIC | ACC_FINAL, name, "(" + node.desc + ")V", null, null);

            InstructionBuilder builder = newBuilder(mn);

            builder.loadThis().loadArgument(0).putField(className, node.name, typeName);
            builder.returnResult();

            addMethod(mn);

            return mn;
        }
View Full Code Here

Examples of org.jplastic.core.InstructionBuilder

        {
            String name = makeUnique(methodNames, "directget_" + node.name);

            MethodNode mn = new MethodNode(ACC_SYNTHETIC | ACC_FINAL, name, "()" + node.desc, null, null);

            InstructionBuilder builder = newBuilder(mn);

            builder.loadThis().getField(className, node.name, typeName).returnResult();

            addMethod(mn);

            return mn;
        }
View Full Code Here

Examples of org.jplastic.core.InstructionBuilder

            String[] constructorTypes = consTypes.toArray(new String[consTypes.size()]);

            MethodNode cons = new MethodNode(ACC_PUBLIC, CONSTRUCTOR_NAME, nameCache.toMethodDescriptor("void",
                    constructorTypes), null, null);

            InstructionBuilder builder = newBuilder(cons);

            // First three arguments go to the super-class

            builder.loadThis();
            builder.loadArgument(0);
            builder.loadArgument(1);
            builder.loadArgument(2);
            builder.invokeConstructor(AbstractMethodInvocation.class, Object.class, InstanceContext.class,
                    MethodAdvice[].class);

            for (int i = 0; i < description.argumentTypes.length; i++)
            {
                String name = "p" + i;
                String type = description.argumentTypes[i];

                builder.loadThis();
                builder.loadArgument(3 + i);
                builder.putField(invocationClassName, name, type);
            }

            builder.returnResult();

            invocationClassNode.methods.add(cons);

            return constructorTypes;
        }
View Full Code Here

Examples of org.jplastic.core.InstructionBuilder

            return newBuilder(mn);
        }

        private void createReturnValueGetter()
        {
            InstructionBuilder builder = newMethod("getReturnValue", Object.class);

            if (isVoid)
            {
                builder.loadNull().returnResult();
            }
            else
            {
                builder.loadThis().getField(invocationClassName, RETURN_VALUE, description.returnType)
                        .boxPrimitive(description.returnType).returnResult();
            }
        }
View Full Code Here

Examples of org.jplastic.core.InstructionBuilder

            }
        }

        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,
                                className));
            }
            else
            {
                builder.loadThis().loadArgument(0);
                builder.castOrUnbox(description.returnType);
                builder.putField(invocationClassName, RETURN_VALUE, description.returnType);

                builder.loadThis().returnResult();
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.