Package webit.script.asm.lib

Examples of webit.script.asm.lib.ClassWriter


    static Class createResolverClass(Class beanClass) throws Exception {
        //XXX: rewrite
        if (ClassUtil.isPublic(beanClass)) {
            final String className = "webit.script.asm.Resolver".concat(ASMUtil.getSn());

            final ClassWriter classWriter = new ClassWriter(Constants.V1_5, Constants.ACC_PUBLIC + Constants.ACC_FINAL, ASMUtil.getInternalName(className), "java/lang/Object", ASM_RESOLVER);
            ASMUtil.visitConstructor(classWriter);

            final FieldInfo[] all = FieldInfoResolver.resolve(beanClass);
            Arrays.sort(all);
            final int size = all.length;
            int[] hashs;
            int[] indexer;
            if (size > 0) {
                hashs = new int[size];
                indexer = new int[size];
                int hashsCount = 0;
                int hash;
                hashs[hashsCount++] = hash = all[0].hashCode;
                int i = 1;
                while (i < size) {
                    FieldInfo fieldInfo = all[i];
                    if (hash != fieldInfo.hashCode) {
                        indexer[hashsCount - 1] = i;
                        hashs[hashsCount++] = hash = fieldInfo.hashCode;
                    }
                    i++;
                }
                indexer[hashsCount - 1] = size;
                hashs = Arrays.copyOf(hashs, hashsCount);
                indexer = Arrays.copyOf(indexer, hashsCount);
            } else {
                hashs = null;
                indexer = null;
            }

            visitXetMethod(true, classWriter, beanClass, all, hashs, indexer);
            visitXetMethod(false, classWriter, beanClass, all, hashs, indexer);

            //getMatchClass
            final MethodWriter m = classWriter.visitMethod(Constants.ACC_PUBLIC, "getMatchClass", "()Ljava/lang/Class;", null);
            m.visitInsn(Constants.ACONST_NULL);
            m.visitInsn(Constants.ARETURN);
            m.visitMaxs();

            return ASMUtil.loadClass(className, classWriter);
View Full Code Here


        return null;
    }

    static MethodDeclare createAccessor(Member obj) throws InstantiationException, IllegalAccessException {
        final String className = "webit.script.asm.Accessor".concat(ASMUtil.getSn());
        final ClassWriter classWriter = new ClassWriter(Constants.V1_5, Constants.ACC_PUBLIC + Constants.ACC_FINAL, ASMUtil.getInternalName(className), "java/lang/Object", METHOD_DECLARE);

        ASMUtil.visitConstructor(classWriter);

        final boolean isInterface;
        final boolean isStatic;
        final boolean isConstructor;
        final String ownerClass;
        final String destName;
        final String destDesc;
        final Class[] paramTypes;
        final Class returnType;

        if (obj instanceof Method) {
            Method method = (Method) obj;
            isInterface = method.getDeclaringClass().isInterface();
            isStatic = ClassUtil.isStatic(method);
            isConstructor = false;
            ownerClass = ASMUtil.getInternalName(method.getDeclaringClass().getName());
            destName = method.getName();
            destDesc = ASMUtil.getDescriptor(method);
            paramTypes = method.getParameterTypes();
            returnType = method.getReturnType();
        } else {
            Constructor constructor = (Constructor) obj;
            isInterface = false;
            isStatic = false;
            isConstructor = true;
            ownerClass = ASMUtil.getInternalName(constructor.getDeclaringClass().getName());
            destName = "<init>";
            destDesc = ASMUtil.getDescriptor(constructor);
            paramTypes = constructor.getParameterTypes();
            returnType = constructor.getDeclaringClass();
        }

        final int paramTypesLen = paramTypes.length;
        final MethodWriter m = classWriter.visitMethod(Constants.ACC_PUBLIC, "invoke", "(Lwebit/script/Context;[Ljava/lang/Object;)Ljava/lang/Object;", null);

        if (paramTypesLen == 0) {
            if (isStatic) {
                m.invokeStatic(ownerClass, destName, destDesc);
                ASMUtil.visitBoxIfNeed(m, returnType);
View Full Code Here

*/
public class AsmTest implements Constants {

    @Test
    public void test() throws Exception {
        ClassWriter clssWriter = new ClassWriter(Constants.V1_5, Constants.ACC_PUBLIC, "x/Example", "java/lang/Object", null);

        ASMUtil.visitConstructor(clssWriter);

        MethodWriter m = clssWriter.visitMethod(ACC_PUBLIC, "test", "([Ljava/lang/Object;)Ljava/lang/Object;", null);

        Label toExcaption = new Label();
        m.visitVarInsn(Constants.ALOAD, 1);
        m.visitJumpInsn(Constants.IFNULL, toExcaption);
        m.visitVarInsn(Constants.ALOAD, 1);
View Full Code Here

TOP

Related Classes of webit.script.asm.lib.ClassWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.