首页 新闻 Reflections—Java运行数据分析

邮件订阅

Reflections—Java运行数据分析 打印 E-mail
用户评价: / 0
好 
作者:JavaEye网站   
2008-12-04 01:07



来自google code项目页:http://code.google.com/p/reflections/

Reflections可以扫描您的类路径,索引的数据,可以允许你在运行时查询、保存和收集您项目中许多模块的信息。

使用Reflections,您可以查询您的元数据:

  • 获取所有子型的某些类型
  • 获取所有类型的一些说明注释,包括注释参数的匹配
  • 所有的方法能获取一些说明


如何来使用呢?

对所有的 Reflections 使用一站式的Reflections对象:

  • 获取一个 Reflections实例,它提供了您的最初配置
  • 查询您的项目元数据


代码如下:

Configuration configuration = new AbstractConfiguration() {
{
setUrls(ClasspathHelper.getUrlsForCurrentClasspath());
setScanners(new SubTypesScanner(), new ClassAnnotationsScanner());
setFilter(new IncludeExcludeChain(
new IncludePrefix("your project's common package prefix here...")
));
}
};

Reflections reflections = new Reflections(configuration);

// get all subtypes of some type
Set<Class><?>> subTypes = reflections.getSubTypesOf(SomeClassOrInterface.class);

// get all types annotated with some annotation
Set<Class><?>> annotated = reflections.getTypesAnnotatedWith(SomeAnnotation.class);

// get all types annotated with some annotation, including annotation parameters matching
Set<Class><?>> annotated1 = reflections.getTypesAnnotatedWith(new SomeAnnotation() {
public String value() {return "1";}
public Class<? extends Annotation> annotationType() {return SomeAnnotation.class;}
}) ;
}




更多详情请点击项目页:http://code.google.com/p/reflections/

 



来自:theserverside.com

最后更新于: 2008-12-04 01:07
 

欢迎转载

本站文章欢迎转载,但请注明出处(http://www.javajia.com,Java家)

其他相关文章