findInterfaceArguments<I> method

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

Finds all interface arguments of the specified class with caching.

{@template class_loader_find_interface_arguments_as} Parameters:

  • parentClass: The class to find interface arguments for
  • declared: Whether to include inherited interface arguments (default: true)

Returns:

  • List of interface arguments
  • Empty list if no interface arguments are found
  • Cached results for subsequent calls

Example

final listClass = await loader.loadClass<List>('dart:core/list.dart.List');
final interfaceArgs = await loader.findInterfaceArguments(listClass);
// Returns: [Iterable, Collection, etc.]

// Direct interface arguments only
final directInterfaceArgs = await loader.findInterfaceArguments(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> findInterfaceArguments<I>(Class parentClass, [bool declared = true]) {
  _checkClosed();

  final clazz = Class<I>();
  final cacheKey = "${_buildCacheKey(parentClass)}:${_buildCacheKey(clazz)}:interfaceArguments:$declared";

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

  _missCount++;

  // Compute classes
  final classes = _computeInterfaceArguments(parentClass, declared, clazz);

  // Cache result
  _interfaceArgumentCache[cacheKey] = classes;

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