/** * @return The list of interfaces implemented by this class or by one of its superclasses, if this is a standard * class, or the superinterfaces extended by this interface, if this is an interface. Returns the empty * list if none. */ public ClassInfoList getInterfaces() { // Classes also implement the interfaces of their superclasses final ReachableAndDirectlyRelatedClasses implementedInterfaces = this .filterClassInfo(RelType.IMPLEMENTED_INTERFACES, /* strictWhitelist = */ false); final Set<ClassInfo> allInterfaces = new LinkedHashSet<>(implementedInterfaces.reachableClasses); for (final ClassInfo superclass : this.filterClassInfo(RelType.SUPERCLASSES, /* strictWhitelist = */ false).reachableClasses) { final Set<ClassInfo> superclassImplementedInterfaces = superclass.filterClassInfo( RelType.IMPLEMENTED_INTERFACES, /* strictWhitelist = */ false).reachableClasses; allInterfaces.addAll(superclassImplementedInterfaces); } return new ClassInfoList(allInterfaces, implementedInterfaces.directlyRelatedClasses, /* sortByName = */ true); }
/** * Get all classes found during the scan. * * @return A list of all classes found during the scan, or the empty list if none. */ static ClassInfoList getAllClasses(final Collection<ClassInfo> classes, final ScanSpec scanSpec, final ScanResult scanResult) { return new ClassInfoList( ClassInfo.filterClassInfo(classes, scanSpec, /* strictWhitelist = */ true, ClassType.ALL), /* sortByName = */ true); }
/** * Get all standard classes found during the scan. * * @return A list of all standard classes found during the scan, or the empty list if none. */ static ClassInfoList getAllStandardClasses(final Collection<ClassInfo> classes, final ScanSpec scanSpec, final ScanResult scanResult) { return new ClassInfoList(ClassInfo.filterClassInfo(classes, scanSpec, /* strictWhitelist = */ true, ClassType.STANDARD_CLASS), /* sortByName = */ true); }
/** * Get all superclasses of this class, in ascending order in the class hierarchy. Does not include * superinterfaces, if this is an interface (use {@link #getInterfaces()} to get superinterfaces of an * interface.} * * @return the list of all superclasses of this class, or the empty list if none. */ public ClassInfoList getSuperclasses() { return new ClassInfoList(this.filterClassInfo(RelType.SUPERCLASSES, /* strictWhitelist = */ false), /* sortByName = */ false); }
/** * @return A list of classes that declare fields that are directly annotated (i.e. are not meta-annotated) with * the requested method annotation, or the empty list if none. */ ClassInfoList getClassesWithFieldAnnotationDirectOnly() { return new ClassInfoList(this.filterClassInfo(RelType.CLASSES_WITH_FIELD_ANNOTATION, /* strictWhitelist = */ !isExternalClass), /* sortByName = */ true); }
/** * Get all annotation classes found during the scan. See also * {@link #getAllInterfacesOrAnnotationClasses(Collection, ScanSpec, ScanResult)} ()}. * * @return A list of all annotation classes found during the scan, or the empty list if none. */ static ClassInfoList getAllAnnotationClasses(final Collection<ClassInfo> classes, final ScanSpec scanSpec, final ScanResult scanResult) { return new ClassInfoList( ClassInfo.filterClassInfo(classes, scanSpec, /* strictWhitelist = */ true, ClassType.ANNOTATION), /* sortByName = */ true); }
/** * @return The list of classes that are directly (i.e. are not meta-annotated) annotated with the requested * annotation, or the empty list if none. */ ClassInfoList getClassesWithAnnotationDirectOnly() { return new ClassInfoList( this.filterClassInfo(RelType.CLASSES_WITH_ANNOTATION, /* strictWhitelist = */ !isExternalClass), /* sortByName = */ true); }
/** * Get all implemented interface (non-annotation interface) classes found during the scan. * * @return A list of all annotation classes found during the scan, or the empty list if none. */ static ClassInfoList getAllImplementedInterfaceClasses(final Collection<ClassInfo> classes, final ScanSpec scanSpec, final ScanResult scanResult) { return new ClassInfoList(ClassInfo.filterClassInfo(classes, scanSpec, /* strictWhitelist = */ true, ClassType.IMPLEMENTED_INTERFACE), /* sortByName = */ true); }
/** * @return A list of the containing outer classes, if this is an inner class, otherwise the empty list. Note * that all containing outer classes are returned, not just the innermost of the containing outer * classes. */ public ClassInfoList getOuterClasses() { return new ClassInfoList( this.filterClassInfo(RelType.CONTAINED_WITHIN_OUTER_CLASS, /* strictWhitelist = */ false), /* sortByName = */ false); }
/** * @return A list of the inner classes contained within this class, or the empty list if none. */ public ClassInfoList getInnerClasses() { return new ClassInfoList(this.filterClassInfo(RelType.CONTAINS_INNER_CLASS, /* strictWhitelist = */ false), /* sortByName = */ true); }
/** * Get all interface or annotation classes found during the scan. (Annotations are technically interfaces, and * they can be implemented.) * * @return A list of all whitelisted interfaces found during the scan, or the empty list if none. */ static ClassInfoList getAllInterfacesOrAnnotationClasses(final Collection<ClassInfo> classes, final ScanSpec scanSpec, final ScanResult scanResult) { return new ClassInfoList(ClassInfo.filterClassInfo(classes, scanSpec, /* strictWhitelist = */ true, ClassType.INTERFACE_OR_ANNOTATION), /* sortByName = */ true); }
/** * @return A list of classes that declare methods that are directly annotated (i.e. are not meta-annotated) with * the requested method annotation, or the empty list if none. */ ClassInfoList getClassesWithMethodAnnotationDirectOnly() { return new ClassInfoList(this.filterClassInfo(RelType.CLASSES_WITH_METHOD_ANNOTATION, /* strictWhitelist = */ !isExternalClass), /* sortByName = */ true); }
/** * @return A list of annotations on fields declared by the class, or the empty list if none. N.B. these * annotations do not contain specific annotation parameters -- call * {@link FieldInfo#getAnnotationInfo()} to get details on specific field annotation instances. */ public ClassInfoList getFieldAnnotations() { if (!scanResult.scanSpec.enableFieldInfo || !scanResult.scanSpec.enableAnnotationInfo) { throw new IllegalArgumentException("Please call ClassGraph#enableFieldInfo() and " + "ClassGraph#enableAnnotationInfo() before #scan()"); } final ReachableAndDirectlyRelatedClasses fieldAnnotations = this.filterClassInfo(RelType.FIELD_ANNOTATIONS, /* strictWhitelist = */ false, ClassType.ANNOTATION); final Set<ClassInfo> fieldAnnotationsAndMetaAnnotations = new LinkedHashSet<>( fieldAnnotations.reachableClasses); for (final ClassInfo fieldAnnotation : fieldAnnotations.reachableClasses) { fieldAnnotationsAndMetaAnnotations.addAll(fieldAnnotation.filterClassInfo(RelType.CLASS_ANNOTATIONS, /* strictWhitelist = */ false).reachableClasses); } return new ClassInfoList(fieldAnnotationsAndMetaAnnotations, fieldAnnotations.directlyRelatedClasses, /* sortByName = */ true); }
/** * @return A list of annotations or meta-annotations on methods declared by the class, (not including methods * declared by the interfaces or superclasses of this class), as a list of {@link ClassInfo} objects, or * the empty list if none. N.B. these annotations do not contain specific annotation parameters -- call * {@link MethodInfo#getAnnotationInfo()} to get details on specific method annotation instances. */ public ClassInfoList getMethodAnnotations() { if (!scanResult.scanSpec.enableMethodInfo || !scanResult.scanSpec.enableAnnotationInfo) { throw new IllegalArgumentException( "Please call ClassGraph#enableMethodInfo() and " + "#enableAnnotationInfo() before #scan()"); } final ReachableAndDirectlyRelatedClasses methodAnnotations = this .filterClassInfo(RelType.METHOD_ANNOTATIONS, /* strictWhitelist = */ false, ClassType.ANNOTATION); final Set<ClassInfo> methodAnnotationsAndMetaAnnotations = new LinkedHashSet<>( methodAnnotations.reachableClasses); for (final ClassInfo methodAnnotation : methodAnnotations.reachableClasses) { methodAnnotationsAndMetaAnnotations.addAll(methodAnnotation.filterClassInfo(RelType.CLASS_ANNOTATIONS, /* strictWhitelist = */ false).reachableClasses); } return new ClassInfoList(methodAnnotationsAndMetaAnnotations, methodAnnotations.directlyRelatedClasses, /* sortByName = */ true); }
/** * @return the list of the classes (and their subclasses) that implement this interface, if this is an * interface, otherwise returns the empty list. */ public ClassInfoList getClassesImplementing() { if (!isInterface) { throw new IllegalArgumentException("Class is not an interface: " + getName()); } // Subclasses of implementing classes also implement the interface final ReachableAndDirectlyRelatedClasses implementingClasses = this .filterClassInfo(RelType.CLASSES_IMPLEMENTING, /* strictWhitelist = */ !isExternalClass); final Set<ClassInfo> allImplementingClasses = new LinkedHashSet<>(implementingClasses.reachableClasses); for (final ClassInfo implementingClass : implementingClasses.reachableClasses) { final Set<ClassInfo> implementingSubclasses = implementingClass.filterClassInfo(RelType.SUBCLASSES, /* strictWhitelist = */ !implementingClass.isExternalClass).reachableClasses; allImplementingClasses.addAll(implementingSubclasses); } return new ClassInfoList(allImplementingClasses, implementingClasses.directlyRelatedClasses, /* sortByName = */ true); }
/** * @return A list of classes that have a field with this annotation or meta-annotation, or the empty list if * none. */ public ClassInfoList getClassesWithFieldAnnotation() { if (!scanResult.scanSpec.enableFieldInfo || !scanResult.scanSpec.enableAnnotationInfo) { throw new IllegalArgumentException("Please call ClassGraph#enableFieldInfo() and " + "ClassGraph#enableAnnotationInfo() before #scan()"); } final ReachableAndDirectlyRelatedClasses classesWithDirectlyAnnotatedFields = this .filterClassInfo(RelType.CLASSES_WITH_FIELD_ANNOTATION, /* strictWhitelist = */ !isExternalClass); final ReachableAndDirectlyRelatedClasses annotationsWithThisMetaAnnotation = this.filterClassInfo( RelType.CLASSES_WITH_ANNOTATION, /* strictWhitelist = */ false, ClassType.ANNOTATION); if (annotationsWithThisMetaAnnotation.reachableClasses.isEmpty()) { // This annotation does not meta-annotate another annotation that annotates a field return new ClassInfoList(classesWithDirectlyAnnotatedFields, /* sortByName = */ true); } else { // Take the union of all classes with fields directly annotated by this annotation, // and classes with fields meta-annotated by this annotation final Set<ClassInfo> allClassesWithAnnotatedOrMetaAnnotatedFields = new LinkedHashSet<>( classesWithDirectlyAnnotatedFields.reachableClasses); for (final ClassInfo metaAnnotatedAnnotation : annotationsWithThisMetaAnnotation.reachableClasses) { allClassesWithAnnotatedOrMetaAnnotatedFields .addAll(metaAnnotatedAnnotation.filterClassInfo(RelType.CLASSES_WITH_FIELD_ANNOTATION, /* strictWhitelist = */ !metaAnnotatedAnnotation.isExternalClass).reachableClasses); } return new ClassInfoList(allClassesWithAnnotatedOrMetaAnnotatedFields, classesWithDirectlyAnnotatedFields.directlyRelatedClasses, /* sortByName = */ true); } }
/** * @return A list of classes that have a declared method with this annotation or meta-annotation, or the empty * list if none. */ public ClassInfoList getClassesWithMethodAnnotation() { if (!scanResult.scanSpec.enableMethodInfo || !scanResult.scanSpec.enableAnnotationInfo) { throw new IllegalArgumentException( "Please call ClassGraph#enableMethodInfo() and " + "#enableAnnotationInfo() before #scan()"); } final ReachableAndDirectlyRelatedClasses classesWithDirectlyAnnotatedMethods = this .filterClassInfo(RelType.CLASSES_WITH_METHOD_ANNOTATION, /* strictWhitelist = */ !isExternalClass); final ReachableAndDirectlyRelatedClasses annotationsWithThisMetaAnnotation = this.filterClassInfo( RelType.CLASSES_WITH_ANNOTATION, /* strictWhitelist = */ !isExternalClass, ClassType.ANNOTATION); if (annotationsWithThisMetaAnnotation.reachableClasses.isEmpty()) { // This annotation does not meta-annotate another annotation that annotates a method return new ClassInfoList(classesWithDirectlyAnnotatedMethods, /* sortByName = */ true); } else { // Take the union of all classes with methods directly annotated by this annotation, // and classes with methods meta-annotated by this annotation final Set<ClassInfo> allClassesWithAnnotatedOrMetaAnnotatedMethods = new LinkedHashSet<>( classesWithDirectlyAnnotatedMethods.reachableClasses); for (final ClassInfo metaAnnotatedAnnotation : annotationsWithThisMetaAnnotation.reachableClasses) { allClassesWithAnnotatedOrMetaAnnotatedMethods .addAll(metaAnnotatedAnnotation.filterClassInfo(RelType.CLASSES_WITH_METHOD_ANNOTATION, /* strictWhitelist = */ !metaAnnotatedAnnotation.isExternalClass).reachableClasses); } return new ClassInfoList(allClassesWithAnnotatedOrMetaAnnotatedMethods, classesWithDirectlyAnnotatedMethods.directlyRelatedClasses, /* sortByName = */ true); } }
/** * Get the subclasses of this class, sorted in order of name. Call {@link ClassInfoList#directOnly()} to get * direct subclasses. * * @return the list of subclasses of this class, or the empty list if none. */ public ClassInfoList getSubclasses() { if (getName().equals("java.lang.Object")) { // Make an exception for querying all subclasses of java.lang.Object return scanResult.getAllClasses(); } else { return new ClassInfoList( this.filterClassInfo(RelType.SUBCLASSES, /* strictWhitelist = */ !isExternalClass), /* sortByName = */ true); } }
buf.append(" extends ").append(superclass.toString(/* typeNameOnly = */ true)); final Set<ClassInfo> interfaces = this.filterClassInfo(RelType.IMPLEMENTED_INTERFACES, /* strictWhitelist = */ false).directlyRelatedClasses; if (!interfaces.isEmpty()) {
/** * @return A list of standard classes and non-annotation interfaces that are annotated by this class, if this is * an annotation class, or the empty list if none. Also handles the {@link Inherited} meta-annotation, * which causes an annotation on a class to be inherited by all of its subclasses. */ public ClassInfoList getClassesWithAnnotation() { if (!scanResult.scanSpec.enableAnnotationInfo) { throw new IllegalArgumentException("Please call ClassGraph#enableAnnotationInfo() before #scan()"); } if (!isAnnotation) { throw new IllegalArgumentException("Class is not an annotation: " + getName()); } // Get classes that have this annotation final ReachableAndDirectlyRelatedClasses classesWithAnnotation = this .filterClassInfo(RelType.CLASSES_WITH_ANNOTATION, /* strictWhitelist = */ !isExternalClass); if (isInherited) { // If this is an inherited annotation, add into the result all subclasses of the annotated classes. final Set<ClassInfo> classesWithAnnotationAndTheirSubclasses = new LinkedHashSet<>( classesWithAnnotation.reachableClasses); for (final ClassInfo classWithAnnotation : classesWithAnnotation.reachableClasses) { classesWithAnnotationAndTheirSubclasses.addAll(classWithAnnotation.getSubclasses()); } return new ClassInfoList(classesWithAnnotationAndTheirSubclasses, classesWithAnnotation.directlyRelatedClasses, /* sortByName = */ true); } else { // If not inherited, only return the annotated classes return new ClassInfoList(classesWithAnnotation, /* sortByName = */ true); } }