Java 类org.apache.bcel.generic.InstructionFactory 实例源码

项目:JRemoting    文件:BcelStubGenerator.java   
/**
 * Method createAndInitializeClass.
 * This method starts creating the class.
 *
 * @param generatedClassName the stub class name
 * @param facadeToStubify
 */
protected void createNewClassDeclaration(String generatedClassName, PublicationItem[] facadesToStubify) {

    String[] facades = new String[facadesToStubify.length + 1];
    for (int i = 0; i < facadesToStubify.length; i++) {
        PublicationItem publicationDescriptionItem = facadesToStubify[i];
        facades[i] = publicationDescriptionItem.getFacadeClass().getName();
    }
    facades[facadesToStubify.length] = "org.codehaus.jremoting.client.Stub";


    classGen = new ClassGen(generatedClassName, "java.lang.Object", generatedClassName + ".java", Constants.ACC_PUBLIC | Constants.ACC_SUPER | Constants.ACC_FINAL, facades);
    constantsPool = classGen.getConstantPool();
    factory = new InstructionFactory(classGen, constantsPool);
    internalFieldRepresentingClasses = new ArrayList<String>();

}
项目:JRemoting    文件:BcelStubGenerator.java   
/**
 * Creates a method class$(String) which is used
 * during SomeClass.class instruction
 *
 * @param generatedClassName the instance class name
 */
protected void createHelperMethodForDotClassCalls(String generatedClassName) {
    InstructionList il = new InstructionList();
    MethodGen method = new MethodGen(Constants.ACC_STATIC, new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, new String[]{"arg0"}, "class$", generatedClassName, il, constantsPool);
    InstructionHandle ih0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
    il.append(factory.createInvoke("java.lang.Class", "forName", new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, Constants.INVOKESTATIC));
    InstructionHandle ih4 = il.append(InstructionFactory.createReturn(Type.OBJECT));
    InstructionHandle ih5 = il.append(InstructionFactory.createStore(Type.OBJECT, 1));
    il.append(factory.createNew("java.lang.NoClassDefFoundError"));
    il.append(InstructionConstants.DUP);
    il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
    il.append(factory.createInvoke("java.lang.Throwable", "getMessage", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
    il.append(factory.createInvoke("java.lang.NoClassDefFoundError", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL));
    il.append(InstructionConstants.ATHROW);
    method.addExceptionHandler(ih0, ih4, ih5, new ObjectType("java.lang.ClassNotFoundException"));
    method.setMaxStack();
    method.setMaxLocals();
    classGen.addMethod(method.getMethod());
    il.dispose();
}
项目:JRemoting    文件:BcelStubGenerator.java   
private void generateEqualsMethod(String generatedClassName) {

        /* public boolean equals(Object o) {
         *   return stubHelper.isEquals(this,o);
         * }
         */

        InstructionList il = new InstructionList();
        MethodGen method = new MethodGen(Constants.ACC_PUBLIC, Type.BOOLEAN, new Type[]{Type.OBJECT}, new String[]{"arg0"}, "equals", generatedClassName, il, constantsPool);

        il.append(InstructionFactory.createLoad(Type.OBJECT, 0));

        il.append(factory.createFieldAccess(generatedClassName, "stubHelper", new ObjectType("org.codehaus.jremoting.client.StubHelper"), Constants.GETFIELD));
        il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
        il.append(InstructionFactory.createLoad(Type.OBJECT, 1));

        il.append(factory.createInvoke("org.codehaus.jremoting.client.StubHelper", "isEquals", Type.BOOLEAN, new Type[]{Type.OBJECT, Type.OBJECT}, Constants.INVOKEINTERFACE));
        il.append(InstructionFactory.createReturn(Type.INT));
        method.setMaxStack();
        method.setMaxLocals();
        classGen.addMethod(method.getMethod());
        il.dispose();
    }
项目:autodao    文件:DAOAnalysis.java   
protected void addTransactionMethod(ParsedMethod pm) {
    String et = EntityTransaction.class.getCanonicalName();

    GeneratedMethod gm = new GeneratedMethod(pm);
    InstructionList il = gm.start();

    writeMethodPreamble(gm, il);
    il.append(_factory.createInvoke(EM_TYPE, "getTransaction",
        new ObjectType(et), Type.NO_ARGS, Constants.INVOKEINTERFACE));
    il.append(_factory.createInvoke(et, pm.getMethod().getName(),
        Type.VOID, Type.NO_ARGS, Constants.INVOKEINTERFACE));

    il.append(InstructionFactory.createReturn(Type.VOID));

    gm.done();
}
项目:autodao    文件:DAOAnalysis.java   
protected void addPassThruMethod(ParsedMethod m) {
    GeneratedMethod gm = new GeneratedMethod(m);
    InstructionList il = gm.start();
    Type returnType = gm.getReturnType();

    boolean hasArg = m.getArgumentLength() > 0;

    writeMethodPreamble(gm, il);
    if (hasArg)
        il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
    il.append(_factory.createInvoke(EM_TYPE, m.getMethod().getName(),
        returnType == Type.VOID ? Type.VOID : Type.OBJECT,
        hasArg ? new Type[] { Type.OBJECT } : Type.NO_ARGS,
        Constants.INVOKEINTERFACE));

    if (returnType != Type.VOID) {
        il.append(_factory.createCheckCast(((ReferenceType) returnType)));
    }
    il.append(InstructionFactory.createReturn(returnType));

    gm.done();
}
项目:autodao    文件:DAOAnalysis.java   
protected void addFindMethod(ParsedMethod m) {
    GeneratedMethod gm = new GeneratedMethod(m);
    InstructionList il = gm.start();

    writeMethodPreamble(gm, il);
    il.append(new PUSH(_cp, (ObjectType) gm.getReturnType()));

    m.getArguments()[0].pushAsObject(il);

    il.append(_factory.createInvoke(EM_TYPE, "find", Type.OBJECT,
        new Type[] { Type.CLASS, Type.OBJECT }, Constants.INVOKEINTERFACE));

    il.append(_factory.createCheckCast(((ReferenceType) gm.getReturnType())));
    il.append(InstructionFactory.createReturn(gm.getReturnType()));

    gm.done();
}
项目:eclectic    文件:CommonGen.java   
public void generateGetModel(Variable v, GenScope scope) {
    InstructionList il       = scope.getInstructionList();
    InstructionFactory ifact = scope.getInstructionFactory();

    try {
        String modelName = Processor.getModel(v, scope.getTransformationContext()).getModelName();
        generateGetModel(modelName, il, ifact, scope);
    } catch ( IdcException e ) {
        // System.out.println("Warning: " + e.getMessage());

        // no model found! -> obtain model dynamically
        generateGetModelManager(il, ifact, scope.getTransformationContext(), scope);

        // get the namespace for the EObject
        scope.loadVariable(v, il);
        il.append(ifact.createInvoke(DefaultTypes.ModelManager.getClassName(),
                "getNamespace", DefaultTypes.IModel, 
                new Type[] { ObjectType.OBJECT },
                Constants.INVOKEVIRTUAL));
    }
}
项目:eclectic    文件:RegularModelStrategy.java   
/**
 * <<GET_IMODEL(THIS)>> 
 * LDC className
    * INVOKEINTERFACE createObject
 */
@Override
public void genCreate(Create c, GenScope scope) {
    InstructionList il       = scope.getInstructionList();
    InstructionFactory ifact = scope.getInstructionFactory();
    ConstantPoolGen cpg      = scope.getConstantPool();

    // generate model access
    scope.generateGetModel(modelName);
    // CommonGen.generateGetModel(modelName, il, ifact, scope.getTransformationContext() );

    // push className
    il.append(new LDC(cpg.addString(c.getClassName())));

    // invoke
    il.append(ifact.createInvoke(DefaultTypes.IModel.getClassName(),
                "createObject", Type.OBJECT, 
                new Type[] { Type.STRING },
                DefaultTypes.IModelCall));

}
项目:eclectic    文件:ApiModelStrategy.java   
private void castIfNeeded(InstructionList il, InstructionFactory ifact, String paramType) {
    if ( paramType.equals("boolean") ) {
        il.append(ifact.createCheckCast(new ObjectType(Boolean.class.getName())));  
        il.append(ifact.createInvoke(Boolean.class.getName(), "booleanValue", Type.BOOLEAN,  Type.NO_ARGS, Constants.INVOKEVIRTUAL));           
    } else if ( paramType.equals("double") ) {
            il.append(ifact.createCheckCast(new ObjectType(Double.class.getName())));   
            il.append(ifact.createInvoke(Double.class.getName(), "doubleValue", Type.DOUBLE,  Type.NO_ARGS, Constants.INVOKEVIRTUAL));
    } else if ( paramType.equals("int") ) {
        il.append(ifact.createInvoke(DefaultTypes.RuntimeUtil.getClassName(), "convertInt", Type.INT, new Type[] { Type.OBJECT }, Constants.INVOKESTATIC));
        //il.append(ifact.createCheckCast(new ObjectType(Integer.class.getName())));    
        //il.append(ifact.createInvoke(Integer.class.getName(), "intValue", Type.INT,  Type.NO_ARGS, Constants.INVOKEVIRTUAL));
    } else {
        ObjectType objectType = new ObjectType(paramType);
        il.append(ifact.createCheckCast(objectType));   
    }
}
项目:eclectic    文件:GetJVMGen.java   
private void appendMethodCall(GenScope scope, InstructionList il, InstructionFactory ifact) {
    MethodCallJVMGen gen = new MethodCallJVMGen();
    gen.setColumn( getColumn() );
    gen.setRow( getRow() );
    gen.setFile( getFile() );
    gen.setName( this.getName() );
    gen.setReceptor( this.getReceptor() );
    gen.setMethodName( this.getFeatureName() );

    gen.generateWithNoVar(scope);

    // calling MethodHandler.execute(Object receptor, String methodName, IModel model)
    /*
    il.append(ifact.createInvoke(DefaultTypes.MethodCallHandler.getClassName(),
            "execute", Type.OBJECT, new Type[] { 
                    DefaultTypes.IModel, Type.OBJECT, Type.STRING
                    }, Constants.INVOKESTATIC));        
    */
}
项目:eclectic    文件:QEmitJVMGen.java   
@Override
public void generate(GenScope scope) {
    QueueJVMGen jvmQ = (QueueJVMGen) this.getQueue();

    // Load the closure into 
    InstructionList il       = scope.getInstructionList();
    InstructionFactory ifact = scope.getInstructionFactory();       

    // Get the queue
    CommonGen.generateGetQueue(scope, jvmQ);

    // Register the closure     
    scope.loadVariable(this.getValue(), il);
    il.append(ifact.createInvoke(jvmQ.getClassName(),
            "put", Type.VOID, new Type[] { Type.OBJECT }, Constants.INVOKEVIRTUAL));
}
项目:eclectic    文件:RequiredQueueJVMGen.java   
@Override
public void generateInitField(InstructionList il, InstructionFactory ifact, GenScope scope) {
    RequiredQueueJVMGen jvmQ = this;
    ClassGen cg = scope.getClassGen();

    il.append(ifact.createNew(jvmQ.getType().getClassName()));
    il.append(new DUP());       

    il.append(ifact.createConstant(jvmQ.getName()));
    // il.append(InstructionConstants.THIS); 
    /*
    il.append(ifact.createInvoke(jvmQ.getClassName(), "<init>",
                Type.VOID, new Type[] { Type.STRING, DefaultTypes.QoolTransformation }, Constants.INVOKESPECIAL));              
    */
    // required queues do not take a qool transformation, but just delegates in one
    il.append(ifact.createInvoke(jvmQ.getClassName(), "<init>",
            Type.VOID, new Type[] { Type.STRING }, Constants.INVOKESPECIAL));               

    // Set the field
    il.append(InstructionConstants.THIS); 
    il.append(InstructionConstants.SWAP); 

    il.append( ifact.createPutField(cg.getClassName(), jvmQ.getFieldName(), jvmQ.getType()) );      
}
项目:eclectic    文件:RequiredQueueJVMGen.java   
public void generateConfigure(InstructionList il, InstructionFactory ifact, GenScope scope) {
    RequiredQueueJVMGen jvmQ = this;
    ClassGen cg = scope.getClassGen();

    // Set the delegate
    // 1. Get the transformation (as a model)
    // 2. Obtain the queue
    il.append( InstructionFactory.THIS );
    il.append( ifact.createGetField(cg.getClassName(), jvmQ.getFieldName(), jvmQ.getType()) );      
    scope.generateGetModel(getImportedModel().getName());
    il.append(ifact.createCheckCast(DefaultTypes.QoolTransformation));
    il.append(ifact.createConstant(this.getName()));
    il.append(ifact.createInvoke(DefaultTypes.QoolTransformation.getClassName(), "getQueue",
                DefaultTypes.IQueue, new Type[] { Type.STRING }, Constants.INVOKEVIRTUAL));
    //CommonGen.print(il, ifact);

    il.append(ifact.createInvoke(jvmQ.getClassName(), "setDelegate",
            Type.VOID, new Type[] { DefaultTypes.IQueue }, Constants.INVOKEVIRTUAL));               

}
项目:eclectic    文件:QForAllJVMGen.java   
@Override
public void generate(GenScope scope) {
    QueueJVMGen jvmQ = (QueueJVMGen) this.getQueue();

    // Generate a closure that will be called 
    QForAllContents closureGen = new QForAllContents();
    closureGen.generate(scope);

    // Load the closure into 
    InstructionList il       = scope.getInstructionList();
    InstructionFactory ifact = scope.getInstructionFactory();       

    // Get the queue
    // TODO: I need to find out a better way of getting the transformation
    //       because when I put some class that is not a closure and the code need
    //       the transformation this just does not work (and fail in the validation with 
    //       "incompatible argument for function call" !
    scope.generateGetTransformation();
    il.append(ifact.createCheckCast(new ObjectType(scope.getTransformationContext().getRuntimeClassName())));       
    il.append(ifact.createGetField(scope.getTransformationContext().getRuntimeClassName(), jvmQ.getFieldName(), jvmQ.getType()));

    // Register the closure      org.eclectic.idc.jvm.runtime
    scope.loadVariable(closureGen, il);
    il.append(ifact.createInvoke(jvmQ.getType().getClassName(),
            "requestAll", Type.VOID, new Type[] { DefaultTypes.IClosure }, Constants.INVOKEVIRTUAL));
}
项目:eclectic    文件:QoolTransformationJVMGen.java   
private void createObserverCreatorMethod(ClassGen cg, ObserverDescription observer, String observerClassName) {
    final String methodName = "create" + observer.getName();
    InstructionList il = new InstructionList();
    InstructionFactory ifact = new InstructionFactory(cg);
    MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, new ObjectType(observerClassName), new Type[] { } , null, methodName,
               cg.getClassName(), il, cg.getConstantPool());

    il.append(ifact.createNew(observerClassName));
    il.append(InstructionConstants.DUP);
    il.append(InstructionConstants.THIS);
    il.append(ifact.createInvoke(observerClassName, "<init>",
            Type.VOID, new Type[] { DefaultTypes.QoolTransformation }, Constants.INVOKESPECIAL));

    il.append(InstructionFactory.ARETURN);  

    mg.setMaxLocals();
    mg.setMaxStack();

    cg.addMethod(mg.getMethod());       
}
项目:eclectic    文件:LocalQueueJVMGen.java   
@Override
public void generateInitField(InstructionList il, InstructionFactory ifact, GenScope scope) {
    LocalQueueJVMGen jvmQ = this;
    ClassGen cg = scope.getClassGen();

    il.append(ifact.createNew(jvmQ.getType().getClassName()));
    il.append(new DUP());       

    il.append(ifact.createConstant(jvmQ.getName()));
    il.append(InstructionConstants.THIS); 
    il.append(ifact.createInvoke(jvmQ.getClassName(), "<init>",
                Type.VOID, new Type[] { Type.STRING, DefaultTypes.QoolTransformation }, Constants.INVOKESPECIAL));              

    // Stack: queue
    il.append(InstructionConstants.THIS); 
    il.append(InstructionConstants.SWAP); 

    il.append( ifact.createPutField(cg.getClassName(), jvmQ.getFieldName(), jvmQ.getType()) );      
}
项目:eclectic    文件:LocalQueueJVMGen.java   
@Override
public void generateConfigureOptimizations(InstructionList il, InstructionFactory ifact, GenScope scope) {
    if ( getOptimizations().size() > 1 ) throw new UnsupportedOperationException("Only one optimization at a time supported by now");
    if ( getOptimizations().size() == 1 ) {
        AccessByFeatureOptimization opt = (AccessByFeatureOptimization) getOptimizations().get(0);

        il.append(new DUP());       
        il.append(ifact.createConstant(opt.getFeatureName()));
        il.append(ifact.createInvoke(this.getClassName(), "configureAccessByFeatureOptimization",
                Type.VOID, new Type[] { Type.STRING }, Constants.INVOKEVIRTUAL));               

        // TODO: Configure if the access is speculative...
    }


    // Sets the model of the queue statically
    // It is compulsory to have a type for the queue to enable optimizations
    if ( getOptimizations().size() > 0 ) {
        il.append(new DUP());   
        scope.generateGetModel(this.getType_().getModel().getName());
        il.append(ifact.createInvoke(this.getClassName(), "setModel",
                Type.VOID, new Type[] { DefaultTypes.IModel }, Constants.INVOKEVIRTUAL));               
    }
}
项目:eclectic    文件:QoolSegmentJVMGen.java   
public void genContinuableCallCode(GenScope transformationScope, ClassGen cg, MethodGen mg) {
    InstructionList il = mg.getInstructionList();
    InstructionFactory ifact = new InstructionFactory(cg);

    il.append(InstructionConstants.THIS);
    il.append(ifact.createConstant(getSegmentClassName()));
    transformationScope.generateGetTransformation();
    transformationScope.generateGetModelManager();
    il.append(ifact.createInvoke(DefaultTypes.QoolTransformation.getClassName(), "startSegment",
            Type.VOID, new Type[] { Type.STRING, DefaultTypes.IdcTransformation, DefaultTypes.ModelManager }, Constants.INVOKEVIRTUAL));        

    /*
    il.append(ifact.createConstant(getSegmentClassName()));
    transformationScope.generateGetTransformation();
    transformationScope.generateGetModelManager();
    il.append(ifact.createInvoke(DefaultTypes.RuntimeUtil.getClassName(), "startSegment",
            Type.VOID, new Type[] { Type.STRING, DefaultTypes.IdcTransformation, DefaultTypes.ModelManager }, Constants.INVOKESTATIC));     
    */
}
项目:eclectic    文件:MethodLibraryJVMGen.java   
private void createStartMethod(GenScope scope, ClassGen cg) {
    InstructionList il = new InstructionList();
    InstructionFactory ifact = new InstructionFactory(cg);

    MethodGen startMg = new MethodGen(Constants.ACC_PUBLIC,// access flags
            Type.VOID, // return type
            null, null, // arg
            // names
            START_METHOD, null, // method, class
            il, cg.getConstantPool());
    scope.processMethod(startMg);       
    il.append(InstructionConstants.RETURN);

    startMg.setMaxLocals();
    startMg.setMaxStack();

    cg.addMethod(startMg.getMethod());      
}
项目:root4j    文件:TLeafORep.java   
public void generateReadCode(InstructionList il, InstructionFactory factory, ConstantPoolGen cp, String className)
{
   String leafClassName = getClass().getName();
   int arrayDim = getArrayDim();
   if (arrayDim == 0)
      il.append(factory.createInvoke(leafClassName, "getValue", Type.BOOLEAN, new Type[]
            {
               Type.LONG
            }, INVOKEVIRTUAL));
   else
      il.append(factory.createInvoke(leafClassName, "getWrappedValue", Type.OBJECT, new Type[]
            {
               Type.LONG
            }, INVOKEVIRTUAL));
}
项目:root4j    文件:TLeafFRep.java   
public void generateReadCode(InstructionList il, InstructionFactory factory, ConstantPoolGen cp, String className)
{
   String leafClassName = getClass().getName();
   int arrayDim = getArrayDim();
   if (arrayDim == 0)
      il.append(factory.createInvoke(leafClassName, "getValue", Type.FLOAT, new Type[]
            {
               Type.LONG
            }, INVOKEVIRTUAL));
   else
      il.append(factory.createInvoke(leafClassName, "getWrappedValue", Type.OBJECT, new Type[]
            {
               Type.LONG
            }, INVOKEVIRTUAL));
}
项目:root4j    文件:TLeafDRep.java   
public void generateReadCode(InstructionList il, InstructionFactory factory, ConstantPoolGen cp, String className)
{
   String leafClassName = getClass().getName();
   int arrayDim = getArrayDim();
   if (arrayDim == 0)
      il.append(factory.createInvoke(leafClassName, "getValue", Type.DOUBLE, new Type[]
            {
               Type.LONG
            }, INVOKEVIRTUAL));
   else
      il.append(factory.createInvoke(leafClassName, "getWrappedValue", Type.OBJECT, new Type[]
            {
               Type.LONG
            }, INVOKEVIRTUAL));
}
项目:root4j    文件:TLeafBRep.java   
public void generateReadCode(InstructionList il, InstructionFactory factory, ConstantPoolGen cp, String className)
{
   String leafClassName = getClass().getName();
   int arrayDim = getArrayDim();
   if (arrayDim == 0)
      il.append(factory.createInvoke(leafClassName, "getValue", Type.BYTE, new Type[]
            {
               Type.LONG
            }, INVOKEVIRTUAL));
   else
      il.append(factory.createInvoke(leafClassName, "getWrappedValue", Type.OBJECT, new Type[]
            {
               Type.LONG
            }, INVOKEVIRTUAL));
}
项目:root4j    文件:TLeafSRep.java   
public void generateReadCode(InstructionList il, InstructionFactory factory, ConstantPoolGen cp, String className)
{
   String leafClassName = getClass().getName();
   int arrayDim = getArrayDim();
   if (arrayDim == 0)
      il.append(factory.createInvoke(leafClassName, "getValue", Type.SHORT, new Type[]
            {
               Type.LONG
            }, INVOKEVIRTUAL));
   else
      il.append(factory.createInvoke(leafClassName, "getWrappedValue", Type.OBJECT, new Type[]
            {
               Type.LONG
            }, INVOKEVIRTUAL));
}
项目:root4j    文件:TLeafIRep.java   
public void generateReadCode(InstructionList il, InstructionFactory factory, ConstantPoolGen cp, String className)
{
   String leafClassName = getClass().getName();
   int arrayDim = getArrayDim();
   if (arrayDim == 0)
      il.append(factory.createInvoke(leafClassName, "getValue", Type.INT, new Type[]
            {
               Type.LONG
            }, INVOKEVIRTUAL));
   else
      il.append(factory.createInvoke(leafClassName, "getWrappedValue", Type.OBJECT, new Type[]
            {
               Type.LONG
            }, INVOKEVIRTUAL));
}
项目:root4j    文件:TLeafCRep.java   
public void generateReadCode(InstructionList il, InstructionFactory factory, ConstantPoolGen cp, String className)
{
   String leafClassName = getClass().getName();
   int arrayDim = getArrayDim();
   if (arrayDim == 0)
      il.append(factory.createInvoke(leafClassName, "getValue", Type.STRING, new Type[]
            {
               Type.LONG
            }, INVOKEVIRTUAL));
   else
      il.append(factory.createInvoke(leafClassName, "getWrappedValue", Type.OBJECT, new Type[]
            {
               Type.LONG
            }, INVOKEVIRTUAL));
}
项目:root4j    文件:TLeafLRep.java   
public void generateReadCode(InstructionList il, InstructionFactory factory, ConstantPoolGen cp, String className)
{
   String leafClassName = getClass().getName();
   int arrayDim = getArrayDim();
   if (arrayDim == 0)
      il.append(factory.createInvoke(leafClassName, "getValue", Type.LONG, new Type[]
            {
               Type.LONG
            }, INVOKEVIRTUAL));
   else
      il.append(factory.createInvoke(leafClassName, "getWrappedValue", Type.OBJECT, new Type[]
            {
               Type.LONG
            }, INVOKEVIRTUAL));
}
项目:root4j    文件:TArrayF.java   
protected void generateStreamer(ConstantPoolGen cp, InstructionList il, InstructionFactory factory, String className, boolean hasHeader)
{
   il.append(InstructionConstants.ALOAD_0);
   il.append(InstructionConstants.ALOAD_1);
   il.append(InstructionConstants.DUP2);
   il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readInt", Type.INT, Type.NO_ARGS, INVOKEINTERFACE));
   il.append(InstructionConstants.DUP_X1);
   il.append(factory.createPutField(className, "fN", Type.INT));
   il.append(new NEWARRAY(Type.FLOAT));
   il.append(InstructionConstants.DUP_X1);
   il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readFixedArray", Type.VOID, arrayArgType, INVOKEINTERFACE));
   il.append(factory.createPutField(className, "fArray", RootType.FLOATARRAY));
}
项目:root4j    文件:TArrayC.java   
protected void generateStreamer(ConstantPoolGen cp, InstructionList il, InstructionFactory factory, String className, boolean hasHeader)
{
   il.append(InstructionConstants.ALOAD_0);
   il.append(InstructionConstants.ALOAD_1);
   il.append(InstructionConstants.DUP2);
   il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readInt", Type.INT, Type.NO_ARGS, INVOKEINTERFACE));
   il.append(InstructionConstants.DUP_X1);
   il.append(factory.createPutField(className, "fN", Type.INT));
   il.append(new NEWARRAY(Type.CHAR));
   il.append(InstructionConstants.DUP_X1);
   il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readFixedArray", Type.VOID, arrayArgType, INVOKEINTERFACE));
   il.append(factory.createPutField(className, "fArray", RootType.CHARARRAY));
}
项目:root4j    文件:TArrayD.java   
protected void generateStreamer(ConstantPoolGen cp, InstructionList il, InstructionFactory factory, String className, boolean hasHeader)
{
   il.append(InstructionConstants.ALOAD_0);
   il.append(InstructionConstants.ALOAD_1);
   il.append(InstructionConstants.DUP2);
   il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readInt", Type.INT, Type.NO_ARGS, INVOKEINTERFACE));
   il.append(InstructionConstants.DUP_X1);
   il.append(factory.createPutField(className, "fN", Type.INT));
   il.append(new NEWARRAY(Type.DOUBLE));
   il.append(InstructionConstants.DUP_X1);
   il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readFixedArray", Type.VOID, arrayArgType, INVOKEINTERFACE));
   il.append(factory.createPutField(className, "fArray", RootType.DOUBLEARRAY));
}
项目:root4j    文件:TArrayI.java   
protected void generateStreamer(ConstantPoolGen cp, InstructionList il, InstructionFactory factory, String className, boolean hasHeader)
{
   il.append(InstructionConstants.ALOAD_0);
   il.append(InstructionConstants.ALOAD_1);
   il.append(InstructionConstants.DUP2);
   il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readInt", Type.INT, Type.NO_ARGS, INVOKEINTERFACE));
   il.append(InstructionConstants.DUP_X1);
   il.append(factory.createPutField(className, "fN", Type.INT));
   il.append(new NEWARRAY(Type.INT));
   il.append(InstructionConstants.DUP_X1);
   il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readFixedArray", Type.VOID, arrayArgType, INVOKEINTERFACE));
   il.append(factory.createPutField(className, "fArray", RootType.INTARRAY));
}
项目:root4j    文件:GenericRootClass.java   
void generateReadCode(InstructionList il, InstructionFactory factory, ConstantPoolGen cp)
{
   il.append(new LDC(cp.addString(name)));
   il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readObject", rootObjectType, new Type[]
         {
            Type.STRING
         }, INVOKEINTERFACE));
   il.append(factory.createCast(rootObjectType, getJavaType()));
}
项目:root4j    文件:StreamerInfoString.java   
public void generateReadCode(InstructionList il, InstructionFactory factory, ConstantPoolGen cp, String className)
{
   if (pointer)
   {
      ((GenericRootClass) varClass).generateReadPointerCode(il, factory, cp);
   }
   else if (dim == 0)
   {
      varClass.generateReadCode(il, factory, cp);
   }
   else if (varCounter == null)
   {
      ((IntrinsicRootClass) varClass).generateReadArrayCode(il, factory, cp, 1, new int[]{index});
   }
   else 
   {
      BasicMember varMember = getMember(varCounter);
      if (varMember == null) throw new RuntimeException("Cannot find variable counter "+varCounter);
      Type varMemberType = varMember.getJavaType();
      il.append(InstructionConstants.ALOAD_0);
      il.append(factory.createInvoke(className, nameMangler.mangleMember(varCounter), varMemberType, Type.NO_ARGS, INVOKESPECIAL));
      if (varMemberType != Type.INT  &&  varMemberType != Type.BYTE  &&  varMemberType != Type.CHAR  &&  varMemberType != Type.SHORT)
          il.append(factory.createCast(varMemberType, Type.INT));

      BasicType type = (BasicType) varClass.getJavaType();
      il.append(new NEWARRAY(type));
      il.append(InstructionConstants.DUP_X1);

      Type[] arrayArgType = new Type[] { new ArrayType(type, 1) };
      il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readFixedArray", Type.VOID, arrayArgType, INVOKEINTERFACE));
   }
   if (varClass.getConvertMethod() != null)
   {
      il.append(factory.createInvoke("org.dianahep.root4j.interfaces." + varClass.getClassName(), varClass.getConvertMethod(), varClass.getJavaTypeForMethod(), Type.NO_ARGS, INVOKEINTERFACE));
   }
}
项目:root4j    文件:CloneLeaf.java   
public void generateReadCode(InstructionList il, InstructionFactory factory, ConstantPoolGen cp, String className)
{
   String leafClassName = getClass().getName();
   il.append(factory.createInvoke(leafClassName, "getValue", Type.OBJECT, new Type[]
         {
            Type.LONG
         }, INVOKEVIRTUAL));
}
项目:root4j    文件:Clone2Builder.java   
private static void generateMethods(RootClass k, ConstantPoolGen cp, InstructionList il, InstructionFactory factory, ClassGen cg, String className, String clonesClassName)
{
   RootMember[] members = k.getMembers();

   for (int i = 0; i < members.length; i++)
   {
      BasicMember member = (BasicMember) members[i];

      Type type = member.getJavaType();
      Type arrayType = new ArrayType(type, 1);
      MethodGen mg = new MethodGen(ACC_PUBLIC, type, null, null, nameMangler.mangleMember(member.getName()), className, il, cp);
      il.append(InstructionConstants.ALOAD_0);
      il.append(factory.createGetField(className, "clones", new ObjectType(clonesClassName)));
      il.append(InstructionConstants.ALOAD_0);
      il.append(factory.createGetField(className, "index", Type.INT));

      il.append(factory.createInvoke(clonesClassName, nameMangler.mangleMember(member.getName()), type, new Type[]
            {
               Type.INT
            }, INVOKEVIRTUAL));

      il.append(InstructionFactory.createReturn(type));
      mg.setMaxStack();
      mg.setMaxLocals();
      cg.addMethod(mg.getMethod());
      il.dispose();
   }
}
项目:root4j    文件:IntrinsicRootClass.java   
public void generateReadArrayCode(InstructionList il, InstructionFactory factory, ConstantPoolGen cp, int dim, int[] maxIndex)
{
   for (int i = 0; i < dim; i++)
      il.append(new PUSH(cp, maxIndex[i]));
   il.append((Instruction) factory.createNewArray(type, (short) dim));
   il.append(InstructionFactory.DUP_X1);
   if (dim == 1)
      il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readFixedArray", Type.VOID, arrayArgType, INVOKEINTERFACE));
   else
      il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readMultiArray", Type.VOID, objectArrayArgType, INVOKEINTERFACE));
}
项目:JRemoting    文件:BcelStubGenerator.java   
/**
 * Method createConstructor.
 * This method adds a constructor that takes in a StubHelper Instance
 *
 * @param generatedClassName the stub class name
 */
protected void createConstructor(String generatedClassName) {
    InstructionList il = new InstructionList();
    MethodGen method = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, new Type[]{new ObjectType("org.codehaus.jremoting.client.StubHelper")}, new String[]{"arg0"}, "<init>", generatedClassName, il, constantsPool);
    il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
    il.append(factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
    il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
    il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
    il.append(factory.createFieldAccess(generatedClassName, "stubHelper", new ObjectType("org.codehaus.jremoting.client.StubHelper"), Constants.PUTFIELD));
    il.append(InstructionFactory.createReturn(Type.VOID));
    method.setMaxStack();
    method.setMaxLocals();
    classGen.addMethod(method.getMethod());
    il.dispose();
}
项目:JRemoting    文件:BcelStubGenerator.java   
/**
 * Add method
 * <pre>
 * public Long jRemotingGetReferenceID(Object factoryThatIsAsking) {
 * return stubHelper.getReference(factoryThatIsAsking);
 * }
 * </pre>
 *
 * @param generatedClassName the generated class name
 */
protected void createGetReferenceIDMethod(String generatedClassName) {
    InstructionList il = new InstructionList();
    MethodGen method = new MethodGen(Constants.ACC_PUBLIC, new ObjectType("java.lang.Long"), new Type[]{Type.OBJECT}, new String[]{"arg0"}, "jRemotingGetReferenceID", generatedClassName, il, constantsPool);
    il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
    il.append(factory.createFieldAccess(generatedClassName, "stubHelper", new ObjectType("org.codehaus.jremoting.client.StubHelper"), Constants.GETFIELD));
    il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
    il.append(factory.createInvoke("org.codehaus.jremoting.client.StubHelper", "getReference", new ObjectType("java.lang.Long"), new Type[]{Type.OBJECT}, Constants.INVOKEINTERFACE));
    il.append(InstructionFactory.createReturn(Type.OBJECT));
    method.setMaxStack();
    method.setMaxLocals();
    classGen.addMethod(method.getMethod());
    il.dispose();
}
项目:JRemoting    文件:BcelStubGenerator.java   
/**
 * Inject common exception catch blocks
 */
public void injectCommonExceptionCatchBlock(InstructionList il, MethodGen method, int variableIndex) {
    il.append(new INSTANCEOF(constantsPool.addClass(new ObjectType("java.lang.RuntimeException"))));
    BranchInstruction b1 = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
    il.append(b1);
    il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex));
    il.append(factory.createCheckCast(new ObjectType("java.lang.RuntimeException")));
    il.append(InstructionConstants.ATHROW);
    InstructionHandle ih1 = il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex));
    il.append(new INSTANCEOF(constantsPool.addClass(new ObjectType("java.lang.Error"))));
    BranchInstruction b2 = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
    il.append(b2);
    il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex));
    il.append(factory.createCheckCast(new ObjectType("java.lang.Error")));
    il.append(InstructionConstants.ATHROW);
    InstructionHandle ih2 = il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex));
    il.append(factory.createInvoke("java.lang.Throwable", "printStackTrace", Type.VOID, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
    il.append(factory.createNew("org.codehaus.jremoting.client.InvocationException"));
    il.append(InstructionConstants.DUP);
    il.append(factory.createNew("java.lang.StringBuffer"));
    il.append(InstructionConstants.DUP);
    il.append(new PUSH(constantsPool, "Should never get here: "));
    il.append(factory.createInvoke("java.lang.StringBuffer", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL));
    il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex));
    il.append(factory.createInvoke("java.lang.Throwable", "getMessage", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
    il.append(factory.createInvoke("java.lang.StringBuffer", "append", Type.STRINGBUFFER, new Type[]{Type.STRING}, Constants.INVOKEVIRTUAL));
    il.append(factory.createInvoke("java.lang.StringBuffer", "toString", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
    il.append(factory.createInvoke("org.codehaus.jremoting.client.InvocationException", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL));
    il.append(InstructionConstants.ATHROW);

    b1.setTarget(ih1);
    b2.setTarget(ih2);

}
项目:cn1    文件:JavaByteCodeOutputProcess.java   
private void createClass(Element clazz) {
    String packageName = clazz.getAttributeValue("package");
    packageName = packageName == null ? "" : packageName;
    String clazzName = clazz.getAttributeValue("name");
    String fileName = clazzName + ".java";
    fullQualifiedClassName = packageName.equals("") ? clazzName : packageName + "." + clazzName;
    String baseClazz = clazz.getAttributeValue("extends");
    // TODO Read interfaces
    String[] interfaces = new String[] {};
    short accessFlags = getAccessFlags(clazz);
    classGen = new ClassGen(fullQualifiedClassName, baseClazz, fileName, accessFlags,
            interfaces);
    constantPoolGen = classGen.getConstantPool();
    factory = new InstructionFactory(classGen, constantPoolGen);
}