package org.simantics.scl.compiler.tests; import java.lang.reflect.Method; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; public class FindAllowedChars { public static class MyClassLoader extends ClassLoader { final String className; final byte[] classBytes; public MyClassLoader(ClassLoader parent, String className, byte[] classBytes) { super(parent); this.className = className; this.classBytes = classBytes; } public MyClassLoader(String className, byte[] classBytes) { this.className = className; this.classBytes = classBytes; } @Override protected Class findClass(String name) throws ClassNotFoundException { if(name.equals(name)) return defineClass(name, classBytes, 0, classBytes.length); else return super.findClass(name); } } public static void test(String className, String methodName) throws Exception { ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS); classWriter.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, className, null, "java/lang/Object", null); MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, methodName, "()V", null, null); /*methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); methodVisitor.visitLdcInsn("Hello world!"); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);*/ methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(0, 0); methodVisitor.visitEnd(); classWriter.visitEnd(); ClassLoader loader = new MyClassLoader(className, classWriter.toByteArray()); Class clazz = loader.loadClass(className); Method method = clazz.getMethod(methodName); method.invoke(null); } public static void main(String[] args) throws Exception { for(int a=Character.MIN_VALUE;a