Class ClassInfoList
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<ClassInfo>
,Collection<ClassInfo>
,List<ClassInfo>
,RandomAccess
ClassInfo
objects, 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, accessing a
ClassInfoList
as a List
returns only reachable classes; by calling directOnly()
, you can
get the directly related classes.)
Most ClassInfoList
objects returned by ClassGraph are sorted into lexicographical order by the value of
ClassInfo.getName()
. One exception to this is the classes returned by
ClassInfo.getSuperclasses()
, which are in ascending order of the class hierarchy.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Filter aClassInfoList
using a predicate mapping aClassInfo
object to a boolean, producing anotherClassInfoList
for all items in the list for which the predicate is true. -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new empty modifiable list ofClassInfo
objects.ClassInfoList
(int sizeHint) Construct a new empty modifiable list ofClassInfo
objects, given a size hint.ClassInfoList
(Collection<ClassInfo> classInfoCollection) Construct a new modifiable emptyClassInfoList
, given an initial list ofClassInfo
objects. -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
boolean
addAll
(int index, Collection<? extends ClassInfo> c) boolean
addAll
(Collection<? extends ClassInfo> c) void
clear()
Get the list of classes that were directly related, as opposed to reachable through multiple steps.static ClassInfoList
Return an unmodifiable emptyClassInfoList
.boolean
exclude
(ClassInfoList other) Find the set difference between thisClassInfoList
and anotherClassInfoList
, i.e.filter
(ClassInfoList.ClassInfoFilter filter) Find the subset of thisClassInfoList
for which the given filter predicate is true.Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph.generateGraphVizDotFile
(float sizeX, float sizeY) Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph.generateGraphVizDotFile
(float sizeX, float sizeY, boolean showFields, boolean showFieldTypeDependencyEdges, boolean showMethods, boolean showMethodTypeDependencyEdges, boolean showAnnotations) Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph.generateGraphVizDotFile
(float sizeX, float sizeY, boolean showFields, boolean showFieldTypeDependencyEdges, boolean showMethods, boolean showMethodTypeDependencyEdges, boolean showAnnotations, boolean useSimpleNames) Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph.void
generateGraphVizDotFile
(File file) Generate a and save a .dot file, which can be fed into GraphViz for layout and visualization of the class graph.Deprecated.Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph.generateGraphVizDotFileFromInterClassDependencies
(float sizeX, float sizeY) Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph.generateGraphVizDotFileFromInterClassDependencies
(float sizeX, float sizeY, boolean includeExternalClasses) Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph.Filter thisClassInfoList
to include only annotations.getAssignableTo
(ClassInfo superclassOrInterface) Filter thisClassInfoList
to include only classes that are assignable to the requested class, assignableToClass (i.e.getEnums()
Filter thisClassInfoList
to include onlyEnum
classes.Filter thisClassInfoList
to include only implemented interfaces, i.e.Filter thisClassInfoList
to include only interfaces that are not annotations.Filter thisClassInfoList
to include only interfaces and annotations (annotations are interfaces, and can be implemented).Filter thisClassInfoList
to include onlyrecord
classes.Filter thisClassInfoList
to include only standard classes (classes that are not interfaces or annotations).int
hashCode()
intersect
(ClassInfoList... others) Find the intersection of thisClassInfoList
with one or more others.iterator()
Convert this list ofClassInfo
objects to a list ofClass<?>
objects.loadClasses
(boolean ignoreExceptions) Convert this list ofClassInfo
objects to a list ofClass<?>
objects.loadClasses
(Class<T> superclassOrInterfaceType) Convert this list ofClassInfo
objects to a list ofClass<?>
objects, casting each item in the list to the requested superclass or interface type.loadClasses
(Class<T> superclassOrInterfaceType, boolean ignoreExceptions) Convert this list ofClassInfo
objects to a list ofClass<?>
objects, casting each item in the list to the requested superclass or interface type.remove
(int index) boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) union
(ClassInfoList... others) Find the union of thisClassInfoList
with one or more others.Methods inherited from class io.github.classgraph.MappableInfoList
asMap, containsName, get
Methods inherited from class io.github.classgraph.InfoList
getAsStrings, getAsStringsWithSimpleNames, getNames
Methods inherited from class java.util.ArrayList
clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, lastIndexOf, listIterator, removeIf, replaceAll, size, sort, spliterator, subList, toArray, toArray, trimToSize
Methods inherited from class java.util.AbstractCollection
containsAll, toString
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
Methods inherited from interface java.util.List
containsAll
-
Constructor Details
-
ClassInfoList
public ClassInfoList()Construct a new empty modifiable list ofClassInfo
objects. -
ClassInfoList
public ClassInfoList(int sizeHint) Construct a new empty modifiable list ofClassInfo
objects, given a size hint.- Parameters:
sizeHint
- the size hint.
-
ClassInfoList
Construct a new modifiable emptyClassInfoList
, given an initial list ofClassInfo
objects.If the passed
Collection
is not aSet
, then theClassInfo
objects will be uniquified (by adding them to a set) before they are added to the returned list.ClassInfo
objects in the returned list will be sorted by name.- Parameters:
classInfoCollection
- the initial collection ofClassInfo
objects to add to theClassInfoList
.
-
-
Method Details
-
emptyList
Return an unmodifiable emptyClassInfoList
.- Returns:
- the unmodifiable empty
ClassInfoList
.
-
loadClasses
Convert this list ofClassInfo
objects 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 eachClassInfo
object, if it is not already loaded.Important note: since
superclassOrInterfaceType
is a class reference for an already-loaded class, it is critical thatsuperclassOrInterfaceType
is loaded by the same classloader as the class referred to by thisClassInfo
object, otherwise the class cast will fail.- Type Parameters:
T
- The superclass or interface.- Parameters:
superclassOrInterfaceType
- The superclass or interface class reference 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 -- instead, skip the element (i.e. the returned list may contain fewer items than this input list). If false,IllegalArgumentException
is thrown if the class could not be loaded or could not be cast to the requested type.- Returns:
- The loaded
Class<?>
objects corresponding to eachClassInfo
object 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
Convert this list ofClassInfo
objects 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 eachClassInfo
object, if it is not already loaded.Important note: since
superclassOrInterfaceType
is a class reference for an already-loaded class, it is critical thatsuperclassOrInterfaceType
is loaded by the same classloader as the class referred to by thisClassInfo
object, otherwise the class cast will fail.- Type Parameters:
T
- The superclass or interface.- Parameters:
superclassOrInterfaceType
- The superclass or interface class reference to cast each loaded class to.- Returns:
- The loaded
Class<?>
objects corresponding to eachClassInfo
object in this list. - Throws:
IllegalArgumentException
- if an exception or error was thrown while trying to load or cast any of the classes.
-
loadClasses
Convert this list ofClassInfo
objects to a list ofClass<?>
objects. Causes the classloader to load the class named by eachClassInfo
object, 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 correspondingClassInfo
object, so the returned list may contain fewer items than this input list. If false,IllegalArgumentException
is thrown if the class could not be loaded.- Returns:
- The loaded
Class<?>
objects corresponding to eachClassInfo
object 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
Convert this list ofClassInfo
objects to a list ofClass<?>
objects. Causes the classloader to load the class named by eachClassInfo
object, if it is not already loaded.- Returns:
- The loaded
Class<?>
objects corresponding to eachClassInfo
object in this list. - Throws:
IllegalArgumentException
- if an exception or error was thrown while trying to load any of the classes.
-
directOnly
Get the list of classes that were directly related, as opposed to reachable through multiple steps. For example, if thisClassInfoList
was 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
Find the union of thisClassInfoList
with one or more others.- Parameters:
others
- The otherClassInfoList
s to union with this one.- Returns:
- The union of this
ClassInfoList
with the others.
-
intersect
Find the intersection of thisClassInfoList
with one or more others.- Parameters:
others
- The otherClassInfoList
s to intersect with this one.- Returns:
- The intersection of this
ClassInfoList
with the others.
-
exclude
Find the set difference between thisClassInfoList
and anotherClassInfoList
, i.e. (this \ other).- Parameters:
other
- The otherClassInfoList
to subtract from this one.- Returns:
- The set difference of this
ClassInfoList
and other, i.e. (this \ other).
-
filter
Find the subset of thisClassInfoList
for which the given filter predicate is true.- Parameters:
filter
- TheClassInfoList.ClassInfoFilter
to apply.- Returns:
- The subset of this
ClassInfoList
for which the given filter predicate is true.
-
getStandardClasses
Filter thisClassInfoList
to include only standard classes (classes that are not interfaces or annotations).- Returns:
- The filtered list, containing only standard classes.
-
getInterfaces
Filter thisClassInfoList
to include only interfaces that are not annotations. See alsogetInterfacesAndAnnotations()
.- Returns:
- The filtered list, containing only interfaces.
-
getInterfacesAndAnnotations
Filter thisClassInfoList
to include only interfaces and annotations (annotations are interfaces, and can be implemented). See alsogetInterfaces()
.- Returns:
- The filtered list, containing only interfaces.
-
getImplementedInterfaces
Filter thisClassInfoList
to 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
Filter thisClassInfoList
to include only annotations.- Returns:
- The filtered list, containing only annotations.
-
getEnums
Filter thisClassInfoList
to include onlyEnum
classes.- Returns:
- The filtered list, containing only enums.
-
getRecords
Filter thisClassInfoList
to include onlyrecord
classes.- Returns:
- The filtered list, containing only
record
classes.
-
getAssignableTo
Filter thisClassInfoList
to include only classes that are assignable to the requested class, assignableToClass (i.e. where assignableToClass is a superclass or implemented interface of the list element).- Parameters:
superclassOrInterface
- the superclass or interface to filter for.- Returns:
- The filtered list, containing only classes for which
assignableToClassRef.isAssignableFrom(listItemClassRef)
is true for the correspondingClass<?>
references for assignableToClass and the list items. Returns the empty list if no classes were assignable to the requested class. - Throws:
IllegalArgumentException
- if classInfo is null.
-
generateGraphVizDotFileFromInterClassDependencies
public String generateGraphVizDotFileFromInterClassDependencies(float sizeX, float sizeY, boolean includeExternalClasses) Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph. The returned graph shows inter-class dependencies only. The sizeX and sizeY parameters are the image output size to use (in inches) when GraphViz is asked to render the .dot file. You must have calledClassGraph.enableInterClassDependencies()
before scanning to use this method.- Parameters:
sizeX
- The GraphViz layout width in inches.sizeY
- The GraphViz layout width in inches.includeExternalClasses
- If true, and ifClassGraph.enableExternalClasses()
was called before scanning, show "external classes" (non-accepted classes) within the dependency graph.- Returns:
- the GraphViz file contents.
- Throws:
IllegalArgumentException
- if thisClassInfoList
is empty orClassGraph.enableInterClassDependencies()
was not called before scanning (since there would be nothing to graph).
-
generateGraphVizDotFileFromInterClassDependencies
Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph. The returned graph shows inter-class dependencies only. The sizeX and sizeY parameters are the image output size to use (in inches) when GraphViz is asked to render the .dot file. You must have calledClassGraph.enableInterClassDependencies()
before scanning to use this method.Equivalent to calling
generateGraphVizDotFileFromInterClassDependencies(float, float, boolean)
with parameters of (10.5f, 8f, scanSpec.enableExternalClasses), where scanSpec.enableExternalClasses is true ifClassGraph.enableExternalClasses()
was called before scanning.- Parameters:
sizeX
- The GraphViz layout width in inches.sizeY
- The GraphViz layout width in inches.- Returns:
- the GraphViz file contents.
- Throws:
IllegalArgumentException
- if thisClassInfoList
is empty orClassGraph.enableInterClassDependencies()
was not called before scanning (since there would be nothing to graph).
-
generateGraphVizDotFileFromInterClassDependencies
Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph. The returned graph shows inter-class dependencies only. The sizeX and sizeY parameters are the image output size to use (in inches) when GraphViz is asked to render the .dot file. You must have calledClassGraph.enableInterClassDependencies()
before scanning to use this method.Equivalent to calling
generateGraphVizDotFileFromInterClassDependencies(float, float, boolean)
with parameters of (10.5f, 8f, scanSpec.enableExternalClasses), where scanSpec.enableExternalClasses is true ifClassGraph.enableExternalClasses()
was called before scanning.- Returns:
- the GraphViz file contents.
- Throws:
IllegalArgumentException
- if thisClassInfoList
is empty orClassGraph.enableInterClassDependencies()
was not called before scanning (since there would be nothing to graph).
-
generateGraphVizDotFileFromClassDependencies
Deprecated.UsegenerateGraphVizDotFileFromInterClassDependencies()
instead.Deprecated: usegenerateGraphVizDotFileFromInterClassDependencies()
instead.- Returns:
- the GraphViz file contents.
- Throws:
IllegalArgumentException
- if thisClassInfoList
is empty orClassGraph.enableInterClassDependencies()
was not called before scanning (since there would be nothing to graph).
-
generateGraphVizDotFile
public String generateGraphVizDotFile(float sizeX, float sizeY, boolean showFields, boolean showFieldTypeDependencyEdges, boolean showMethods, boolean showMethodTypeDependencyEdges, boolean showAnnotations, boolean useSimpleNames) 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.To show non-public classes, call
ClassGraph.ignoreClassVisibility()
before scanning.To show fields, call
ClassGraph.enableFieldInfo()
before scanning. To show non-public fields, also callClassGraph.ignoreFieldVisibility()
before scanning.To show methods, call
ClassGraph.enableMethodInfo()
before scanning. To show non-public methods, also callClassGraph.ignoreMethodVisibility()
before scanning.To show annotations, call
ClassGraph.enableAnnotationInfo()
before scanning. To show non-public annotations, also callClassGraph.ignoreFieldVisibility()
before scanning (there is no separate visibility modifier for annotations).- 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.showFieldTypeDependencyEdges
- If true, show edges between classes and the types of their fields.showMethods
- If true, show methods within class nodes in the graph.showMethodTypeDependencyEdges
- If true, show edges between classes and the return types and/or parameter types of their methods.showAnnotations
- If true, show annotations in the graph.useSimpleNames
- whether to use simple names for classes in type signatures (if true, the package name is stripped from class names in method and field type signatures).- Returns:
- the GraphViz file contents.
- Throws:
IllegalArgumentException
- if thisClassInfoList
is empty orClassGraph.enableClassInfo()
was not called before scanning (since there would be nothing to graph).
-
generateGraphVizDotFile
public String generateGraphVizDotFile(float sizeX, float sizeY, boolean showFields, boolean showFieldTypeDependencyEdges, boolean showMethods, boolean showMethodTypeDependencyEdges, 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.To show non-public classes, call
ClassGraph.ignoreClassVisibility()
before scanning.To show fields, call
ClassGraph.enableFieldInfo()
before scanning. To show non-public fields, also callClassGraph.ignoreFieldVisibility()
before scanning.To show methods, call
ClassGraph.enableMethodInfo()
before scanning. To show non-public methods, also callClassGraph.ignoreMethodVisibility()
before scanning.To show annotations, call
ClassGraph.enableAnnotationInfo()
before scanning. To show non-public annotations, also callClassGraph.ignoreFieldVisibility()
before scanning (there is no separate visibility modifier for annotations).This method uses simple names for class names in type signatures of fields and methods (package names are stripped).
- 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.showFieldTypeDependencyEdges
- If true, show edges between classes and the types of their fields.showMethods
- If true, show methods within class nodes in the graph.showMethodTypeDependencyEdges
- If true, show edges between classes and the return types and/or parameter types of their methods.showAnnotations
- If true, show annotations in the graph.- Returns:
- the GraphViz file contents.
- Throws:
IllegalArgumentException
- if thisClassInfoList
is empty orClassGraph.enableClassInfo()
was not called before scanning (since there would be nothing to graph).
-
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
ClassGraph.enableMethodInfo()
,ClassGraph.enableFieldInfo()
andClassGraph.enableAnnotationInfo()
.Only public classes, methods, and fields are shown, unless
ClassGraph.ignoreClassVisibility()
,ClassGraph.ignoreMethodVisibility()
, and/orClassGraph.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.
- Throws:
IllegalArgumentException
- if thisClassInfoList
is empty orClassGraph.enableClassInfo()
was not called before scanning (since there would be nothing to graph).
-
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
ClassGraph.enableMethodInfo()
,ClassGraph.enableFieldInfo()
andClassGraph.enableAnnotationInfo()
.Only public classes, methods, and fields are shown, unless
ClassGraph.ignoreClassVisibility()
,ClassGraph.ignoreMethodVisibility()
, and/orClassGraph.ignoreFieldVisibility()
has/have been called.- Returns:
- the GraphViz file contents.
- Throws:
IllegalArgumentException
- if thisClassInfoList
is empty orClassGraph.enableClassInfo()
was not called before scanning (since there would be nothing to graph).
-
generateGraphVizDotFile
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
ClassGraph.enableMethodInfo()
,ClassGraph.enableFieldInfo()
andClassGraph.enableAnnotationInfo()
.Only public classes, methods, and fields are shown, unless
ClassGraph.ignoreClassVisibility()
,ClassGraph.ignoreMethodVisibility()
, and/orClassGraph.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.IllegalArgumentException
- if thisClassInfoList
is empty orClassGraph.enableClassInfo()
was not called before scanning (since there would be nothing to graph).
-
equals
-
hashCode
public int hashCode() -
add
-
add
-
remove
-
remove
-
addAll
-
addAll
-
removeAll
-
retainAll
-
clear
public void clear() -
set
-
iterator
-
listIterator
- Specified by:
listIterator
in interfaceList<T>
- Overrides:
listIterator
in classArrayList<T>
-
generateGraphVizDotFileFromInterClassDependencies()
instead.