findSuperClassArguments method
Finds the type arguments of the superclass of a given parentClass
.
Parameters:
parentClass
: The class whose superclass should be located.declared
: Iftrue
(default), returns the directly declared superclass.
Iffalse
, searches up the hierarchy.
Returns:
- A list of Class instances representing the type arguments of the superclass.
Example
final listClass = await loader.loadClass<List>('dart:core/list.dart.List');
final superIterableArgs = loader.findSuperClassArguments(listClass);
print(superIterableArgs.map((arg) => arg.qualifiedName)); // e.g., ["dart:core/iterable.dart.Iterable"]
Implementation
@override
List<Class> findSuperClassArguments(Class parentClass, [bool declared = true]) {
_checkClosed();
final cacheKey = "${_buildCacheKey(parentClass)}:superClassArguments:$declared";
// Check cache first
final cached = _superClassArgumentCache[cacheKey];
if (cached != null) {
_hitCount++;
return List.from(cached);
}
_missCount++;
final superType = parentClass.getTypeDeclaration().asClass()?.getSuperClass();
if(superType == null) return [];
final result = superType.getTypeArguments().map((t) => _getFromLink(t, parentClass.getProtectionDomain(), useType: declared)).toList();
// Cache result
_superClassArgumentCache[cacheKey] = result;
return List.from(result.toSet().toList());
}