Package org.apache.tapestry5.ioc.util

Examples of org.apache.tapestry5.ioc.util.BodyBuilder


            values.add(conduitPropertyName);
            values.add(annotationProvider);
            values.add(interner.format("PropertyConduit[%s %s]", rootType.getName(), expression));
            values.add(typeCoercer);

            BodyBuilder builder = new BodyBuilder().begin();

            builder.addln("super($1,$2,$3,$4,$5);");

            int index = 6;

            for (ConstructorParameter p : parameters)
            {
                types.add(p.getType());
                values.add(p.getValue());

                builder.addln("%s = $%d;", p.getFieldName(), index++);
            }

            builder.end();

            Class[] arrayOfTypes = types.toArray(new Class[0]);

            classFab.addConstructor(arrayOfTypes, null, builder.toString());

            return values.toArray();
        }
View Full Code Here


            return type != DEREF && type != SAFEDEREF;
        }

        private void createGetRoot()
        {
            BodyBuilder builder = new BodyBuilder().begin();

            builder.addln("%s root = (%<s) $1;", ClassFabUtils.toJavaClassName(rootType));

            builder.addln(
                    "if (root == null) throw new NullPointerException(\"Root object of property expression '%s' is null.\");",
                    expression);

            builder.addln("return root;");

            builder.end();

            MethodSignature sig = new MethodSignature(rootType, "getRoot", new Class[]
            { Object.class }, null);

            classFab.addMethod(Modifier.PRIVATE, sig, builder.toString());
        }
View Full Code Here

            }
        }

        private void createRangeOpGetter(Tree node, String rootName)
        {
            BodyBuilder builder = new BodyBuilder().begin();

            addRootVariable(builder);

            builder.addln("return %s;", createMethodInvocation(builder, node, rootName, 0, RANGE));

            builder.end();

            classFab.addMethod(Modifier.PUBLIC, GET_SIGNATURE, builder.toString());
        }
View Full Code Here

            classFab.addMethod(Modifier.PUBLIC, GET_SIGNATURE, builder.toString());
        }

        private void createNotOpGetter(Tree node, String rootName)
        {
            BodyBuilder builder = new BodyBuilder().begin();

            addRootVariable(builder);

            builder.addln("return ($w) %s;", createMethodInvocation(builder, node, rootName, 0, INVERT));

            builder.end();

            classFab.addMethod(Modifier.PUBLIC, GET_SIGNATURE, builder.toString());
        }
View Full Code Here

            classFab.addMethod(Modifier.PUBLIC, GET_SIGNATURE, builder.toString());
        }

        public void createListGetter(Tree node, String rootName)
        {
            BodyBuilder builder = new BodyBuilder().begin();

            addRootVariable(builder);

            builder.addln("return %s;", createListConstructor(builder, node, rootName));

            builder.end();

            classFab.addMethod(Modifier.PUBLIC, GET_SIGNATURE, builder.toString());
        }
View Full Code Here

            {
                createNoOpSetter();
                return;
            }

            BodyBuilder builder = new BodyBuilder().begin();

            addRootVariable(builder);

            builder.addln("%s target = navigate(root);", ClassFabUtils.toJavaClassName(navigateMethod.getReturnType()));

            // I.e. due to ?. operator. The navigate method will already have
            // checked for nulls
            // if they are not allowed.

            builder.addln("if (target == null) return;");

            String propertyTypeName = ClassFabUtils.toJavaClassName(info.getType());

            String reference = ClassFabUtils.castReference("$2", propertyTypeName);

            if (info.isField())
            {
                builder.add("target.%s = %s;", info.getPropertyName(), reference);
            }
            else
            {
                builder.addln("target.%s(%s);", method.getName(), reference);
            }

            builder.end();

            classFab.addMethod(Modifier.PUBLIC, SET_SIGNATURE, builder.toString());
        }
View Full Code Here

                createNoOp(classFab, GET_SIGNATURE, "Expression %s for class %s is write-only.", expression,
                        rootType.getName());
                return;
            }

            BodyBuilder builder = new BodyBuilder().begin();

            addRootVariable(builder);

            builder.addln("%s target = navigate(root);", ClassFabUtils.toJavaClassName(navigateMethod.getReturnType()));

            // I.e. due to ?. operator. The navigate method will already have
            // checked for nulls
            // if they are not allowed.

            builder.addln("if (target == null) return null;");

            String reference = info.isField() ? info.getPropertyName() : createMethodInvocation(builder, node, "root",
                    method);

            builder.addln("return ($w) target.%s;", reference);

            builder.end();

            classFab.addMethod(Modifier.PUBLIC, GET_SIGNATURE, builder.toString());
        }
View Full Code Here

        CtClass[] parameterTypes = new CtClass[parameterCount + 2];

        parameterTypes[0] = toCtClass(ComponentMethodInvocationInfo.class);
        parameterTypes[1] = toCtClass(Component.class);

        BodyBuilder builder = new BodyBuilder().begin().addln("super($1,$2);");

        for (int i = 0; i < parameterCount; i++)
        {
            String name = FIELD_NAME + i;

            String parameterTypeName = advisedMethod.getParameterTypes()[i];

            CtClass parameterType = classSource.toCtClass(parameterTypeName);

            CtField field = new CtField(parameterType, name, invocationCtClass);
            field.setModifiers(Modifier.PRIVATE);
            invocationCtClass.addField(field);

            parameterTypes[2 + i] = parameterType;

            builder.addln("%s = $%d;", name, 3 + i);
        }

        builder.end();

        CtConstructor constructor = new CtConstructor(parameterTypes, invocationCtClass);
        constructor.setBody(builder.toString());

        invocationCtClass.addConstructor(constructor);
    }
View Full Code Here

        return classSource.toCtClass(input);
    }

    private void implementOverride() throws CannotCompileException
    {
        BodyBuilder builder = new BodyBuilder().begin();

        builder.addln("switch ($1)").begin();

        int count = advisedMethod.getParameterTypes().length;

        for (int i = 0; i < count; i++)
        {
            String type = advisedMethod.getParameterTypes()[i];

            builder.addln("case %d: %s = %s; break;", i, FIELD_NAME + i, ClassFabUtils
                    .castReference("$2", type));
        }

        builder.addln("default: throw new IllegalArgumentException(\"Index out of range.\");");

        builder.end().end();

        CtMethod method = new CtMethod(CtClass.voidType, "override", new CtClass[]
        { CtClass.intType, toCtClass(Object.class) }, invocationCtClass);

        method.setModifiers(PUBLIC_FINAL);
        method.setBody(builder.toString());

        invocationCtClass.addMethod(method);
    }
View Full Code Here

        invocationCtClass.addMethod(method);
    }

    private void implementGetParameter() throws CannotCompileException
    {
        BodyBuilder builder = new BodyBuilder().begin();

        builder.addln("switch ($1)").begin();

        int count = advisedMethod.getParameterTypes().length;

        for (int i = 0; i < count; i++)
        {
            builder.addln("case %d: return ($w) %s;", i, FIELD_NAME + i);
        }

        builder.addln("default: throw new IllegalArgumentException(\"Index out of range.\");");

        builder.end().end();

        CtMethod method = new CtMethod(toCtClass(Object.class), "getParameter", new CtClass[]
        { CtClass.intType }, invocationCtClass);

        method.setModifiers(PUBLIC_FINAL);
        method.setBody(builder.toString());

        invocationCtClass.addMethod(method);
    }
View Full Code Here

TOP

Related Classes of org.apache.tapestry5.ioc.util.BodyBuilder

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.