or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdcore-operations.mdfunctional-queries.mdindex.mdlegacy-api.mdscanners.mdserialization.mdutilities.md
tile.json

tessl/maven-org-reflections--reflections

Java runtime metadata analysis library that enables reverse querying of classpath metadata for type system introspection

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.reflections/reflections@0.10.x

To install, run

npx @tessl/cli install tessl/maven-org-reflections--reflections@0.10.0

index.mddocs/

Reflections

Reflections is a Java runtime metadata analysis library that enables reverse querying of the type system by scanning and indexing classpath metadata. It provides comprehensive functionality to discover subtypes, annotated types/methods/fields, method signatures, resources, and more using both modern functional query APIs and legacy backward-compatible methods.

Package Information

  • Package Name: org.reflections:reflections
  • Package Type: maven
  • Language: Java
  • Installation:
    <dependency>
      <groupId>org.reflections</groupId>
      <artifactId>reflections</artifactId>
      <version>0.10.2</version>
    </dependency>

Core Imports

import org.reflections.Reflections;
import org.reflections.util.ConfigurationBuilder;
import org.reflections.util.ClasspathHelper;
import org.reflections.util.FilterBuilder;
import org.reflections.scanners.Scanners;

Basic Usage

import org.reflections.Reflections;
import org.reflections.util.ConfigurationBuilder;
import org.reflections.scanners.Scanners;
import static org.reflections.scanners.Scanners.*;

// Simple package scanning with default scanners
Reflections reflections = new Reflections("com.mycompany");

// Advanced configuration with all scanners
Reflections reflections = new Reflections(new ConfigurationBuilder()
    .forPackages("com.mycompany.package1", "com.mycompany.package2")
    .addScanners(Scanners.values()) // all available scanners
    .filterInputsBy(new FilterBuilder()
        .includePackage("com.mycompany")
        .excludePackage("com.mycompany.exclude")));

// Query using modern functional API
Set<Class<?>> subtypes = reflections.get(SubTypes.of(MyInterface.class).asClass());
Set<Method> methods = reflections.get(MethodsAnnotated.with(MyAnnotation.class).as(Method.class));
Set<String> resources = reflections.get(Resources.with(".*\\.properties"));

// Query using legacy backward-compatible API
Set<Class<? extends MyInterface>> legacySubtypes = reflections.getSubTypesOf(MyInterface.class);
Set<Class<?>> annotatedTypes = reflections.getTypesAnnotatedWith(MyAnnotation.class);

Architecture

Reflections is built around several key components:

  • Core Reflections Class: Main entry point providing both modern functional and legacy query APIs
  • Scanner System: Pluggable scanners for different metadata types (SubTypes, TypesAnnotated, MethodsAnnotated, etc.)
  • Configuration System: Flexible configuration via ConfigurationBuilder for URLs, scanners, filters, and class loaders
  • Storage System: Efficient multimap-based Store for indexed metadata with serialization support
  • Virtual File System: VFS abstraction handling different URL types (JAR files, directories, JBoss VFS, etc.)
  • Query System: Both modern QueryFunction-based functional API and legacy backward-compatible methods
  • Utility Classes: Comprehensive helpers for classpath handling, filtering, name resolution, and reflection operations

Capabilities

Core Scanning and Querying

Central scanning functionality for indexing classpath metadata and performing reverse queries on the type system. Supports both configuration and querying operations.

class Reflections {
    Reflections(Configuration configuration);
    Reflections(String prefix, Scanner... scanners);
    <T> Set<T> get(QueryFunction<Store, T> query);
    static Reflections collect();
}

Core Operations

Scanner System

Comprehensive scanning capabilities for different types of metadata including types, annotations, methods, constructors, fields, resources, and signatures.

enum Scanners implements Scanner, QueryBuilder, NameHelper {
    SubTypes, TypesAnnotated, MethodsAnnotated, ConstructorsAnnotated, 
    FieldsAnnotated, Resources, MethodsParameter, ConstructorsParameter, 
    MethodsSignature, ConstructorsSignature, MethodsReturn;
}

interface Scanner {
    List<Map.Entry<String, String>> scan(ClassFile classFile);
    String index();
    boolean acceptsInput(String file);
}

Scanners

Configuration and Setup

Flexible configuration system for setting up scanning parameters, URLs, filters, class loaders, and scanner selection.

class ConfigurationBuilder implements Configuration {
    static ConfigurationBuilder build(Object... params);
    ConfigurationBuilder forPackage(String pkg, ClassLoader... classLoaders);
    ConfigurationBuilder forPackages(String... packages);
    ConfigurationBuilder setScanners(Scanner... scanners);
    ConfigurationBuilder addScanners(Scanner... scanners);
    ConfigurationBuilder setUrls(Collection<URL> urls);
    ConfigurationBuilder addUrls(Collection<URL> urls);
    ConfigurationBuilder setInputsFilter(Predicate<String> inputsFilter);
}

Configuration

Utility and Helper Functions

Extensive utility classes for classpath operations, filtering, name resolution, and reflection operations to support the core scanning functionality.

abstract class ClasspathHelper {
    static Collection<URL> forPackage(String name, ClassLoader... classLoaders);
    static Collection<URL> forResource(String resourceName, ClassLoader... classLoaders);
    static Collection<URL> forClassLoader(ClassLoader... classLoaders);
    static Collection<URL> forJavaClassPath();
}

class FilterBuilder implements Predicate<String> {
    FilterBuilder includePackage(String value);
    FilterBuilder excludePackage(String value);
    FilterBuilder includePattern(String regex);
    FilterBuilder excludePattern(String regex);
}

Utilities

Functional Query API

Modern functional query system using QueryFunction for composable, type-safe metadata queries with filtering, mapping, and transformation capabilities.

interface QueryFunction<C, T> extends Function<C, Set<T>>, NameHelper {
    Set<T> apply(C ctx);
    QueryFunction<C, T> filter(Predicate<? super T> predicate);
    <R> QueryFunction<C, R> map(Function<? super T, ? extends R> function);
    <R> QueryFunction<C, R> as(Class<? extends R> type, ClassLoader... loaders);
    QueryFunction<C, Class<?>> asClass(ClassLoader... loaders);
}

abstract class ReflectionUtils {
    static <C, T> Set<T> get(QueryFunction<C, T> function);
    static final UtilQueryBuilder<Class<?>, Class<?>> SuperTypes;
    static final UtilQueryBuilder<AnnotatedElement, Annotation> Annotations;
    static final UtilQueryBuilder<Class<?>, Method> Methods;
    static final UtilQueryBuilder<Class<?>, Constructor> Constructors;
    static final UtilQueryBuilder<Class<?>, Field> Fields;
}

Functional Queries

Legacy Compatibility API

Backward-compatible methods providing the same functionality as earlier versions of Reflections for easy migration and compatibility.

class Reflections {
    <T> Set<Class<? extends T>> getSubTypesOf(Class<T> type);
    Set<Class<?>> getTypesAnnotatedWith(Class<? extends Annotation> annotation);
    Set<Method> getMethodsAnnotatedWith(Class<? extends Annotation> annotation);
    Set<Constructor> getConstructorsAnnotatedWith(Class<? extends Annotation> annotation);
    Set<Field> getFieldsAnnotatedWith(Class<? extends Annotation> annotation);
    Set<String> getResources(String pattern);
}

Legacy API

Serialization and Persistence

Serialization capabilities for saving and loading scanned metadata in multiple formats including XML, JSON, and Java code generation.

interface Serializer {
    Reflections read(InputStream inputStream);
    File save(Reflections reflections, String filename);
}

class XmlSerializer implements Serializer;
class JsonSerializer implements Serializer;
class JavaCodeSerializer implements Serializer;

class Reflections {
    File save(String filename);
    File save(String filename, Serializer serializer);
    static Reflections collect();
    static Reflections collect(String packagePrefix, Predicate<String> resourceNameFilter);
}

Serialization

Types

interface Configuration {
    Set<Scanner> getScanners();
    Set<URL> getUrls();
    Predicate<String> getInputsFilter();
    boolean isParallel();
    ClassLoader[] getClassLoaders();
    boolean shouldExpandSuperTypes();
}

class Store extends HashMap<String, Map<String, Set<String>>> {
    Store();
    Store(Map<String, Map<String, Set<String>>> storeMap);
}

class ReflectionsException extends RuntimeException {
    ReflectionsException(String message);
    ReflectionsException(String message, Throwable cause);
    ReflectionsException(Throwable cause);
}

interface QueryBuilder extends NameHelper {
    String index();
    QueryFunction<Store, String> get(String key);
    QueryFunction<Store, String> get(AnnotatedElement element);
    QueryFunction<Store, String> get(Collection<String> keys);
    QueryFunction<Store, String> getAll(Collection<String> keys);
    QueryFunction<Store, String> of(Collection<String> keys);
    QueryFunction<Store, String> of(String key);
    QueryFunction<Store, String> of(AnnotatedElement... elements);
}

interface NameHelper {
    String toName(AnnotatedElement element);
    String toName(Class<?> type);
    String toName(Constructor<?> constructor);
    String toName(Method method);
    String toName(Field field);
    Collection<String> toNames(Collection<? extends AnnotatedElement> elements);
    <T> T forName(String name, Class<T> resultType, ClassLoader... loaders);
    Class<?> forClass(String typeName, ClassLoader... loaders);
    Member forMember(String descriptor, ClassLoader... loaders);
    Method forMethod(String descriptor, ClassLoader... loaders);
    Constructor<?> forConstructor(String descriptor, ClassLoader... loaders);
    Field forField(String descriptor, ClassLoader... loaders);
}