/** * Get the list of classes that were directly related, as opposed to reachable through multiple steps. For * example, if this {@link ClassInfoList} was produced by querying for all superclasses of a given class, then * {@link #directOnly()} will return only the direct superclass of this class. * * @return The list of directly-related classes. */ public ClassInfoList directOnly() { return new ClassInfoList(directlyRelatedClasses, directlyRelatedClasses, sortByName); }
/** Get the {@link ClassInfo} objects for all classes that are members of this package. */ public ClassInfoList getClassInfo() { return new ClassInfoList(classInfoSet, /* sortByName = */ true); }
/** Get the {@link ClassInfo} objects for all classes that are members of this package. */ public ClassInfoList getClassInfo() { return new ClassInfoList(new HashSet<>(memberClassNameToClassInfo.values()), /* 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); }
/** * Find the set difference between this {@link ClassInfoList} and another {@link ClassInfoList}, i.e. (this \ * other). * * @param other * The other {@link ClassInfoList} to subtract from this one. * @return The set difference of this {@link ClassInfoList} and other, i.e. (this \ other). */ public ClassInfoList exclude(final ClassInfoList other) { final Set<ClassInfo> reachableClassesDifference = new LinkedHashSet<>(this); final Set<ClassInfo> directlyRelatedClassesDifference = new LinkedHashSet<>(directlyRelatedClasses); reachableClassesDifference.removeAll(other); directlyRelatedClassesDifference.removeAll(other.directlyRelatedClasses); return new ClassInfoList(reachableClassesDifference, directlyRelatedClassesDifference, sortByName); }
/** * Find the union of this {@link ClassInfoList} with one or more others. * * @param others * The other {@link ClassInfoList}s to union with this one. * @return The union of this {@link ClassInfoList} with the others. */ public ClassInfoList union(final ClassInfoList... others) { final Set<ClassInfo> reachableClassesUnion = new LinkedHashSet<>(this); final Set<ClassInfo> directlyRelatedClassesUnion = new LinkedHashSet<>(directlyRelatedClasses); for (final ClassInfoList other : others) { reachableClassesUnion.addAll(other); directlyRelatedClassesUnion.addAll(other.directlyRelatedClasses); } return new ClassInfoList(reachableClassesUnion, directlyRelatedClassesUnion, sortByName); }
/** * 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 the {@link ClassInfo} objects for all classes that are members of this package or a sub-package. */ public ClassInfoList getClassInfoRecursive() { final Set<ClassInfo> reachableClassInfo = new HashSet<>(); getClassInfoRecursive(reachableClassInfo); return new ClassInfoList(reachableClassInfo, /* 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 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); }
/** * 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); }
/** * Filter this {@link ClassInfoList} to include only standard classes (classes that are not interfaces or * annotations). * * @return The filtered list, containing only standard classes. */ public ClassInfoList getStandardClasses() { final Set<ClassInfo> reachableClassesFiltered = new LinkedHashSet<>(size()); final Set<ClassInfo> directlyRelatedClassesFiltered = new LinkedHashSet<>(directlyRelatedClasses.size()); for (final ClassInfo ci : this) { if (ci.isStandardClass()) { reachableClassesFiltered.add(ci); if (directlyRelatedClasses.contains(ci)) { directlyRelatedClassesFiltered.add(ci); } } } return new ClassInfoList(reachableClassesFiltered, directlyRelatedClassesFiltered, sortByName); }
/** * Filter this {@link ClassInfoList} to include only annotations. * * @return The filtered list, containing only annotations. */ public ClassInfoList getAnnotations() { final Set<ClassInfo> reachableClassesFiltered = new LinkedHashSet<>(size()); final Set<ClassInfo> directlyRelatedClassesFiltered = new LinkedHashSet<>(directlyRelatedClasses.size()); for (final ClassInfo ci : this) { if (ci.isAnnotation()) { reachableClassesFiltered.add(ci); if (directlyRelatedClasses.contains(ci)) { directlyRelatedClassesFiltered.add(ci); } } } return new ClassInfoList(reachableClassesFiltered, directlyRelatedClassesFiltered, sortByName); }
/** * 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); } }