Package org.cojen.classfile

Examples of org.cojen.classfile.MethodInfo


        try {
            cf.setTarget(System.getProperty("java.specification.version"));
        } catch (Exception e) {
        }

        MethodInfo ctor = cf.addConstructor(Modifiers.PUBLIC, null);
        ctor.markSynthetic();
        CodeBuilder b = new CodeBuilder(ctor);

        b.loadThis();
        b.invokeSuperConstructor(null);
        b.returnVoid();
View Full Code Here


    private static void generateAccessMethod(ClassFile cf,
                                             Class beanType,
                                             BeanProperty[] properties,
                                             int methodType)
    {
        MethodInfo mi;
        switch (methodType) {
        case READ_METHOD: default: {
            TypeDesc[] params = {TypeDesc.OBJECT, TypeDesc.STRING};
            mi = cf.addMethod
                (Modifiers.PUBLIC, "getPropertyValue", TypeDesc.OBJECT, params);
            break;
        }
        case WRITE_METHOD: {
            TypeDesc[] params = new TypeDesc[] {
                TypeDesc.OBJECT, TypeDesc.STRING, TypeDesc.OBJECT
            };
            mi = cf.addMethod(Modifiers.PUBLIC, "setPropertyValue", null, params);
            break;
        }
        case TRY_READ_METHOD: {
            TypeDesc[] params = {TypeDesc.OBJECT, TypeDesc.STRING};
            mi = cf.addMethod
                (Modifiers.PUBLIC, "tryGetPropertyValue", TypeDesc.OBJECT, params);
            break;
        }
        case TRY_WRITE_METHOD: {
            TypeDesc[] params = new TypeDesc[] {
                TypeDesc.OBJECT, TypeDesc.STRING, TypeDesc.OBJECT
            };
            mi = cf.addMethod(Modifiers.PUBLIC, "trySetPropertyValue", TypeDesc.BOOLEAN, params);
            break;
        }
        case HAS_READ_METHOD: {
            TypeDesc[] params = {TypeDesc.STRING};
            mi = cf.addMethod(Modifiers.PUBLIC, "hasReadableProperty", TypeDesc.BOOLEAN, params);
            break;
        }
        case HAS_WRITE_METHOD: {
            TypeDesc[] params = {TypeDesc.STRING};
            mi = cf.addMethod(Modifiers.PUBLIC, "hasWritableProperty", TypeDesc.BOOLEAN, params);
            break;
        }
        }

        mi.markSynthetic();
        CodeBuilder b = new CodeBuilder(mi);

        LocalVariable beanVar, propertyVar, valueVar;

        switch (methodType) {
View Full Code Here

    private static void generateSearchMethod(ClassFile cf,
                                             Class beanType,
                                             BeanProperty[] properties)
    {
        MethodInfo mi;
        {
            TypeDesc[] params = {TypeDesc.OBJECT, TypeDesc.OBJECT};
            mi = cf.addMethod(Modifiers.PUBLIC, "hasPropertyValue", TypeDesc.BOOLEAN, params);
        }

        mi.markSynthetic();
        CodeBuilder b = new CodeBuilder(mi);

        LocalVariable beanVar = b.getParameter(0);
        b.loadLocal(beanVar);
        b.checkCast(TypeDesc.forClass(beanType));
View Full Code Here

            cf.setSourceFile(PatternMatcher.class.getName());
           
            // constructor
            TypeDesc objectArrayType = TypeDesc.OBJECT.toArrayType();
            TypeDesc[] params = {objectArrayType};
            MethodInfo mi = cf.addConstructor(Modifiers.PUBLIC, params);
            mBuilder = new CodeBuilder(mi);
            mBuilder.loadThis();
            mBuilder.loadLocal(mBuilder.getParameter(0));
            mBuilder.invokeSuperConstructor(params);
            mBuilder.returnVoid();
View Full Code Here

        // Create constructor to initialize fields.
        TypeDesc[] paramTypes = {
            comparatorArrayType, comparatorArrayType
        };
        MethodInfo ctor = cf.addConstructor(Modifiers.PUBLIC, paramTypes);
        ctor.markSynthetic();
        CodeBuilder builder = new CodeBuilder(ctor);

        builder.loadThis();
        builder.invokeSuperConstructor(null);
        builder.loadThis();
        builder.loadLocal(builder.getParameter(0));
        builder.storeField("mCollators", comparatorArrayType);
        builder.loadThis();
        builder.loadLocal(builder.getParameter(1));
        builder.storeField("mUsingComparators", comparatorArrayType);
        builder.returnVoid();

        // Create the all-important compare method.
        Method compareMethod, compareToMethod;
        try {
            compareMethod = Comparator.class.getMethod
                ("compare", new Class[] {Object.class, Object.class});
            compareToMethod = Comparable.class.getMethod
                ("compareTo", new Class[] {Object.class});
        } catch (NoSuchMethodException e) {
            throw new InternalError(e.toString());
        }

        MethodInfo mi = cf.addMethod(compareMethod);
        mi.markSynthetic();
        builder = new CodeBuilder(mi);

        Label endLabel = builder.createLabel();
        LocalVariable obj1 = builder.getParameter(0);
        LocalVariable obj2 = builder.getParameter(1);
View Full Code Here

        cf.setSourceFile("HelloWorld.java");

        cf.addDefaultConstructor();

        TypeDesc[] params = new TypeDesc[] { TypeDesc.STRING.toArrayType() };
        MethodInfo mi = cf.addMethod(Modifiers.PUBLIC_STATIC,
                "main",
                null,
                params);
        org.cojen.classfile.CodeBuilder b = new org.cojen.classfile.CodeBuilder(mi);
        b.loadStaticField("java.lang.System", "out", printStream);
View Full Code Here

        // Create constructor to initialize fields.
        TypeDesc[] paramTypes = {
            comparatorArrayType, comparatorArrayType
        };
        MethodInfo ctor = cf.addConstructor(Modifiers.PUBLIC, paramTypes);
        ctor.markSynthetic();
        CodeBuilder builder = new CodeBuilder(ctor);

        builder.loadThis();
        builder.invokeSuperConstructor(null);
        builder.loadThis();
        builder.loadLocal(builder.getParameter(0));
        builder.storeField("mCollators", comparatorArrayType);
        builder.loadThis();
        builder.loadLocal(builder.getParameter(1));
        builder.storeField("mUsingComparators", comparatorArrayType);
        builder.returnVoid();

        // Create the all-important compare method.
        Method compareMethod, compareToMethod;
        try {
            compareMethod = Comparator.class.getMethod
                ("compare", new Class[] {Object.class, Object.class});
            compareToMethod = Comparable.class.getMethod
                ("compareTo", new Class[] {Object.class});
        } catch (NoSuchMethodException e) {
            throw new InternalError(e.toString());
        }

        MethodInfo mi = cf.addMethod(compareMethod);
        mi.markSynthetic();
        builder = new CodeBuilder(mi);

        Label endLabel = builder.createLabel();
        LocalVariable obj1 = builder.getParameter(0);
        LocalVariable obj2 = builder.getParameter(1);
View Full Code Here

            cf.setSourceFile(PatternMatcher.class.getName());
           
            // constructor
            TypeDesc objectArrayType = TypeDesc.OBJECT.toArrayType();
            TypeDesc[] params = {objectArrayType};
            MethodInfo mi = cf.addConstructor(Modifiers.PUBLIC, params);
            mBuilder = new CodeBuilder(mi);
            mBuilder.loadThis();
            mBuilder.loadLocal(mBuilder.getParameter(0));
            mBuilder.invokeSuperConstructor(params);
            mBuilder.returnVoid();
View Full Code Here

        try {
            cf.setTarget(System.getProperty("java.specification.version"));
        } catch (Exception e) {
        }

        MethodInfo ctor = cf.addConstructor(Modifiers.PUBLIC, null);
        ctor.markSynthetic();
        CodeBuilder b = new CodeBuilder(ctor);

        b.loadThis();
        b.invokeSuperConstructor(null);
        b.returnVoid();
View Full Code Here

    private static void generateAccessMethod(ClassFile cf,
                                             Class beanType,
                                             BeanProperty[] properties,
                                             int methodType)
    {
        MethodInfo mi;
        switch (methodType) {
        case READ_METHOD: default: {
            TypeDesc[] params = {TypeDesc.OBJECT, TypeDesc.STRING};
            mi = cf.addMethod
                (Modifiers.PUBLIC, "getPropertyValue", TypeDesc.OBJECT, params);
            break;
        }
        case WRITE_METHOD: {
            TypeDesc[] params = new TypeDesc[] {
                TypeDesc.OBJECT, TypeDesc.STRING, TypeDesc.OBJECT
            };
            mi = cf.addMethod(Modifiers.PUBLIC, "setPropertyValue", null, params);
            break;
        }
        case TRY_READ_METHOD: {
            TypeDesc[] params = {TypeDesc.OBJECT, TypeDesc.STRING};
            mi = cf.addMethod
                (Modifiers.PUBLIC, "tryGetPropertyValue", TypeDesc.OBJECT, params);
            break;
        }
        case TRY_WRITE_METHOD: {
            TypeDesc[] params = new TypeDesc[] {
                TypeDesc.OBJECT, TypeDesc.STRING, TypeDesc.OBJECT
            };
            mi = cf.addMethod(Modifiers.PUBLIC, "trySetPropertyValue", TypeDesc.BOOLEAN, params);
            break;
        }
        case HAS_READ_METHOD: {
            TypeDesc[] params = {TypeDesc.STRING};
            mi = cf.addMethod(Modifiers.PUBLIC, "hasReadableProperty", TypeDesc.BOOLEAN, params);
            break;
        }
        case HAS_WRITE_METHOD: {
            TypeDesc[] params = {TypeDesc.STRING};
            mi = cf.addMethod(Modifiers.PUBLIC, "hasWritableProperty", TypeDesc.BOOLEAN, params);
            break;
        }
        }

        mi.markSynthetic();
        CodeBuilder b = new CodeBuilder(mi);

        LocalVariable beanVar, propertyVar, valueVar;

        switch (methodType) {
View Full Code Here

TOP

Related Classes of org.cojen.classfile.MethodInfo

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.