public class ClassInfoList extends MappableInfoList<ClassInfo>
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.
Modifier and Type | Class and Description |
---|---|
static interface |
ClassInfoList.ClassInfoFilter
Filter a
ClassInfoList using a predicate mapping a ClassInfo object to a boolean, producing
another ClassInfoList for all items in the list for which the predicate is true. |
Constructor and Description |
---|
ClassInfoList()
Construct a new empty modifiable list of
ClassInfo objects. |
ClassInfoList(Collection<ClassInfo> classInfoCollection)
Construct a new modifiable empty
ClassInfoList , given an initial list of ClassInfo objects. |
ClassInfoList(int sizeHint)
Construct a new empty modifiable list of
ClassInfo objects, given a size hint. |
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
T element) |
boolean |
add(T element) |
boolean |
addAll(Collection<? extends T> c) |
boolean |
addAll(int index,
Collection<? extends T> c) |
void |
clear() |
ClassInfoList |
directOnly()
Get the list of classes that were directly related, as opposed to reachable through multiple steps.
|
static ClassInfoList |
emptyList()
Return an unmodifiable empty
ClassInfoList . |
boolean |
equals(Object obj) |
ClassInfoList |
exclude(ClassInfoList other)
Find the set difference between this
ClassInfoList and another ClassInfoList , i.e. |
ClassInfoList |
filter(ClassInfoList.ClassInfoFilter filter)
Find the subset of this
ClassInfoList for which the given filter predicate is true. |
String |
generateGraphVizDotFile()
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.
|
String |
generateGraphVizDotFile(float sizeX,
float sizeY)
Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph.
|
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.
|
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.
|
String |
generateGraphVizDotFileFromClassDependencies()
Deprecated.
Use
generateGraphVizDotFileFromInterClassDependencies() instead. |
String |
generateGraphVizDotFileFromInterClassDependencies()
Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph.
|
String |
generateGraphVizDotFileFromInterClassDependencies(float sizeX,
float sizeY)
Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph.
|
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.
|
ClassInfoList |
getAnnotations()
Filter this
ClassInfoList to include only annotations. |
ClassInfoList |
getAssignableTo(ClassInfo superclassOrInterface)
Filter this
ClassInfoList to include only classes that are assignable to the requested class,
assignableToClass (i.e. |
ClassInfoList |
getEnums()
Filter this
ClassInfoList to include only Enum classes. |
ClassInfoList |
getImplementedInterfaces()
Filter this
ClassInfoList to include only implemented interfaces, i.e. |
ClassInfoList |
getInterfaces()
Filter this
ClassInfoList to include only interfaces that are not annotations. |
ClassInfoList |
getInterfacesAndAnnotations()
Filter this
ClassInfoList to include only interfaces and annotations (annotations are interfaces, and
can be implemented). |
ClassInfoList |
getRecords()
Filter this
ClassInfoList to include only record classes. |
ClassInfoList |
getStandardClasses()
Filter this
ClassInfoList to include only standard classes (classes that are not interfaces or
annotations). |
int |
hashCode() |
ClassInfoList |
intersect(ClassInfoList... others)
Find the intersection of this
ClassInfoList with one or more others. |
Iterator<T> |
iterator() |
ListIterator<T> |
listIterator() |
List<Class<?>> |
loadClasses()
Convert this list of
ClassInfo objects to a list of Class<?> objects. |
List<Class<?>> |
loadClasses(boolean ignoreExceptions)
Convert this list of
ClassInfo objects to a list of Class<?> objects. |
<T> List<Class<T>> |
loadClasses(Class<T> superclassOrInterfaceType)
Convert this list of
ClassInfo objects to a list of Class<?> 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 of
ClassInfo objects to a list of Class<?> objects, casting each item in
the list to the requested superclass or interface type. |
T |
remove(int index) |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
retainAll(Collection<?> c) |
T |
set(int index,
T element) |
ClassInfoList |
union(ClassInfoList... others)
Find the union of this
ClassInfoList with one or more others. |
asMap, containsName, get
getAsStrings, getAsStringsWithSimpleNames, getNames
clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, lastIndexOf, listIterator, removeIf, replaceAll, size, sort, spliterator, subList, toArray, toArray, trimToSize
containsAll, toString
containsAll
parallelStream, stream
public ClassInfoList()
ClassInfo
objects.public ClassInfoList(int sizeHint)
ClassInfo
objects, given a size hint.sizeHint
- the size hint.public ClassInfoList(Collection<ClassInfo> classInfoCollection)
ClassInfoList
, given an initial list of ClassInfo
objects.
If the passed Collection
is not a Set
, then the ClassInfo
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.
classInfoCollection
- the initial collection of ClassInfo
objects to add to the ClassInfoList
.public static ClassInfoList emptyList()
ClassInfoList
.ClassInfoList
.public <T> List<Class<T>> loadClasses(Class<T> superclassOrInterfaceType, boolean ignoreExceptions)
ClassInfo
objects to a list of Class<?>
objects, casting each item in
the list to the requested superclass or interface type. Causes the classloader to load the class named by
each ClassInfo
object, if it is not already loaded.
Important note: since superclassOrInterfaceType
is a class reference for an already-loaded
class, it is critical that superclassOrInterfaceType
is loaded by the same classloader as the class
referred to by this ClassInfo
object, otherwise the class cast will fail.
T
- The superclass or interface.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 resulting Class<?>
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.Class<?>
objects corresponding to each ClassInfo
object in this list.IllegalArgumentException
- if ignoreExceptions is false and an exception or error was thrown while trying to load or cast
any of the classes.public <T> List<Class<T>> loadClasses(Class<T> superclassOrInterfaceType)
ClassInfo
objects to a list of Class<?>
objects, casting each item in
the list to the requested superclass or interface type. Causes the classloader to load the class named by
each ClassInfo
object, if it is not already loaded.
Important note: since superclassOrInterfaceType
is a class reference for an already-loaded
class, it is critical that superclassOrInterfaceType
is loaded by the same classloader as the class
referred to by this ClassInfo
object, otherwise the class cast will fail.
T
- The superclass or interface.superclassOrInterfaceType
- The superclass or interface class reference to cast each loaded class to.Class<?>
objects corresponding to each ClassInfo
object in this list.IllegalArgumentException
- if an exception or error was thrown while trying to load or cast any of the classes.public List<Class<?>> loadClasses(boolean ignoreExceptions)
ClassInfo
objects to a list of Class<?>
objects. Causes the classloader
to load the class named by each ClassInfo
object, if it is not already loaded.ignoreExceptions
- If true, ignore any exceptions or errors thrown during classloading. If an exception or error is
thrown during classloading, no Class<?>
reference is added to the output class for the
corresponding ClassInfo
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.Class<?>
objects corresponding to each ClassInfo
object in this list.IllegalArgumentException
- if ignoreExceptions is false and an exception or error was thrown while trying to load any of the
classes.public List<Class<?>> loadClasses()
ClassInfo
objects to a list of Class<?>
objects. Causes the classloader
to load the class named by each ClassInfo
object, if it is not already loaded.Class<?>
objects corresponding to each ClassInfo
object in this list.IllegalArgumentException
- if an exception or error was thrown while trying to load any of the classes.public ClassInfoList directOnly()
ClassInfoList
was produced by querying for all superclasses of a given class, then
directOnly()
will return only the direct superclass of this class.public ClassInfoList union(ClassInfoList... others)
ClassInfoList
with one or more others.others
- The other ClassInfoList
s to union with this one.ClassInfoList
with the others.public ClassInfoList intersect(ClassInfoList... others)
ClassInfoList
with one or more others.others
- The other ClassInfoList
s to intersect with this one.ClassInfoList
with the others.public ClassInfoList exclude(ClassInfoList other)
ClassInfoList
and another ClassInfoList
, i.e. (this \
other).other
- The other ClassInfoList
to subtract from this one.ClassInfoList
and other, i.e. (this \ other).public ClassInfoList filter(ClassInfoList.ClassInfoFilter filter)
ClassInfoList
for which the given filter predicate is true.filter
- The ClassInfoList.ClassInfoFilter
to apply.ClassInfoList
for which the given filter predicate is true.public ClassInfoList getStandardClasses()
ClassInfoList
to include only standard classes (classes that are not interfaces or
annotations).public ClassInfoList getInterfaces()
ClassInfoList
to include only interfaces that are not annotations. See also
getInterfacesAndAnnotations()
.public ClassInfoList getInterfacesAndAnnotations()
ClassInfoList
to include only interfaces and annotations (annotations are interfaces, and
can be implemented). See also getInterfaces()
.public ClassInfoList getImplementedInterfaces()
ClassInfoList
to include only implemented interfaces, i.e. non-annotation interfaces, or
annotations that have been implemented by a class.public ClassInfoList getAnnotations()
ClassInfoList
to include only annotations.public ClassInfoList getEnums()
ClassInfoList
to include only Enum
classes.public ClassInfoList getRecords()
ClassInfoList
to include only record
classes.record
classes.public ClassInfoList getAssignableTo(ClassInfo superclassOrInterface)
ClassInfoList
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).superclassOrInterface
- the superclass or interface to filter for.assignableToClassRef.isAssignableFrom(listItemClassRef)
is true for the corresponding
Class<?>
references for assignableToClass and the list items. Returns the empty list if no
classes were assignable to the requested class.IllegalArgumentException
- if classInfo is null.public String generateGraphVizDotFileFromInterClassDependencies(float sizeX, float sizeY, boolean includeExternalClasses)
ClassGraph.enableInterClassDependencies()
before scanning to use this method.sizeX
- The GraphViz layout width in inches.sizeY
- The GraphViz layout width in inches.includeExternalClasses
- If true, and if ClassGraph.enableExternalClasses()
was called before scanning, show
"external classes" (non-accepted classes) within the dependency graph.IllegalArgumentException
- if this ClassInfoList
is empty or ClassGraph.enableInterClassDependencies()
was
not called before scanning (since there would be nothing to graph).public String generateGraphVizDotFileFromInterClassDependencies(float sizeX, float sizeY)
ClassGraph.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 if
ClassGraph.enableExternalClasses()
was called before scanning.
sizeX
- The GraphViz layout width in inches.sizeY
- The GraphViz layout width in inches.IllegalArgumentException
- if this ClassInfoList
is empty or ClassGraph.enableInterClassDependencies()
was
not called before scanning (since there would be nothing to graph).public String generateGraphVizDotFileFromInterClassDependencies()
ClassGraph.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 if
ClassGraph.enableExternalClasses()
was called before scanning.
IllegalArgumentException
- if this ClassInfoList
is empty or ClassGraph.enableInterClassDependencies()
was
not called before scanning (since there would be nothing to graph).@Deprecated public String generateGraphVizDotFileFromClassDependencies()
generateGraphVizDotFileFromInterClassDependencies()
instead.generateGraphVizDotFileFromInterClassDependencies()
instead.IllegalArgumentException
- if this ClassInfoList
is empty or ClassGraph.enableInterClassDependencies()
was
not called before scanning (since there would be nothing to graph).public String generateGraphVizDotFile(float sizeX, float sizeY, boolean showFields, boolean showFieldTypeDependencyEdges, boolean showMethods, boolean showMethodTypeDependencyEdges, boolean showAnnotations, boolean useSimpleNames)
To show non-public classes, call ClassGraph.ignoreClassVisibility()
before scanning.
To show fields, call ClassGraph.enableFieldInfo()
before scanning. To show non-public fields, also
call ClassGraph.ignoreFieldVisibility()
before scanning.
To show methods, call ClassGraph.enableMethodInfo()
before scanning. To show non-public methods, also
call ClassGraph.ignoreMethodVisibility()
before scanning.
To show annotations, call ClassGraph.enableAnnotationInfo()
before scanning. To show non-public
annotations, also call ClassGraph.ignoreFieldVisibility()
before scanning (there is no separate
visibility modifier for annotations).
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).IllegalArgumentException
- if this ClassInfoList
is empty or ClassGraph.enableClassInfo()
was not called
before scanning (since there would be nothing to graph).public String generateGraphVizDotFile(float sizeX, float sizeY, boolean showFields, boolean showFieldTypeDependencyEdges, boolean showMethods, boolean showMethodTypeDependencyEdges, boolean showAnnotations)
To show non-public classes, call ClassGraph.ignoreClassVisibility()
before scanning.
To show fields, call ClassGraph.enableFieldInfo()
before scanning. To show non-public fields, also
call ClassGraph.ignoreFieldVisibility()
before scanning.
To show methods, call ClassGraph.enableMethodInfo()
before scanning. To show non-public methods, also
call ClassGraph.ignoreMethodVisibility()
before scanning.
To show annotations, call ClassGraph.enableAnnotationInfo()
before scanning. To show non-public
annotations, also call ClassGraph.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).
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.IllegalArgumentException
- if this ClassInfoList
is empty or ClassGraph.enableClassInfo()
was not called
before scanning (since there would be nothing to graph).public String generateGraphVizDotFile(float sizeX, float sizeY)
Methods, fields and annotations are shown if enabled, via ClassGraph.enableMethodInfo()
,
ClassGraph.enableFieldInfo()
and ClassGraph.enableAnnotationInfo()
.
Only public classes, methods, and fields are shown, unless ClassGraph.ignoreClassVisibility()
,
ClassGraph.ignoreMethodVisibility()
, and/or ClassGraph.ignoreFieldVisibility()
has/have been
called.
sizeX
- The GraphViz layout width in inches.sizeY
- The GraphViz layout width in inches.IllegalArgumentException
- if this ClassInfoList
is empty or ClassGraph.enableClassInfo()
was not called
before scanning (since there would be nothing to graph).public String generateGraphVizDotFile()
Methods, fields and annotations are shown if enabled, via ClassGraph.enableMethodInfo()
,
ClassGraph.enableFieldInfo()
and ClassGraph.enableAnnotationInfo()
.
Only public classes, methods, and fields are shown, unless ClassGraph.ignoreClassVisibility()
,
ClassGraph.ignoreMethodVisibility()
, and/or ClassGraph.ignoreFieldVisibility()
has/have been
called.
IllegalArgumentException
- if this ClassInfoList
is empty or ClassGraph.enableClassInfo()
was not called
before scanning (since there would be nothing to graph).public void generateGraphVizDotFile(File file) throws IOException
Methods, fields and annotations are shown if enabled, via ClassGraph.enableMethodInfo()
,
ClassGraph.enableFieldInfo()
and ClassGraph.enableAnnotationInfo()
.
Only public classes, methods, and fields are shown, unless ClassGraph.ignoreClassVisibility()
,
ClassGraph.ignoreMethodVisibility()
, and/or ClassGraph.ignoreFieldVisibility()
has/have been
called.
file
- the file to save the GraphViz .dot file to.IOException
- if the file could not be saved.IllegalArgumentException
- if this ClassInfoList
is empty or ClassGraph.enableClassInfo()
was not called
before scanning (since there would be nothing to graph).public boolean equals(Object obj)
public int hashCode()
public boolean add(T element)
public void add(int index, T element)
public boolean remove(Object o)
public T remove(int index)
public boolean addAll(Collection<? extends T> c)
public boolean addAll(int index, Collection<? extends T> c)
public boolean removeAll(Collection<?> c)
public boolean retainAll(Collection<?> c)
public void clear()
public T set(int index, T element)
public Iterator<T> iterator()
public ListIterator<T> listIterator()
listIterator
in interface List<T>
listIterator
in class ArrayList<T>
Copyright © 2021. All rights reserved.