Beispiel #1
0
  public void toAsm(JarOutputStream jos) {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    //        ClassWriter cw = new ClassWriter(0);
    CheckClassAdapter cca = new CheckClassAdapter(cw);

    cca.visit(version, access, name, sig, superName, interfaces);
    Iterator it = fieldVisitors.entrySet().iterator();

    while (it.hasNext()) {
      Map.Entry pairs = (Map.Entry) it.next();
      ByteCodeFieldVisitor fv = (ByteCodeFieldVisitor) pairs.getValue();
      fv.toAsm(cca);
    }

    it = methodVisitors.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry pairs = (Map.Entry) it.next();
      ByteCodeMethodVisitor mv = (ByteCodeMethodVisitor) pairs.getValue();
      mv.toAsm(cca);
    }

    byte[] bytes = cw.toByteArray();
    if (ProjectProperties.getBoolean("fortress.bytecode.verify", false)) {
      PrintWriter pw = new PrintWriter(System.out);
      CheckClassAdapter.verify(new ClassReader(bytes), true, pw);
    }
    System.out.println("About to write " + name);
    ByteCodeWriter.writeJarredClass(jos, name, bytes);
  }
Beispiel #2
0
  public void print() {
    Iterator it = fieldVisitors.entrySet().iterator();

    while (it.hasNext()) {
      Map.Entry pairs = (Map.Entry) it.next();
      System.out.println("Printing Field: " + pairs.getKey() + ":");
      ByteCodeFieldVisitor fv = (ByteCodeFieldVisitor) pairs.getValue();
      fv.print();
    }

    it = methodVisitors.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry pairs = (Map.Entry) it.next();
      ByteCodeMethodVisitor bcmv = (ByteCodeMethodVisitor) pairs.getValue();
      System.out.println("Printing Method: Key = " + pairs.getKey() + " bcmv says " + bcmv.name);

      bcmv.print();
    }
  }