public class ImplementRunnable1 implements Runnable1{
@Override
public void method() {
System.out.println("Test");
}
void Method1(){
System.out.println("hhhhh");
method() ;
}
}
package compare;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.util.*;
import org.objectweb.asm.*;
import org.objectweb.asm.attrs.*;
public class ImplementRunnable1Dump implements Opcodes {
// public static void main(String[] args) throws Exception {
//
// }
public static byte[] dump() throws Exception {
ClassWriter cw = new ClassWriter(0);
FieldVisitor fv;
MethodVisitor mv;
AnnotationVisitor av0;
cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, "compare/NoRunnable",
null, "java/lang/Object", new String[] { "compare/Runnable1" });
cw.visitSource("NoRunnable.java", null);
{
fv = cw.visitField(ACC_PRIVATE, "x", "Ljava/lang/String;", null,
null);
fv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>",
"()V");
mv.visitInsn(RETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", "Lcompare/NoRunnable;", null,
l0, l1, 0);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC, "method", "()V", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out",
"Ljava/io/PrintStream;");
mv.visitLdcInsn("Test");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println",
"(Ljava/lang/String;)V");
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitInsn(RETURN);
Label l2 = new Label();
mv.visitLabel(l2);
mv.visitLocalVariable("this", "Lcompare/NoRunnable;", null,
l0, l2, 0);
mv.visitMaxs(2, 1);
mv.visitEnd();
}
{
mv = cw.visitMethod(0, "Method1", "()V", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out",
"Ljava/io/PrintStream;");
mv.visitLdcInsn("hhhhh");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println",
"(Ljava/lang/String;)V");
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, "compare/NoRunnable",
"method", "()V");
Label l2 = new Label();
mv.visitLabel(l2);
mv.visitInsn(RETURN);
Label l3 = new Label();
mv.visitLabel(l3);
mv.visitLocalVariable("this", "Lcompare/NoRunnable;", null,
l0, l3, 0);
mv.visitMaxs(2, 1);
mv.visitEnd();
}
cw.visitEnd();
return cw.toByteArray();
}
}
package compare;
public class NoRunnable {
void Method1(){
System.out.println("i");
}
}
package compare;
public interface Runnable1 {
void method();
}
package compare;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.junit.Test;
public class TestP {
@Test
public void MethodTest() throws IOException, Exception{
ImplementRunnable1Dump d=new ImplementRunnable1Dump();
File outputDir=new File("bin/compare");
DataOutputStream dout=new DataOutputStream(new FileOutputStream(new File(outputDir,"NoRunnable.class")));
dout.write(d.dump());
NoRunnable y=new NoRunnable();
y.Method1();
}
}