Reputation: 159
I am not able to find much documentation about ConfigurationBuilder,FilterBuilder,Scanners in java reflection. Can someone explain me what is there use case ?
Upvotes: 1
Views: 989
Reputation: 22292
You seem to be talking about classes from Java Reflections library, and not standard java.lang.reflect
code.
To make things simple, all three classes are used to configure the Reflections object, which will parse your source code and allow you to query it.
As the GitHub page states, there is some Javadoc :
If you take a glance at ConfigurationBuilder
javadoc, a kind of pattern appear (I took freedom to add some comments to make things shine) :
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)));
I guess reflections authors could indeed improve their doc a little ...
Upvotes: 2