findAllInterfaces method

  1. @override
List<Class> findAllInterfaces(
  1. Class parentClass, [
  2. bool declared = true
])
override

Finds all interfaces implemented by the specified class with caching.

Parameters:

  • parentClass: The class to find interfaces for
  • declared: 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

Implementation

@override
List<Class> findAllInterfaces(Class parentClass, [bool declared = true]) {
  _checkClosed();

  final cacheKey = "${_buildCacheKey(parentClass)}:interfaces:$declared";

  // Check cache first
  final cached = _interfaceCache[cacheKey];
  if (cached != null) {
    _hitCount++;
    return List.from(cached);
  }

  _missCount++;

  // Compute classes
  final classes = _computeAllInterfaces(parentClass, declared);
  // Cache result
  _interfaceCache[cacheKey] = classes;

  return List.from(classes.toSet().toList());
}