java反射中的ConfigurationBuilder,FilterBuilder,扫描器



我无法在java反射中找到关于ConfigurationBuilder,FilterBuilder,扫描仪的很多文档。谁能给我解释一下用例是什么?

您似乎在谈论Java Reflections库中的类,而不是标准java.lang.reflect代码。

为了简单起见,所有三个类都用于配置Reflections对象,该对象将解析源代码并允许您查询它。

正如GitHub页面所述,有一些Javadoc:

  • ConfigurationBuilder
  • FilterBuilder
  • Scanner

如果您看一眼ConfigurationBuilder javadoc,就会出现一种模式(我冒昧地添加了一些注释以使其更清晰):

  new Reflections(
    /* 
     * ConfigurationBuilder is used to build a configuration parsable by Reflection.
     * This configuration must include a few things :
     * - where to look for classes
     * - what to look in classes
     */
      new ConfigurationBuilder()
        /*
         * FilterBuilder answers the *where* question by specifying which fragments 
         * of classpath are to be scanned. Indeed, as far as I understand, 
         * Reflections can parse the whole classpath, which will be way to slow 
         * for anybody  (and contains lots of useless java.* classes). So your 
         FilterBuilder defines include patterns for the packages you need
         */
          .filterInputsBy(new FilterBuilder().include("your project's common package prefix here..."))
          .setUrls(ClasspathHelper.forClassLoader())
          /*
           * Scanner defines the what : if you look for subclasses, you'll need 
           * to add a subclass scanner. if you look for 
           * annotations, the type annotation scanner is required, and so on.
           */
          .setScanners(new SubTypesScanner(), new TypeAnnotationsScanner().filterResultsBy(myClassAnnotationsFilter)));

相关内容

  • 没有找到相关文章

最新更新