Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.Method


    patchMethod();
   
    mGen.setMaxStack();
    mGen.setMaxLocals();
   
    Method newMethod  = mGen.getMethod();

        LVTTRemover.removeLVTTs( newMethod, constPoolGen );       
   
        iList.dispose();
View Full Code Here


   
    unpatchMethod();
   
    mGen.setMaxStack();
    mGen.setMaxLocals();
    Method newMethod  = mGen.getMethod();

        LVTTRemover.removeLVTTs( newMethod, constPoolGen );       
       
    iList.dispose();
View Full Code Here

    patchMethod();
   
    mGen.setMaxStack();
    mGen.setMaxLocals();
   
    Method newMethod  = mGen.getMethod();
       
        LVTTRemover.removeLVTTs( newMethod, constPoolGen );
       
    iList.dispose();
View Full Code Here

    unpatchMethod();
   
    mGen.setMaxStack();
    mGen.setMaxLocals();
   
    Method newMethod  = mGen.getMethod();

        LVTTRemover.removeLVTTs( newMethod, constPoolGen );       
       
    iList.dispose();
View Full Code Here

            {
                String fieldName = fmd.getName();
                boolean found = false;
                if( fmd.isProperty() )
                {
                    Method method = BCELUtils.getGetterByName(fieldName, newClass);
                    if (method != null)
                    {
                        found = true;
                    }
                }
View Full Code Here

        if (VerificationResult.VERIFIED_OK != result.getStatus())
        {
            JPOXLogger.ENHANCER.fatal(result.getMessage());
            return;
        }
        Method methods[] = ((BCELClassMetaData) cmd).getClassGen().getMethods();
        JPOXLogger.ENHANCER.info("methods num:" + methods.length);
        for (int i = 0; i < methods.length; i++)
        {
            try
            {
View Full Code Here

                {
                    return true;
                }
            }
        }
        Method methods[] = newClass.getMethods();
        if (methods != null)
        {
            for (int i = 0; i < methods.length; i++)
            {
                if (methods[i].getName().equals("jdoReplaceField"))
View Full Code Here

     * Original class must has default(no arg) constructor.
     * @return Return null if this class has default constructor.
     */
    protected String checkHasDefaultConstructor()
    {
        Method methods[] = newClass.getMethods();
        for (int i = 0; i < methods.length; i++)
        {
            if (methods[i].getName().equals(Constants.CONSTRUCTOR_NAME))
            {
                if (methods[i].getSignature().equals("()V"))
View Full Code Here

    protected void enhanceStaticInitializers()
    {
        InstructionList il = null;
        InstructionFactory factory = new InstructionFactory(newClass);
        Method clinit = null;
        InstructionList ilOriginal = null;
        MethodGen methodGen = null;

        MethodGen methodGenOriginal = null;
        {
            Method methods[] = newClass.getMethods();
            for (int i = 0; i < methods.length; i++)
            {
                if (methods[i].getName().equals(Constants.STATIC_INITIALIZER_NAME))
                {
                    clinit = methods[i];
                    methodGenOriginal = new MethodGen(clinit, className, constantPoolGen);
                    ilOriginal = methodGenOriginal.getInstructionList();
                    break;
                }
            }
        }

        il = new InstructionList();
        methodGen = new MethodGen(Constants.ACC_STATIC, Type.VOID, Type.NO_ARGS, null, Constants.STATIC_INITIALIZER_NAME,
            className, il, constantPoolGen);

        if (ilOriginal != null)
        {
            // remove return instruction and add to top of static initialization block
            il.append(ilOriginal);

            InstructionHandle h[] = il.getInstructionHandles();
            if ("return".equalsIgnoreCase(h[h.length - 1].getInstruction().getName()))
            {
                try
                {
                    il.delete(h[h.length - 1]);
                }
                catch (TargetLostException e)
                {
                    InstructionHandle[] targets = e.getTargets();
                    for (int i2 = 0; i2 < targets.length; i2++)
                    {
                        InstructionTargeter[] targeters = targets[i2].getTargeters();
                        for (int j = 0; j < targeters.length; j++)
                        {
                            targeters[j].updateTarget(targets[i2], h[j]);
                        }
                    }
                }
            }

        }

        if (addSerialVersionUID != 0)
        {
            int svUidIndex = constantPoolGen.addLong(addSerialVersionUID);
            il.append(new LDC2_W(svUidIndex));
            il.append(factory.createPutStatic(className, FN_serialVersionUID, Type.LONG));
        }
        // field init MN_jdoFieldNamesInit
        il.append(factory.createInvoke(className, MN_FieldNamesInitMethod, new ArrayType(Type.STRING, 1), Type.NO_ARGS,
            Constants.INVOKESTATIC));
        il.append(factory.createPutStatic(className, FN_FieldNames, new ArrayType(Type.STRING, 1)));

        // field init MN_jdoFieldTypesInit
        il.append(factory.createInvoke(className, MN_FieldTypesInitMethod, new ArrayType(OT_CLASS, 1), Type.NO_ARGS, Constants.INVOKESTATIC));
        il.append(factory.createPutStatic(className, FN_FieldTypes, new ArrayType(OT_CLASS, 1)));

        // field init MN_FieldFlagsInitMethod
        il.append(factory.createInvoke(className, MN_FieldFlagsInitMethod, new ArrayType(Type.BYTE, 1), Type.NO_ARGS,
            Constants.INVOKESTATIC));
        il.append(factory.createPutStatic(className, FN_FieldFlags, new ArrayType(Type.BYTE, 1)));

        // field init MN_JdoFieldCounInitMethod
        il.append(factory.createInvoke(className, MN_JdoGetInheritedFieldCount, Type.INT, Type.NO_ARGS, Constants.INVOKESTATIC));
        il.append(factory.createPutStatic(className, FN_JdoInheritedFieldCount, Type.INT));

        // ___jdo$PersistenceCapableSuperclass =
        // ___jdo$PersistenceCapableSuperclassInit();
        il.append(factory.createInvoke(className, MN_JdoPersistenceCapableSuperclassInit, OT_CLASS, Type.NO_ARGS, Constants.INVOKESTATIC));
        il.append(factory.createPutStatic(className, FN_PersistenceCapableSuperclass, OT_CLASS));

        // class init
        /*
         * JDOImplHelper.registerClass( ___jdo$loadClass("fullclassname"),
         * ___jdo$fieldNames, ___jdo$fieldTypes, ___jdo$FieldFlags,
         * ___jdo$PersistenceCapableSuperclass, new ClassConstrutor());
         */
        il.append(new LDC(constantPoolGen.addString(className)));
        il.append(factory.createInvoke(className, MN_jdoLoadClass, OT_CLASS, new Type[]{Type.STRING}, Constants.INVOKESTATIC));
        il.append(factory.createGetStatic(className, FN_FieldNames, new ArrayType(Type.STRING, 1)));
        il.append(factory.createGetStatic(className, FN_FieldTypes, new ArrayType(OT_CLASS, 1)));
        il.append(factory.createGetStatic(className, FN_FieldFlags, new ArrayType(Type.BYTE, 1)));
        il.append(factory.createGetStatic(className, FN_PersistenceCapableSuperclass, OT_CLASS));

        if (((BCELClassMetaData) cmd).getClassGen().isAbstract())
        {
            // null
            il.append(InstructionConstants.ACONST_NULL);
        }
        else
        {
            // new ClassConstrutor()
            il.append(factory.createNew(new ObjectType(className)));
            il.append(InstructionConstants.DUP);
            il.append(factory.createInvoke(className, Constants.CONSTRUCTOR_NAME, Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
        }
        il.append(factory.createInvoke(CN_JDOImplHelper, "registerClass", Type.VOID, new Type[]{OT_CLASS, new ArrayType(Type.STRING, 1),
                new ArrayType(OT_CLASS, 1), new ArrayType(Type.BYTE, 1), OT_CLASS, OT_PersistenceCapable}, Constants.INVOKESTATIC));

        staticInitializerAppend(factory, il);
        il.append(InstructionConstants.RETURN);

        // newClass.addMethod(method);
        if (clinit != null)
        {
            newClass.removeMethod(clinit);
        }
        methodGen.setMaxLocals();
        methodGen.setMaxStack();
        Method method = methodGen.getMethod();
        {
            Method allMethod[] = newClass.getMethods();
            newClass.replaceMethod(allMethod[0], method);
            newClass.addMethod(allMethod[0]);
        }
        // BCELUtil.addSynthetic(method, constantPoolGen);
        il.dispose();
View Full Code Here

        newClass.addMethod(methodGen.getMethod());
    }

    protected void enhanceOriginalMethods()
    {
        Method methods[] = newClass.getMethods();
        for (int i = 0; i < methods.length; i++)
        {
            // see JSR12 version 1.0 10.3
            if ("jdoPreClear".equals(methods[i].getName()) || "jdoPostLoad".equals(methods[i].getName()))
            {
View Full Code Here

TOP

Related Classes of org.apache.bcel.classfile.Method

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.