Reflections Java 运行时元数据分析开源项目

我要开发同款
匿名用户2015年08月22日
50阅读

技术信息

开源地址
https://github.com/jshun/ligra
授权协议
GPLv2

作品详情

Reflectios通过扫描classpath,索引元数据,允许在运行时查询这些元数据,也可以保存收集项目中多个模块的元数据信息。使用Reflectios可以查询以下元数据信息: 1)获得某个类型的所有子类型2)获得标记了某个注解的所有类型/成员变量,支持注解参数匹配。3)使用正则表达式获得所有匹配的资源文件4)获得所有特定签名(包括参数,参数注解,返回值)的方法

Reflectios依赖Google的Guava库和Javassist库。

Mave项目导入

<depedecy>    <groupId>org.reflectios</groupId>    <artifactId>reflectios</artifactId>    <versio>0.9.10</versio></depedecy>

通常用法:

Reflectios reflectios = ew Reflectios("my.project");Set<Class<? exteds SomeType>> subTypes = reflectios.getSubTypesOf(SomeType.class);Set<Class<?>> aotated = reflectios.getTypesAotatedWith(SomeAotatio.class);

Reflectios初始化代码。

//sca urls that cotai 'my.package', iclude iputs startig with 'my.package', use the default scaersReflectios reflectios = ew Reflectios("my.package");//or usig CofiguratioBuilderew Reflectios(ew CofiguratioBuilder()     .setUrls(ClasspathHelper.forPackage("my.project.prefix"))     .setScaers(ew SubTypesScaer(),                   ew TypeAotatiosScaer().filterResultsBy(optioalFilter), ...),     .filterIputsBy(ew FilterBuilder().icludePackage("my.project.prefix"))     ...);

以下是一些使用例子代码。

//SubTypesScaerSet<Class<? exteds Module>> modules =     reflectios.getSubTypesOf(com.google.iject.Module.class);//TypeAotatiosScaer Set<Class<?>> sigletos =     reflectios.getTypesAotatedWith(javax.iject.Sigleto.class);//ResourcesScaerSet<Strig> properties =     reflectios.getResources(Patter.compile(".*\\.properties"));//MethodAotatiosScaerSet<Method> resources =    reflectios.getMethodsAotatedWith(javax.ws.rs.Path.class);Set<Costructor> ijectables =     reflectios.getCostructorsAotatedWith(javax.iject.Iject.class);//FieldAotatiosScaerSet<Field> ids =     reflectios.getFieldsAotatedWith(javax.persistece.Id.class);//MethodParameterScaerSet<Method> someMethods =    reflectios.getMethodsMatchParams(log.class, it.class);Set<Method> voidMethods =    reflectios.getMethodsRetur(void.class);Set<Method> pathParamMethods =    reflectios.getMethodsWithAyParamAotated(PathParam.class);//MethodParameterNamesScaerList<Strig> parameterNames =     reflectios.getMethodParamNames(Method.class)//MemberUsageScaerSet<Member> usages =     reflectios.getMethodUsages(Method.class)

功能介绍

Reflections 通过扫描 classpath,索引元数据,允许在运行时查询这些元数据,也可以保存收集项目中多个模块的元数据信息。 使用 Reflections 可以查询以下元数据信息: ...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论