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


Java ClassPath.getAllClasses方法代碼示例

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


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

示例1: loadAllProvider

import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
@Unsafe(Unsafe.ASM_API)
private static void loadAllProvider() throws Exception {
	ClassPath path = ClassPath.from(AlchemyTransformerManager.class.getClassLoader());
	for (ClassInfo info : path.getAllClasses())
		if (info.getName().startsWith(MOD_PACKAGE)) {
			ClassReader reader = new ClassReader(info.url().openStream());
			ClassNode node = new ClassNode(ASM5);
			reader.accept(node, 0);
			if (checkSideOnly(node)) {
				loadPatch(node);
				loadField(node);
				loadProxy(node);
				loadHook(node);
				loadTransform(node, info);
			}
		}
}
 
開發者ID:NekoCaffeine,項目名稱:Alchemy,代碼行數:18,代碼來源:AlchemyTransformerManager.java

示例2: tesstByteBuf

import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
public void tesstByteBuf() throws InterruptedException, IOException {
    ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
    ClassPath from = ClassPath.from(systemClassLoader);
    StdInstantiatorStrategy instantiator = new StdInstantiatorStrategy();

    Class<Request> requestClazz = Request.class;
    for (ClassPath.ClassInfo clazz : from.getAllClasses()) {
        Class<?> load;
        try {
            load = clazz.load();
        } catch (NoClassDefFoundError e) {
            continue;
        }

        for (Class<?> aClass : load.getInterfaces()) {
            if (aClass.equals(requestClazz)) {
                Object o = instantiator.newInstantiatorOf(aClass).newInstance();
                testByteBuf((Request) o);
            }
        }
    }
}
 
開發者ID:buremba,項目名稱:kume,代碼行數:23,代碼來源:SerializationTest.java

示例3: getRecognizedClasses

import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
private Set<ClassPath.ClassInfo> getRecognizedClasses(ClassLoader classLoader, List<String> packages) {
    Set<ClassPath.ClassInfo> result = new HashSet<>();
    try {
        ClassPath classPath = ClassPath.from(classLoader);
        for (ClassPath.ClassInfo classInfo : classPath.getAllClasses()) {
            String packageName = classInfo.getPackageName();
            for (String aPackage : packages) {
                if (packageName.startsWith(aPackage)) {
                    result.add(classInfo);
                }
            }
        }
    } catch (IOException e) {
        logger.severe("Cannot create ClassPath: " + e);
    }
    return result;
}
 
開發者ID:crispab,項目名稱:codekvast,代碼行數:18,代碼來源:CodeBaseScanner.java

示例4: AutomaticPacketDeserializer

import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
public AutomaticPacketDeserializer() {
	constructors = new Constructor<?>[0xFFFF];
	try {
		ClassPath cp = ClassPath.from(AutomaticPacketDeserializer.class.getClassLoader());
		for (ClassPath.ClassInfo info : cp.getAllClasses()) {
			Class<?> c = info.load();
			if (Packet.class.isAssignableFrom(c)) {
				for (Constructor<?> constructor : c.getConstructors()) {
					if (constructor.isAnnotationPresent(Opcode.class)) {
						constructors[constructor.getAnnotation(Opcode.class).value()] = constructor;
					}
				}
			}
		}
	} catch (IOException e) {
		throw new Error("OpenMaple was unable to access classpath resources.", e);
	}
}
 
開發者ID:aatxe,項目名稱:OpenMaple,代碼行數:19,代碼來源:AutomaticPacketDeserializer.java

示例5: documentEndpoints

import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
/**
 * Discover and document all web service endpoints using reflection.
 */
public static void documentEndpoints(Predicate<ClassPath.ClassInfo> filter, PrintWriter out) throws Exception {

    final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    final ClassPath classPath = ClassPath.from(classLoader);
    final ImmutableSet<ClassPath.ClassInfo> allClasses = classPath.getAllClasses();
    allClasses.forEach(info -> {
        if (filter == null || filter.test(info)) {
            Class<?> c = info.load();
            if (!Modifier.isAbstract(c.getModifiers()) && !c.isInterface()) {
                documentEndpoint(c, out);
            }
        }
    });
}
 
開發者ID:pwalser75,項目名稱:jee-demo,代碼行數:18,代碼來源:WebServiceEndpointIntrospection.java

示例6: execute

import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
	if (args.length > 0)
		try {
			String name = Joiner.on(' ').join(args);
			File file = new File(AlchemyModLoader.mc_dir, "mods/" + name);
			if (file.exists() && !file.isDirectory()) {
				ClassLoader loader = new URLClassLoader(new URL[]{ file.toURI().toURL() }, null);
				ClassPath path = ClassPath.from(loader);
				StringBuilder builder = new StringBuilder();
				for (ClassInfo info : path.getAllClasses()) {
					ClassReader reader = new ClassReader(info.getName());
					ClassWriter writer = new ClassWriter(0);
					ClassNode node = new ClassNode(ASM5);
					reader.accept(node, 0);
					for (MethodNode method : node.methods) {
						int index = 0;
						for (Iterator<AbstractInsnNode> iterator = method.instructions.iterator(); iterator.hasNext();) {
							AbstractInsnNode insn = iterator.next();
							if (insn instanceof LdcInsnNode) {
								LdcInsnNode ldc = (LdcInsnNode) insn;
								if (ldc.cst instanceof String)
									builder.append('-').append(info.getName()).append('#').append(method.name).append('@')
									.append(index++).append('=').append(((String) ldc.cst).replace("\n", "\\n")).append('\n');
							}
						}
					}
				}
				File dir = new File(AlchemyModLoader.mc_dir, "lang"),
						lang = new File(AlchemyModLoader.mc_dir, "lang/" + file.getName() + ".lang");
				if (!dir.exists())
					dir.mkdirs();
				Tool.save(lang, builder.toString());
			} else
				sender.addChatMessage(new TextComponentString(file.getCanonicalPath() + "not found."));
		} catch(Exception e) { e.printStackTrace(); }
}
 
開發者ID:NekoCaffeine,項目名稱:Alchemy,代碼行數:38,代碼來源:CommandMakeLang.java

示例7: findClassFromURL

import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
public static List<String> findClassFromURL(URL url) throws Exception {
	List<String> result = Lists.newLinkedList();
	ClassLoader loader = new URLClassLoader(new URL[]{ url }, null);
	ClassPath path = ClassPath.from(loader);
	for (ClassInfo info : path.getAllClasses())
		if (!info.getName().matches(".*\\$[0-9]+") && !info.getName().contains("$$"))
			result.add(info.getName());
	return result;
}
 
開發者ID:NekoCaffeine,項目名稱:Alchemy,代碼行數:10,代碼來源:AlchemyEngine.java

示例8: scanAndInstantiate

import com.google.common.reflect.ClassPath; //導入方法依賴的package包/類
List<Plugin> scanAndInstantiate(ClassLoader classLoader, String packageName) throws IOException
{
	boolean developerPlugins = RuneLite.getOptions().has("developer-mode");

	List<Plugin> scannedPlugins = new ArrayList<>();
	ClassPath classPath = ClassPath.from(classLoader);

	ImmutableSet<ClassInfo> classes = packageName == null ? classPath.getAllClasses()
		: classPath.getTopLevelClassesRecursive(packageName);
	for (ClassInfo classInfo : classes)
	{
		Class<?> clazz = classInfo.load();
		PluginDescriptor pluginDescriptor = clazz.getAnnotation(PluginDescriptor.class);

		if (pluginDescriptor == null)
		{
			if (clazz.getSuperclass() == Plugin.class)
			{
				log.warn("Class {} is a plugin, but has no plugin descriptor",
					clazz);
			}
			continue;
		}

		if (clazz.getSuperclass() != Plugin.class)
		{
			log.warn("Class {} has plugin descriptor, but is not a plugin",
				clazz);
			continue;
		}

		if (!pluginDescriptor.loadWhenOutdated() && isOutdated)
		{
			continue;
		}

		if (pluginDescriptor.developerPlugin() && !developerPlugins)
		{
			continue;
		}

		Plugin plugin;
		try
		{
			plugin = instantiate(pluginDescriptor, (Class<Plugin>) clazz);
		}
		catch (PluginInstantiationException ex)
		{
			log.warn("error instantiating plugin!", ex);
			continue;
		}

		scannedPlugins.add(plugin);
	}

	return scannedPlugins;
}
 
開發者ID:runelite,項目名稱:runelite,代碼行數:58,代碼來源:PluginManager.java


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