com.github.czyzby.autumn.fcs.scanner.DesktopClassScanner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gdx-autumn-fcs Show documentation
Show all versions of gdx-autumn-fcs Show documentation
Desktop natives for LibGDX Autumn - dependency injection library.
package com.github.czyzby.autumn.fcs.scanner;
import java.lang.annotation.Annotation;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectSet;
import com.github.czyzby.autumn.AutumnRoot;
import com.github.czyzby.autumn.scanner.ClassScanner;
import com.github.czyzby.kiwi.util.gdx.collection.GdxArrays;
import com.github.czyzby.kiwi.util.gdx.collection.GdxSets;
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner;
import io.github.lukehutch.fastclasspathscanner.matchprocessor.ClassAnnotationMatchProcessor;
/** Default, efficient class scanner for desktop. Does not rely on reflection and does not load scanned classes. Uses
* {@link FastClasspathScanner} wrapped with and adapted to {@link ClassScanner} interface to serve as default class
* scanner for desktop LibGDX applications using Autumn. If for some reason this scanner does not work for you, try
* {@link com.github.czyzby.nongwt.autumn.scanner.FallbackDesktopClassScanner} (which is much slower, as it depends on
* reflection) or {@link com.github.czyzby.autumn.scanner.FixedClassScanner} (which will force you to register class
* pool to scan, sacrificing true component scanning).
*
* @author MJ
* @see FastClasspathScanner */
public class DesktopClassScanner implements ClassScanner {
@Override
public Array> findClassesAnnotatedWith(final Class> root,
final Iterable> annotations) {
final ObjectSet> result = GdxSets.newSet(); // Using set to remove duplicates.
final FastClasspathScanner scanner = new FastClasspathScanner(root.getPackage().getName(),
AutumnRoot.class.getPackage().getName());
for (final Class extends Annotation> annotation : annotations) {
scanner.matchClassesWithAnnotation(annotation, new ClassAnnotationMatchProcessor() {
@Override
public void processMatch(final Class> matchingClass) {
result.add(matchingClass);
}
});
}
scanner.scan();
return GdxArrays.newArray(result);
}
}