Skip to content

Panda Utilities: AnnotationsScanner

Dzikoysk edited this page Aug 14, 2018 · 1 revision

AnnotationsScanner

The lightweight and actively developed alternative to reflections. Source code is partly based on the reflections library to avoid repeating the same mistakes.

Usage

Firstly, you have to create AnnotationsScanner which keeps a collection of added sources to scan

AnnotationsScanner scanner = AnnotationsScanner.createScanner()
        .includeSources(Main.class)
        .build();

Searching is based on AnnotationsScannerProcess, the process will only collect the classes of interest to you and cache them for some future queries

AnnotationsScannerProcess process = scanner.createWorker()
        .addDefaultProjectFilters("org.example")
        .fetch();

Now, you can finally select annotated classes

Set<Class<?>> classes = process.createSelector()
        .selectTypesAnnotatedWith(AnnotationTest.class);

You can also select subtypes of classes, AnnotationsScannerProcess contains prepared inheritance map

Set<Class<?>> classes = process.createSelector()
        .selectSubtypesOf(Object.class);

You also should be able to create custom selector, like:

Set<Class<?>> classes = process.createSelector()
        .select(new AnnotationsSelector() {
            @Override
            public Collection<String> select(AnnotationsScannerProcess process, AnnotationScannerStore store) {
                return null;
            }
        })
Clone this wiki locally