fix jasmin format on switch

--HG--
branch : 2.x
This commit is contained in:
Bob Pan 2015-04-06 17:54:23 +08:00
parent d980a8728a
commit bb78e1ce7b
4 changed files with 61 additions and 12 deletions

View File

@ -428,10 +428,11 @@ public class JasminDumper implements Opcodes {
pw.print("tableswitch ");
pw.println(min);
for (Label label : labels) {
pw.print(" ");
print(label);
pw.println();
}
pw.print("default : ");
pw.print(" default : ");
print(dflt);
pw.println();
}
@ -468,7 +469,7 @@ public class JasminDumper implements Opcodes {
}
if (mn.localVariables != null) {
for (LocalVariableNode lv : mn.localVariables) {
pw.print(".var ");
pw.print(" .var ");
pw.print(lv.index);
pw.print(" is '");
pw.print(lv.name);
@ -486,8 +487,8 @@ public class JasminDumper implements Opcodes {
pw.println();
}
}
println(".limit locals ", Integer.toString(mn.maxLocals));
println(".limit stack ", Integer.toString(mn.maxStack));
println(" .limit locals ", Integer.toString(mn.maxLocals));
println(" .limit stack ", Integer.toString(mn.maxStack));
}
pw.println(".end method");
}

View File

@ -11,6 +11,6 @@ public interface MethodInvocation {
String getMethodDesc();
Object getThis();
// @Nullale
Object[] getArguments();
}

View File

@ -1,7 +1,19 @@
package com.googlecode.d2j.tools.jar.test;
import com.googlecode.d2j.jasmin.JasminDumper;
import com.googlecode.d2j.tools.jar.InvocationWeaver;
import com.googlecode.d2j.tools.jar.MethodInvocation;
import com.googlecode.dex2jar.tools.BaseCmd;
import org.junit.Assert;
import org.junit.Test;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import com.googlecode.d2j.asm.*;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URISyntaxException;
@ -10,13 +22,6 @@ import java.net.URLClassLoader;
import java.nio.file.FileSystem;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import com.googlecode.d2j.tools.jar.InvocationWeaver;
import com.googlecode.d2j.tools.jar.MethodInvocation;
import com.googlecode.dex2jar.tools.BaseCmd;
/**
* public class Res extends ArrayList { public static void main(String... args) { System.out.append("");
* System.out.println("test"); }
@ -78,4 +83,33 @@ public class WaveTest {
}
}
@Test
public void test2() {
ClassNode cn = new ClassNode();
cn.name = "A";
cn.version = Opcodes.V1_6;
MethodVisitor mv = cn.visitMethod(0, "m", "()V", null, null);
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(-1, -1);
mv.visitEnd();
cn.visitEnd();
new JasminDumper(new PrintWriter(System.out, true)).dump(cn);
InvocationWeaver iw = new InvocationWeaver();
iw.setInvocationInterfaceDesc("Lp;");
iw.withConfig("d LA;.m()V=LB;.t(Lp;)Ljava/lang/Object;");
ClassNode nc = new ClassNode();
cn.accept(iw.wrapper(LdcOptimizeAdapter.wrap(nc)));
new JasminDumper(new PrintWriter(System.out, true)).dump(nc);
ClassNode nc2 = new ClassNode();
iw.buildInvocationClz(LdcOptimizeAdapter.wrap(nc2));
new JasminDumper(new PrintWriter(System.out, true)).dump(nc2);
}
}

View File

@ -15,6 +15,7 @@
*/
package com.googlecode.d2j.asm;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
@ -114,4 +115,17 @@ public class LdcOptimizeAdapter extends MethodVisitor implements Opcodes {
}
}
public static MethodVisitor wrap(MethodVisitor mv) {
return mv == null ? null : new LdcOptimizeAdapter(mv);
}
public static ClassVisitor wrap(ClassVisitor cv) {
return cv == null ? null : new ClassVisitor(Opcodes.ASM5, cv) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
return wrap(super.visitMethod(access, name, desc, signature, exceptions));
}
};
}
}