findConstraints<I> method
Retrieves the constraints applied to a class.
Type Parameters:
I
: The constraint type to match.
Parameters:
parentClass
: The class whose constraints should be found.declared
: Whether to include inherited constraints (default:true
).
Returns:
- A list of Class instances representing the constraints.
Example
final exampleClass = await loader.loadClass<MyClass>('com.example.MyClass');
final constraints = loader.findConstraints<SomeConstraint>(exampleClass);
Implementation
@override
List<Class<I>> findConstraints<I>(Class parentClass, [bool declared = true]) {
_checkClosed();
final clazz = Class<I>();
final cacheKey = "${_buildCacheKey(parentClass)}:${_buildCacheKey(clazz)}:constraints:$declared";
// Check cache first
final cached = _constraintCache[cacheKey];
if (cached != null) {
_hitCount++;
return List.from(cached);
}
_missCount++;
// Compute classes
final classes = _computeConstraints(parentClass, declared, clazz);
// Cache result
_constraintCache[cacheKey] = classes;
return List.from(classes.toSet().toList());
}