当前位置: 首页>>代码示例>>Java>>正文


Java Reflections.getTypesAnnotatedWith方法代码示例

本文整理汇总了Java中org.reflections.Reflections.getTypesAnnotatedWith方法的典型用法代码示例。如果您正苦于以下问题:Java Reflections.getTypesAnnotatedWith方法的具体用法?Java Reflections.getTypesAnnotatedWith怎么用?Java Reflections.getTypesAnnotatedWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.reflections.Reflections的用法示例。


在下文中一共展示了Reflections.getTypesAnnotatedWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerAnnotations

import org.reflections.Reflections; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void registerAnnotations() {
    final Reflections reflections = new Reflections(packagePrefix);
    final Set<Class<?>> namedClasses = reflections.getTypesAnnotatedWith(Named.class);
    for (final Class<?> namedClass : namedClasses) {
        final ServiceReference reference = namedClassReference(namedClass);
        final Constructor<?> namedConstructor = constructorFinder.apply(namedClass);
        final ServiceReference<?>[] parameters = stream(namedConstructor.getParameterTypes())
                .map(NamedClassReference::namedClassReference)
                .toArray(ServiceReference<?>[]::new);
        accept(serviceDefinition(
                namedClassReference(namedClass),
                constructor(reference, namedConstructor, parameters),
                postConstructDependencyFinder.apply(namedClass)
        ));
        stream(serviceFromMethodFinder.apply(namedClass)).forEach(this);
    }
}
 
开发者ID:slezhnin,项目名称:yadi,代码行数:19,代码来源:PackageScanModule.java

示例2: searchRouters

import org.reflections.Reflections; //导入方法依赖的package包/类
private void searchRouters(RouteRegister register, String pacakge) {
    Reflections reflections = new Reflections(pacakge);
    Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(Route.class);
    for (Class<?> c : annotated) {
        Route annotation = c.getAnnotation(Route.class);
        try {
            if (annotation.method().length > 0)
                register.registerRouter(annotation.method()[0], annotation.path(),
                        (Handler<RoutingContext>) c.newInstance());
            else
                register.registerRouter(annotation.path(), (Handler<RoutingContext>) c.newInstance());
        } catch (InstantiationException | IllegalAccessException | RegisterException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:DSM-DMS,项目名称:DMS,代码行数:17,代码来源:RouteRegister.java

示例3: autoRegister

import org.reflections.Reflections; //导入方法依赖的package包/类
/**
 * Auto register classes annotated with `Service`
 */
private void autoRegister() {

    Reflections reflections = ReflectKit.getReflections(appClass);

    // scan inject annotated class
    Set<Class<?>> types = reflections.getTypesAnnotatedWith(Service.class);
    types.forEach(this::recursiveRegisterType);

    // cache constructors
    types.forEach(t -> {
        try {

            ConstructorWalker.findInjectConstructor(t);
        } catch (Exception e) {

            log.error(e.getMessage());
        }
    });
}
 
开发者ID:thundernet8,项目名称:Razor,代码行数:23,代码来源:ContainerBuilder.java

示例4: getMethodMap

import org.reflections.Reflections; //导入方法依赖的package包/类
/**
 * 获取方法映射map
 *
 * @param reflections 反射类列表
 * @return 方法映射map
 */
private Map<String, ServerMethod> getMethodMap(Reflections reflections)
        throws IllegalAccessException, InstantiationException {
    // 获取HermesService注解类
    Set<Class<?>> classes = reflections.getTypesAnnotatedWith(HermesService.class);
    Map<String, ServerMethod> map = new TreeMap<>();
    for (Class<?> c : classes) {
        for (Method method : c.getDeclaredMethods()) {
            Object object = c.newInstance();
            HermesMapping hermesMapping = method.getAnnotation(HermesMapping.class);
            if (hermesMapping != null) {
                map.put(hermesMapping.value(), new ServerMethod(object, method));
            }
        }
    }
    return map;
}
 
开发者ID:cwdtom,项目名称:hermes-java,代码行数:23,代码来源:HermesRegister.java

示例5: EventListener

import org.reflections.Reflections; //导入方法依赖的package包/类
EventListener() {
    final Reflections loader = new Reflections("jukebot.commands");

    Set<Class<?>> discoveredCommands = loader.getTypesAnnotatedWith(CommandProperties.class);
    JukeBot.LOG.info("Discovered " + discoveredCommands.size() + " commands");

    for (Class klass : discoveredCommands) {
        try {
            final Command cmd = (Command) klass.newInstance();

            if (!cmd.properties().enabled())
                continue;

            commands.put(cmd.name().toLowerCase(), cmd);
        } catch (InstantiationException | IllegalAccessException e) {
            JukeBot.LOG.error("An error occurred while creating a new instance of command '" + klass.getName() + "'");
        }
    }
}
 
开发者ID:Devoxin,项目名称:JukeBot,代码行数:20,代码来源:EventListener.java

示例6: main

import org.reflections.Reflections; //导入方法依赖的package包/类
public static void main(String[] args) throws FileNotFoundException {
    if (args.length != 1) throw new IllegalArgumentException("Missing argument 0: Path to write routes");

    Reflections reflections = new Reflections("io.t2l.matrix.homeserver.federation.transport.http.routes");
    Set<Class<?>> routedClasses = reflections.getTypesAnnotatedWith(Route.class);

    try (PrintWriter writer = new PrintWriter(args[0])) {
        writer.println("# !!!!! This file is automatically generated !!!!!");
        writer.println("# !  Any changes you make may not be saved. Use  !");
        writer.println("# !  `gradle buildRoutes` to change these routes !");
        writer.println("# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        for (Class<?> clazz : routedClasses) {
            String route = clazz.getAnnotation(Route.class).value();
            writer.println("rest." + route + "=" + clazz.getName());
            System.out.println("Writing route " + route + " for class " + clazz.getName());
        }
    }
}
 
开发者ID:turt2live,项目名称:matrix-embedded-federation,代码行数:19,代码来源:RouteFinder.java

示例7: load

import org.reflections.Reflections; //导入方法依赖的package包/类
public void load() throws Exception {
    Reflections reflections = ReflectionsUtils.getSharedReflectionsInstance();
    Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(Module.class);

    for (Class<?> moduleClass : annotated) {
        Module moduleInfo = moduleClass.getAnnotation(Module.class);

        if (!UnknownPandaModule.class.isAssignableFrom(moduleClass)) {
            UnknownPandaServer.getLogger().error(moduleClass + " is not a description");
            continue;
        }

        UnknownPandaServer.getLogger().info("Including " + moduleInfo.author() + ":" + moduleInfo.name() + " v" + moduleInfo.version());
        UnknownPandaModule module = (UnknownPandaModule) moduleClass.newInstance();
        module.description = moduleInfo;

        manager.registerModule(module);
    }

    UnknownPandaServer.getLogger().info(manager.countModules() + " modules have been loaded");
}
 
开发者ID:dzikoysk,项目名称:UnknownPandaServer,代码行数:22,代码来源:ModuleLoader.java

示例8: lookupAnnotatedClasses

import org.reflections.Reflections; //导入方法依赖的package包/类
/**
 * Searches the class path for types with the given annotation
 *
 * @param annotationClass The annotation for which to search
 * @return A map of classes with the given annotation
 */
private Map<ComponentKey, Class<?>> lookupAnnotatedClasses(Class<? extends Annotation> annotationClass) {
	Reflections reflections = new Reflections("gov.cms");
	Set<Class<?>> annotatedClasses = reflections.getTypesAnnotatedWith(annotationClass);
	Map<ComponentKey, Class<?>> registry = new HashMap<>(annotatedClasses.size());

	for (Class<?> annotatedClass : annotatedClasses) {
		for (ComponentKey key : getComponentKeys(annotatedClass)) {
			registry.put(key, annotatedClass);
		}
	}

	return registry;
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:20,代码来源:Registry.java

示例9: scan

import org.reflections.Reflections; //导入方法依赖的package包/类
public void scan(List<String> scanPackages) {
    ExecutionTimer timer = new ExecutionTimer(LogLevel.Info, true);
    for (String scanPackage : scanPackages) {
        logger.debug("Scanning for limberest services in package: {}", scanPackage);
        Reflections reflect = new Reflections(scanPackage);
        // service classes
        for (Class<?> classWithPath : reflect.getTypesAnnotatedWith(Path.class)) {
            logger.info("Found service class: {}", classWithPath.getName());
            Path pathAnnotation = classWithPath.getAnnotation(Path.class);
            if (pathAnnotation != null) {
                String path = pathAnnotation.value();
                if (path != null) {
                    logger.info("  -> and registering with path: {}", path);
                    Produces producesAnnotation = classWithPath.getAnnotation(Produces.class);
                    if (producesAnnotation != null && producesAnnotation.value() != null) {
                        // TODO can only produce one thing and consume if present must match produce
                        Consumes consumesAnnotation = classWithPath.getAnnotation(Consumes.class);
                        for (String contentType : producesAnnotation.value()) {
                            logger.info("  -> for content-type: {}", contentType);
                            @SuppressWarnings({"unchecked", "rawtypes"})
                            Class<? extends RestService<?>> serviceClass = (Class)classWithPath.asSubclass(RestService.class);
                            if (!RestService.class.isAssignableFrom(serviceClass))
                                throw new IllegalArgumentException(serviceClass + " does not extend " + RestService.class);
                            RegistryKey key = new RegistryKey(new ResourcePath(path), contentType);
                            ServiceRegistry.getInstance().put(key, serviceClass);
                        }
                    }
                }
            }
        }
    }
    if (timer.isEnabled())
        timer.log("limberest initializer scanned " + scanPackages.size() + " packages in ");
}
 
开发者ID:limberest,项目名称:limberest,代码行数:35,代码来源:Initializer.java

示例10: findService

import org.reflections.Reflections; //导入方法依赖的package包/类
/**
 * 发现服务, 查找所有扩展了abstractService的类, 这些类保存下来作为service
 */
private static void findService() {
    try {
        Reflections reflections = new Reflections("com.recklessMo.rpc");
        Set<Class<?>> classSet = reflections.getTypesAnnotatedWith(RpcServiceFlag.class, true);
        for (Class<?> inner : classSet) {
            RpcServiceFlag rpcServiceFlag = inner.getAnnotation(RpcServiceFlag.class);
            if (!serverMap.containsKey(rpcServiceFlag.value())) {
                serverMap.put(rpcServiceFlag.value(), inner.newInstance());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:recklessMo,项目名称:nettyRpc,代码行数:18,代码来源:RpcServer.java

示例11: entityList

import org.reflections.Reflections; //导入方法依赖的package包/类
@Bean
public Map<String, Class<?>> entityList() {
	Map<String, Class<?>> result = new HashMap<>();
	Reflections reflections = new Reflections("com.bats.criteriagenerator.entity");
	Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(Entity.class);
	for (Class<?> clazz : annotated)
	{
		Entity entity = clazz.getAnnotation(Entity.class);
		result.put(entity.name(), clazz);
	}
	return result;
}
 
开发者ID:tairmansd,项目名称:CriteriaBuilder,代码行数:13,代码来源:AppConfig.java

示例12: registerAllAnnotated

import org.reflections.Reflections; //导入方法依赖的package包/类
public static Kryo registerAllAnnotated(Kryo destination, Class<? extends Annotation> annotationType,
          String sourcePackageName)
  {
Reflections reflections = new Reflections(getUsedPackageName());
      Set<Class<?>> registerableTypes = reflections.getTypesAnnotatedWith(annotationType);
      destination = registerCollection(destination, registerableTypes);
      Set<Class<?>> registerableBaseTypes = reflections.getTypesAnnotatedWith(defaultAnnotationBase);
      destination = registerSubTypesOf(destination, registerableBaseTypes);
      return destination;
  }
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:11,代码来源:PacketsRegisterer.java

示例13: registerEntityTypes

import org.reflections.Reflections; //导入方法依赖的package包/类
private static void registerEntityTypes(Configuration config)
{
	Reflections reflections = new Reflections("pl.mmorpg.prototype.server.database.entities");
	Set<Class<?>> entityTypes = reflections.getTypesAnnotatedWith(Table.class);
	for (Class<?> type : entityTypes)
		config = config.addAnnotatedClass(type);
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:8,代码来源:HibernateUtil.java

示例14: init

import org.reflections.Reflections; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void init() {
	final Reflections reflections = new Reflections();
	final Set<Class<?>> exporterClasses = reflections.getTypesAnnotatedWith(Exporter.class);
	exporterClasses.forEach(clazz -> {
		final String key = clazz.getAnnotation(Exporter.class).value();
		exporters.put(key, (Class<? extends DictionaryExporter>) clazz);
	});
}
 
开发者ID:sean-liang,项目名称:stardict,代码行数:10,代码来源:ExporterRegistry.java

示例15: init

import org.reflections.Reflections; //导入方法依赖的package包/类
public static boolean init() {
	LogUtils.infof("Initializing commands...");

	Reflections reflections = new Reflections(Shadbot.class.getPackage().getName(), new SubTypesScanner(), new TypeAnnotationsScanner());
	for(Class<?> cmdClass : reflections.getTypesAnnotatedWith(Command.class)) {
		if(!AbstractCommand.class.isAssignableFrom(cmdClass)) {
			LogUtils.errorf("An error occurred while generating command, %s cannot be cast to AbstractCommand.", cmdClass.getSimpleName());
			continue;
		}

		try {
			AbstractCommand cmd = (AbstractCommand) cmdClass.newInstance();

			List<String> names = cmd.getNames();
			if(!cmd.getAlias().isEmpty()) {
				names.add(cmd.getAlias());
			}

			for(String name : names) {
				if(COMMANDS_MAP.putIfAbsent(name, cmd) != null) {
					LogUtils.errorf(String.format("Command name collision between %s and %s",
							cmdClass.getSimpleName(), COMMANDS_MAP.get(name).getClass().getSimpleName()));
					continue;
				}
			}
		} catch (InstantiationException | IllegalAccessException err) {
			LogUtils.errorf(err, "An error occurred while initializing command %s.", cmdClass.getDeclaringClass().getSimpleName());
			return false;
		}
	}

	LogUtils.infof("%s initialized.", StringUtils.pluralOf((int) COMMANDS_MAP.values().stream().distinct().count(), "command"));
	return true;
}
 
开发者ID:Shadorc,项目名称:Shadbot,代码行数:35,代码来源:CommandManager.java


注:本文中的org.reflections.Reflections.getTypesAnnotatedWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。