本文整理匯總了Java中com.google.common.reflect.ClassPath.getTopLevelClasses方法的典型用法代碼示例。如果您正苦於以下問題:Java ClassPath.getTopLevelClasses方法的具體用法?Java ClassPath.getTopLevelClasses怎麽用?Java ClassPath.getTopLevelClasses使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.reflect.ClassPath
的用法示例。
在下文中一共展示了ClassPath.getTopLevelClasses方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAllModels
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
public Collection<Class> getAllModels() throws IOException {
Class<Charge> chargeClass = Charge.class;
ClassPath classPath = ClassPath.from(chargeClass.getClassLoader());
ImmutableSet<ClassPath.ClassInfo> topLevelClasses = classPath.getTopLevelClasses(chargeClass.getPackage().getName());
List<Class> classList = Lists.newArrayListWithExpectedSize(topLevelClasses.size());
for (ClassPath.ClassInfo classInfo : topLevelClasses) {
Class c = classInfo.load();
// Skip things that aren't APIResources
if (!APIResource.class.isAssignableFrom(c)) {
continue;
}
// Skip the APIResource itself
if (APIResource.class == c) {
continue;
}
classList.add(classInfo.load());
}
return classList;
}
示例2: scanPack
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
protected void scanPack(String pack, ClassPath classPath)
throws MojoExecutionException, IOException {
this.getLog().info("Scanning package " + pack);
if (Strings.isNullOrEmpty(pack)) {
ClassLoaderUtils.restoreOriginalClassLoader();
throw new MojoExecutionException("Invalid target package: " + pack);
}
for (ClassPath.ClassInfo classInfo : classPath.getTopLevelClasses(pack)) {
try {
Class<?> c = classInfo.load();
if (!ignoredList.contains(c.getPackage().getName()) && !ignoredList.contains(c.getName())) {
scanClass(c);
}
} catch (Throwable ex) {
this.getLog().warn("Skipping Class: Unable to load" + classInfo.getName(), ex);
}
}
}
示例3: getModuleClasses
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
/**
* Finds all the fully qualified (ie: full package names) module classnames
* by recursively searching the rootDirectories
*
* @return
*/
//only load attempt to add .class files
private Collection<Class<? extends GuiModule>> getModuleClasses() {
Collection<Class<? extends GuiModule>> results = new ArrayList<>();
try {
ClassPath classPath = ClassPath.from(this.getClass().getClassLoader());
ImmutableSet<ClassPath.ClassInfo> set = classPath.getTopLevelClasses(PIPE_GUI_PLUGIN_CONCRETE_PACKAGE);
for (ClassPath.ClassInfo classInfo : set) {
Class<?> clazz = classInfo.load();
if (GuiModule.class.isAssignableFrom(clazz)) {
results.add((Class<? extends GuiModule>) clazz);
}
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, e.getMessage());
}
return results;
}
示例4: main
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
public static void main(String[] args) {
try {
ClassPath classPath = ClassPath.from(ClassTest.class.getClassLoader());
System.out.println(classPath.getResources());
for (ClassInfo classInfo : classPath.getTopLevelClasses("java")) {
System.out.println(classInfo.getName());
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例5: getAllTestClasses
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
/**
* Finds all tests to run for the TCK.
*
* @return A list of test classes to run.
*/
List<Class<?>> getAllTestClasses() {
try {
ClassPath cp = ClassPath.from(getClass().getClassLoader());
ImmutableSet<ClassInfo> classes =
cp.getTopLevelClasses("org.apache.calcite.avatica.tck.tests");
List<Class<?>> testClasses = new ArrayList<>(classes.size());
for (ClassInfo classInfo : classes) {
if (classInfo.getSimpleName().equals("package-info")) {
continue;
}
Class<?> clz = Class.forName(classInfo.getName());
if (Modifier.isAbstract(clz.getModifiers())) {
// Ignore abstract classes
continue;
}
testClasses.add(clz);
}
return testClasses;
} catch (Exception e) {
LOG.error("Failed to instantiate test classes", e);
Unsafe.systemExit(TestRunnerExitCodes.TEST_CASE_INSTANTIATION.ordinal());
// Unreachable..
return null;
}
}
示例6: testGuava
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
@Test
public void testGuava() throws Exception {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
String packageName = "com.github.ianrae.world";
ClassPath classpath = ClassPath.from(loader); // scans the class path used by classloader
for (ClassPath.ClassInfo classInfo : classpath.getTopLevelClasses(packageName)) {
System.out.println("aa: " + classInfo.getName());
Class<?> clazz = classInfo.getClass();
// System.out.println("bb: " + clazz.getName() );
}
}
示例7: getCheckstyleModules
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
/**
* 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);
final Set<Class<?>> checkstyleModules = new HashSet<Class<?>>();
for (String pkg : packages) {
for (ClassPath.ClassInfo clazz : classPath.getTopLevelClasses(pkg)) {
final Class<?> loadedClass = clazz.load();
if (isCheckstyleModule(loadedClass)) {
checkstyleModules.add(loadedClass);
}
}
}
return checkstyleModules;
}
示例8: testInitialize
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
@Test
public void testInitialize() throws Exception {
BuiltinDataTypeDictionaryInitializer.initialize();
ClassLoader classLoader = getClass().getClassLoader();
ClassPath classPath = ClassPath.from(classLoader);
ImmutableSet<ClassPath.ClassInfo> structures =
classPath.getTopLevelClasses("org.eclipse.milo.opcua.stack.core.types.structured");
assertNotEquals(structures.size(), 0);
for (ClassPath.ClassInfo classInfo : structures) {
Class<?> clazz = classInfo.load();
OpcUaBinaryDataTypeCodec<?> binaryCodec = OpcUaDataTypeManager.getInstance().getBinaryCodec(
OpcUaDataTypeManager.BINARY_NAMESPACE_URI,
clazz.getSimpleName()
);
assertNotNull(binaryCodec, "no binary codec found for " + clazz.getSimpleName());
OpcUaXmlDataTypeCodec<?> xmlCodec = OpcUaDataTypeManager.getInstance().getXmlCodec(
OpcUaDataTypeManager.XML_NAMESPACE_URI,
xpathify(clazz.getSimpleName())
);
assertNotNull(xmlCodec, "no xml codec found for " + clazz.getSimpleName());
}
}
示例9: setPackagesToSearch
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
/**
* Set the packages to search
*
* @param packages
* the packages needs to be search and parsing
* @throws EasyJsonApiInvalidPackageException
*/
public void setPackagesToSearch(String... packages) throws EasyJsonApiInvalidPackageException {
this.packagesSearched = packages;
for (String packageToSearch : packages) {
try {
ClassPath classpath = ClassPath.from(getClass().getClassLoader());
List<Class<?>> attrClasses = new ArrayList<>();
List<Class<?>> metaClasses = new ArrayList<>();
List<Class<?>> metaRelationshipsClasses = new ArrayList<>();
for (ClassPath.ClassInfo classInfo : classpath.getTopLevelClasses(packageToSearch)) {
Class<?> clazz = classInfo.load();
if (Assert.notNull(clazz.getAnnotation(Attributes.class))) {
attrClasses.add(clazz);
} else if (Assert.notNull(clazz.getAnnotation(Meta.class))) {
metaClasses.add(clazz);
} else if (Assert.notNull(clazz.getAnnotation(MetaRelationship.class))) {
metaRelationshipsClasses.add(clazz);
}
}
this.classesParsed.put(EasyJsonApiTypeToken.TOKEN_ATTR, attrClasses);
this.classesParsed.put(EasyJsonApiTypeToken.TOKEN_META, metaClasses);
this.classesParsed.put(EasyJsonApiTypeToken.TOKEN_META_RELATIONSHIP, metaRelationshipsClasses);
} catch (IOException ex) {
throw new EasyJsonApiInvalidPackageException("Invalid packages inserted!", ex);
}
}
}
示例10: TransformerInjectOptifine
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
protected TransformerInjectOptifine(ClassLoader classloader) throws IOException, URISyntaxException {
ClassPath path = ClassPath.from(classloader);
for (ClassInfo info : path.getTopLevelClasses("optifine"))
if (info.getSimpleName().equals("OptiFineClassTransformer")) {
Class<?> optifine = info.load();
URL url = optifine.getProtectionDomain().getCodeSource().getLocation();
if (url.getFile().endsWith(".jar"))
jar = new JarFile(new File(url.toURI()));
}
if (jar == null)
throw new RuntimeException("Can't find Optifine jar file !");
}
示例11: listExamples
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
private static void listExamples(final @NonNull PrintWriter printWriter) {
log.debug("Listing examples.");
try {
final ClassPath classPath = ClassPath.from(TestCommand.class.getClassLoader());
final ImmutableSet<ClassPath.ClassInfo> classes = classPath.getTopLevelClasses(EXAMPLES_PACKAGE);
log.debug("Class path {}.", classes);
classes.forEach(klass -> printWriter.println(klass.getSimpleName()));
} catch (final IOException e) {
log.error("Cannot load classes.", e);
printWriter.println("Error: Cannot load classes.");
}
}
示例12: build
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
public ApplicationContext build() {
try {
if (injectAnnotation != null) {
pico = new PicoBuilder().withAnnotatedFieldInjection(injectAnnotation).build();
} else {
pico = new PicoBuilder().withAnnotatedFieldInjection().build();
}
for (String scan : scans) {
ClassPath classpath = ClassPath.from(ApplicationContext.class.getClassLoader());
for (ClassPath.ClassInfo classInfo : classpath.getTopLevelClasses(scan)) {
Class<?> loadedClass = classInfo.load();
classes.add(loadedClass);
}
}
for (Class<?> aClass : classes) {
pico.addComponent(aClass);
}
pico.addComponent(this);
pico.addAdapter(new ContextInjector(vertx, container));
pico.addAdapter(new VertxInjector(vertx));
pico.addAdapter(new ContainerInjector(container));
pico.addAdapter(new LoggerInjector(container.logger()));
pico.addAdapter(new EventBusInjector(vertx.eventBus()));
pico.addAdapter(new BusModInjector(container));
for (ComponentAdapter<?> componentAdapter : componentAdapters) {
pico.addAdapter(componentAdapter);
}
return this;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例13: init
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
/**
* Initializes Content to search within packageName for blocks/items.
*
* @param classLoader The ClassLoader from any class inside the mod. Most reliably, use the class with the @Mod annotation. This must come from a class within the mod's jar file.
* @param packageName The full package name to search within. It doesn't recursively search in child packages.
* @throws Exception
*/
public void init(ClassLoader classLoader, String packageName) throws Exception {
// Gets the classpath, and searches it for all classes in packageName.
ClassPath classPath = ClassPath.from(classLoader);
for (ClassPath.ClassInfo info : classPath.getTopLevelClasses(packageName)) {
Class objClass = Class.forName(info.getName());
checkAndRegister(objClass);
for (Class subClass : objClass.getClasses()) {
checkAndRegister(subClass);
}
}
}
示例14: matchClass
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
private static String matchClass(String className) throws Exception{
// deal with normal names
String lower = className.toLowerCase();
String realName = null;
ClassPath classPath = ClassPath.from(Thread.currentThread().getContextClassLoader());
ImmutableSet<ClassPath.ClassInfo> classes = classPath.getTopLevelClasses("edu.neu.ccs.pyramid.application");
for (ClassPath.ClassInfo classInfo: classes){
if (classInfo.getSimpleName().toLowerCase().equals(lower)){
realName = classInfo.getName();
break;
}
}
return realName;
}
示例15: removeRecipes
import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
private static void removeRecipes(EventTime event, String packageName) throws IOException
{
ClassPath classpath = ClassPath.from(RecipeTweakingCore.class.getClassLoader());
Set<ClassInfo> classes = classpath.getTopLevelClasses(packageName);
for (ClassInfo c : classes)
{
for (Method m : loadClassSafe(c))
{
RecipeRemoval r = m.getAnnotation(RecipeRemoval.class);
if (r != null && allModsLoaded(r.requiredModids()) && r.time() == event)
{
try
{
log("Processing remove method \"" + m.getName() + "\" in class \"" + c.getName() + "\"");
m.invoke(null, new Object[] {});
}
catch (Throwable t)
{
logErr("[Removals] An exception was thrown processing \"" + m.getName() + "\" in class \"" + c.getName() + "\"" + "these removals will likely not occur.");
t.printStackTrace();
}
}
}
}
TweakingRegistry.removeRecipes();
}