package me.qmx.jitescript;

import java.io.PrintStream;
import static me.qmx.jitescript.util.CodegenUtils.*;
import org.junit.Test;
import org.objectweb.asm.MethodVisitor;

/**
 *
 * @author qmx
 */
public class JiteClassTest {

    @Test
    public void testDSL() {
        JiteClass jiteClass = new JiteClass("invokedynamic") {
    public static class DynamicClassLoader extends ClassLoader {

        public Class<?> define(String className, byte[] bytecode) {
            return super.defineClass(className, bytecode, 0, bytecode.length);
        }
    };


            {
                defineMethod("main", ACC_PUBLIC + ACC_STATIC, sig(void.class, String[].class), new MethodBody() {

                    public void executableMethodBody(MethodVisitor mv) {
                        ldc("helloWorld");
                        getstatic(ci(System.class),
                                "out",
                                ci(PrintStream.class));
                        swap();
                        invokevirtual(p(PrintStream.class), "println", sig(void.class, Object.class));
                        voidreturn();
                    }
                });
            }
        };

        byte[] classBytes = jiteClass.toBytes();


    }
}

@@ -49,16 +49,101 @@
 Stream;%0A
+import java.lang.reflect.InvocationTargetException;%0Aimport java.lang.reflect.Method;%0A
 import s
@@ -187,16 +187,16 @@
 tils.*;%0A
-
 import o
@@ -311,109 +311,8 @@
  %7B%0A%0A
-    @Test%0A    public void testDSL() %7B%0A        JiteClass jiteClass = new JiteClass(%22invokedynamic%22) %7B%0A
     
@@ -535,24 +535,271 @@
  %7D%0A    %7D;%0A%0A%0A
+    @Test%0A    public void testDSL() throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException %7B%0A        final String className = %22helloTest%22;%0A        JiteClass jiteClass = new JiteClass(className) %7B%0A
             

extracting class name