Class ClassInfoList
- java.lang.Object
-
- io.github.lukehutch.fastclasspathscanner.ClassInfoList
-
public class ClassInfoList extends Object implements List<ClassInfo>
A list ofClassInfoobjects, which stores both reachable classes (obtained through a given class relationship, either by direct relationship or through an indirect path), and directly related classes (classes reachable through a direct relationship only).By default, this list returns reachable classes. By calling
directOnly(), you can get the directly related classes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceClassInfoList.ClassInfoFilterFilter aClassInfoListusing a predicate mapping aClassInfoobject to a boolean, producing anotherClassInfoListfor all items in the list for which the predicate is true.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, ClassInfo element)booleanadd(ClassInfo e)booleanaddAll(int index, Collection<? extends ClassInfo> c)booleanaddAll(Collection<? extends ClassInfo> c)voidclear()booleancontains(Object o)booleancontainsAll(Collection<?> c)booleancontainsName(String className)Return true if thisClassInfolist contains a class with the given name.ClassInfoListdirectOnly()Get the list of classes that were directly related, as opposed to reachable through multiple steps.ClassInfoListexclude(ClassInfoList other)Find the set difference between thisClassInfoListand anotherClassInfoList, i.e.ClassInfoListfilter(ClassInfoList.ClassInfoFilter filter)Find the set difference between this ClassInfoList and another ClassInfoList, i.e.StringgenerateGraphVizDotFile()Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph.StringgenerateGraphVizDotFile(float sizeX, float sizeY)Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph.StringgenerateGraphVizDotFile(float sizeX, float sizeY, boolean showFields, boolean showMethods, boolean showAnnotations)Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph.voidgenerateGraphVizDotFile(File file)Generate a and save a .dot file, which can be fed into GraphViz for layout and visualization of the class graph.ClassInfoget(int index)ClassInfoget(String name)Return theClassInfoobject in the list with the given name, or null if not found.ClassInfoListgetAnnotations()Filter thisClassInfoListto include only annotations.List<String>getAsStrings()Get the string representations of all classes in this list (with annotations, modifiers, etc.), by callingClassInfo.toString()on each item in the list.ClassInfoListgetEnums()Filter thisClassInfoListto include onlyEnumclasses.ClassInfoListgetImplementedInterfaces()Filter thisClassInfoListto include only implemented interfaces, i.e.ClassInfoListgetInterfaces()Filter thisClassInfoListto include only interfaces that are not annotations.ClassInfoListgetInterfacesAndAnnotations()Filter thisClassInfoListto include only interfaces and annotations (annotations are interfaces, and can be implemented).List<String>getNames()Get the names of all classes in this list.ClassInfoListgetStandardClasses()Filter thisClassInfoListto include only standard classes (classes that are not interfaces or annotations).intindexOf(Object o)ClassInfoListintersect(ClassInfoList... others)Find the intersection of thisClassInfoListwith one or more others.booleanisEmpty()Iterator<ClassInfo>iterator()intlastIndexOf(Object o)ListIterator<ClassInfo>listIterator()ListIterator<ClassInfo>listIterator(int index)List<Class<?>>loadClasses()Convert this list ofClassInfoobjects to a list ofClass<?>objects.List<Class<?>>loadClasses(boolean ignoreExceptions)Convert this list ofClassInfoobjects to a list ofClass<?>objects.<T> List<Class<T>>loadClasses(Class<T> superclassOrInterfaceType)Convert this list ofClassInfoobjects to a list ofClass<?>objects, casting each item in the list to the requested superclass or interface type.<T> List<Class<T>>loadClasses(Class<T> superclassOrInterfaceType, boolean ignoreExceptions)Convert this list ofClassInfoobjects to a list ofClass<?>objects, casting each item in the list to the requested superclass or interface type.ClassInforemove(int index)booleanremove(Object o)booleanremoveAll(Collection<?> c)booleanretainAll(Collection<?> c)ClassInfoset(int index, ClassInfo element)intsize()List<ClassInfo>subList(int fromIndex, int toIndex)Object[]toArray()<T> T[]toArray(T[] a)StringtoString()ClassInfoListunion(ClassInfoList... others)Find the union of thisClassInfoListwith one or more others.-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream
-
Methods inherited from interface java.util.List
equals, hashCode, replaceAll, sort, spliterator
-
-
-
-
Method Detail
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
contains
public boolean contains(Object o)
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<ClassInfo>- Specified by:
containsAllin interfaceList<ClassInfo>
-
toArray
public Object[] toArray()
-
toArray
public <T> T[] toArray(T[] a)
-
lastIndexOf
public int lastIndexOf(Object o)
- Specified by:
lastIndexOfin interfaceList<ClassInfo>
-
listIterator
public ListIterator<ClassInfo> listIterator()
- Specified by:
listIteratorin interfaceList<ClassInfo>
-
listIterator
public ListIterator<ClassInfo> listIterator(int index)
- Specified by:
listIteratorin interfaceList<ClassInfo>
-
add
public boolean add(ClassInfo e)
-
remove
public boolean remove(Object o)
-
addAll
public boolean addAll(Collection<? extends ClassInfo> c)
-
addAll
public boolean addAll(int index, Collection<? extends ClassInfo> c)
-
removeAll
public boolean removeAll(Collection<?> c)
-
retainAll
public boolean retainAll(Collection<?> c)
-
clear
public void clear()
-
loadClasses
public <T> List<Class<T>> loadClasses(Class<T> superclassOrInterfaceType, boolean ignoreExceptions)
Convert this list ofClassInfoobjects to a list ofClass<?>objects, casting each item in the list to the requested superclass or interface type. Causes the classloader to load the class named by eachClassInfoobject, if it is not already loaded.Important note: since
superclassOrInterfaceTypeis a class reference for an already-loaded class, it is critical thatsuperclassOrInterfaceTypeis loaded by the same classloader as the class referred to by thisClassInfoobject, otherwise the class cast will fail.- Parameters:
superclassOrInterfaceType- The type to cast each loaded class to.ignoreExceptions- If true, ignore any exceptions or errors thrown during classloading, or when attempting to cast the resultingClass<?>reference to the requested type. If an exception or error is thrown, noClass<?>reference is added to the output class for the correspondingClassInfoobject, so the returned list may contain fewer items than this input list. If false,IllegalArgumentExceptionis thrown if the class could not be loaded or cast to the requested type.- Returns:
- The loaded
Class<?>objects corresponding to eachClassInfoobject in this list. - Throws:
IllegalArgumentException- if ignoreExceptions is false and an exception or error was thrown while trying to load or cast any of the classes.
-
loadClasses
public <T> List<Class<T>> loadClasses(Class<T> superclassOrInterfaceType)
Convert this list ofClassInfoobjects to a list ofClass<?>objects, casting each item in the list to the requested superclass or interface type. Causes the classloader to load the class named by eachClassInfoobject, if it is not already loaded.Important note: since
superclassOrInterfaceTypeis a class reference for an already-loaded class, it is critical thatsuperclassOrInterfaceTypeis loaded by the same classloader as the class referred to by thisClassInfoobject, otherwise the class cast will fail.- Parameters:
superclassOrInterfaceType- The type to cast each loaded class to.- Returns:
- The loaded
Class<?>objects corresponding to eachClassInfoobject in this list. - Throws:
IllegalArgumentException- if an exception or error was thrown while trying to load or cast any of the classes.
-
loadClasses
public List<Class<?>> loadClasses(boolean ignoreExceptions)
Convert this list ofClassInfoobjects to a list ofClass<?>objects. Causes the classloader to load the class named by eachClassInfoobject, if it is not already loaded.- Parameters:
ignoreExceptions- If true, ignore any exceptions or errors thrown during classloading. If an exception or error is thrown during classloading, noClass<?>reference is added to the output class for the correspondingClassInfoobject, so the returned list may contain fewer items than this input list. If false,IllegalArgumentExceptionis thrown if the class could not be loaded.- Returns:
- The loaded
Class<?>objects corresponding to eachClassInfoobject in this list. - Throws:
IllegalArgumentException- if ignoreExceptions is false and an exception or error was thrown while trying to load any of the classes.
-
loadClasses
public List<Class<?>> loadClasses()
Convert this list ofClassInfoobjects to a list ofClass<?>objects. Causes the classloader to load the class named by eachClassInfoobject, if it is not already loaded.- Returns:
- The loaded
Class<?>objects corresponding to eachClassInfoobject in this list. - Throws:
IllegalArgumentException- if an exception or error was thrown while trying to load any of the classes.
-
getAsStrings
public List<String> getAsStrings()
Get the string representations of all classes in this list (with annotations, modifiers, etc.), by callingClassInfo.toString()on each item in the list.
-
containsName
public boolean containsName(String className)
Return true if thisClassInfolist contains a class with the given name.
-
get
public ClassInfo get(String name)
Return theClassInfoobject in the list with the given name, or null if not found.
-
directOnly
public ClassInfoList directOnly()
Get the list of classes that were directly related, as opposed to reachable through multiple steps. For example, if thisClassInfoListwas produced by querying for all superclasses of a given class, thendirectOnly()will return only the direct superclass of this class.- Returns:
- The list of directly-related classes.
-
union
public ClassInfoList union(ClassInfoList... others)
Find the union of thisClassInfoListwith one or more others.- Parameters:
others- The otherClassInfoLists to union with this one.- Returns:
- The union of this
ClassInfoListwith the others.
-
intersect
public ClassInfoList intersect(ClassInfoList... others)
Find the intersection of thisClassInfoListwith one or more others.- Parameters:
others- The otherClassInfoLists to intersect with this one.- Returns:
- The intersection of this
ClassInfoListwith the others.
-
exclude
public ClassInfoList exclude(ClassInfoList other)
Find the set difference between thisClassInfoListand anotherClassInfoList, i.e. (this \ other).- Parameters:
other- The otherClassInfoListto subtract from this one.- Returns:
- The set difference of this
ClassInfoListand other, i.e. (this \ other).
-
filter
public ClassInfoList filter(ClassInfoList.ClassInfoFilter filter)
Find the set difference between this ClassInfoList and another ClassInfoList, i.e. (this \ other).- Parameters:
filter- TheClassInfoList.ClassInfoFilterto apply.- Returns:
- The set difference of this
ClassInfoListand other, i.e. (this \ other).
-
getStandardClasses
public ClassInfoList getStandardClasses()
Filter thisClassInfoListto include only standard classes (classes that are not interfaces or annotations).- Returns:
- The filtered list, containing only standard classes.
-
getInterfaces
public ClassInfoList getInterfaces()
Filter thisClassInfoListto include only interfaces that are not annotations. See alsogetInterfacesAndAnnotations().- Returns:
- The filtered list, containing only interfaces.
-
getInterfacesAndAnnotations
public ClassInfoList getInterfacesAndAnnotations()
Filter thisClassInfoListto include only interfaces and annotations (annotations are interfaces, and can be implemented). See alsogetInterfaces().- Returns:
- The filtered list, containing only interfaces.
-
getImplementedInterfaces
public ClassInfoList getImplementedInterfaces()
Filter thisClassInfoListto include only implemented interfaces, i.e. non-annotation interfaces, or annotations that have been implemented by a class.- Returns:
- The filtered list, containing only implemented interfaces.
-
getAnnotations
public ClassInfoList getAnnotations()
Filter thisClassInfoListto include only annotations.- Returns:
- The filtered list, containing only annotations.
-
getEnums
public ClassInfoList getEnums()
Filter thisClassInfoListto include onlyEnumclasses.- Returns:
- The filtered list, containing only enums.
-
generateGraphVizDotFile
public String generateGraphVizDotFile(float sizeX, float sizeY, boolean showFields, boolean showMethods, boolean showAnnotations)
Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph. The sizeX and sizeY parameters are the image output size to use (in inches) when GraphViz is asked to render the .dot file.Note that if you call this with showFields or showMethods set to false, but with method and/or field info enabled during scanning, then arrows will still be added between classes even if the field or method that created that dependency is not shown.
- Parameters:
sizeX- The GraphViz layout width in inches.sizeY- The GraphViz layout width in inches.showFields- If true, show fields within class nodes in the graph. To show fields,FastClasspathScanner.enableFieldInfo()must be called before scanning. You may also want to callFastClasspathScanner.ignoreFieldVisibility()before scanning, to show non-public fields.showMethods- If true, show methods within class nodes in the graph. To show methods,FastClasspathScanner.enableMethodInfo()must be called before scanning. You may also want to callFastClasspathScanner.ignoreMethodVisibility()before scanning, to show non-public methods.showAnnotations- If true, show annotations in the graph. To show annotations,FastClasspathScanner.enableAnnotationInfo()must be called before scanning. You may also want to callFastClasspathScanner.ignoreClassVisibility()before scanning, to show non-public classes (including non-public annotation classes).- Returns:
- the GraphViz file contents.
-
generateGraphVizDotFile
public String generateGraphVizDotFile(float sizeX, float sizeY)
Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph.Methods, fields and annotations are shown if enabled, via
FastClasspathScanner.enableMethodInfo(),FastClasspathScanner.enableFieldInfo()andFastClasspathScanner.enableAnnotationInfo().Only public classes, methods, and fields are shown, unless
FastClasspathScanner.ignoreClassVisibility(),FastClasspathScanner.ignoreMethodVisibility(), and/orFastClasspathScanner.ignoreFieldVisibility()has/have been called.- Parameters:
sizeX- The GraphViz layout width in inches.sizeY- The GraphViz layout width in inches.- Returns:
- the GraphViz file contents.
-
generateGraphVizDotFile
public String generateGraphVizDotFile()
Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph.Methods, fields and annotations are shown if enabled, via
FastClasspathScanner.enableMethodInfo(),FastClasspathScanner.enableFieldInfo()andFastClasspathScanner.enableAnnotationInfo().Only public classes, methods, and fields are shown, unless
FastClasspathScanner.ignoreClassVisibility(),FastClasspathScanner.ignoreMethodVisibility(), and/orFastClasspathScanner.ignoreFieldVisibility()has/have been called.- Returns:
- the GraphViz file contents.
-
generateGraphVizDotFile
public void generateGraphVizDotFile(File file) throws IOException
Generate a and save a .dot file, which can be fed into GraphViz for layout and visualization of the class graph.Methods, fields and annotations are shown if enabled, via
FastClasspathScanner.enableMethodInfo(),FastClasspathScanner.enableFieldInfo()andFastClasspathScanner.enableAnnotationInfo().Only public classes, methods, and fields are shown, unless
FastClasspathScanner.ignoreClassVisibility(),FastClasspathScanner.ignoreMethodVisibility(), and/orFastClasspathScanner.ignoreFieldVisibility()has/have been called.- Parameters:
file- the file to save the GraphViz .dot file to.- Throws:
IOException- if the file could not be saved.
-
-