1010import org .jspecify .annotations .Nullable ;
1111
1212/**
13- * @author JavaSaBr
13+ * Scanner for discovering classes and resources on the classpath.
14+ *
15+ * @since 10.0.0
1416 */
1517public interface ClassPathScanner {
1618
19+ /**
20+ * The JAR file extension.
21+ */
1722 String JAR_EXTENSION = ".jar" ;
23+
24+ /**
25+ * The Java source file extension.
26+ */
1827 String SOURCE_EXTENSION = ".java" ;
28+
29+ /**
30+ * The compiled class file extension.
31+ */
1932 String CLASS_EXTENSION = ".class" ;
2033
34+ /**
35+ * A null scanner constant.
36+ */
2137 @ Nullable ClassPathScanner NULL_SCANNER = null ;
2238
39+ /**
40+ * An empty scanner that performs no operations.
41+ */
2342 ClassPathScanner EMPTY_SCANNER = new ClassPathScannerImpl (ClassPathScanner .class .getClassLoader ()) {
2443
2544 @ Override
@@ -38,55 +57,172 @@ public void addResources(Array<String> resources) {}
3857 public void scan (Predicate <String > filter ) {}
3958 };
4059
60+ /**
61+ * An empty class loader with no URLs.
62+ */
4163 URLClassLoader EMPTY_CLASS_LOADER = new URLClassLoader (new URL [0 ], ClassPathScanner .class .getClassLoader ());
4264
65+ /**
66+ * A null class loader constant.
67+ */
4368 @ Nullable URLClassLoader NULL_CLASS_LOADER = null ;
4469
70+ /**
71+ * Adds discovered classes to the specified collection.
72+ *
73+ * @param classes the collection to add classes to
74+ * @since 10.0.0
75+ */
4576 void addClasses (Array <Class <?>> classes );
4677
78+ /**
79+ * Adds discovered resources to the specified collection.
80+ *
81+ * @param resources the collection to add resources to
82+ * @since 10.0.0
83+ */
4784 void addResources (Array <String > resources );
4885
86+ /**
87+ * Sets whether to include the system classpath in scanning.
88+ *
89+ * @param useSystemClasspath true to include system classpath
90+ * @since 10.0.0
91+ */
4992 void useSystemClassPath (boolean useSystemClasspath );
5093
94+ /**
95+ * Finds all implementations of the specified interface.
96+ *
97+ * @param <T> the type of the interface
98+ * @param interfaceClass the interface class to find implementations for
99+ * @return an array of implementing classes
100+ * @since 10.0.0
101+ */
51102 default <T > Array <Class <T >> findImplementations (Class <T > interfaceClass ) {
52103 MutableArray <Class <T >> result = MutableArray .ofType (Class .class );
53104 findImplementationsTo (result , interfaceClass );
54105 return result ;
55106 }
56107
108+ /**
109+ * Finds all implementations of the specified interface and adds them to the container.
110+ *
111+ * @param <T> the type of the interface
112+ * @param container the container to add implementations to
113+ * @param interfaceClass the interface class to find implementations for
114+ * @since 10.0.0
115+ */
57116 <T > void findImplementationsTo (MutableArray <Class <T >> container , Class <T > interfaceClass );
58117
118+ /**
119+ * Finds all classes that inherit from the specified parent class.
120+ *
121+ * @param <T> the type of the parent class
122+ * @param parentClass the parent class to find subclasses for
123+ * @return an array of subclasses
124+ * @since 10.0.0
125+ */
59126 default <T > Array <Class <T >> findInherited (Class <T > parentClass ) {
60127 MutableArray <Class <T >> result = MutableArray .ofType (Class .class );
61128 findInheritedTo (result , parentClass );
62129 return result ;
63130 }
64131
132+ /**
133+ * Finds all classes that inherit from the specified parent class and adds them to the container.
134+ *
135+ * @param <T> the type of the parent class
136+ * @param container the container to add subclasses to
137+ * @param parentClass the parent class to find subclasses for
138+ * @since 10.0.0
139+ */
65140 <T > void findInheritedTo (MutableArray <Class <T >> container , Class <T > parentClass );
66141
142+ /**
143+ * Finds all classes annotated with the specified annotation.
144+ *
145+ * @param annotationClass the annotation class to search for
146+ * @return an array of annotated classes
147+ * @since 10.0.0
148+ */
67149 default Array <Class <?>> findAnnotated (Class <? extends Annotation > annotationClass ) {
68150 MutableArray <Class <?>> result = MutableArray .ofType (Class .class );
69151 findAnnotatedTo (result , annotationClass );
70152 return result ;
71153 }
72154
155+ /**
156+ * Finds all classes annotated with the specified annotation and adds them to the container.
157+ *
158+ * @param container the container to add annotated classes to
159+ * @param annotationClass the annotation class to search for
160+ * @since 10.0.0
161+ */
73162 void findAnnotatedTo (MutableArray <Class <?>> container , Class <? extends Annotation > annotationClass );
74163
164+ /**
165+ * Adds all found classes to the specified container.
166+ *
167+ * @param container the container to add classes to
168+ * @since 10.0.0
169+ */
75170 void foundClassesTo (MutableArray <Class <?>> container );
76171
172+ /**
173+ * Adds all found resources to the specified container.
174+ *
175+ * @param container the container to add resources to
176+ * @since 10.0.0
177+ */
77178 void foundResourcesTo (MutableArray <String > container );
78179
180+ /**
181+ * Returns all classes found during scanning.
182+ *
183+ * @return an array of found classes
184+ * @since 10.0.0
185+ */
79186 Array <Class <?>> foundClasses ();
80187
188+ /**
189+ * Returns all resources found during scanning.
190+ *
191+ * @return an array of found resource paths
192+ * @since 10.0.0
193+ */
81194 Array <String > foundResources ();
82195
196+ /**
197+ * Scans the classpath without any filter.
198+ *
199+ * @since 10.0.0
200+ */
83201 default void scan () {
84202 scan (null );
85203 }
86204
205+ /**
206+ * Scans the classpath with the specified filter.
207+ *
208+ * @param filter the filter to apply during scanning, or null for no filter
209+ * @since 10.0.0
210+ */
87211 void scan (@ Nullable Predicate <String > filter );
88212
213+ /**
214+ * Adds an additional path to scan.
215+ *
216+ * @param path the path to add
217+ * @since 10.0.0
218+ */
89219 void addAdditionalPath (String path );
90220
221+ /**
222+ * Adds additional paths to scan.
223+ *
224+ * @param paths the paths to add
225+ * @since 10.0.0
226+ */
91227 void addAdditionalPaths (String [] paths );
92228}
0 commit comments