X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=tests%2Forg.simantics.scl.compiler.tests%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftests%2FFindAllowedChars.java;h=7d8f1dbab958f6698b0acf641f02a6e3903b6b15;hp=1e4078670f9275adbb8c2d07cfe59531db1219b7;hb=fad36d463b75c3a9944d875fc627c3533f6da74d;hpb=d70b5f7a4cdeea05c7526560303feffeb03596b0 diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/FindAllowedChars.java b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/FindAllowedChars.java index 1e4078670..7d8f1dbab 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/FindAllowedChars.java +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/FindAllowedChars.java @@ -1,66 +1,66 @@ -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 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