Changeset 2268


Ignore:
Timestamp:
Jan 22, 2007, 3:24:44 PM (14 years ago)
Author:
yura
Message:

Using ClassAdapter?. Methods are empty.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/java/org/refal/plus/wrapgen/WrapGen.java

    r2266 r2268  
    22import java.io.FileInputStream;
    33import java.io.FileOutputStream;
    4 import org.objectweb.asm.*;
     4import org.objectweb.asm.ClassAdapter;
     5import org.objectweb.asm.ClassReader;
     6import org.objectweb.asm.ClassVisitor;
    57import org.objectweb.asm.ClassWriter;
     8import org.objectweb.asm.FieldVisitor;
     9import org.objectweb.asm.MethodVisitor;
     10import org.objectweb.asm.Opcodes;
    611
    7 public class WrapGen extends ClassWriter {
    8         String name;
     12public class WrapGen extends ClassAdapter {
     13        public String name;
    914
    10         public WrapGen (String name) {
    11                 super(0);
    12                 this.name = name;
     15        public WrapGen (ClassVisitor cv) {
     16                super(cv);
    1317        }
    1418       
    1519        public void visit (int version, int access, String name, String signature, String superName, String[] interfaces) {
    16                 super.visit(version, access, this.name, signature, superName, interfaces);
     20                this.name = "org/refal/plus/javawrap/"+name;
     21                super.visit(version, access, this.name, signature, name, null);
    1722        }
    1823
     
    2631       
    2732        public MethodVisitor visitMethod (int access, String name, String desc, String signature, String[] exceptions) {
    28                 MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC+Opcodes.ACC_STATIC, name, desc, signature, new String[] {"org.refal.plus.RefalException"});
     33                if ((access & Opcodes.ACC_PUBLIC)==0)
     34                        return null;
     35                MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC+Opcodes.ACC_STATIC, name, desc, signature, new String[] {"org/refal/plus/RefalException"});
    2936                mv.visitCode();
    30                 mv.visitEnd();
     37                mv.visitInsn(Opcodes.ACONST_NULL);
     38                mv.visitInsn(Opcodes.ARETURN);
     39                mv.visitMaxs(0,0);
     40                mv.visitEnd();         
    3141                return null;
    3242        }
     
    3444        public static void main(String[] args) throws Exception {
    3545                String in = args[0];
    36                 String out = args[1];
    3746                FileInputStream ins = new FileInputStream(in);
    38                 FileOutputStream outs = new FileOutputStream(out);
    3947                ClassReader cr = new ClassReader(ins);
    40                 ClassWriter cw = new WrapGen(out.replaceAll(".class", ""));
    41                 cr.accept(cw, 0);
     48                ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES+ClassWriter.COMPUTE_MAXS);
     49                WrapGen wg = new WrapGen(cw);
     50                cr.accept(wg, 0);
     51                FileOutputStream outs = new FileOutputStream(wg.name.replaceFirst(".*/", "")+".class");
    4252                outs.write(cw.toByteArray());
    4353        }
Note: See TracChangeset for help on using the changeset viewer.