本文整理匯總了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;
}
示例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();
}
示例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());
}
示例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);
}
示例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);
}
}
示例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));
}
}
示例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));
}
}
}
示例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()));
}
}
示例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;
}
示例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);
}
}
}
示例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 !");
}
示例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();
}
}
示例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);
}
}
}
示例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();
}
}
示例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[] {};
}
}