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 ExecutorServiceprivate booleanprotected MetadataAdapterprivate 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 ConfigurationBuilderconstructs aConfigurationBuilderusing 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 scannedvoidsetClassLoaders(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.voidsetInputsFilter(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 scannedbooleanif 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 aConfigurationBuilderusing the given parameters, in a non statically typed way. that is, each element inparamsis 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
FilterBuilderwill be set according to given packages.use any parameter type in any order. this constructor uses instanceof on each param and instantiate a
ConfigurationBuilderappropriately. -
forPackages
-
getScanners
Description copied from interface:Configurationthe scanner instances used for scanning different metadata- Specified by:
getScannersin interfaceConfiguration
-
setScanners
set the scanners instances for scanning different metadata -
addScanners
set the scanners instances for scanning different metadata -
getUrls
Description copied from interface:Configurationthe urls to be scanned- Specified by:
getUrlsin interfaceConfiguration
-
setUrls
set the urls to be scanneduse
ClasspathHelperconvenient methods to get the relevant urls -
setUrls
set the urls to be scanneduse
ClasspathHelperconvenient methods to get the relevant urls -
addUrls
add urls to be scanneduse
ClasspathHelperconvenient methods to get the relevant urls -
addUrls
add urls to be scanneduse
ClasspathHelperconvenient methods to get the relevant urls -
getMetadataAdapter
returns the metadata adapter. if javassist library exists in the classpath, this method returnsJavassistAdapterotherwise defaults toJavaReflectionAdapter.the
JavassistAdapteris preferred in terms of performance and class loading.- Specified by:
getMetadataAdapterin interfaceConfiguration
-
setMetadataAdapter
sets the metadata adapter used to fetch metadata from classes -
getInputsFilter
Description copied from interface:Configurationget the fully qualified name filter used to filter types to be scanned- Specified by:
getInputsFilterin interfaceConfiguration
-
setInputsFilter
sets the input filter for all resources to be scanned.supply a
Predicateor use theFilterBuilder -
filterInputsBy
sets the input filter for all resources to be scanned.supply a
Predicateor use theFilterBuilder -
getExecutorService
Description copied from interface:Configurationexecutor service used to scan files. if null, scanning is done in a simple for loop- Specified by:
getExecutorServicein 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:Configurationthe default serializer to use when saving Reflection- Specified by:
getSerializerin 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:
getClassLoadersin interfaceConfiguration
-
shouldExpandSuperTypes
public boolean shouldExpandSuperTypes()Description copied from interface:Configurationif true (default), expand super types after scanning, for super types that were not scanned.- Specified by:
shouldExpandSuperTypesin 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
-