Skip to content

Commit dfb6217

Browse files
CopilotCopilot
andcommitted
Add JavaDoc comments to TypeFinder non-private methods and constructor
Add comprehensive JavaDoc documentation with Example Usage sections to all 12 non-private methods and the public constructor in TypeFinder.java that were missing documentation. Each JavaDoc includes parameter descriptions, return value descriptions, concrete examples using Java class hierarchy navigation (ArrayList, HashMap, LinkedList, etc.), and @SInCE tags. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d5606b7 commit dfb6217

1 file changed

Lines changed: 209 additions & 0 deletions

File tree

microsphere-java-core/src/main/java/io/microsphere/util/TypeFinder.java

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,31 @@ public static enum Include {
112112

113113
private final Function<T, ? super T[]> getInterfacesFunction;
114114

115+
/**
116+
* Constructs a new {@code TypeFinder} with the specified type and configuration options.
117+
*
118+
* <h3>Example Usage</h3>
119+
* <pre>{@code
120+
* TypeFinder<Class<?>> finder = new TypeFinder<>(
121+
* ArrayList.class,
122+
* (Function) Class::getSuperclass,
123+
* (Function) Class::getInterfaces,
124+
* true, // includeSelf
125+
* true, // includeHierarchicalTypes
126+
* true, // includeSuperclass
127+
* true // includeInterfaces
128+
* );
129+
* }</pre>
130+
*
131+
* @param type the root type to find related types from
132+
* @param getSuperClassFunction a function to retrieve the superclass of a given type
133+
* @param getInterfacesFunction a function to retrieve the interfaces of a given type
134+
* @param includeSelf whether to include the type itself in the results
135+
* @param includeHierarchicalTypes whether to recursively include types from the hierarchy
136+
* @param includeSuperclass whether to include the direct superclass
137+
* @param includeInterfaces whether to include the directly implemented interfaces
138+
* @since 1.0.0
139+
*/
115140
public TypeFinder(T type, Function<T, T> getSuperClassFunction,
116141
Function<T, T[]> getInterfacesFunction, boolean includeSelf,
117142
boolean includeHierarchicalTypes, boolean includeSuperclass, boolean includeInterfaces) {
@@ -127,19 +152,61 @@ public TypeFinder(T type, Function<T, T> getSuperClassFunction,
127152
this.includeInterfaces = includeInterfaces;
128153
}
129154

155+
/**
156+
* Returns all related types based on the configuration of this {@code TypeFinder},
157+
* without applying any filters.
158+
*
159+
* <h3>Example Usage</h3>
160+
* <pre>{@code
161+
* TypeFinder<Class<?>> finder = TypeFinder.classFinder(ArrayList.class, TypeFinder.Include.HIERARCHICAL);
162+
* List<Class<?>> types = finder.getTypes();
163+
* // types contains AbstractList, AbstractCollection, Object, List, Collection, Iterable, ...
164+
* }</pre>
165+
*
166+
* @return an immutable list of related types, or an empty list if none are found
167+
* @since 1.0.0
168+
*/
130169
@Nonnull
131170
@Immutable
132171
public List<T> getTypes() {
133172
return findTypes(EMPTY_PREDICATE_ARRAY);
134173
}
135174

175+
/**
176+
* Finds related types that match all the specified filters.
177+
*
178+
* <h3>Example Usage</h3>
179+
* <pre>{@code
180+
* TypeFinder<Class<?>> finder = TypeFinder.classFinder(HashMap.class, TypeFinder.Include.HIERARCHICAL);
181+
* List<Class<?>> interfaces = finder.findTypes(Class::isInterface);
182+
* // interfaces contains Map, Cloneable, Serializable, ...
183+
* }</pre>
184+
*
185+
* @param typeFilters zero or more predicates to filter the found types; all predicates must match
186+
* @return an immutable list of matching types, or an empty list if none match
187+
* @since 1.0.0
188+
*/
136189
@Nonnull
137190
@Immutable
138191
public List<T> findTypes(Predicate<? super T>... typeFilters) {
139192
List<T> types = doFindTypes(typeFilters);
140193
return types.isEmpty() ? emptyList() : unmodifiableList(types);
141194
}
142195

196+
/**
197+
* Performs the actual type finding logic by collecting related types and applying filters.
198+
*
199+
* <h3>Example Usage</h3>
200+
* <pre>{@code
201+
* // Typically invoked internally by findTypes:
202+
* TypeFinder<Class<?>> finder = TypeFinder.classFinder(LinkedList.class, TypeFinder.Include.HIERARCHICAL);
203+
* List<Class<?>> types = finder.findTypes(t -> t != Object.class);
204+
* }</pre>
205+
*
206+
* @param typeFilters an array of predicates to filter the found types
207+
* @return a mutable list of types matching the filters
208+
* @since 1.0.0
209+
*/
143210
protected List<T> doFindTypes(Predicate<? super T>[] typeFilters) {
144211

145212
List<T> allTypes = newLinkedList();
@@ -160,6 +227,23 @@ protected List<T> doFindTypes(Predicate<? super T>[] typeFilters) {
160227
return allTypes;
161228
}
162229

230+
/**
231+
* Retrieves the direct super types (superclass and/or interfaces) of the given type.
232+
*
233+
* <h3>Example Usage</h3>
234+
* <pre>{@code
235+
* TypeFinder<Class<?>> finder = TypeFinder.classFinder(ArrayList.class, TypeFinder.Include.HIERARCHICAL);
236+
* // Internally called as:
237+
* // getSuperTypes(ArrayList.class, true, true)
238+
* // returns [AbstractList, List, RandomAccess, Cloneable, Serializable]
239+
* }</pre>
240+
*
241+
* @param type the type whose super types are to be retrieved
242+
* @param includeSuperclass whether to include the direct superclass
243+
* @param includedGenericInterfaces whether to include the directly implemented interfaces
244+
* @return a list of direct super types, or an empty list if none are found
245+
* @since 1.0.0
246+
*/
163247
protected List<T> getSuperTypes(T type, boolean includeSuperclass, boolean includedGenericInterfaces) {
164248

165249
T superclass = includeSuperclass && type != null ? getSuperClass(type) : null;
@@ -192,14 +276,57 @@ protected List<T> getSuperTypes(T type, boolean includeSuperclass, boolean inclu
192276
return types;
193277
}
194278

279+
/**
280+
* Returns the superclass of the given type using the configured function.
281+
*
282+
* <h3>Example Usage</h3>
283+
* <pre>{@code
284+
* TypeFinder<Class<?>> finder = TypeFinder.classFinder(HashMap.class, TypeFinder.Include.SUPER_CLASS);
285+
* // Internally: getSuperClass(HashMap.class) returns AbstractMap.class
286+
* }</pre>
287+
*
288+
* @param type the type whose superclass is to be retrieved
289+
* @return the superclass of the given type, or {@code null} if none exists
290+
* @since 1.0.0
291+
*/
195292
protected T getSuperClass(T type) {
196293
return (T) getSuperClassFunction.apply(type);
197294
}
198295

296+
/**
297+
* Returns the interfaces directly implemented by the given type using the configured function.
298+
*
299+
* <h3>Example Usage</h3>
300+
* <pre>{@code
301+
* TypeFinder<Class<?>> finder = TypeFinder.classFinder(ArrayList.class, TypeFinder.Include.INTERFACES);
302+
* // Internally: getInterfaces(ArrayList.class) returns [List, RandomAccess, Cloneable, Serializable]
303+
* }</pre>
304+
*
305+
* @param type the type whose interfaces are to be retrieved
306+
* @return an array of interfaces implemented by the given type
307+
* @since 1.0.0
308+
*/
199309
protected T[] getInterfaces(T type) {
200310
return (T[]) getInterfacesFunction.apply(type);
201311
}
202312

313+
/**
314+
* Recursively adds the super types of the given type to the accumulated list.
315+
*
316+
* <h3>Example Usage</h3>
317+
* <pre>{@code
318+
* TypeFinder<Class<?>> finder = TypeFinder.classFinder(LinkedList.class, TypeFinder.Include.HIERARCHICAL);
319+
* // Internally, addSuperTypes is called recursively to collect:
320+
* // AbstractSequentialList, AbstractList, AbstractCollection, Object, List, Deque, Queue, ...
321+
* }</pre>
322+
*
323+
* @param allTypes the accumulated list of types to add to
324+
* @param type the current type whose super types are being added
325+
* @param includeHierarchicalTypes whether to recursively traverse the type hierarchy
326+
* @param includeSuperclass whether to include superclasses
327+
* @param includeInterfaces whether to include interfaces
328+
* @since 1.0.0
329+
*/
203330
protected void addSuperTypes(List<T> allTypes, T type, boolean includeHierarchicalTypes, boolean includeSuperclass, boolean includeInterfaces) {
204331
if (isObjectType(type)) {
205332
return;
@@ -245,26 +372,108 @@ protected void addSuperTypes(List<T> allTypes, T type, boolean includeHierarchic
245372
return klass == null ? null : klass.getGenericInterfaces();
246373
};
247374

375+
/**
376+
* Creates a {@code TypeFinder} for {@link Class} types using the specified include options.
377+
*
378+
* <h3>Example Usage</h3>
379+
* <pre>{@code
380+
* TypeFinder<Class<?>> finder = TypeFinder.classFinder(ArrayList.class,
381+
* TypeFinder.Include.SELF, TypeFinder.Include.INTERFACES);
382+
* List<Class<?>> types = finder.getTypes();
383+
* // types contains ArrayList plus its directly implemented interfaces
384+
* }</pre>
385+
*
386+
* @param type the class to find related types from
387+
* @param includes one or more {@link Include} options specifying which types to include
388+
* @return a new {@code TypeFinder} configured for the given class and options
389+
* @since 1.0.0
390+
*/
248391
public static TypeFinder<Class<?>> classFinder(Class type, TypeFinder.Include... includes) {
249392
assertNotEmpty(includes, () -> "The 'includes' must not be empty");
250393
assertNoNullElements(includes, () -> "The 'includes' must not contain null element");
251394
return classFinder(type, contains(includes, SELF), contains(includes, HIERARCHICAL),
252395
contains(includes, SUPER_CLASS), contains(includes, INTERFACES));
253396
}
254397

398+
/**
399+
* Creates a {@code TypeFinder} for {@link Class} types with explicit boolean configuration.
400+
*
401+
* <h3>Example Usage</h3>
402+
* <pre>{@code
403+
* TypeFinder<Class<?>> finder = TypeFinder.classFinder(HashMap.class,
404+
* true, // includeSelf
405+
* true, // includeHierarchicalTypes
406+
* true, // includeSuperclass
407+
* false // includeInterfaces
408+
* );
409+
* List<Class<?>> types = finder.getTypes();
410+
* // types contains HashMap, AbstractMap, Object
411+
* }</pre>
412+
*
413+
* @param type the class to find related types from
414+
* @param includeSelf whether to include the class itself
415+
* @param includeHierarchicalTypes whether to recursively include types from the hierarchy
416+
* @param includeSuperclass whether to include superclasses
417+
* @param includeInterfaces whether to include interfaces
418+
* @return a new {@code TypeFinder} configured for the given class and options
419+
* @since 1.0.0
420+
*/
255421
public static TypeFinder<Class<?>> classFinder(Class type, boolean includeSelf, boolean includeHierarchicalTypes,
256422
boolean includeSuperclass, boolean includeInterfaces) {
257423
return new TypeFinder(type, classGetSuperClassFunction, classGetInterfacesFunction, includeSelf,
258424
includeHierarchicalTypes, includeSuperclass, includeInterfaces);
259425
}
260426

427+
/**
428+
* Creates a {@code TypeFinder} for generic {@link Type} instances using the specified include options.
429+
* Unlike {@link #classFinder(Class, Include...)}, this method resolves generic superclass and
430+
* generic interface types.
431+
*
432+
* <h3>Example Usage</h3>
433+
* <pre>{@code
434+
* TypeFinder<Type> finder = TypeFinder.genericTypeFinder(ArrayList.class,
435+
* TypeFinder.Include.SELF, TypeFinder.Include.HIERARCHICAL);
436+
* List<Type> types = finder.getTypes();
437+
* // types contains generic types such as AbstractList<E>, List<E>, Collection<E>, Iterable<E>, ...
438+
* }</pre>
439+
*
440+
* @param type the type to find related generic types from
441+
* @param includes one or more {@link Include} options specifying which types to include
442+
* @return a new {@code TypeFinder} configured for the given generic type and options
443+
* @since 1.0.0
444+
*/
261445
public static TypeFinder<Type> genericTypeFinder(Type type, TypeFinder.Include... includes) {
262446
assertNotEmpty(includes, () -> "The 'includes' must not be empty");
263447
assertNoNullElements(includes, () -> "The 'includes' must not contain null element");
264448
return genericTypeFinder(type, contains(includes, SELF), contains(includes, HIERARCHICAL),
265449
contains(includes, SUPER_CLASS), contains(includes, INTERFACES));
266450
}
267451

452+
/**
453+
* Creates a {@code TypeFinder} for generic {@link Type} instances with explicit boolean configuration.
454+
* Unlike {@link #classFinder(Class, boolean, boolean, boolean, boolean)}, this method resolves
455+
* generic superclass and generic interface types.
456+
*
457+
* <h3>Example Usage</h3>
458+
* <pre>{@code
459+
* TypeFinder<Type> finder = TypeFinder.genericTypeFinder(HashMap.class,
460+
* true, // includeSelf
461+
* false, // includeHierarchicalTypes
462+
* true, // includeSuperclass
463+
* true // includeInterfaces
464+
* );
465+
* List<Type> types = finder.getTypes();
466+
* // types contains HashMap, AbstractMap<K,V>, Map<K,V>, Cloneable, Serializable
467+
* }</pre>
468+
*
469+
* @param type the type to find related generic types from
470+
* @param includeSelf whether to include the type itself
471+
* @param includeHierarchicalTypes whether to recursively include types from the hierarchy
472+
* @param includeSuperclass whether to include superclasses
473+
* @param includeInterfaces whether to include interfaces
474+
* @return a new {@code TypeFinder} configured for the given generic type and options
475+
* @since 1.0.0
476+
*/
268477
public static TypeFinder<Type> genericTypeFinder(Type type, boolean includeSelf, boolean includeHierarchicalTypes,
269478
boolean includeSuperclass, boolean includeInterfaces) {
270479
return new TypeFinder(type, genericTypeGetSuperClassFunction, genericTypeGetInterfacesFunction, includeSelf,

0 commit comments

Comments
 (0)