Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.InstructionFactory$MethodObject


            LOG.debug("Creating accessor: " + methodName);

        MethodFabricator mf =
            _classFabricator.createMethod(Constants.ACC_PUBLIC, fieldType, methodName);

        InstructionFactory factory = _classFabricator.getInstructionFactory();

        mf.append(factory.createThis());
        mf.append(factory.createGetField(_subclassName, fieldName, fieldType));
        mf.append(factory.createReturn(fieldType));

        mf.commit();
    }
View Full Code Here


        String fieldName = "$type$" + _parameterName;

        cf.addField(Constants.ACC_PRIVATE | Constants.ACC_STATIC, _classType, fieldName);

        MethodFabricator mf = cf.getStaticInitializerMethod();
        InstructionFactory factory = cf.getInstructionFactory();
        String className = cf.getClassName();
        Type throwableType = _factory.getObjectType(Throwable.class.getName());

        mf.append(factory.createGetStatic(className, fieldName, _classType));

        BranchInstruction ifNotNullBI = new IFNONNULL(null);

        mf.append(ifNotNullBI);

        // Invoke Class.forName and store ther result.
        // Concern: will the class be visible to the right class loader?
        // May need to use alternate forName() and pass Thread's context class loader.

        mf.append(new PUSH(cf.getConstantPool(), _typeClassName));
        InstructionHandle tryStart =
            mf.append(
                factory.createInvoke(
                    "java.lang.Class",
                    "forName",
                    _classType,
                    new Type[] { Type.STRING },
                    Constants.INVOKESTATIC));
        mf.append(factory.createPutStatic(className, fieldName, _classType));

        GOTO jumpOut = new GOTO(null);

        InstructionHandle tryEnd = mf.append(jumpOut);

        String exceptionClassName = ApplicationRuntimeException.class.getName();

        InstructionHandle catchHandle = mf.append(factory.createNew(exceptionClassName));

        // This stuff can make my head spin, so let's map it out a little.
        // CCE = ClassCastException, ARE = ApplicationRuntimeException

        // Stack: CCE, ARE --> ARE, CCE, ARE

        mf.append(InstructionConstants.DUP_X1);

        // Stack: ARE, CCE, ARE -> ARE, ARE, CCE

        mf.append(InstructionConstants.SWAP);

        mf.append(
            factory.createInvoke(
                exceptionClassName,
                Constants.CONSTRUCTOR_NAME,
                Type.VOID,
                new Type[] { throwableType },
                Constants.INVOKESPECIAL));
View Full Code Here

        Type[] noArgs = new Type[] {
        };

        MethodFabricator mf = cf.createMethod(Constants.ACC_PUBLIC, _type, methodName);

        InstructionFactory factory = cf.getInstructionFactory();

        mf.append(factory.createThis());
        mf.append(
            factory.createInvoke(
                cf.getClassName(),
                readBindingMethodName,
                _bindingType,
                noArgs,
                Constants.INVOKEVIRTUAL));

        String accessMethodName = null;

        if (isBoolean(_type))
            accessMethodName = "getBoolean";
        else
            if (isInt(_type))
                accessMethodName = "getInt";
            else
                if (isDouble(_type))
                    accessMethodName = "getDouble";
                else
                    if (isString(_type))
                        accessMethodName = "getString";

        if (accessMethodName != null)
        {
            // The binding object is on top of the stack
            mf.append(
                factory.createInvoke(
                    IBinding.class.getName(),
                    accessMethodName,
                    _type,
                    noArgs,
                    Constants.INVOKEINTERFACE));
        }
        else
        {
            // Type is either an object type or an array type

            // To invoke getObject(parameterName, type) we need the type.
            // We mimic what Java compiler does; create a private static field
            // to store the type, and add a static initializer that invokes Class.forName.

            String fieldName = createParameterTypeField(cf);

            mf.append(new PUSH(cf.getConstantPool(), _parameterName));
            mf.append(factory.createGetStatic(cf.getClassName(), fieldName, _classType));

            mf.append(
                factory.createInvoke(
                    IBinding.class.getName(),
                    "getObject",
                    Type.OBJECT,
                    new Type[] { Type.STRING, _classType },
                    Constants.INVOKEINTERFACE));

            // ReferenceType is superclass to ObjectType and ArrayType

            mf.append(factory.createCheckCast((ReferenceType) _type));
        }

        mf.append(factory.createReturn(_type));

        mf.commit();
    }
View Full Code Here

            LOG.debug("Creating method: " + methodName);

        MethodFabricator mf = cf.createMethod(methodName);
        mf.addArgument(_type, _propertyName);

        InstructionFactory factory = cf.getInstructionFactory();

        String updateMethodName = null;
        Type argumentType = _type;

        if (isBoolean(_type))
            updateMethodName = "setBoolean";
        else
            if (isInt(_type))
                updateMethodName = "setInt";
            else
                if (isDouble(_type))
                    updateMethodName = "setDouble";
                else
                    if (isString(_type))
                        updateMethodName = "setString";
                    else
                    {
                        updateMethodName = "setObject";
                        argumentType = Type.OBJECT;
                    }

        // Get the binding

        mf.append(factory.createThis());
        mf
            .append(
                factory
                .createInvoke(cf.getClassName(), readBindingMethodName, _bindingType, new Type[] {
        }, Constants.INVOKEVIRTUAL));

        // Push the parameter value (remember,
        // parameter 0 is "this")

        mf.append(factory.createLoad(_type, 1));

        // Invoke the update method

        mf.append(
            factory.createInvoke(
                IBinding.class.getName(),
                updateMethodName,
                Type.VOID,
                new Type[] { argumentType },
                Constants.INVOKEINTERFACE));
View Full Code Here

    }

    public InstructionFactory getInstructionFactory()
    {
        if (_instructionFactory == null)
            _instructionFactory = new InstructionFactory(_classGen);

        return _instructionFactory;
    }
View Full Code Here

                AbstractLDAPSSLSocketFactory.class.getName(),
                "<generated>",
                ACC_PUBLIC | ACC_SUPER,
                null);
        ConstantPoolGen constantPoolGen = classGen.getConstantPool();
        InstructionFactory factory = new InstructionFactory(classGen);

        createSslContextStaticField(classGen, constantPoolGen);
        createGetDefaultStaticMethod(classGen, constantPoolGen, factory);

        classGen.addEmptyConstructor(Constants.ACC_PROTECTED);
View Full Code Here

  public ComplexObjectCreator(String objectType) {
    _cg = new ClassGen(objectType, "java.lang.Object", "ComplexObject.java", ACC_PUBLIC | ACC_SUPER, new String[] { "com.betfair.cougar.api.Result" });

    _cp = _cg.getConstantPool();
    _factory = new InstructionFactory(_cg, _cp);
    this.objectType = objectType;
  }
View Full Code Here

                break;
            }
        }
        final ConstantPoolGen cpg = cg.getConstantPool();
        final String className = cg.getClassName();
        final InstructionFactory factory = new InstructionFactory(cg);

        final Set callerSideJoinPoints = new HashSet();

        Method clInitMethod = null;
        final Map methodSequences = new HashMap();
View Full Code Here

            return;
        }
        m_transformed.add(cg.getClassName());

        final ConstantPoolGen cpg = cg.getConstantPool();
        final InstructionFactory factory = new InstructionFactory(cg);
        addIntroductions(context, cg, cpg, factory);
    }
View Full Code Here

        if (classFilter(classMetaData, cg)) {
            return;
        }

        final InstructionFactory factory = new InstructionFactory(cg);
        final ConstantPoolGen cpg = cg.getConstantPool();
        final Method[] methods = cg.getMethods();

        // get the index for the <clinit> method (if there is one)
        boolean noClinitMethod = true;
View Full Code Here

TOP

Related Classes of org.apache.bcel.generic.InstructionFactory$MethodObject

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.