本文整理了Java中com.google.common.reflect.ClassPath.getAllClasses()
方法的一些代码示例,展示了ClassPath.getAllClasses()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClassPath.getAllClasses()
方法的具体详情如下:
包路径:com.google.common.reflect.ClassPath
类名称:ClassPath
方法名:getAllClasses
[英]Returns all classes loadable from the current class path.
[中]返回可从当前类路径加载的所有类。
代码示例来源:origin: runelite/runelite
ClassPath classPath = ClassPath.from(classLoader);
ImmutableSet<ClassInfo> classes = packageName == null ? classPath.getAllClasses()
: classPath.getTopLevelClassesRecursive(packageName);
for (ClassInfo classInfo : classes)
代码示例来源:origin: stackoverflow.com
ClassPath cp = ClassPath.from(ClassLoader.getSystemClassLoader());
for (ClassPath.ClassInfo n : cp.getAllClasses()) {
Class cl = n.load();
if (BaseClass.isAssignableFrom(cl)) {
}
}
代码示例来源:origin: adobe/aem-core-wcm-components
private static List<Class> getClasses(String packageName) throws ClassNotFoundException, IOException {
List<Class> classes = new ArrayList<>();
ClassPath classpath = ClassPath.from(AbstractModelTest.class.getClassLoader());
String packagePrefix = packageName + '.';
ImmutableSet.Builder<ClassPath.ClassInfo> builder = ImmutableSet.builder();
classpath.getAllClasses().stream().filter(classInfo -> classInfo.getName().startsWith(packagePrefix)).forEach(builder::add);
ImmutableSet<ClassPath.ClassInfo> packageClasses = builder.build();
classes.addAll(packageClasses.stream().map(ClassPath.ClassInfo::load).collect(Collectors.toList()));
return classes;
}
代码示例来源:origin: zolyfarkas/spf4j
public static List<Invocation> findUsages(final String packageName, final Set<Method> invokedMethods)
throws IOException {
final ClassLoader cl = ClassLoader.getSystemClassLoader();
ClassPath cp = ClassPath.from(cl);
ImmutableSet<ClassPath.ClassInfo> classes = cp.getAllClasses();
List<Invocation> result = new ArrayList();
for (ClassPath.ClassInfo info : classes) {
if (info.getName().startsWith(packageName)) {
result.addAll(findUsages(cl, info.getResourceName(), invokedMethods));
}
}
return result;
}
代码示例来源:origin: io.github.factoryfx/factory
/**
* @param basePackage base package for the factory to avoid scanning the whole classpath
* @return list of factories
*/
@SuppressWarnings("unchecked")
public List<Class<? extends FactoryBase>> get(String basePackage) {
List<Class<? extends FactoryBase>> result = new ArrayList<>();
try {
for (ClassPath.ClassInfo classInfo : ClassPath.from(ClasspathBasedFactoryProvider.class.getClassLoader()).getAllClasses()) {
if (classInfo.getName().startsWith(basePackage)) {
Class<?> clazz = classInfo.load();
if (FactoryBase.class.isAssignableFrom(clazz) && clazz != FactoryBase.class) {
result.add((Class<FactoryBase>) clazz);
}
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return result;
}
代码示例来源:origin: JackOfMostTrades/gadgetinspector
public Collection<ClassResource> getAllClasses() throws IOException {
Collection<ClassResource> result = new ArrayList<>(getRuntimeClasses());
for (ClassPath.ClassInfo classInfo : ClassPath.from(classLoader).getAllClasses()) {
result.add(new ClassLoaderClassResource(classLoader, classInfo.getResourceName()));
}
return result;
}
代码示例来源:origin: JackOfMostTrades/gadgetinspector
private Collection<ClassResource> getRuntimeClasses() throws IOException {
// A hacky way to get the current JRE's rt.jar. Depending on the class loader, rt.jar may be in the
// bootstrap classloader so all the JDK classes will be excluded from classpath scanning with this!
// However, this only works up to Java 8, since after that Java uses some crazy module magic.
URL stringClassUrl = Object.class.getResource("String.class");
URLConnection connection = stringClassUrl.openConnection();
Collection<ClassResource> result = new ArrayList<>();
if (connection instanceof JarURLConnection) {
URL runtimeUrl = ((JarURLConnection) connection).getJarFileURL();
URLClassLoader classLoader = new URLClassLoader(new URL[]{runtimeUrl});
for (ClassPath.ClassInfo classInfo : ClassPath.from(classLoader).getAllClasses()) {
result.add(new ClassLoaderClassResource(classLoader, classInfo.getResourceName()));
}
return result;
}
// Try finding all the JDK classes using the Java9+ modules method:
try {
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
Files.walk(fs.getPath("/")).forEach(p -> {
if (p.toString().toLowerCase().endsWith(".class")) {
result.add(new PathClassResource(p));
}
});
} catch (ProviderNotFoundException e) {
// Do nothing; this is expected on versions below Java9
}
return result;
}
代码示例来源:origin: sbtqa/page-factory
final Set<Class<?>> allClasses = new HashSet<>();
try {
for (ClassPath.ClassInfo info : ClassPath.from(loader).getAllClasses()) {
if (info.getName().startsWith(packageName + ".")) {
allClasses.add(info.load());
代码示例来源:origin: cinchapi/concourse
Thread.currentThread().getContextClassLoader());
ClassPath classpath = ClassPath.from(typeClassLoader);
for (ClassInfo info : classpath.getAllClasses()) {
String name = info.getName();
Class<?> clazz = serverClassLoader.loadClass(name);
代码示例来源:origin: ProjectKorra/ProjectKorra
for (final ClassInfo info : ClassPath.from(loader).getAllClasses()) {
if (!info.getPackageName().startsWith(packagePrefix)) {
continue;
内容来源于网络,如有侵权,请联系作者删除!