Package org.apache.tapestry5.plastic

Examples of org.apache.tapestry5.plastic.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


            // 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();

            addMethod(mn);

            return name;
        }
View Full Code Here

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

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

            InstructionBuilder builder = newBuilder(setAccess);

            pushFieldConduitOntoStack(conduitFieldName, builder);

            builder.loadThis();

            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", Object.class, InstanceContext.class, Object.class);

            if (isWriteBehindEnabled())
            {
                builder.loadThis().loadArgument(0).putField(className, node.name, typeName);
            }

            builder.returnResult();

            addMethod(setAccess);

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

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

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

            InstructionBuilder builder = newBuilder(getAccess);

            // Get the correct FieldConduit object on the stack

            pushFieldConduitOntoStack(conduitFieldName, builder);

            builder.loadThis();

            // Now push the instance context on the stack

            pushInstanceContextFieldOntoStack(builder);

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

            if (writeBehindEnabled)
            {
                // Dupe the value, then push this, then swap

                if (isWide())
                {
                    // Dupe this under the wide value, then pop the wide value

                    builder.dupeWide().loadThis().dupe(2).pop();
                }
                else
                {
                    builder.dupe().loadThis().swap();
                }

                // At which point the stack is the result value, this, the result value

                builder.putField(className, node.name, typeName);

                // And now it is just the result value
            }

            builder.returnResult();

            addMethod(getAccess);

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

            // 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);

            fieldTransformMethods.add(mn);
View Full Code Here

        {
            String name = makeUnique(methodNames, "shimget_" + 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);

            fieldTransformMethods.add(mn);
View Full Code Here

            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,
                    MethodInvocationBundle.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

            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

            }
        }

        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().invoke(AbstractMethodInvocation.class, void.class, "clearCheckedException");

                builder.loadThis().returnResult();
            }
        }
View Full Code Here

            }
        }

        private void createGetParameter()
        {
            InstructionBuilder builder = newMethod("getParameter", Object.class, int.class);

            if (description.argumentTypes.length == 0)
            {
                indexOutOfRange(builder);
            }
            else
            {
                builder.loadArgument(0);
                builder.startSwitch(0, description.argumentTypes.length - 1, new SwitchCallback()
                {

                    public void doSwitch(SwitchBlock block)
                    {
                        for (int i = 0; i < description.argumentTypes.length; i++)
                        {
                            final int index = i;

                            block.addCase(i, false, new InstructionBuilderCallback()
                            {

                                public void doBuild(InstructionBuilder builder)
                                {
                                    String type = description.argumentTypes[index];

                                    builder.loadThis();
                                    builder.getField(invocationClassName, "p" + index, type).boxPrimitive(type)
                                            .returnResult();
                                }
                            });
                        }
                    }
View Full Code Here

TOP

Related Classes of org.apache.tapestry5.plastic.InstructionBuilder

Copyright © 2018 www.massapicom. 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.