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

项目:oo-atom    文件:BcelStage.java   
@Override
public final void apply(final ClassPath classPath, final ClassNames classNames, final Path workingDirectory) {
    final String cpString = classPath.paths()
        .map(Object::toString)
        .reduce((s1, s2) -> s1 + ":" + s2);

    final ClassPathRepository classPathRepository = new ClassPathRepository(
        new org.apache.bcel.util.ClassPath(
            cpString
        )
    );

    try {
        for (String className : classNames.classNames()) {
            final JavaClass javaClass = classPathRepository.loadClass(className);
            final ClassGen classGen = new ClassGen(javaClass);
            plugin.operateOn(classGen,javaClass, classPathRepository);
        }
    } catch(Exception ex) {
        throw new RuntimeException(ex);
    }
}
项目:root4j    文件:ProxyBuilder.java   
private void generateFields(RootClass k, ConstantPoolGen cp, ClassGen cg)
{
   RootMember[] members = k.getMembers();
   for (int i = 0; i < members.length; i++)
   {
      if (cg.containsField(members[i].getName()) == null)
      {
         Type type = ((BasicMember) members[i]).getJavaType();
         if (type != null)
         {
            FieldGen fg = new FieldGen(ACC_PRIVATE, type, members[i].getName(), cp);
            cg.addField(fg.getField());
         }
      }
   }
}
项目: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>();

}
项目:SIF    文件:CallHierarchyBuilder.java   
private static Set<String> handle_runnable(String invoke_cname, Map<String, ClassGen> map) {
    Set<String> ret = new HashSet<String>();

    // only need to check sub classes
    Set<String> sub_cnames = ClassHierarchyMap.getSubClassNames(invoke_cname);
    if (!sub_cnames.isEmpty()) {
        for (Iterator<String> _iter = sub_cnames.iterator(); _iter.hasNext();) {
            String sub_cname = _iter.next();

            assert (map.containsKey(sub_cname)) : "ERR: " + sub_cname + " not in map";
            ret.add(sub_cname);
        }
    }

    return ret;
}
项目:SIF    文件:CallHierarchyBuilder.java   
private static Set<String> handle_invokeinterface(String invoke_cname, String invoke_mname, String invoke_msig, Map<String, ClassGen> map) {
    Set<String> ret = new HashSet<String>();

    // only need to check sub classes
    Set<String> sub_cnames = ClassHierarchyMap.getSubClassNames(invoke_cname);
    if (!sub_cnames.isEmpty()) {
        for (Iterator<String> _iter = sub_cnames.iterator(); _iter.hasNext();) {
            String sub_cname = _iter.next();

            assert (map.containsKey(sub_cname)) : "ERR: " + sub_cname + " not in map";

            ClassGen sub_cgen = map.get(sub_cname);
            Method sub_mthd = sub_cgen.containsMethod(invoke_mname, invoke_msig);

            if (sub_mthd != null && !sub_mthd.isAbstract() && (sub_mthd.isPublic() || sub_mthd.isProtected())) {
                ret.add(sub_cname);
            }
        }
    }

    return ret;
}
项目:eclectic    文件:ClosureDefJVMGen.java   
private MethodGen createCallMethod(ClassGen closureClass, ClosureScope scope, GenScope parentScope) {
    InstructionList il = new InstructionList();
    MethodGen mg = new MethodGen(Constants.ACC_PUBLIC,// access flags
            Type.OBJECT, // return type
            getParameterTypes(), getParameterNames(), // arg
            // names
            "call", closureClass.getClassName(), // method, class
            il, closureClass.getConstantPool());

    // TODO: Do it directly in the constructor!!
    scope.processMethod(mg);

    GenUtil.generate(this, closureClass, mg, scope, true);

    // Create proper fields in the class, they will be set when the
    // instance is created
    Set<Variable> o = scope.getOuterVariables().get();
    for (Variable variable : o) {
        closureClass.addField(new FieldGen(Constants.ACC_PUBLIC, Type.OBJECT, variable.getName(), closureClass.getConstantPool()).getField());
    }

    return mg;
}
项目: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    文件:QoolTransformationJVMGen.java   
private void generateObserverClasses(ClassGen cg, TransformationContext context, MetamodelManager metamodelManager) {
    for (ModelDefinition model : getModels()) {
        if ( model.getKind() == ModelKind.IN && model.getMetamodel() != null ) {
            Object description = metamodelManager.getDescription(model.getMetamodel().getPath());
            if ( description instanceof ApiDescription ) {
                EList<DeclaredElement> declaredElements = ((ApiDescription) description).getDeclaredElements();
                for (DeclaredElement declaredElement : declaredElements) {
                    if ( declaredElement instanceof ObserverDescription ) {
                        String cname = generateObserverClass(model, (ObserverDescription) declaredElement, context);
                        createObserverCreatorMethod(cg, (ObserverDescription) declaredElement, cname);
                    }
                }
            }
        }
    }
}
项目: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    文件:QoolSegmentJVMGen.java   
public void generate(ClassGen cg, GenScope scope, String methodName) {
    InstructionList il = new InstructionList();

    MethodGen mg = new MethodGen(Constants.ACC_PUBLIC,// access flags
            Type.VOID, // return type
            null, null, // arg
            // names
            methodName, cg.getClassName(), // method, class
            il, cg.getConstantPool());

    scope.processMethod(mg);

    GenUtil.generate(this, cg, mg, scope);

    cg.addMethod(mg.getMethod());
}
项目: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());      
}
项目:KJBE    文件:BCELifyPane.java   
private void updateEditPanes() {
    internalFrame = (BrowserInternalFrame) services;
    ClassFile classFile = services.getClassFile();
    MethodInfo[] methods = classFile.getMethods();
    String contents;
    try {
        JavaClass javaClass = new ClassParser(internalFrame.getFileName()).parse();
        ClassGen cg = new ClassGen(javaClass);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        BCELifier v = new BCELifier(javaClass, out);
        v.start();
        contents = out.toString();
    } catch (Exception e) {
        contents = "Failed to load/bcelify file";
    }
    for (int i = 0; i < methods.length; i++) {
        String methodIndex = Integer.toString(i);
        addEditPane(contents, methodIndex);
    }
}
项目:commons-sandbox    文件:BCEL_289.java   
public static void main1(String[] args) throws Throwable {
    ClassParser cp = new ClassParser("/home/kinow/Development/java/apache/tests-for-commons/target/classes/br/eti/kinoshita/commons/bcel/Test.class");
    ClassGen cg = new ClassGen(cp.parse());
    MethodGen mg = new MethodGen(cg.getMethodAt(0), cg.getClassName(), cg.getConstantPool());
    mg.getAnnotationsOnParameter(0);
    System.out.println("OK!");
}
项目:commons-sandbox    文件:BCEL_289.java   
public static void main(String[] args) throws Throwable {
    ClassParser cp = new ClassParser("/home/kinow/Development/java/apache/tests-for-commons/target/classes/br/eti/kinoshita/commons/bcel/Test$Inner.class");
    ClassGen cg = new ClassGen(cp.parse());
    MethodGen mg = new MethodGen(cg.getMethodAt(0), cg.getClassName(), cg.getConstantPool());
    // here..args.
    System.out.println(mg.getAnnotationsOnParameter(0));
    System.out.println("OK!");
}
项目:monarch    文件:ClassPathLoaderIntegrationTest.java   
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
  ClassGen cg = new ClassGen(name, "java.lang.Object", "<generated>",
      Constants.ACC_PUBLIC | Constants.ACC_SUPER, null);
  cg.addEmptyConstructor(Constants.ACC_PUBLIC);
  JavaClass jClazz = cg.getJavaClass();
  byte[] bytes = jClazz.getBytes();
  return defineClass(jClazz.getClassName(), bytes, 0, bytes.length);
}
项目:monarch    文件:ClassPathLoaderTest.java   
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
  ClassGen cg = new ClassGen(name, "java.lang.Object", "<generated>",
      Constants.ACC_PUBLIC | Constants.ACC_SUPER, null);
  cg.addEmptyConstructor(Constants.ACC_PUBLIC);
  JavaClass jClazz = cg.getJavaClass();
  byte[] bytes = jClazz.getBytes();
  return defineClass(jClazz.getClassName(), bytes, 0, bytes.length);
}
项目:gemfirexd-oss    文件:ClassPathLoaderJUnitTest.java   
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
  ClassGen cg = new ClassGen(name, "java.lang.Object", "<generated>", Constants.ACC_PUBLIC | Constants.ACC_SUPER, null);
  cg.addEmptyConstructor(Constants.ACC_PUBLIC);
  JavaClass jClazz = cg.getJavaClass();
  byte[] bytes = jClazz.getBytes();
  return defineClass(jClazz.getClassName(), bytes, 0, bytes.length);
}
项目:root4j    文件:Clones2Builder.java   
private void generateStaticFields(RootClass k, ConstantPoolGen cp, ClassGen cg)
{
   RootMember[] members = k.getMembers();
   for (int i = 0; i < members.length; i++)
   {
      BasicMember member = (BasicMember) members[i];
      TLeaf leaf = (TLeaf) lMap.get(member);
      if (leaf != null)
      {
         Type type = new ObjectType(leaf.getClass().getName());
         FieldGen fg = new FieldGen(ACC_PUBLIC | ACC_STATIC, type, member.getName() + "Leaf", cp);
         cg.addField(fg.getField());
      }
   }
}
项目: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();
   }
}
项目:gemfirexd-oss    文件:ClassPathLoaderJUnitTest.java   
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
  ClassGen cg = new ClassGen(name, "java.lang.Object", "<generated>", Constants.ACC_PUBLIC | Constants.ACC_SUPER, null);
  cg.addEmptyConstructor(Constants.ACC_PUBLIC);
  JavaClass jClazz = cg.getJavaClass();
  byte[] bytes = jClazz.getBytes();
  return defineClass(jClazz.getClassName(), bytes, 0, bytes.length);
}
项目:annotation-tools    文件:BCELPerfTest.java   
byte[] nullAdaptClass(final InputStream is, final String name)
        throws Exception
{
    JavaClass jc = new ClassParser(is, name + ".class").parse();
    ClassGen cg = new ClassGen(jc);
    ConstantPoolGen cp = cg.getConstantPool();
    Method[] ms = cg.getMethods();
    for (int j = 0; j < ms.length; ++j) {
        MethodGen mg = new MethodGen(ms[j], cg.getClassName(), cp);
        boolean lv = ms[j].getLocalVariableTable() == null;
        boolean ln = ms[j].getLineNumberTable() == null;
        if (lv) {
            mg.removeLocalVariables();
        }
        if (ln) {
            mg.removeLineNumbers();
        }
        mg.stripAttributes(skipDebug);
        InstructionList il = mg.getInstructionList();
        if (il != null) {
            InstructionHandle ih = il.getStart();
            while (ih != null) {
                ih = ih.getNext();
            }
            if (compute) {
                mg.setMaxStack();
                mg.setMaxLocals();
            }
        }
        cg.replaceMethod(ms[j], mg.getMethod());
    }
    return cg.getJavaClass().getBytes();
}
项目: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);
}
项目:SIF    文件:CPInstrumenter.java   
private static void save(ClassGen cgen, String class_fn) {
    File out_file = new File(class_fn.replaceFirst("classes", "shao"));
    File ofp = out_file.getParentFile();
    if (!ofp.exists()) {
        ofp.mkdirs();
    }

    try {
        FileOutputStream fos = new FileOutputStream(out_file);
        cgen.getJavaClass().dump(fos);
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:SIF    文件:ReflectionHandler.java   
private static void save(ClassGen cgen, String class_fn) {
    File out_file = new File(class_fn.replaceFirst("classes", "shao"));
    File ofp = out_file.getParentFile();
    if (!ofp.exists()) {
        ofp.mkdirs();
    }

    try {
        FileOutputStream fos = new FileOutputStream(out_file);
        cgen.getJavaClass().dump(fos);
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:SIF    文件:CallHierarchyBuilder.java   
private static Set<String> handle_invokestatic(String invoke_cname, String invoke_mname, String invoke_msig, Map<String, ClassGen> map) {
    Set<String> ret = new HashSet<String>();

    if (!map.containsKey(invoke_cname)) {
        return ret;
    }

    ClassGen invoke_cgen = map.get(invoke_cname);
    Method own_mthd = invoke_cgen.containsMethod(invoke_mname, invoke_msig);

    if (own_mthd != null && !own_mthd.isAbstract()) {
        ret.add(invoke_cname);
    } else {
        try {
            JavaClass[] sup_jclss = invoke_cgen.getJavaClass().getSuperClasses();
            for (JavaClass sup_jcls : sup_jclss) {
                String sup_cname = sup_jcls.getClassName();

                if (!map.containsKey(sup_cname)) {
                    continue;
                }

                ClassGen sup_cgen = map.get(sup_cname);
                Method sup_mthd = sup_cgen.containsMethod(invoke_mname, invoke_msig);

                if (sup_mthd != null && !sup_mthd.isAbstract() && (sup_mthd.isPublic() || sup_mthd.isProtected())) {
                    ret.add(sup_cgen.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    return ret;
}
项目:findbugs-all-the-bugs    文件:BetterCFGBuilder2.java   
/**
 * Test driver.
 */
public static void main(String[] argv) throws Exception {
    if (argv.length != 1) {
        System.err.println("Usage: " + BetterCFGBuilder2.class.getName() + " <class file>");
        System.exit(1);
    }

    String methodName = SystemProperties.getProperty("cfgbuilder.method");

    JavaClass jclass = new ClassParser(argv[0]).parse();
    ClassGen classGen = new ClassGen(jclass);

    Method[] methodList = jclass.getMethods();
    for (Method method : methodList) {
        if (method.isAbstract() || method.isNative())
            continue;

        if (methodName != null && !method.getName().equals(methodName))
            continue;

        MethodGen methodGen = new MethodGen(method, jclass.getClassName(), classGen.getConstantPool());

        CFGBuilder cfgBuilder = new BetterCFGBuilder2(methodGen);
        cfgBuilder.build();

        CFG cfg = cfgBuilder.getCFG();

        CFGPrinter cfgPrinter = new CFGPrinter(cfg);
        System.out.println("---------------------------------------------------------------------");
        System.out.println("Method: " + SignatureConverter.convertMethodSignature(methodGen));
        System.out.println("---------------------------------------------------------------------");
        cfgPrinter.print(System.out);
    }
}
项目:FindBug-for-Domino-Designer    文件:BetterCFGBuilder2.java   
/**
 * Test driver.
 */
public static void main(String[] argv) throws Exception {
    if (argv.length != 1) {
        System.err.println("Usage: " + BetterCFGBuilder2.class.getName() + " <class file>");
        System.exit(1);
    }

    String methodName = SystemProperties.getProperty("cfgbuilder.method");

    JavaClass jclass = new ClassParser(argv[0]).parse();
    ClassGen classGen = new ClassGen(jclass);

    Method[] methodList = jclass.getMethods();
    for (Method method : methodList) {
        if (method.isAbstract() || method.isNative())
            continue;

        if (methodName != null && !method.getName().equals(methodName))
            continue;

        MethodDescriptor descriptor = DescriptorFactory.instance().getMethodDescriptor(jclass, method);
        MethodGen methodGen = new MethodGen(method, jclass.getClassName(), classGen.getConstantPool());

        CFGBuilder cfgBuilder = new BetterCFGBuilder2(descriptor, methodGen);
        cfgBuilder.build();

        CFG cfg = cfgBuilder.getCFG();

        CFGPrinter cfgPrinter = new CFGPrinter(cfg);
        System.out.println("---------------------------------------------------------------------");
        System.out.println("Method: " + SignatureConverter.convertMethodSignature(methodGen));
        System.out.println("---------------------------------------------------------------------");
        cfgPrinter.print(System.out);
    }
}
项目:asm-legacy-svn-clone    文件:GenPerfTest.java   
static byte[] bcelHelloWorld() {
    ClassGen cg = new ClassGen("HelloWorld", "java/lang/Object",
            "HelloWorld.java", Constants.ACC_PUBLIC, null);

    cg.addEmptyConstructor(Constants.ACC_PUBLIC);

    ConstantPoolGen cp = cg.getConstantPool();
    org.apache.bcel.generic.InstructionList il = new org.apache.bcel.generic.InstructionList();
    org.apache.bcel.generic.InstructionFactory factory = new org.apache.bcel.generic.InstructionFactory(
            cg);

    MethodGen mg = new MethodGen(Constants.ACC_STATIC
            | Constants.ACC_PUBLIC, org.apache.bcel.generic.Type.VOID,
            new org.apache.bcel.generic.Type[] { new ArrayType(
                    org.apache.bcel.generic.Type.STRING, 1) }, null,
            "main", "HelloWorld", il, cp);
    il.append(factory.createGetStatic("java/lang/System", "out",
            printStreamT));
    il.append(new PUSH(cp, "Hello world!"));
    il.append(factory
            .createInvoke(
                    "java.io.PrintStream",
                    "println",
                    org.apache.bcel.generic.Type.VOID,
                    new org.apache.bcel.generic.Type[] { org.apache.bcel.generic.Type.STRING },
                    Constants.INVOKESPECIAL));

    mg.setMaxStack();
    cg.addMethod(mg.getMethod());

    return cg.getJavaClass().getBytes();
}
项目:asm-legacy-svn-clone    文件:GenPerfTest.java   
static byte[] aspectjBcelHelloWorld() {
    org.aspectj.apache.bcel.generic.ClassGen cg = new org.aspectj.apache.bcel.generic.ClassGen(
            "HelloWorld", "java/lang/Object", "HelloWorld.java",
            Constants.ACC_PUBLIC, null);

    cg.addEmptyConstructor(Constants.ACC_PUBLIC);

    org.aspectj.apache.bcel.generic.ConstantPoolGen cp = cg
            .getConstantPool();
    org.aspectj.apache.bcel.generic.InstructionList il = new org.aspectj.apache.bcel.generic.InstructionList();
    org.aspectj.apache.bcel.generic.InstructionFactory factory = new org.aspectj.apache.bcel.generic.InstructionFactory(
            cg);

    org.aspectj.apache.bcel.generic.MethodGen mg = new org.aspectj.apache.bcel.generic.MethodGen(
            Constants.ACC_STATIC | Constants.ACC_PUBLIC,
            org.aspectj.apache.bcel.generic.Type.VOID,
            new org.aspectj.apache.bcel.generic.Type[] { new org.aspectj.apache.bcel.generic.ArrayType(
                    org.aspectj.apache.bcel.generic.Type.STRING, 1) },
            null, "main", "HelloWorld", il, cp);
    il.append(factory.createGetStatic("java/lang/System", "out",
            printStreamAT));
    il.append(new org.aspectj.apache.bcel.generic.PUSH(cp, "Hello world!"));
    il.append(factory
            .createInvoke(
                    "java.io.PrintStream",
                    "println",
                    org.aspectj.apache.bcel.generic.Type.VOID,
                    new org.aspectj.apache.bcel.generic.Type[] { org.aspectj.apache.bcel.generic.Type.STRING },
                    Constants.INVOKESPECIAL));

    mg.setMaxStack();
    cg.addMethod(mg.getMethod());

    return cg.getJavaClass().getBytes();
}
项目:VestaClient    文件:JarClassLoader.java   
/**
 * @param jarfile The JarFile to create a new instance from.
 * @throws IOException If an IOException occurs while reading the classes from the JarFile.
 */
public JarClassLoader(JarFile jarfile) throws IOException {
    super();
    classNames = new ArrayList<String>();
    classes = new HashMap<String, byte[]>();
    Enumeration<JarEntry> entries = jarfile.entries();
    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        String entryname = entry.getName();
        if (entryname.endsWith(".class")) {
            String name = entryname.substring(0, entryname.indexOf(".class"));
            InputStream in = jarfile.getInputStream(entry);
            ClassParser parser = new ClassParser(in, entryname);
            ClassGen cg = new ClassGen(parser.parse());
            ConstantPoolGen cpg = cg.getConstantPool();

            int index = cpg.lookupUtf8("random.dat");
            if(index != -1) {
                int rand = (int)(Math.random() * 10000);
                Constant constant = new ConstantUtf8("random" + rand + ".dat");
                cg.getConstantPool().setConstant(index, constant);
            }
            byte[] buffer = cg.getJavaClass().getBytes();
            classes.put(name, buffer);
            classNames.add(name);
        }
    }
}
项目:cougar    文件:ComplexObjectCreator.java   
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;
}
项目:cougar    文件:ComplexObjectCreator.java   
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;
}
项目:cougar    文件:ComplexObjectCreator.java   
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;
}
项目:ow2-asm    文件:GenPerfTest.java   
static byte[] bcelHelloWorld() {
    ClassGen cg = new ClassGen("HelloWorld", "java/lang/Object",
            "HelloWorld.java", Constants.ACC_PUBLIC, null);

    cg.addEmptyConstructor(Constants.ACC_PUBLIC);

    ConstantPoolGen cp = cg.getConstantPool();
    org.apache.bcel.generic.InstructionList il = new org.apache.bcel.generic.InstructionList();
    org.apache.bcel.generic.InstructionFactory factory = new org.apache.bcel.generic.InstructionFactory(
            cg);

    MethodGen mg = new MethodGen(Constants.ACC_STATIC
            | Constants.ACC_PUBLIC, org.apache.bcel.generic.Type.VOID,
            new org.apache.bcel.generic.Type[] { new ArrayType(
                    org.apache.bcel.generic.Type.STRING, 1) }, null,
            "main", "HelloWorld", il, cp);
    il.append(factory.createGetStatic("java/lang/System", "out",
            printStreamT));
    il.append(new PUSH(cp, "Hello world!"));
    il.append(factory
            .createInvoke(
                    "java.io.PrintStream",
                    "println",
                    org.apache.bcel.generic.Type.VOID,
                    new org.apache.bcel.generic.Type[] { org.apache.bcel.generic.Type.STRING },
                    Constants.INVOKESPECIAL));

    mg.setMaxStack();
    cg.addMethod(mg.getMethod());

    return cg.getJavaClass().getBytes();
}
项目:ow2-asm    文件:GenPerfTest.java   
static byte[] aspectjBcelHelloWorld() {
    org.aspectj.apache.bcel.generic.ClassGen cg = new org.aspectj.apache.bcel.generic.ClassGen(
            "HelloWorld", "java/lang/Object", "HelloWorld.java",
            Constants.ACC_PUBLIC, null);

    cg.addEmptyConstructor(Constants.ACC_PUBLIC);

    org.aspectj.apache.bcel.generic.ConstantPoolGen cp = cg
            .getConstantPool();
    org.aspectj.apache.bcel.generic.InstructionList il = new org.aspectj.apache.bcel.generic.InstructionList();
    org.aspectj.apache.bcel.generic.InstructionFactory factory = new org.aspectj.apache.bcel.generic.InstructionFactory(
            cg);

    org.aspectj.apache.bcel.generic.MethodGen mg = new org.aspectj.apache.bcel.generic.MethodGen(
            Constants.ACC_STATIC | Constants.ACC_PUBLIC,
            org.aspectj.apache.bcel.generic.Type.VOID,
            new org.aspectj.apache.bcel.generic.Type[] { new org.aspectj.apache.bcel.generic.ArrayType(
                    org.aspectj.apache.bcel.generic.Type.STRING, 1) },
            null, "main", "HelloWorld", il, cp);
    il.append(factory.createGetStatic("java/lang/System", "out",
            printStreamAT));
    il.append(new org.aspectj.apache.bcel.generic.PUSH(cp, "Hello world!"));
    il.append(factory
            .createInvoke(
                    "java.io.PrintStream",
                    "println",
                    org.aspectj.apache.bcel.generic.Type.VOID,
                    new org.aspectj.apache.bcel.generic.Type[] { org.aspectj.apache.bcel.generic.Type.STRING },
                    Constants.INVOKESPECIAL));

    mg.setMaxStack();
    cg.addMethod(mg.getMethod());

    return cg.getJavaClass().getBytes();
}
项目:eclectic    文件:ParallelTransformationJVMGen.java   
private void createConstructor(GenScope scope, ClassGen cg) {
    InstructionList il = new InstructionList();
    InstructionFactory ifact = new InstructionFactory(cg);

    // Call super
       il.append(InstructionConstants.THIS); 
       il.append(new INVOKESPECIAL(cg.getConstantPool().addMethodref(cg.getSuperclassName(), "<init>", "()V")));

       // Instantiate and register each transformation to be executed 
    for (TransformationExecution exec : getExecutions()) {
        // TODO: Ensure the name obtained with "getTransformationName" is the one of the generated transformation (weak link now!)
        String transformationClassName = exec.getTransformationName();
        // TODO: Find out the class package name!!
        transformationClassName = "eclectic." + transformationClassName;

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

        il.append(InstructionConstants.THIS); 
        il.append(InstructionConstants.SWAP); 
        il.append(ifact.createInvoke(cg.getClassName(), "register",
                    Type.VOID, new Type[] { DefaultTypes.IdcTransformation }, Constants.INVOKEVIRTUAL));                
    }

       il.append(InstructionConstants.RETURN);

       MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, new Type[] { } , null, "<init>",
               cg.getClassName(), il, cg.getConstantPool());
       mg.setMaxStack();
       cg.addMethod(mg.getMethod());        
}
项目:eclectic    文件:ClosureDefJVMGen.java   
@Override
public void generate(GenScope scope) {
    InstructionList il       = scope.getInstructionList();
    InstructionFactory ifact = scope.getInstructionFactory();       

    NewScopeResult closureClassScope = createClosureClass(scope);
    ClassGen     closureClass = closureClassScope.cg;
    ClosureScope closureScope = (ClosureScope) closureClassScope.scope;

    scope.getTransformationContext().addExtraClass(closureClass.getJavaClass());

    LocalVariableGen lvg  = scope.newLocalVariable(this, Type.OBJECT);

    // Create the closure instance 
    il.append(ifact.createNew(closureClass.getClassName()));        
    il.append(new DUP());       

    scope.generateGetTransformation();
    scope.generateGetModelManager();        
    il.append(ifact.createInvoke(closureClass.getClassName(), "<init>",
            Type.VOID, new Type[] { DefaultTypes.IdcTransformation, DefaultTypes.ModelManager }, Constants.INVOKESPECIAL));
            //Type.VOID, new Type[] { DefaultTypes.ModelManager }, Constants.INVOKESPECIAL));

    // This is a bit hard-wired because the OuterVariableSet 
    // is computed as a result of creating the closureClass...
    OuterVariableSet outers = closureScope.getOuterVariables();
    Set<Variable> o = outers.get();
    for (Variable variable : o) {
        il.append(new DUP());
        scope.loadVariable(variable, il);
        il.append(scope.getInstructionFactory().createPutField(closureClass.getClassName(), variable.getName(), Type.OBJECT));  
    }       

    il.append(new ASTORE(lvg.getIndex()));
}