當前位置: 首頁>>代碼示例>>Java>>正文


Java ClassInfo.load方法代碼示例

本文整理匯總了Java中com.google.common.reflect.ClassPath.ClassInfo.load方法的典型用法代碼示例。如果您正苦於以下問題:Java ClassInfo.load方法的具體用法?Java ClassInfo.load怎麽用?Java ClassInfo.load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.reflect.ClassPath.ClassInfo的用法示例。


在下文中一共展示了ClassInfo.load方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCheckstyleModulesRecursive

import com.google.common.reflect.ClassPath.ClassInfo; //導入方法依賴的package包/類
/**
 * Gets checkstyle's modules in the given package recursively.
 * @param packageName the package name to use
 * @param loader the class loader used to load Checkstyle package name
 * @return the set of checkstyle's module classes
 * @throws IOException if the attempt to read class path resources failed
 * @see ModuleReflectionUtils#isCheckstyleModule(Class)
 */
private static Set<Class<?>> getCheckstyleModulesRecursive(
        String packageName, ClassLoader loader) throws IOException {
    final ClassPath classPath = ClassPath.from(loader);
    final Set<Class<?>> result = new HashSet<Class<?>>();
    for (ClassInfo clsInfo : classPath.getTopLevelClassesRecursive(packageName)) {
        final Class<?> cls = clsInfo.load();

        if (ModuleReflectionUtils.isCheckstyleModule(cls)
                && !cls.getName().endsWith("Stub")
                && !cls.getCanonicalName()
                .startsWith("com.puppycrawl.tools.checkstyle.internal.testmodules")
                && !cls.getCanonicalName()
                .startsWith("com.puppycrawl.tools.checkstyle.packageobjectfactory")) {
            result.add(cls);
        }
    }
    return result;
}
 
開發者ID:rnveach,項目名稱:checkstyle-backport-jre6,代碼行數:27,代碼來源:CheckUtil.java

示例2: getAllCommandClasses

import com.google.common.reflect.ClassPath.ClassInfo; //導入方法依賴的package包/類
/**
 * Gets the set of all non-abstract classes implementing the {@link Command} interface (abstract
 * class and interface subtypes of Command aren't expected to have cli commands). Note that this
 * also filters out HelpCommand, which has special handling in {@link RegistryCli} and isn't in
 * the command map.
 *
 * @throws IOException if reading the classpath resources fails.
 */
@SuppressWarnings("unchecked")
private ImmutableSet<Class<? extends Command>> getAllCommandClasses() throws IOException {
  ImmutableSet.Builder<Class<? extends Command>> builder = new ImmutableSet.Builder<>();
  for (ClassInfo classInfo : ClassPath
      .from(getClass().getClassLoader())
      .getTopLevelClassesRecursive(getPackageName(getClass()))) {
    Class<?> clazz = classInfo.load();
    if (Command.class.isAssignableFrom(clazz)
        && !Modifier.isAbstract(clazz.getModifiers())
        && !Modifier.isInterface(clazz.getModifiers())
        && !clazz.equals(HelpCommand.class)) {
      builder.add((Class<? extends Command>) clazz);
    }
  }
  return builder.build();
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:25,代碼來源:RegistryToolTest.java

示例3: initialize

import com.google.common.reflect.ClassPath.ClassInfo; //導入方法依賴的package包/類
@PostConstruct
public void initialize() {
  annotationByServiceInterface = new HashMap<>();

  ImmutableSet<ClassInfo> classInfos;
  try {
    classInfos =
        ClassPath.from(DiqubeThriftServiceInfoManager.class.getClassLoader()).getTopLevelClassesRecursive(BASE_PKG);
  } catch (IOException e) {
    throw new RuntimeException("Could not parse ClassPath.");
  }

  for (ClassInfo classInfo : classInfos) {
    Class<?> clazz = classInfo.load();

    DiqubeThriftService annotation = clazz.getAnnotation(DiqubeThriftService.class);
    if (annotation != null)
      annotationByServiceInterface.put(annotation.serviceInterface(), new DiqubeThriftServiceInfo<>(annotation));
  }
  logger.info("Found {} diqube services in {} scanned classes.", annotationByServiceInterface.size(),
      classInfos.size());
}
 
開發者ID:diqube,項目名稱:diqube,代碼行數:23,代碼來源:DiqubeThriftServiceInfoManager.java

示例4: main

import com.google.common.reflect.ClassPath.ClassInfo; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException, InstantiationException, IllegalAccessException {
  Collection<ClassInfo> classInfos =
      ClassPath.from(Tool.class.getClassLoader()).getTopLevelClassesRecursive(BASE_PKG);

  Map<String, ToolFunction> toolFunctions = new HashMap<>();

  for (ClassInfo classInfo : classInfos) {
    Class<?> clazz = classInfo.load();
    ToolFunctionName toolFunctionName = clazz.getAnnotation(ToolFunctionName.class);
    if (toolFunctionName != null) {
      ToolFunction functionInstance = (ToolFunction) clazz.newInstance();
      toolFunctions.put(toolFunctionName.value(), functionInstance);
    }
  }

  new Tool(toolFunctions).execute(args);
}
 
開發者ID:diqube,項目名稱:diqube,代碼行數:18,代碼來源:Tool.java

示例5: loadActualFunctions

import com.google.common.reflect.ClassPath.ClassInfo; //導入方法依賴的package包/類
private Map<String, Pair<AbstractActualIdentityToolFunction, IsActualIdentityToolFunction>> loadActualFunctions() {
  try {
    Collection<ClassInfo> classInfos =
        ClassPath.from(getClass().getClassLoader()).getTopLevelClassesRecursive(BASE_PKG);

    Map<String, Pair<AbstractActualIdentityToolFunction, IsActualIdentityToolFunction>> toolFunctions =
        new HashMap<>();

    for (ClassInfo classInfo : classInfos) {
      Class<?> clazz = classInfo.load();
      IsActualIdentityToolFunction isActualIdentityToolFunctionAnnotation =
          clazz.getAnnotation(IsActualIdentityToolFunction.class);
      if (isActualIdentityToolFunctionAnnotation != null) {
        AbstractActualIdentityToolFunction functionInstance =
            (AbstractActualIdentityToolFunction) clazz.newInstance();

        toolFunctions.put(isActualIdentityToolFunctionAnnotation.identityFunctionName(),
            new Pair<>(functionInstance, isActualIdentityToolFunctionAnnotation));
      }
    }

    return toolFunctions;
  } catch (IOException | InstantiationException | IllegalAccessException e) {
    throw new RuntimeException(e);
  }
}
 
開發者ID:diqube,項目名稱:diqube,代碼行數:27,代碼來源:IdentityToolFunction.java

示例6: testCopy

import com.google.common.reflect.ClassPath.ClassInfo; //導入方法依賴的package包/類
@Test
public void testCopy() throws IOException {
  // We use top level classes to ignore node types defined as inner classes for tests.
  ImmutableSet<ClassInfo> topLevelClasses =
      ClassPath.from(ClassLoader.getSystemClassLoader()).getTopLevelClasses();
  Set<String> errors = new LinkedHashSet<>();
  for (ClassInfo clazz : topLevelClasses) {
    if (clazz.getPackageName().startsWith("com.google.template.soy")) {
      Class<?> cls = clazz.load();
      if (Node.class.isAssignableFrom(cls)) {
        if (cls.isInterface()) {
          continue;
        }
        if (Modifier.isAbstract(cls.getModifiers())) {
          checkAbstractNode(cls, errors);
        } else {
          checkConcreteNode(cls, errors);
        }
      }
    }
  }
  if (!errors.isEmpty()) {
    fail("Copy policy failure:\n" + Joiner.on('\n').join(errors));
  }
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:26,代碼來源:CopyPolicyTest.java

示例7: allModelsSerializable

import com.google.common.reflect.ClassPath.ClassInfo; //導入方法依賴的package包/類
@Test
public void allModelsSerializable() throws IOException, NoSuchFieldException, IllegalAccessException {
    final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    for (ClassInfo classInfo : from(contextClassLoader).getTopLevelClasses("com.github.dockerjava.api.model")) {
        if (classInfo.getName().endsWith("Test")) {
            continue;
        }

        final Class<?> aClass = classInfo.load();
        if (aClass.getProtectionDomain().getCodeSource().getLocation().getPath().endsWith("test-classes/")
                || aClass.isEnum()) {
            continue;
        }

        LOG.debug("aClass: {}", aClass);
        assertThat(aClass, typeCompatibleWith(Serializable.class));

        final Object serialVersionUID = FieldUtils.readDeclaredStaticField(aClass, "serialVersionUID", true);
        if (!excludeClasses.contains(aClass.getName())) {
            assertThat(serialVersionUID, instanceOf(Long.class));
            assertThat("Follow devel docs", (Long) serialVersionUID, is(1L));
        }
    }
}
 
開發者ID:docker-java,項目名稱:docker-java,代碼行數:25,代碼來源:ModelsSerializableTest.java

示例8: initProviders

import com.google.common.reflect.ClassPath.ClassInfo; //導入方法依賴的package包/類
private void initProviders() {
    ClassPath classPath;
    try {
        classPath = ClassPath.from(ProviderContext.class.getClassLoader());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    
    Set<ClassInfo> classInfos = classPath.getTopLevelClassesRecursive(basePackage);
    
    for (ClassInfo classInfo : classInfos) {
        
        Class<?> clazz = classInfo.load();
        if (clazz.getAnnotation(Provider.class) == null) {
            continue;
        }
        
        Class<?>[] interfaces = clazz.getInterfaces();
        if (interfaces == null || interfaces.length == 0) {
            throw new RuntimeException("Must implement interface");
        }
        
        Object providerInstance = objenesis.newInstance(clazz);
        providerContainer.register(interfaces[0], providerInstance);
        registry.register(new Registration(NetUtils.getLocalAddress(), port, interfaces[0].getName()));
    }
    
}
 
開發者ID:DanceFirstThinkLater,項目名稱:PetiteRPC,代碼行數:29,代碼來源:ProviderContext.java

示例9: hasTestMethod

import com.google.common.reflect.ClassPath.ClassInfo; //導入方法依賴的package包/類
private boolean hasTestMethod(ClassInfo input) {
  Class<?> cls = input.load();
  Method[] mm = cls.getDeclaredMethods();
  for (Method method : mm) {
    if (method.getAnnotation(org.junit.Test.class) != null) {
      return true;
    }
  }
  return false;
}
 
開發者ID:wizards-of-lua,項目名稱:wizards-of-lua,代碼行數:11,代碼來源:WolTestEnvironment.java

示例10: before

import com.google.common.reflect.ClassPath.ClassInfo; //導入方法依賴的package包/類
@Before
public void before() throws IOException
{
	RuneLite.setOptions(mock(OptionSet.class));

	Injector injector = Guice.createInjector(new RuneLiteModule(),
		BoundFieldModule.of(this));
	RuneLite.setInjector(injector);

	runelite = injector.getInstance(RuneLite.class);
	runelite.setGui(clientUi);
	runelite.setNotifier(notifier);

	// Find plugins we expect to have
	pluginClasses = new HashSet<>();
	Set<ClassInfo> classes = ClassPath.from(getClass().getClassLoader()).getTopLevelClassesRecursive(PLUGIN_PACKAGE);
	for (ClassInfo classInfo : classes)
	{
		Class<?> clazz = classInfo.load();
		PluginDescriptor pluginDescriptor = clazz.getAnnotation(PluginDescriptor.class);
		if (pluginDescriptor != null)
		{
			pluginClasses.add(clazz);
		}
	}

}
 
開發者ID:runelite,項目名稱:runelite,代碼行數:28,代碼來源:PluginManagerTest.java

示例11: TransformerInjectOptifine

import com.google.common.reflect.ClassPath.ClassInfo; //導入方法依賴的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 !");
}
 
開發者ID:NekoCaffeine,項目名稱:Alchemy,代碼行數:13,代碼來源:TransformerInjectOptifine.java

示例12: constantsFrom

import com.google.common.reflect.ClassPath.ClassInfo; //導入方法依賴的package包/類
private Set<Field> constantsFrom(ClassInfo classInfo) {
    try {
        Class<?> loaded = classInfo.load();
        // Reflection.initialize(loaded);
        return Reflections.constantsFrom(loaded).stream().filter(f -> !Reflections.isSerialVersionUid(f))
                .collect(Collectors.toSet());
    } catch (Throwable e) {
        LOGGER.warn("Could not load class " + classInfo + ". Ignoring it.");
        return Collections.emptySet();
    }
}
 
開發者ID:tensorics,項目名稱:tensorics-core,代碼行數:12,代碼來源:ClasspathConstantScanner.java

示例13: initialize

import com.google.common.reflect.ClassPath.ClassInfo; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@PostConstruct
public void initialize() throws IOException {
  commandClasses = new HashMap<>();
  Set<ClassInfo> classInfos =
      ClassPath.from(getClass().getClassLoader()).getTopLevelClassesRecursive("org.diqube.ui");
  for (ClassInfo classInfo : classInfos) {
    Class<?> clazz = classInfo.load();
    if (clazz.isAnnotationPresent(CommandInformation.class) && JsonCommand.class.isAssignableFrom(clazz)) {
      CommandInformation annotation = clazz.getAnnotation(CommandInformation.class);

      commandClasses.put(annotation.name(), (Class<? extends JsonCommand>) clazz);
    }
  }
}
 
開發者ID:diqube,項目名稱:diqube,代碼行數:16,代碼來源:JsonRequestDeserializer.java

示例14: initAnalizers

import com.google.common.reflect.ClassPath.ClassInfo; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private static void initAnalizers() {

	ImmutableSet<ClassInfo> classInfos = null;
	try {
		classInfos = ClassPath.from(Analyzers.class.getClassLoader())
				.getTopLevelClassesRecursive(
						Analyzers.class.getPackage().getName());
		for (ClassInfo classInfo : classInfos) {
			Class<?> claz = classInfo.load();
			try {

				if (NodeAnalyzer.class.isAssignableFrom(claz)
						&& !claz.isInterface()
						&& !Modifier.isAbstract(claz.getModifiers())) {
					register((NodeAnalyzer<QueryTreeNode, AnalyzeResult>) claz
							.newInstance());
				}
			} catch (Exception e) {
				// TODO LOG Auto-generated catch block
				e.printStackTrace();
				System.out.println(claz);
			}
		}
	} catch (IOException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}

}
 
開發者ID:58code,項目名稱:Oceanus,代碼行數:31,代碼來源:Analyzers.java

示例15: loadClassSafe

import com.google.common.reflect.ClassPath.ClassInfo; //導入方法依賴的package包/類
private static Method[] loadClassSafe(ClassInfo c)
{
	try
	{
		Class<?> clazz = c.load();
		return clazz.getDeclaredMethods();
	}
	catch (Throwable t)
	{
		logErr(String.format("Class %s threw an error on load, skipping...", c.getName()));
		return new Method[] {};
	}
}
 
開發者ID:TPPIDev,項目名稱:RecipeTweakingCore,代碼行數:14,代碼來源:RecipeTweakingCore.java


注:本文中的com.google.common.reflect.ClassPath.ClassInfo.load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。