Skip to content

Commit 2054e1c

Browse files
committed
Add ReflectionUtils.isFieldStringCollection
1 parent 5733e67 commit 2054e1c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

loader/src/main/java/com/fox2code/foxloader/utils/ReflectionUtils.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package com.fox2code.foxloader.utils;
2525

2626
import java.lang.reflect.Constructor;
27+
import java.lang.reflect.Field;
2728
import java.lang.reflect.InvocationTargetException;
2829
import java.lang.reflect.Modifier;
2930

@@ -66,4 +67,26 @@ public static <T> T invokeConstructorSafe(Constructor<T> constructor, Object...
6667
} catch (ReflectiveOperationException ignored) {}
6768
return null;
6869
}
70+
71+
public static boolean isFieldStringCollection(Field field) {
72+
Class<?> type = field.getType();
73+
switch (type.getName()) {
74+
case "java.util.Collection":
75+
case "java.util.Set":
76+
case "java.util.HashSet":
77+
case "java.util.LinkedHashSet":
78+
case "java.util.List":
79+
case "java.util.ArrayList":
80+
case "java.util.LinkedList": {
81+
break;
82+
}
83+
default: {
84+
return false;
85+
}
86+
}
87+
String signature = field.getGenericType().getTypeName();
88+
int start = signature.indexOf('<');
89+
return start != -1 && signature.endsWith(">") &&
90+
signature.substring(start + 1, signature.length() - 1).equals("java.lang.String");
91+
}
6992
}

0 commit comments

Comments
 (0)