Class ConfigurationBuilder
- All Implemented Interfaces:
Configuration
Configuration
, to be used for constructing a Reflections
instance
usage:
new Reflections( new ConfigurationBuilder() .filterInputsBy(new FilterBuilder().include("your project's common package prefix here...")) .setUrls(ClasspathHelper.forClassLoader()) .setScanners(new SubTypesScanner(), new TypeAnnotationsScanner().filterResultsBy(myClassAnnotationsFilter)));
executorService
is used optionally used for parallel scanning. if value is null then scanning is done in a simple for loop
defaults: accept all for inputsFilter
,
executorService
is null,
serializer
is XmlSerializer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ClassLoader[]
private ExecutorService
private boolean
protected MetadataAdapter
private Serializer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddClassLoader
(ClassLoader classLoader) add class loader, might be used for resolving methods/fieldsaddClassLoaders
(ClassLoader... classLoaders) add class loader, might be used for resolving methods/fieldsaddClassLoaders
(Collection<ClassLoader> classLoaders) add class loader, might be used for resolving methods/fieldsaddScanners
(Scanner... scanners) set the scanners instances for scanning different metadataadd urls to be scannedaddUrls
(Collection<URL> urls) add urls to be scannedstatic ConfigurationBuilder
constructs aConfigurationBuilder
using the given parameters, in a non statically typed way.filterInputsBy
(Predicate<String> inputsFilter) sets the input filter for all resources to be scanned.forPackages
(String... packages) get class loader, might be used for scanning or resolving methods/fieldsexecutor service used to scan files.get the fully qualified name filter used to filter types to be scannedreturns the metadata adapter.the scanner instances used for scanning different metadatathe default serializer to use when saving ReflectiongetUrls()
the urls to be scannedvoid
setClassLoaders
(ClassLoader[] classLoaders) set class loader, might be used for resolving methods/fieldssetExecutorService
(ExecutorService executorService) sets the executor service used for scanning.setExpandSuperTypes
(boolean expandSuperTypes) if set to true, Reflections will expand super types after scanning.void
setInputsFilter
(Predicate<String> inputsFilter) sets the input filter for all resources to be scanned.setMetadataAdapter
(MetadataAdapter metadataAdapter) sets the metadata adapter used to fetch metadata from classessetScanners
(Scanner... scanners) set the scanners instances for scanning different metadatasetSerializer
(Serializer serializer) sets the serializer used when issuingReflections.save(java.lang.String)
set the urls to be scannedsetUrls
(Collection<URL> urls) set the urls to be scannedboolean
if true (default), expand super types after scanning, for super types that were not scanned.sets the executor service used for scanning to ThreadPoolExecutor with core size asRuntime.availableProcessors()
useParallelExecutor
(int availableProcessors) sets the executor service used for scanning to ThreadPoolExecutor with core size as the given availableProcessors parameter.
-
Field Details
-
scanners
-
urls
-
metadataAdapter
-
inputsFilter
-
serializer
-
executorService
-
classLoaders
-
expandSuperTypes
private boolean expandSuperTypes
-
-
Constructor Details
-
ConfigurationBuilder
public ConfigurationBuilder()
-
-
Method Details
-
build
constructs aConfigurationBuilder
using the given parameters, in a non statically typed way. that is, each element inparams
is guessed by it's type and populated into the configuration.String
- add urls usingClasspathHelper.forPackage(String, ClassLoader...)
()}Class
- add urls usingClasspathHelper.forClass(Class, ClassLoader...)
ClassLoader
- use these classloaders in order to find urls in ClasspathHelper.forPackage(), ClasspathHelper.forClass() and for resolving typesScanner
- use given scanner, overriding the default scannersURL
- add the given url for scanningObject[]
- flatten and use each element as above
FilterBuilder
will be set according to given packages.use any parameter type in any order. this constructor uses instanceof on each param and instantiate a
ConfigurationBuilder
appropriately. -
forPackages
-
getScanners
Description copied from interface:Configuration
the scanner instances used for scanning different metadata- Specified by:
getScanners
in interfaceConfiguration
-
setScanners
set the scanners instances for scanning different metadata -
addScanners
set the scanners instances for scanning different metadata -
getUrls
Description copied from interface:Configuration
the urls to be scanned- Specified by:
getUrls
in interfaceConfiguration
-
setUrls
set the urls to be scanneduse
ClasspathHelper
convenient methods to get the relevant urls -
setUrls
set the urls to be scanneduse
ClasspathHelper
convenient methods to get the relevant urls -
addUrls
add urls to be scanneduse
ClasspathHelper
convenient methods to get the relevant urls -
addUrls
add urls to be scanneduse
ClasspathHelper
convenient methods to get the relevant urls -
getMetadataAdapter
returns the metadata adapter. if javassist library exists in the classpath, this method returnsJavassistAdapter
otherwise defaults toJavaReflectionAdapter
.the
JavassistAdapter
is preferred in terms of performance and class loading.- Specified by:
getMetadataAdapter
in interfaceConfiguration
-
setMetadataAdapter
sets the metadata adapter used to fetch metadata from classes -
getInputsFilter
Description copied from interface:Configuration
get the fully qualified name filter used to filter types to be scanned- Specified by:
getInputsFilter
in interfaceConfiguration
-
setInputsFilter
sets the input filter for all resources to be scanned.supply a
Predicate
or use theFilterBuilder
-
filterInputsBy
sets the input filter for all resources to be scanned.supply a
Predicate
or use theFilterBuilder
-
getExecutorService
Description copied from interface:Configuration
executor service used to scan files. if null, scanning is done in a simple for loop- Specified by:
getExecutorService
in interfaceConfiguration
-
setExecutorService
sets the executor service used for scanning. -
useParallelExecutor
sets the executor service used for scanning to ThreadPoolExecutor with core size asRuntime.availableProcessors()
default is ThreadPoolExecutor with a single core
-
useParallelExecutor
sets the executor service used for scanning to ThreadPoolExecutor with core size as the given availableProcessors parameter. the executor service spawns daemon threads by default.default is ThreadPoolExecutor with a single core
-
getSerializer
Description copied from interface:Configuration
the default serializer to use when saving Reflection- Specified by:
getSerializer
in interfaceConfiguration
-
setSerializer
sets the serializer used when issuingReflections.save(java.lang.String)
-
getClassLoaders
get class loader, might be used for scanning or resolving methods/fields- Specified by:
getClassLoaders
in interfaceConfiguration
-
shouldExpandSuperTypes
public boolean shouldExpandSuperTypes()Description copied from interface:Configuration
if true (default), expand super types after scanning, for super types that were not scanned.- Specified by:
shouldExpandSuperTypes
in interfaceConfiguration
-
setExpandSuperTypes
if set to true, Reflections will expand super types after scanning. -
setClassLoaders
set class loader, might be used for resolving methods/fields -
addClassLoader
add class loader, might be used for resolving methods/fields -
addClassLoaders
add class loader, might be used for resolving methods/fields -
addClassLoaders
add class loader, might be used for resolving methods/fields
-