Package io.hawt.util.introspect.support
Class ClassScanner
- java.lang.Object
-
- io.hawt.util.introspect.support.ClassScanner
-
public class ClassScanner extends Object
A helper class to scan classes on the classpath
-
-
Constructor Summary
Constructors Constructor Description ClassScanner(ClassLoader... classLoaders)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddClassesForPackage(ClassResource classResource, String filter, Integer limit, Set<Class<?>> classes)protected voidaddClassNamesInDirectoryWithMethodsAnnotatedWith(SortedSet<String> answer, File dir, Class<? extends Annotation> annotationClass, String packageName)protected voidaddPackageResources(Package aPackage, Map<String,ClassResource> urlSet, ClassLoader[] classLoaders)protected booleanclassNameMatches(String className, String search)Returns true if the given class name matches the filter searchvoidclearCache()protected CacheValuecreateCacheValue(String key, ClassResource classResource)Class<?>findClass(String className)Finds a class from its nameSortedSet<String>findClassNames(String search, Integer limit)Searches for the available class names given the text searchprotected SortedSet<String>findClassNames(Map<Package,ClassLoader[]> packages, Predicate<String> filter, Integer limit)SortedSet<String>findClassNamesInDirectoryWithMethodAnnotatedWith(File dir, String annotationClassName)SortedSet<String>findClassNamesInPackages(String search, Integer limit, Map<Package,ClassLoader[]> packages)SortedSet<String>findClassNamesMethodsAnnotatedWith(String annotationClassName)SortedSet<String>findClassNamesMethodsAnnotatedWith(String annotationClassName, Integer limit, Map<Package,ClassLoader[]> packages)SortedMap<String,Class<?>>getAllClassesMap()Returns all the classes found in a sorted mapSet<Class<?>>getClassesForPackage(ClassResource classResource, String filter, Integer limit)SortedMap<String,Class<?>>getClassesMap(Package... packages)Returns all the classes found in a sorted map for the given list of packagesList<ClassLoader>getClassLoaders()Set<String>getIgnorePackages()protected StringgetJavaResourceKey(URL resource)protected StringgetPackageRelativePath(String packageName)protected List<URL>getResources(String relPath, ClassLoader... classLoaders)static ClassScannernewInstance()protected Class<? extends Annotation>optionallyFindAnnotationClass(String annotationClassName)Class<?>optionallyFindClass(String className)Returns the given class or null if it cannot be loadedList<Class<?>>optionallyFindClasses(Iterable<String> classNames)Tries to find as many of the class names on the class loaders as possible and return themprotected voidprocessDirectory(File directory, String packageName, Set<Class<?>> classes, String filter, Integer limit)protected voidprocessDirectoryClassNames(File directory, String packageName, Set<String> classes)protected voidprocessJar(ClassResource classResource, Set<Class<?>> classes, String filter, Integer limit)protected voidprocessJarClassNames(ClassResource classResource, Set<String> classes)voidsetClassLoaderProvider(String id, ClassLoaderProvider classLoaderProvider)Registers a named class loader provider or removes it if the classLoaderProvider is nullvoidsetIgnorePackages(Set<String> ignorePackages)protected Class<?>tryFindClass(String className, String filter)protected booleanwithinLimit(Integer limit, Collection<?> collection)Returns true if we are within the limit value for the number of results in the collection
-
-
-
Constructor Detail
-
ClassScanner
public ClassScanner(ClassLoader... classLoaders)
-
-
Method Detail
-
newInstance
public static ClassScanner newInstance()
-
clearCache
public void clearCache()
-
setClassLoaderProvider
public void setClassLoaderProvider(String id, ClassLoaderProvider classLoaderProvider)
Registers a named class loader provider or removes it if the classLoaderProvider is null
-
findClassNames
public SortedSet<String> findClassNames(String search, Integer limit)
Searches for the available class names given the text search- Returns:
- all the class names found on the current classpath using the given text search filter
-
findClassNamesMethodsAnnotatedWith
public SortedSet<String> findClassNamesMethodsAnnotatedWith(String annotationClassName)
-
findClassNamesInDirectoryWithMethodAnnotatedWith
public SortedSet<String> findClassNamesInDirectoryWithMethodAnnotatedWith(File dir, String annotationClassName)
-
addClassNamesInDirectoryWithMethodsAnnotatedWith
protected void addClassNamesInDirectoryWithMethodsAnnotatedWith(SortedSet<String> answer, File dir, Class<? extends Annotation> annotationClass, String packageName)
-
optionallyFindAnnotationClass
protected Class<? extends Annotation> optionallyFindAnnotationClass(String annotationClassName)
-
findClassNamesMethodsAnnotatedWith
public SortedSet<String> findClassNamesMethodsAnnotatedWith(String annotationClassName, Integer limit, Map<Package,ClassLoader[]> packages)
-
findClassNamesInPackages
public SortedSet<String> findClassNamesInPackages(String search, Integer limit, Map<Package,ClassLoader[]> packages)
-
findClassNames
protected SortedSet<String> findClassNames(Map<Package,ClassLoader[]> packages, Predicate<String> filter, Integer limit)
-
getAllClassesMap
public SortedMap<String,Class<?>> getAllClassesMap()
Returns all the classes found in a sorted map
-
getClassesMap
public SortedMap<String,Class<?>> getClassesMap(Package... packages)
Returns all the classes found in a sorted map for the given list of packages
-
getClassesForPackage
public Set<Class<?>> getClassesForPackage(ClassResource classResource, String filter, Integer limit)
-
findClass
public Class<?> findClass(String className) throws ClassNotFoundException
Finds a class from its name- Throws:
ClassNotFoundException
-
optionallyFindClass
public Class<?> optionallyFindClass(String className)
Returns the given class or null if it cannot be loaded
-
optionallyFindClasses
public List<Class<?>> optionallyFindClasses(Iterable<String> classNames)
Tries to find as many of the class names on the class loaders as possible and return them
-
addPackageResources
protected void addPackageResources(Package aPackage, Map<String,ClassResource> urlSet, ClassLoader[] classLoaders)
-
createCacheValue
protected CacheValue createCacheValue(String key, ClassResource classResource)
-
processDirectoryClassNames
protected void processDirectoryClassNames(File directory, String packageName, Set<String> classes)
-
processJarClassNames
protected void processJarClassNames(ClassResource classResource, Set<String> classes)
-
addClassesForPackage
protected void addClassesForPackage(ClassResource classResource, String filter, Integer limit, Set<Class<?>> classes)
-
processDirectory
protected void processDirectory(File directory, String packageName, Set<Class<?>> classes, String filter, Integer limit)
-
processJar
protected void processJar(ClassResource classResource, Set<Class<?>> classes, String filter, Integer limit)
-
getResources
protected List<URL> getResources(String relPath, ClassLoader... classLoaders)
-
classNameMatches
protected boolean classNameMatches(String className, String search)
Returns true if the given class name matches the filter search
-
withinLimit
protected boolean withinLimit(Integer limit, Collection<?> collection)
Returns true if we are within the limit value for the number of results in the collection
-
getClassLoaders
public List<ClassLoader> getClassLoaders()
-
-