don't travel into basic class

This commit is contained in:
金戟 2021-03-24 13:17:15 +08:00
parent 9871a96db0
commit 52878364ee
3 changed files with 13 additions and 9 deletions

View File

@ -105,7 +105,7 @@ public class OmniAccessor {
}
private static List<String> generateMemberIndex(Class<?> clazz, String basePath, Set<Class<?>> classPool) {
if (isAtomicType(clazz)) {
if (TypeUtil.isBasicType(clazz)) {
return Collections.emptyList();
}
classPool.add(clazz);
@ -121,13 +121,6 @@ public class OmniAccessor {
return paths;
}
private static boolean isAtomicType(Class<?> clazz) {
return clazz.isEnum() || clazz.equals(Integer.class) || clazz.equals(Short.class) || clazz.equals(Long.class)
|| clazz.equals(Byte.class) || clazz.equals(Character.class) || clazz.equals(Float.class)
|| clazz.equals(Double.class) || clazz.equals(Boolean.class) || clazz.equals(Class.class)
|| clazz.equals(String.class);
}
private static String toPath(Field field) {
return field.getName() + BRACE_START + field.getType().getSimpleName() + BRACE_END;
}

View File

@ -159,7 +159,7 @@ public class OmniConstructor {
for (int i = 0; i < Array.getLength(fieldIns); i++) {
handleCircleReference(Array.get(fieldIns, i), classPool);
}
} else if (!fieldType.isPrimitive() && !fieldType.isEnum()) {
} else if (!fieldType.isPrimitive() && !TypeUtil.isBasicType(fieldType)) {
if (fieldIns == null && classPool.containsKey(fieldType)) {
f.set(instance, classPool.get(fieldType));
} else if (fieldIns != null && !classPool.containsKey(fieldType)) {

View File

@ -99,6 +99,17 @@ public class TypeUtil {
}
}
/**
* whether class is a system basic type
* @param clazz type to check
*/
public static boolean isBasicType(Class<?> clazz) {
return clazz.isEnum() || clazz.equals(Integer.class) || clazz.equals(Short.class) || clazz.equals(Long.class)
|| clazz.equals(Byte.class) || clazz.equals(Character.class) || clazz.equals(Float.class)
|| clazz.equals(Double.class) || clazz.equals(Boolean.class) || clazz.equals(Class.class)
|| clazz.equals(String.class);
}
/**
* type equals
* @param classesLeft class to be compared