ronmamo/reflections is an open-source project on GitHub with 4.8k stars, written primarily in Java. Java runtime metadata analysis
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
❗ Please note: Reflections library is currently NOT under active development or maintenance ❗
Thank you for your continuous support!
There are open issues and also workarounds. Release version will be considered incase contributing PR fixing the main issues.
Last released org.reflections:reflections:0.10.2 (Oct 2021)
Java runtime metadata analysis
Reflections scans and indexes your project's classpath metadata, allowing reverse transitive query of the type system on runtime.
Using Reflections you can query for example:
Subtypes of a type
Types annotated with an annotation
Methods with annotation, parameters, return type
Resources found in classpath
And more...
Reflections was written in the spirit of Scannotations library
Note that there are some breaking changes with Reflections 0.10+, along with performance improvements and more functional API, see below.
Scan
Creating Reflections instance requires ConfigurationBuilder, typically configured with packages and Scanners to use:
// typical usage: scan package with the default scanners SubTypes, TypesAnnotated
Reflections reflections = new Reflections(
new ConfigurationBuilder()
.forPackage("com.my.project")
.filterInputsBy(new FilterBuilder().includePackage("com.my.project")));
Other examples:
import static org.reflections.scanners.Scanners.*;
// scan package with specific scanners
Reflections reflections = new Reflections(
new ConfigurationBuilder()
.forPackage("com.my.project")
.filterInputsBy(new FilterBuilder().includePackage("com.my.project").excludePackage("com.my.project.exclude"))
.setScanners(TypesAnnotated, MethodsAnnotated, MethodsReturn));
Note that:
Scanner must be configured in order to be queried, otherwise an empty result is returned
If not specified, default scanners will be used SubTypes, TypesAnnotated.
For all standard scanners use Scanners.values(). See more scanners in the source package.
All relevant URLs should be configured
Consider .filterInputsBy() in case too many classes are scanned.
If required, Reflections will expand super types in order to get the transitive closure metadata without scanning large 3rd party urls.
Classloader can optionally be used for resolving runtime classes from names.
Query
Once Reflections was instantiated and scanning was successful, it can be used for querying the indexed metadata.
(1): The equivalent of getTypesAnnotatedWith(A) is get(SubTypes.of(TypesAnnotated.with(A))), including SubTypes
(2): MethodsAnnotatedScanner does not include constructor annotation scanning, use instead Scanners.ConstructorsAnnotated
(3): MethodParameterScanner is obsolete, use instead as required:
Scanners.MethodsParameter, Scanners.MethodsSignature, Scanners.MethodsReturn, Scanners.ConstructorsParameter, Scanners.ConstructorsSignature
ReflectionUtils
Apart from scanning classpath metadata using Javassist,
Java Reflection convenient methods are available using
ReflectionsUtils:
Previous ReflectionUtils 0.9.x API is still supported though marked for removal, more info in the javadocs.
Query API
Each Scanner and ReflectionUtils function implements QueryBuilder, and supports:
get() - function returns direct values
with() or of() - function returns all transitive values
For example, Scanners.SubTypes.get(T) return direct subtypes,
while Scanners.SubTypes.of(T) return transitive subtypes hierarchy.
Same goes for Scanners.TypesAnnotated and ReflectionUtils.SuperTypes etc.
Next, each function implements QueryFunction,
and provides fluent functional interface for composing filter(), map(), flatMap(), as() and more, such that:
// filter, as/map
QueryFunction<Store, Method> getters =
Methods.of(C1.class)
.filter(withModifier(Modifier.PUBLIC))
.filter(withPrefix("get").and(withParametersCount(0)))
.as(Method.class);
// compose Scanners and ReflectionUtils functions
QueryFunction<Store, Method> methods =
SubTypes.of(type).asClass() // <-- classpath scanned metadata
.flatMap(Methods::of); // <-- java reflection api
// function of function
QueryFunction<Store, Class<? extends Annotation>> queryAnnotations =
Annotations.of(Methods.of(C4.class))
.map(Annotation::annotationType);
See more in ReflectionUtilsQueryTest
A more complex example demonstrates getting merged annotations of rest controllers endpoints:
// get all annotations of RequestMapping hierarchy (GetMapping, PostMapping, ...)
Set<Class<?>> metaAnnotations =
reflections.get(TypesAnnotated.getAllIncluding(RequestMapping.class.getName()).asClass());
QueryFunction<Store, Map<String, Object>> queryAnnotations =
// get all controller endpoint methods
MethodsAnnotated.with(metaAnnotations).as(Method.class)
.map(method ->
// get both method's + declaring class's RequestMapping annotations
get(Annotations.of(method.getDeclaringClass())
.add(Annotations.of(method))
.filter(a -> metaAnnotations.contains(a.annotationType())))
.stream()
// merge annotations' member values into a single hash map
.collect(new AnnotationMergeCollector(method)));
// apply query and map merged hashmap into java annotation proxy
Set<RequestMapping> mergedAnnotations =
reflections.get(mergedAnnotation
.map(map -> ReflectionUtils.toAnnotation(map, metaAnnotation)));
Check the tests folder for more examples and API usage
What else?
Integrating with build lifecycle
It is sometime useful to Reflections.save() the scanned metadata into xml/json as part of the build lifecycle for generating resources,
and then collect it on bootstrap with Reflections.collect() and avoid scanning. See reflections-maven for example.
JavaCodeSerializer - scanned metadata can be persisted into a generated Java source code.
Although less common, it can be useful for accessing types and members in a strongly typed manner. (see example)
AnnotationMergeCollector - can be used to merge similar annotations. (see test)
MemberUsageScanner - experimental scanner allow querying for member usages getMemberUsages() of packages/types/elements in the classpath.
Can be used for finding usages between packages, layers, modules, types etc.
Spread the spirit of open-source and collaboration, clean code and simplicity
No homepage URL was recorded for ronmamo/reflections in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
Is ronmamo/reflections open source?
Yes — ronmamo/reflections ships under the WTFPL license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/ronmamo/reflections.
What is ronmamo/reflections?
ronmamo/reflections (ronmamo/reflections) is a Java project on GitHub. From the project's own README: Java runtime metadata analysis
What license does ronmamo/reflections use?
ronmamo/reflections is released under the WTFPL license. Always verify the LICENSE file directly on GitHub for the authoritative terms — license strings can be edited out of sync with a project's actual stance.
Where do I read more about ronmamo/reflections?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/ronmamo/reflections is the definitive source.
Read full README in the tab above.
Curious whether reflections is right for you?
Let ChatGPT, Claude, or Perplexity look into it — click below and see what AI actually says about reflections.