public List<String> getClassNamesByPackageName(String packageName) {
List<String> classNameList = new ArrayList<>();
try {
ClassLoader e = Thread.currentThread().getContextClassLoader();
String path = packageName.replace('.', '/');
Enumeration<URL> resources = e.getResources(path);
List<File> dirs = new ArrayList<>();
while (resources.hasMoreElements()) {
URL directory = resources.nextElement();
dirs.add(new File(directory.getFile()));
}
Iterator<File> arg6 = dirs.iterator();
while (arg6.hasNext()) {
File directory1 = arg6.next();
classNameList.addAll(findClasses(directory1, packageName));
}
} catch (Exception arg7) {
arg7.printStackTrace();
}
return classNameList;
}
private List<String> findClasses(File directory, String packageName) throws ClassNotFoundException {
List<String> className = new ArrayList();
if (!directory.exists()) {
return className;
} else {
File[] files = directory.listFiles();
File[] arg6 = files;
int arg5 = files.length;
for (int arg4 = 0; arg4 < arg5; ++arg4) {
File file = arg6[arg4];
if (file.isDirectory()) {
assert !file.getName().contains(".");
className.addAll(findClasses(file, packageName + '.' + file.getName()));
} else if (file.getName().endsWith(".class")) {
className.add(packageName + "." + file.getName().substring(0, file.getName().length() - 6));
}
}
return className;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/107514.html