findInterfaces<I> method
Finds all interfaces implemented by the specified class with caching.
{@template class_loader_find_interfaces_as} Parameters:
parentClass
: The class to find interfaces fordeclared
: Whether to include inherited interfaces (default: true)
Returns:
- List of implemented interfaces
- Empty list if no interfaces are implemented
- Cached results for subsequent calls
Interface Resolution
- Transitive (default): Includes interfaces from superclasses and mixins
- Direct only: Only interfaces explicitly declared on this class
Example
final listClass = await loader.loadClass<List>('dart:core/list.dart.List');
final interfaces = await loader.findInterfaces(listClass);
// Returns: [Iterable, Collection, etc.]
// Direct interfaces only
final directInterfaces = await loader.findInterfaces(listClass, false);
Caching Behavior
- Separate caches for transitive and direct interface queries
- Cache keys include the transitive flag for proper segregation
- Automatic cache invalidation on class hierarchy changes {@endtemplate}
Implementation
@override
List<Class<I>> findInterfaces<I>(Class parentClass, [bool declared = true]) {
_checkClosed();
final clazz = Class<I>();
final cacheKey = "${_buildCacheKey(parentClass)}:${_buildCacheKey(clazz)}:interfaces:$declared";
// Check cache first
final cached = _interfaceCache[cacheKey];
if (cached != null) {
_hitCount++;
return List.from(cached);
}
_missCount++;
// Compute classes
final classes = _computeInterfaces(parentClass, declared, clazz);
// Cache result
_interfaceCache[cacheKey] = classes;
return List.from(classes.toSet().toList());
}