use of com.massivecraft.massivecore.xlib.guava.reflect.ClassPath.ClassInfo in project MassiveCore by MassiveCraft.
the class ReflectionUtil method getPackageClasses.
// -------------------------------------------- //
// GET PACKAGE CLASSES
// -------------------------------------------- //
@SuppressWarnings("unchecked")
public static List<Class<?>> getPackageClasses(String packageName, ClassLoader classLoader, boolean recursive, Predicate<Class<?>>... predicates) {
// Create ret
List<Class<?>> ret = new MassiveList<>();
try {
// Get info
ClassPath classPath = ClassPath.from(classLoader);
Predicate<Class<?>> predicateCombined = PredicateAnd.get(predicates);
Collection<ClassInfo> classInfos = recursive ? classPath.getTopLevelClassesRecursive(packageName) : classPath.getTopLevelClasses(packageName);
for (ClassInfo classInfo : classInfos) {
// Get name of class
String className = classInfo.getName();
// Apparently it found a "EngineMassiveCoreCollTick 3" which we don't want
if (className.contains(" "))
continue;
// Try and load it
Class<?> clazz;
try {
clazz = classInfo.load();
} catch (NoClassDefFoundError ex) {
// Just skip it
continue;
}
// And it must not be ignored
if (!predicateCombined.apply(clazz))
continue;
ret.add(clazz);
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
Collections.sort(ret, new Comparator<Class<?>>() {
@Override
public int compare(Class<?> class1, Class<?> class2) {
return ComparatorNaturalOrder.get().compare(class1.getName(), class2.getName());
}
});
return ret;
}
Aggregations