本文整理了Java中com.google.common.reflect.ClassPath.getTopLevelClasses()
方法的一些代码示例,展示了ClassPath.getTopLevelClasses()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClassPath.getTopLevelClasses()
方法的具体详情如下:
包路径:com.google.common.reflect.ClassPath
类名称:ClassPath
方法名:getTopLevelClasses
[英]Returns all top level classes loadable from the current class path.
[中]返回可从当前类路径加载的所有顶级类。
代码示例来源:origin: google/guava
/** Returns all top level classes whose package name is {@code packageName}. */
public ImmutableSet<ClassInfo> getTopLevelClasses(String packageName) {
checkNotNull(packageName);
ImmutableSet.Builder<ClassInfo> builder = ImmutableSet.builder();
for (ClassInfo classInfo : getTopLevelClasses()) {
if (classInfo.getPackageName().equals(packageName)) {
builder.add(classInfo);
}
}
return builder.build();
}
代码示例来源:origin: google/guava
/**
* Returns all top level classes whose package name is {@code packageName} or starts with {@code
* packageName} followed by a '.'.
*/
public ImmutableSet<ClassInfo> getTopLevelClassesRecursive(String packageName) {
checkNotNull(packageName);
String packagePrefix = packageName + '.';
ImmutableSet.Builder<ClassInfo> builder = ImmutableSet.builder();
for (ClassInfo classInfo : getTopLevelClasses()) {
if (classInfo.getName().startsWith(packagePrefix)) {
builder.add(classInfo);
}
}
return builder.build();
}
代码示例来源:origin: google/guava
private List<Class<?>> loadClassesInPackage() throws IOException {
List<Class<?>> classes = Lists.newArrayList();
String packageName = getClass().getPackage().getName();
for (ClassPath.ClassInfo classInfo :
ClassPath.from(getClass().getClassLoader()).getTopLevelClasses(packageName)) {
Class<?> cls;
try {
cls = classInfo.load();
} catch (NoClassDefFoundError e) {
// In case there were linking problems, this is probably not a class we care to test anyway.
logger.log(Level.SEVERE, "Cannot load class " + classInfo + ", skipping...", e);
continue;
}
if (!cls.isInterface()) {
classes.add(cls);
}
}
return classes;
}
代码示例来源:origin: google/j2objc
/** Returns all top level classes whose package name is {@code packageName}. */
public ImmutableSet<ClassInfo> getTopLevelClasses(String packageName) {
checkNotNull(packageName);
ImmutableSet.Builder<ClassInfo> builder = ImmutableSet.builder();
for (ClassInfo classInfo : getTopLevelClasses()) {
if (classInfo.getPackageName().equals(packageName)) {
builder.add(classInfo);
}
}
return builder.build();
}
代码示例来源:origin: google/j2objc
/**
* Returns all top level classes whose package name is {@code packageName} or starts with {@code
* packageName} followed by a '.'.
*/
public ImmutableSet<ClassInfo> getTopLevelClassesRecursive(String packageName) {
checkNotNull(packageName);
String packagePrefix = packageName + '.';
ImmutableSet.Builder<ClassInfo> builder = ImmutableSet.builder();
for (ClassInfo classInfo : getTopLevelClasses()) {
if (classInfo.getName().startsWith(packagePrefix)) {
builder.add(classInfo);
}
}
return builder.build();
}
代码示例来源:origin: wildfly/wildfly
/** Returns all top level classes whose package name is {@code packageName}. */
public ImmutableSet<ClassInfo> getTopLevelClasses(String packageName) {
checkNotNull(packageName);
ImmutableSet.Builder<ClassInfo> builder = ImmutableSet.builder();
for (ClassInfo classInfo : getTopLevelClasses()) {
if (classInfo.getPackageName().equals(packageName)) {
builder.add(classInfo);
}
}
return builder.build();
}
代码示例来源:origin: wildfly/wildfly
/**
* Returns all top level classes whose package name is {@code packageName} or starts with {@code
* packageName} followed by a '.'.
*/
public ImmutableSet<ClassInfo> getTopLevelClassesRecursive(String packageName) {
checkNotNull(packageName);
String packagePrefix = packageName + '.';
ImmutableSet.Builder<ClassInfo> builder = ImmutableSet.builder();
for (ClassInfo classInfo : getTopLevelClasses()) {
if (classInfo.getName().startsWith(packagePrefix)) {
builder.add(classInfo);
}
}
return builder.build();
}
代码示例来源:origin: checkstyle/checkstyle
/**
* Gets checkstyle's modules (directly, not recursively) in the given packages.
* @param packages the collection of package names to use
* @param loader the class loader used to load Checkstyle package names
* @return the set of checkstyle's module classes
* @throws IOException if the attempt to read class path resources failed
* @see #isCheckstyleModule(Class)
*/
public static Set<Class<?>> getCheckstyleModules(
Collection<String> packages, ClassLoader loader) throws IOException {
final ClassPath classPath = ClassPath.from(loader);
return packages.stream()
.flatMap(pkg -> classPath.getTopLevelClasses(pkg).stream())
.map(ClassPath.ClassInfo::load)
.filter(ModuleReflectionUtil::isCheckstyleModule)
.collect(Collectors.toSet());
}
代码示例来源:origin: Netflix/zuul
.map(String::trim)
.filter(blank.negate())
.flatMap(packageName -> cp.getTopLevelClasses(packageName).stream())
.map(ClassPath.ClassInfo::load)
.filter(ZuulFilter.class::isAssignableFrom)
代码示例来源:origin: google/guava
@AndroidIncompatible // Android forbids null parent ClassLoader
// https://github.com/google/guava/issues/2152
public void testJarFileWithSpaces() throws Exception {
URL url = makeJarUrlWithName("To test unescaped spaces in jar file name.jar");
URLClassLoader classloader = new URLClassLoader(new URL[] {url}, null);
assertThat(ClassPath.from(classloader).getTopLevelClasses()).isNotEmpty();
}
代码示例来源:origin: Netflix/zuul
.map(String::trim)
.filter(blank.negate())
.flatMap(packageName -> cp.getTopLevelClasses(packageName).stream())
.map(ClassPath.ClassInfo::load)
.filter(ZuulFilter.class::isAssignableFrom)
代码示例来源:origin: jamesagnew/hapi-fhir
/**
* This is really only useful for unit tests, do not call otherwise
*/
public static void scanEntities(String packageName) throws IOException, ClassNotFoundException {
ImmutableSet<ClassInfo> classes = ClassPath.from(TestUtil.class.getClassLoader()).getTopLevelClasses(packageName);
Set<String> names = new HashSet<String>();
if (classes.size() <= 1) {
throw new InternalErrorException("Found no classes");
}
for (ClassInfo classInfo : classes) {
Class<?> clazz = Class.forName(classInfo.getName());
Entity entity = clazz.getAnnotation(Entity.class);
if (entity == null) {
continue;
}
scanClass(names, clazz, false);
}
}
代码示例来源:origin: apache/accumulo
.getTopLevelClasses(IteratorTestCase.class.getPackage().getName());
代码示例来源:origin: jamesagnew/hapi-fhir
ImmutableSet<ClassInfo> tlc = ClassPath.from(getClass().getClassLoader()).getTopLevelClasses(StringDt.class.getPackage().getName());
for (ClassInfo classInfo : tlc) {
DatatypeDef def = Class.forName(classInfo.getName()).getAnnotation(DatatypeDef.class);
ImmutableSet<ClassInfo> tlc = ClassPath.from(getClass().getClassLoader()).getTopLevelClasses(thePackageBase + ".composite");
for (ClassInfo classInfo : tlc) {
DatatypeDef def = Class.forName(classInfo.getName()).getAnnotation(DatatypeDef.class);
代码示例来源:origin: jamesagnew/hapi-fhir
components = ClassPath
.from(VersionPropertyFileGeneratorMojo.class.getClassLoader())
.getTopLevelClasses()
.stream()
.filter(t -> {
代码示例来源:origin: google/bundletool
@Test
public void eachSubValidatorIsRegistered() throws Exception {
// Load sub-classes of SubValidator that live within the same package as top-level classes.
ImmutableSet<Class<?>> existingSubValidators =
ClassPath.from(SubValidator.class.getClassLoader())
.getTopLevelClasses(Reflection.getPackageName(SubValidator.class))
.stream()
.map(ClassInfo::load)
.filter(clazz -> isConcreteSubValidator(clazz))
.collect(toImmutableSet());
ImmutableSet<Class<?>> registeredSubValidators =
ImmutableSet.<Class<?>>builder()
.addAll(toClasses(AppBundleValidator.BUNDLE_FILE_SUB_VALIDATORS))
.addAll(toClasses(AppBundleValidator.BUNDLE_SUB_VALIDATORS))
.addAll(toClasses(BundleModulesValidator.MODULE_FILE_SUB_VALIDATORS))
.addAll(toClasses(BundleModulesValidator.MODULES_SUB_VALIDATORS))
.build();
assertThat(existingSubValidators).containsExactlyElementsIn(registeredSubValidators);
}
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) throws IOException {
ClassPath p = ClassPath.from(ClassLoader.getSystemClassLoader()); // might need to provide different ClassLoader
ImmutableSet<ClassInfo> classes = p.getTopLevelClasses("com.example");
for (ClassInfo classInfo : classes) {
Class clazz = classInfo.load();
int modifiers = clazz.getModifiers();
if (Modifier.isAbstract(modifiers)) {
System.out.println("Class '" + clazz.getName() + "' is abstract.");
}
}
}
代码示例来源:origin: org.hudsonci.lib.guava/guava
/** Returns all top level classes whose package name is {@code packageName}. */
public ImmutableSet<ClassInfo> getTopLevelClasses(String packageName) {
checkNotNull(packageName);
ImmutableSet.Builder<ClassInfo> builder = ImmutableSet.builder();
for (ClassInfo classInfo : getTopLevelClasses()) {
if (classInfo.getPackageName().equals(packageName)) {
builder.add(classInfo);
}
}
return builder.build();
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
/** Returns all top level classes whose package name is {@code packageName}. */
public ImmutableSet<ClassInfo> getTopLevelClasses(String packageName) {
checkNotNull(packageName);
ImmutableSet.Builder<ClassInfo> builder = ImmutableSet.builder();
for (ClassInfo classInfo : getTopLevelClasses()) {
if (classInfo.getPackageName().equals(packageName)) {
builder.add(classInfo);
}
}
return builder.build();
}
代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.google.guava
/** Returns all top level classes whose package name is {@code packageName}. */
public ImmutableSet<ClassInfo> getTopLevelClasses(String packageName) {
checkNotNull(packageName);
ImmutableSet.Builder<ClassInfo> builder = ImmutableSet.builder();
for (ClassInfo classInfo : getTopLevelClasses()) {
if (classInfo.getPackageName().equals(packageName)) {
builder.add(classInfo);
}
}
return builder.build();
}
内容来源于网络,如有侵权,请联系作者删除!