-
-
Save ryan-williams/20b96b78c3414e7292302a9e6f799e8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import org.objectweb.asm.*; | |
public class Test$Dump implements Opcodes { | |
public static byte[] dump() throws Exception { | |
ClassWriter cw = new ClassWriter(0); | |
FieldVisitor fv; | |
MethodVisitor mv; | |
AnnotationVisitor av0; | |
cw.visit(V1_6, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, "Test$", null, "java/lang/Object", null); | |
cw.visitSource("Test.scala", null); | |
// ATTRIBUTE Scala | |
// ATTRIBUTE ScalaInlineInfo | |
cw.visitInnerClass("scala/Predef$ArrowAssoc$", "scala/Predef", "ArrowAssoc$", ACC_PUBLIC + ACC_STATIC); | |
{ | |
fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "MODULE$", "LTest$;", null, null); | |
fv.visitEnd(); | |
} | |
{ | |
fv = cw.visitField(ACC_PRIVATE + ACC_FINAL, "tuple", "Lscala/Tuple2;", "Lscala/Tuple2<Ljava/lang/String;Ljava/lang/String;>;", null); | |
fv.visitEnd(); | |
} | |
{ | |
mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "<clinit>", "()V", null, null); | |
mv.visitCode(); | |
mv.visitTypeInsn(NEW, "Test$"); | |
mv.visitMethodInsn(INVOKESPECIAL, "Test$", "<init>", "()V", false); | |
mv.visitInsn(RETURN); | |
mv.visitMaxs(1, 0); | |
mv.visitEnd(); | |
} | |
{ | |
mv = cw.visitMethod(ACC_PUBLIC, "tuple", "()Lscala/Tuple2;", "()Lscala/Tuple2<Ljava/lang/String;Ljava/lang/String;>;", null); | |
mv.visitCode(); | |
Label l0 = new Label(); | |
mv.visitLabel(l0); | |
mv.visitLineNumber(2, l0); | |
mv.visitVarInsn(ALOAD, 0); | |
mv.visitFieldInsn(GETFIELD, "Test$", "tuple", "Lscala/Tuple2;"); | |
mv.visitInsn(ARETURN); | |
Label l1 = new Label(); | |
mv.visitLabel(l1); | |
mv.visitLocalVariable("this", "LTest$;", null, l0, l1, 0); | |
mv.visitMaxs(1, 1); | |
mv.visitEnd(); | |
} | |
{ | |
mv = cw.visitMethod(ACC_PRIVATE, "<init>", "()V", null, null); | |
mv.visitCode(); | |
Label l0 = new Label(); | |
mv.visitLabel(l0); | |
mv.visitLineNumber(3, l0); | |
mv.visitVarInsn(ALOAD, 0); | |
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); | |
mv.visitVarInsn(ALOAD, 0); | |
mv.visitFieldInsn(PUTSTATIC, "Test$", "MODULE$", "LTest$;"); | |
Label l1 = new Label(); | |
mv.visitLabel(l1); | |
mv.visitLineNumber(2, l1); | |
mv.visitVarInsn(ALOAD, 0); | |
mv.visitFieldInsn(GETSTATIC, "scala/Predef$ArrowAssoc$", "MODULE$", "Lscala/Predef$ArrowAssoc$;"); | |
mv.visitFieldInsn(GETSTATIC, "scala/Predef$", "MODULE$", "Lscala/Predef$;"); | |
mv.visitLdcInsn("aaa"); | |
mv.visitMethodInsn(INVOKEVIRTUAL, "scala/Predef$", "ArrowAssoc", "(Ljava/lang/Object;)Ljava/lang/Object;", false); | |
mv.visitLdcInsn("bbb"); | |
mv.visitMethodInsn(INVOKEVIRTUAL, "scala/Predef$ArrowAssoc$", "$minus$greater$extension", "(Ljava/lang/Object;Ljava/lang/Object;)Lscala/Tuple2;", false); | |
mv.visitFieldInsn(PUTFIELD, "Test$", "tuple", "Lscala/Tuple2;"); | |
mv.visitInsn(RETURN); | |
Label l2 = new Label(); | |
mv.visitLabel(l2); | |
mv.visitLocalVariable("this", "LTest$;", null, l0, l2, 0); | |
mv.visitMaxs(4, 1); | |
mv.visitEnd(); | |
} | |
cw.visitEnd(); | |
return cw.toByteArray(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Test { | |
val tuple = "aaa" -> "bbb" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment