findConstraintArguments<I> method

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

Retrieves the type arguments for a specific constraint applied to a class.

Type Parameters:

  • I: The constraint type to match.

Parameters:

  • parentClass: The class whose constraint arguments should be found.
  • declared: Whether to include inherited constraints (default: true).

Returns:

  • A list of Class instances representing the type arguments.

Example

final exampleClass = await loader.loadClass<MyClass>('com.example.MyClass');
final constraintArgs = loader.findConstraintArguments<SomeConstraint>(exampleClass);

Implementation

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

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

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

  _missCount++;

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

  // Cache result
  _constraintArgumentCache[cacheKey] = classes;

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