Java 类com.alibaba.fastjson.util.ASMUtils 实例源码

项目:boohee_v5.6    文件:ASMDeserializerFactory.java   
private void _newCollection(MethodVisitor mw, Class<?> fieldClass) {
    if (fieldClass.isAssignableFrom(ArrayList.class)) {
        mw.visitTypeInsn(187, "java/util/ArrayList");
        mw.visitInsn(89);
        mw.visitMethodInsn(183, "java/util/ArrayList", "<init>", "()V");
    } else if (fieldClass.isAssignableFrom(LinkedList.class)) {
        mw.visitTypeInsn(187, ASMUtils.getType(LinkedList.class));
        mw.visitInsn(89);
        mw.visitMethodInsn(183, ASMUtils.getType(LinkedList.class), "<init>", "()V");
    } else if (fieldClass.isAssignableFrom(HashSet.class)) {
        mw.visitTypeInsn(187, ASMUtils.getType(HashSet.class));
        mw.visitInsn(89);
        mw.visitMethodInsn(183, ASMUtils.getType(HashSet.class), "<init>", "()V");
    } else if (fieldClass.isAssignableFrom(TreeSet.class)) {
        mw.visitTypeInsn(187, ASMUtils.getType(TreeSet.class));
        mw.visitInsn(89);
        mw.visitMethodInsn(183, ASMUtils.getType(TreeSet.class), "<init>", "()V");
    } else {
        mw.visitTypeInsn(187, ASMUtils.getType(fieldClass));
        mw.visitInsn(89);
        mw.visitMethodInsn(183, ASMUtils.getType(fieldClass), "<init>", "()V");
    }
    mw.visitTypeInsn(192, ASMUtils.getType(fieldClass));
}
项目:itmarry    文件:ASMDeserializerFactory.java   
private void _setContext(Context context, MethodVisitor mw) {
    mw.visitVarInsn(ALOAD, 1); // parser
    mw.visitVarInsn(ALOAD, context.var("context"));
    mw.visitMethodInsn(INVOKEVIRTUAL, getType(DefaultJSONParser.class), "setContext",
                       "(" + ASMUtils.getDesc(ParseContext.class) + ")V");

    Label endIf_ = new Label();
    mw.visitVarInsn(ALOAD, context.var("childContext"));
    mw.visitJumpInsn(IFNULL, endIf_);

    mw.visitVarInsn(ALOAD, context.var("childContext"));
    mw.visitVarInsn(ALOAD, context.var("instance"));
    mw.visitMethodInsn(INVOKEVIRTUAL, getType(ParseContext.class), "setObject", "(Ljava/lang/Object;)V");

    mw.visitLabel(endIf_);
}
项目:GitHub    文件:JSONScanner.java   
public final String subString(int offset, int count) {
    if (ASMUtils.IS_ANDROID) {
        if (count < sbuf.length) {
            text.getChars(offset, offset + count, sbuf, 0);
            return new String(sbuf, 0, count);
        } else {
            char[] chars = new char[count];
            text.getChars(offset, offset + count, chars, 0);
            return new String(chars);
        }
    } else {
        return text.substring(offset, offset + count);
    }
}
项目:GitHub    文件:JSONScanner.java   
public final char[] sub_chars(int offset, int count) {
    if (ASMUtils.IS_ANDROID && count < sbuf.length) {
        text.getChars(offset, offset + count, sbuf, 0);
        return sbuf;
    } else {
        char[] chars = new char[count];
        text.getChars(offset, offset + count, chars, 0);
        return chars;
    }
}
项目:GitHub    文件:JSONASMUtilTest.java   
public void test_error_1() throws Exception {
    new ASMUtils();

    Exception error = null;
    try {
        ASMUtils.getPrimitiveLetter(Long.class);
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
项目:GitHub    文件:DataClassSimpleTest.java   
public void test_user() throws Exception {
    ExtClassLoader classLoader = new ExtClassLoader();
    Class clazz = classLoader.loadClass("DataClassSimple");

    String[] names = ASMUtils.lookupParameterNames(clazz.getConstructors()[0]);
    System.out.println(JSON.toJSONString(names));

    String json = "{\"a\":1001,\"b\":1002}";
    Object obj = JSON.parseObject(json, clazz);
    assertEquals("{\"a\":1001,\"b\":1002}", JSON.toJSONString(obj));

}
项目:boohee_v5.6    文件:ASMDeserializerFactory.java   
private void _createInstance(Context context, MethodVisitor mw) {
    if (Modifier.isPublic(context.getBeanInfo().getDefaultConstructor().getModifiers())) {
        mw.visitTypeInsn(187, ASMUtils.getType(context.getClazz()));
        mw.visitInsn(89);
        mw.visitMethodInsn(183, ASMUtils.getType(context.getClazz()), "<init>", "()V");
        mw.visitVarInsn(58, context.var("instance"));
        return;
    }
    mw.visitVarInsn(25, 0);
    mw.visitVarInsn(25, 1);
    mw.visitMethodInsn(183, "com/alibaba/fastjson/parser/deserializer/ASMJavaBeanDeserializer", "createInstance", "(Lcom/alibaba/fastjson/parser/DefaultJSONParser;)Ljava/lang/Object;");
    mw.visitTypeInsn(192, ASMUtils.getType(context.getClazz()));
    mw.visitVarInsn(58, context.var("instance"));
}
项目:boohee_v5.6    文件:ASMDeserializerFactory.java   
private void _set(Context context, MethodVisitor mw, FieldInfo fieldInfo) {
    if (fieldInfo.getMethod() != null) {
        mw.visitMethodInsn(182, ASMUtils.getType(fieldInfo.getDeclaringClass()), fieldInfo.getMethod().getName(), ASMUtils.getDesc(fieldInfo.getMethod()));
        if (!fieldInfo.getMethod().getReturnType().equals(Void.TYPE)) {
            mw.visitInsn(87);
            return;
        }
        return;
    }
    mw.visitFieldInsn(181, ASMUtils.getType(fieldInfo.getDeclaringClass()), fieldInfo.getField().getName(), ASMUtils.getDesc(fieldInfo.getFieldClass()));
}
项目:boohee_v5.6    文件:ASMDeserializerFactory.java   
private void _getCollectionFieldItemDeser(Context context, MethodVisitor mw, FieldInfo fieldInfo, Class<?> itemType) {
    Label notNull_ = new Label();
    mw.visitVarInsn(25, 0);
    mw.visitFieldInsn(180, context.getClassName(), fieldInfo.getName() + "_asm_list_item_deser__", "Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;");
    mw.visitJumpInsn(199, notNull_);
    mw.visitVarInsn(25, 0);
    mw.visitVarInsn(25, 1);
    mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/DefaultJSONParser", "getConfig", "()Lcom/alibaba/fastjson/parser/ParserConfig;");
    mw.visitLdcInsn(com.alibaba.fastjson.asm.Type.getType(ASMUtils.getDesc((Class) itemType)));
    mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/ParserConfig", "getDeserializer", "(Ljava/lang/reflect/Type;)Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;");
    mw.visitFieldInsn(181, context.getClassName(), fieldInfo.getName() + "_asm_list_item_deser__", "Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;");
    mw.visitLabel(notNull_);
    mw.visitVarInsn(25, 0);
    mw.visitFieldInsn(180, context.getClassName(), fieldInfo.getName() + "_asm_list_item_deser__", "Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;");
}
项目:boohee_v5.6    文件:ASMDeserializerFactory.java   
private void _deserObject(Context context, MethodVisitor mw, FieldInfo fieldInfo, Class<?> fieldClass) {
    _getFieldDeser(context, mw, fieldInfo);
    mw.visitVarInsn(25, 1);
    if (fieldInfo.getFieldType() instanceof Class) {
        mw.visitLdcInsn(com.alibaba.fastjson.asm.Type.getType(ASMUtils.getDesc(fieldInfo.getFieldClass())));
    } else {
        mw.visitVarInsn(25, 0);
        mw.visitLdcInsn(fieldInfo.getName());
        mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/deserializer/ASMJavaBeanDeserializer", "getFieldType", "(Ljava/lang/String;)Ljava/lang/reflect/Type;");
    }
    mw.visitLdcInsn(fieldInfo.getName());
    mw.visitMethodInsn(185, "com/alibaba/fastjson/parser/deserializer/ObjectDeserializer", "deserialze", "(Lcom/alibaba/fastjson/parser/DefaultJSONParser;Ljava/lang/reflect/Type;Ljava/lang/Object;)Ljava/lang/Object;");
    mw.visitTypeInsn(192, ASMUtils.getType(fieldClass));
    mw.visitVarInsn(58, context.var(fieldInfo.getName() + "_asm"));
}
项目:boohee_v5.6    文件:ASMDeserializerFactory.java   
private void _getFieldDeser(Context context, MethodVisitor mw, FieldInfo fieldInfo) {
    Label notNull_ = new Label();
    mw.visitVarInsn(25, 0);
    mw.visitFieldInsn(180, context.getClassName(), fieldInfo.getName() + "_asm_deser__", "Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;");
    mw.visitJumpInsn(199, notNull_);
    mw.visitVarInsn(25, 0);
    mw.visitVarInsn(25, 1);
    mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/DefaultJSONParser", "getConfig", "()Lcom/alibaba/fastjson/parser/ParserConfig;");
    mw.visitLdcInsn(com.alibaba.fastjson.asm.Type.getType(ASMUtils.getDesc(fieldInfo.getFieldClass())));
    mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/ParserConfig", "getDeserializer", "(Ljava/lang/reflect/Type;)Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;");
    mw.visitFieldInsn(181, context.getClassName(), fieldInfo.getName() + "_asm_deser__", "Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;");
    mw.visitLabel(notNull_);
    mw.visitVarInsn(25, 0);
    mw.visitFieldInsn(180, context.getClassName(), fieldInfo.getName() + "_asm_deser__", "Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;");
}
项目:boohee_v5.6    文件:ASMDeserializerFactory.java   
private void _createInstance(ClassWriter cw, Context context) {
    MethodVisitor mw = cw.visitMethod(1, "createInstance", "(Lcom/alibaba/fastjson/parser/DefaultJSONParser;Ljava/lang/reflect/Type;)Ljava/lang/Object;", null, null);
    mw.visitTypeInsn(187, ASMUtils.getType(context.getClazz()));
    mw.visitInsn(89);
    mw.visitMethodInsn(183, ASMUtils.getType(context.getClazz()), "<init>", "()V");
    mw.visitInsn(176);
    mw.visitMaxs(3, 3);
    mw.visitEnd();
}
项目:boohee_v5.6    文件:JSONScanner.java   
public final String subString(int offset, int count) {
    if (!ASMUtils.isAndroid()) {
        return this.text.substring(offset, offset + count);
    }
    char[] chars = new char[count];
    for (int i = offset; i < offset + count; i++) {
        chars[i - offset] = this.text.charAt(i);
    }
    return new String(chars);
}
项目:boohee_v5.6    文件:ASMSerializerFactory.java   
private void initNature(Class<?> clazz, MethodVisitor mw, Context context) {
    mw.visitVarInsn(25, 0);
    mw.visitTypeInsn(187, "com/alibaba/fastjson/serializer/JavaBeanSerializer");
    mw.visitInsn(89);
    mw.visitLdcInsn(Type.getType(ASMUtils.getDesc((Class) clazz)));
    mw.visitMethodInsn(183, "com/alibaba/fastjson/serializer/JavaBeanSerializer", "<init>", "(Ljava/lang/Class;)V");
    mw.visitFieldInsn(181, context.getClassName(), "nature", "Lcom/alibaba/fastjson/serializer/JavaBeanSerializer;");
}
项目:boohee_v5.6    文件:ASMSerializerFactory.java   
private void _get(MethodVisitor mw, Context context, FieldInfo property) {
    Method method = property.getMethod();
    if (method != null) {
        mw.visitVarInsn(25, context.var("entity"));
        mw.visitMethodInsn(182, ASMUtils.getType(method.getDeclaringClass()), method.getName(), ASMUtils.getDesc(method));
        return;
    }
    mw.visitVarInsn(25, context.var("entity"));
    mw.visitFieldInsn(180, ASMUtils.getType(property.getDeclaringClass()), property.getField().getName(), ASMUtils.getDesc(property.getFieldClass()));
}
项目:boohee_v5.6    文件:SerializeConfig.java   
public ObjectSerializer createJavaBeanSerializer(Class<?> clazz) {
    if (!Modifier.isPublic(clazz.getModifiers())) {
        return new JavaBeanSerializer(clazz);
    }
    boolean asm = this.asm;
    if ((asm && this.asmFactory.isExternalClass(clazz)) || clazz == Serializable.class || clazz == Object.class) {
        asm = false;
    }
    JSONType annotation = (JSONType) clazz.getAnnotation(JSONType.class);
    if (!(annotation == null || annotation.asm())) {
        asm = false;
    }
    if (asm && !ASMUtils.checkName(clazz.getName())) {
        asm = false;
    }
    if (asm) {
        try {
            ObjectSerializer asmSerializer = createASMSerializer(clazz);
            if (asmSerializer != null) {
                return asmSerializer;
            }
        } catch (ClassCastException e) {
        } catch (Throwable e2) {
            JSONException jSONException = new JSONException("create asm serializer error, class " + clazz, e2);
        }
    }
    return new JavaBeanSerializer(clazz);
}
项目:GitHub    文件:Issue109.java   
public void test_for_issue() throws Exception {
    Assert.assertFalse(ASMUtils.isAndroid(null));
}
项目:GitHub    文件:JSONASMUtilTest.java   
public void test_1() throws Exception {
    Assert.assertEquals("V", ASMUtils.desc(Void.TYPE));
    Assert.assertEquals("J", ASMUtils.desc(Long.TYPE));
    Assert.assertEquals("[J", ASMUtils.desc(long[].class));
    Assert.assertEquals("[Ljava/lang/Long;", ASMUtils.desc(Long[].class));
}
项目:GitHub    文件:TestType.java   
public void test_getType() throws Exception {
    Assert.assertEquals(Type.VOID_TYPE, Type.getType(ASMUtils.desc(void.class)));

    Assert.assertEquals(Type.BOOLEAN_TYPE, Type.getType(ASMUtils.desc(boolean.class)));

    Assert.assertEquals(Type.CHAR_TYPE, Type.getType(ASMUtils.desc(char.class)));

    Assert.assertEquals(Type.BYTE_TYPE, Type.getType(ASMUtils.desc(byte.class)));

    Assert.assertEquals(Type.SHORT_TYPE, Type.getType(ASMUtils.desc(short.class)));

    Assert.assertEquals(Type.INT_TYPE, Type.getType(ASMUtils.desc(int.class)));

    Assert.assertEquals(Type.LONG_TYPE, Type.getType(ASMUtils.desc(long.class)));

    Assert.assertEquals(Type.FLOAT_TYPE, Type.getType(ASMUtils.desc(float.class)));

    Assert.assertEquals(Type.DOUBLE_TYPE, Type.getType(ASMUtils.desc(double.class)));

    Assert.assertEquals("[D", Type.getType(ASMUtils.desc(double[].class)).getInternalName());
    Assert.assertEquals("[[D", Type.getType(ASMUtils.desc(double[][].class)).getInternalName());
    Assert.assertEquals("[Ljava/lang/Double;", Type.getType(ASMUtils.desc(Double[].class)).getInternalName());
}
项目:GitHub    文件:ASMUtilsTest.java   
public void test_isAnroid() throws Exception {
    Assert.assertTrue(ASMUtils.isAndroid("Dalvik"));
}
项目:GitHub    文件:ASMUtilsTest.java   
public void test_getDescs() throws Exception {
    Assert.assertEquals("Lcom/alibaba/fastjson/parser/ParseContext;", ASMUtils.desc(ParseContext.class));
}
项目:GitHub    文件:ASMUtilsTest.java   
public void test_getType_null() throws Exception {
    Assert.assertNull(ASMUtils.getMethodType(ParseContext.class, "XX"));
}
项目:GitHub    文件:JSONASMUtilTest.java   
public void test_0() throws Exception {
    Assert.assertEquals("()I", ASMUtils.desc(HashMap.class.getMethod("size")));
    Assert.assertEquals("(Ljava/lang/Object;)Ljava/lang/Object;", ASMUtils.desc(HashMap.class.getMethod("get", Object.class)));
    Assert.assertEquals("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", ASMUtils.desc(HashMap.class.getMethod("put", Object.class, Object.class)));
}
项目:GitHub    文件:JSONASMUtilTest.java   
public void test_1() throws Exception {
    Assert.assertEquals("I", ASMUtils.type(int.class));
    Assert.assertEquals("java/lang/Integer", ASMUtils.type(Integer.class));
}
项目:GitHub    文件:JSONASMUtilTest.java   
public void test_2() throws Exception {
    Assert.assertEquals("[I", ASMUtils.type(int[].class));
    Assert.assertEquals("[Ljava/lang/Integer;", ASMUtils.type(Integer[].class));
}
项目:boohee_v5.6    文件:ASMDeserializerFactory.java   
private void _loadAndSet(Context context, MethodVisitor mw, FieldInfo fieldInfo) {
    Class<?> fieldClass = fieldInfo.getFieldClass();
    Type fieldType = fieldInfo.getFieldType();
    if (fieldClass == Boolean.TYPE) {
        mw.visitVarInsn(25, context.var("instance"));
        mw.visitVarInsn(21, context.var(fieldInfo.getName() + "_asm"));
        _set(context, mw, fieldInfo);
    } else if (fieldClass == Byte.TYPE || fieldClass == Short.TYPE || fieldClass == Integer.TYPE || fieldClass == Character.TYPE) {
        mw.visitVarInsn(25, context.var("instance"));
        mw.visitVarInsn(21, context.var(fieldInfo.getName() + "_asm"));
        _set(context, mw, fieldInfo);
    } else if (fieldClass == Long.TYPE) {
        mw.visitVarInsn(25, context.var("instance"));
        mw.visitVarInsn(22, context.var(fieldInfo.getName() + "_asm", 2));
        if (fieldInfo.getMethod() != null) {
            mw.visitMethodInsn(182, ASMUtils.getType(context.getClazz()), fieldInfo.getMethod().getName(), ASMUtils.getDesc(fieldInfo.getMethod()));
            if (!fieldInfo.getMethod().getReturnType().equals(Void.TYPE)) {
                mw.visitInsn(87);
                return;
            }
            return;
        }
        mw.visitFieldInsn(181, ASMUtils.getType(fieldInfo.getDeclaringClass()), fieldInfo.getField().getName(), ASMUtils.getDesc(fieldInfo.getFieldClass()));
    } else if (fieldClass == Float.TYPE) {
        mw.visitVarInsn(25, context.var("instance"));
        mw.visitVarInsn(23, context.var(fieldInfo.getName() + "_asm"));
        _set(context, mw, fieldInfo);
    } else if (fieldClass == Double.TYPE) {
        mw.visitVarInsn(25, context.var("instance"));
        mw.visitVarInsn(24, context.var(fieldInfo.getName() + "_asm", 2));
        _set(context, mw, fieldInfo);
    } else if (fieldClass == String.class) {
        mw.visitVarInsn(25, context.var("instance"));
        mw.visitVarInsn(25, context.var(fieldInfo.getName() + "_asm"));
        _set(context, mw, fieldInfo);
    } else if (fieldClass.isEnum()) {
        mw.visitVarInsn(25, context.var("instance"));
        mw.visitVarInsn(25, context.var(fieldInfo.getName() + "_asm"));
        _set(context, mw, fieldInfo);
    } else if (Collection.class.isAssignableFrom(fieldClass)) {
        mw.visitVarInsn(25, context.var("instance"));
        if (getCollectionItemClass(fieldType) == String.class) {
            mw.visitVarInsn(25, context.var(fieldInfo.getName() + "_asm"));
            mw.visitTypeInsn(192, ASMUtils.getType(fieldClass));
        } else {
            mw.visitVarInsn(25, context.var(fieldInfo.getName() + "_asm"));
        }
        _set(context, mw, fieldInfo);
    } else {
        mw.visitVarInsn(25, context.var("instance"));
        mw.visitVarInsn(25, context.var(fieldInfo.getName() + "_asm"));
        _set(context, mw, fieldInfo);
    }
}
项目:boohee_v5.6    文件:ASMDeserializerFactory.java   
public FieldDeserializer createStringFieldDeserializer(ParserConfig mapping, Class<?> clazz, FieldInfo fieldInfo) throws Exception {
    Class<?> superClass;
    int INVAKE_TYPE;
    Class<?> fieldClass = fieldInfo.getFieldClass();
    Method method = fieldInfo.getMethod();
    String className = getGenFieldDeserializer(clazz, fieldInfo);
    ClassWriter cw = new ClassWriter();
    if (fieldClass == Integer.TYPE) {
        superClass = IntegerFieldDeserializer.class;
    } else if (fieldClass == Long.TYPE) {
        superClass = LongFieldDeserializer.class;
    } else {
        superClass = StringFieldDeserializer.class;
    }
    if (clazz.isInterface()) {
        INVAKE_TYPE = 185;
    } else {
        INVAKE_TYPE = 182;
    }
    cw.visit(49, 33, className, ASMUtils.getType(superClass), null);
    MethodVisitor mw = cw.visitMethod(1, "<init>", "(Lcom/alibaba/fastjson/parser/ParserConfig;Ljava/lang/Class;Lcom/alibaba/fastjson/util/FieldInfo;)V", null, null);
    mw.visitVarInsn(25, 0);
    mw.visitVarInsn(25, 1);
    mw.visitVarInsn(25, 2);
    mw.visitVarInsn(25, 3);
    mw.visitMethodInsn(183, ASMUtils.getType(superClass), "<init>", "(Lcom/alibaba/fastjson/parser/ParserConfig;Ljava/lang/Class;Lcom/alibaba/fastjson/util/FieldInfo;)V");
    mw.visitInsn(177);
    mw.visitMaxs(4, 6);
    mw.visitEnd();
    if (method != null) {
        if (fieldClass == Integer.TYPE) {
            mw = cw.visitMethod(1, "setValue", "(Ljava/lang/Object;I)V", null, null);
            mw.visitVarInsn(25, 1);
            mw.visitTypeInsn(192, ASMUtils.getType(method.getDeclaringClass()));
            mw.visitVarInsn(21, 2);
            mw.visitMethodInsn(INVAKE_TYPE, ASMUtils.getType(method.getDeclaringClass()), method.getName(), ASMUtils.getDesc(method));
            mw.visitInsn(177);
            mw.visitMaxs(3, 3);
            mw.visitEnd();
        } else if (fieldClass == Long.TYPE) {
            mw = cw.visitMethod(1, "setValue", "(Ljava/lang/Object;J)V", null, null);
            mw.visitVarInsn(25, 1);
            mw.visitTypeInsn(192, ASMUtils.getType(method.getDeclaringClass()));
            mw.visitVarInsn(22, 2);
            mw.visitMethodInsn(INVAKE_TYPE, ASMUtils.getType(method.getDeclaringClass()), method.getName(), ASMUtils.getDesc(method));
            mw.visitInsn(177);
            mw.visitMaxs(3, 4);
            mw.visitEnd();
        } else {
            mw = cw.visitMethod(1, "setValue", "(Ljava/lang/Object;Ljava/lang/Object;)V", null, null);
            mw.visitVarInsn(25, 1);
            mw.visitTypeInsn(192, ASMUtils.getType(method.getDeclaringClass()));
            mw.visitVarInsn(25, 2);
            mw.visitTypeInsn(192, ASMUtils.getType(fieldClass));
            mw.visitMethodInsn(INVAKE_TYPE, ASMUtils.getType(method.getDeclaringClass()), method.getName(), ASMUtils.getDesc(method));
            mw.visitInsn(177);
            mw.visitMaxs(3, 3);
            mw.visitEnd();
        }
    }
    byte[] code = cw.toByteArray();
    return (FieldDeserializer) this.classLoader.defineClassPublic(className, code, 0, code.length).getConstructor(new Class[]{ParserConfig.class, Class.class, FieldInfo.class}).newInstance(new Object[]{mapping, clazz, fieldInfo});
}
项目:boohee_v5.6    文件:ParserConfig.java   
public ObjectDeserializer createJavaBeanDeserializer(Class<?> clazz, Type type) {
    boolean asmEnable = this.asmEnable;
    if (asmEnable) {
        Class<?> superClass = clazz;
        while (Modifier.isPublic(superClass.getModifiers())) {
            superClass = superClass.getSuperclass();
            if (superClass != Object.class) {
                if (superClass == null) {
                    break;
                }
            }
            break;
        }
        asmEnable = false;
    }
    if (clazz.getTypeParameters().length != 0) {
        asmEnable = false;
    }
    if (asmEnable && this.asmFactory != null && this.asmFactory.isExternalClass(clazz)) {
        asmEnable = false;
    }
    if (asmEnable) {
        asmEnable = ASMUtils.checkName(clazz.getName());
    }
    if (asmEnable) {
        if (clazz.isInterface()) {
            asmEnable = false;
        }
        DeserializeBeanInfo beanInfo = DeserializeBeanInfo.computeSetters(clazz, type);
        if (beanInfo.getFieldList().size() > 200) {
            asmEnable = false;
        }
        if (beanInfo.getDefaultConstructor() == null && !clazz.isInterface()) {
            asmEnable = false;
        }
        for (FieldInfo fieldInfo : beanInfo.getFieldList()) {
            if (fieldInfo.isGetOnly()) {
                asmEnable = false;
                break;
            }
            Class<?> fieldClass = fieldInfo.getFieldClass();
            if (!Modifier.isPublic(fieldClass.getModifiers())) {
                asmEnable = false;
                break;
            }
            if (fieldClass.isMemberClass() && !Modifier.isStatic(fieldClass.getModifiers())) {
                asmEnable = false;
            }
            if (!ASMUtils.checkName(fieldInfo.getMember().getName())) {
                asmEnable = false;
            }
        }
    }
    if (asmEnable && clazz.isMemberClass() && !Modifier.isStatic(clazz.getModifiers())) {
        asmEnable = false;
    }
    if (!asmEnable) {
        return new JavaBeanDeserializer(this, clazz, type);
    }
    try {
        return this.asmFactory.createJavaBeanDeserializer(this, clazz, type);
    } catch (NoSuchMethodException e) {
        return new JavaBeanDeserializer(this, clazz, type);
    } catch (ASMException e2) {
        return new JavaBeanDeserializer(this, clazz, type);
    } catch (Exception e3) {
        throw new JSONException("create asm deserializer error, " + clazz.getName(), e3);
    }
}
项目:boohee_v5.6    文件:SerializeConfig.java   
public SerializeConfig(int tableSize) {
    super(tableSize);
    this.asm = !ASMUtils.isAndroid();
    this.typeKey = JSON.DEFAULT_TYPE_KEY;
    try {
        this.asmFactory = new ASMSerializerFactory();
    } catch (ExceptionInInitializerError e) {
        this.asm = false;
    }
    put(Boolean.class, BooleanCodec.instance);
    put(Character.class, CharacterCodec.instance);
    put(Byte.class, IntegerCodec.instance);
    put(Short.class, IntegerCodec.instance);
    put(Integer.class, IntegerCodec.instance);
    put(Long.class, LongCodec.instance);
    put(Float.class, FloatCodec.instance);
    put(Double.class, DoubleSerializer.instance);
    put(BigDecimal.class, BigDecimalCodec.instance);
    put(BigInteger.class, BigIntegerCodec.instance);
    put(String.class, StringCodec.instance);
    put(byte[].class, ByteArraySerializer.instance);
    put(short[].class, ShortArraySerializer.instance);
    put(int[].class, IntArraySerializer.instance);
    put(long[].class, LongArraySerializer.instance);
    put(float[].class, FloatArraySerializer.instance);
    put(double[].class, DoubleArraySerializer.instance);
    put(boolean[].class, BooleanArraySerializer.instance);
    put(char[].class, CharArraySerializer.instance);
    put(Object[].class, ObjectArraySerializer.instance);
    put(Class.class, ClassSerializer.instance);
    put(SimpleDateFormat.class, DateFormatSerializer.instance);
    put(Locale.class, LocaleCodec.instance);
    put(Currency.class, CurrencyCodec.instance);
    put(TimeZone.class, TimeZoneCodec.instance);
    put(UUID.class, UUIDCodec.instance);
    put(InetAddress.class, InetAddressCodec.instance);
    put(Inet4Address.class, InetAddressCodec.instance);
    put(Inet6Address.class, InetAddressCodec.instance);
    put(InetSocketAddress.class, InetSocketAddressCodec.instance);
    put(File.class, FileCodec.instance);
    put(URI.class, URICodec.instance);
    put(URL.class, URLCodec.instance);
    put(Appendable.class, AppendableSerializer.instance);
    put(StringBuffer.class, AppendableSerializer.instance);
    put(StringBuilder.class, AppendableSerializer.instance);
    put(Pattern.class, PatternCodec.instance);
    put(Charset.class, CharsetCodec.instance);
    put(AtomicBoolean.class, AtomicBooleanSerializer.instance);
    put(AtomicInteger.class, AtomicIntegerSerializer.instance);
    put(AtomicLong.class, AtomicLongSerializer.instance);
    put(AtomicReference.class, ReferenceCodec.instance);
    put(AtomicIntegerArray.class, AtomicIntegerArrayCodec.instance);
    put(AtomicLongArray.class, AtomicLongArrayCodec.instance);
    put(WeakReference.class, ReferenceCodec.instance);
    put(SoftReference.class, ReferenceCodec.instance);
    try {
        put(Class.forName("java.awt.Color"), ColorCodec.instance);
        put(Class.forName("java.awt.Font"), FontCodec.instance);
        put(Class.forName("java.awt.Point"), PointCodec.instance);
        put(Class.forName("java.awt.Rectangle"), RectangleCodec.instance);
    } catch (Throwable th) {
    }
    try {
        put(Class.forName("java.time.LocalDateTime"), Jdk8DateCodec.instance);
        put(Class.forName("java.time.LocalDate"), Jdk8DateCodec.instance);
        put(Class.forName("java.time.LocalTime"), Jdk8DateCodec.instance);
        put(Class.forName("java.time.ZonedDateTime"), Jdk8DateCodec.instance);
        put(Class.forName("java.time.OffsetDateTime"), Jdk8DateCodec.instance);
        put(Class.forName("java.time.OffsetTime"), Jdk8DateCodec.instance);
        put(Class.forName("java.time.ZoneOffset"), Jdk8DateCodec.instance);
        put(Class.forName("java.time.ZoneRegion"), Jdk8DateCodec.instance);
        put(Class.forName("java.time.Period"), Jdk8DateCodec.instance);
        put(Class.forName("java.time.Duration"), Jdk8DateCodec.instance);
        put(Class.forName("java.time.Instant"), Jdk8DateCodec.instance);
    } catch (Throwable th2) {
    }
}