allSuperClasses method
A list of AstProxyApis where each extends
the API that follows it.
Returns an empty list if this api does not extend a ProxyApi.
This method assumes the super classes of each ProxyApi doesn't create a loop. Throws a ArgumentError if a loop is found.
This method also assumes that all super classes are ProxyApis. Otherwise, throws an ArgumentError.
Implementation
Iterable<AstProxyApi> allSuperClasses() {
final List<AstProxyApi> superClassChain = <AstProxyApi>[];
if (superClass != null && !superClass!.isProxyApi) {
throw ArgumentError(
'Could not find a ProxyApi for super class: ${superClass!.baseName}',
);
}
AstProxyApi? currentProxyApi = superClass?.associatedProxyApi;
while (currentProxyApi != null) {
if (superClassChain.contains(currentProxyApi)) {
throw ArgumentError(
'Loop found when processing super classes for a ProxyApi: '
'$name, ${superClassChain.map((AstProxyApi api) => api.name)}',
);
}
superClassChain.add(currentProxyApi);
if (currentProxyApi.superClass != null &&
!currentProxyApi.superClass!.isProxyApi) {
throw ArgumentError(
'Could not find a ProxyApi for super class: '
'${currentProxyApi.superClass!.baseName}',
);
}
currentProxyApi = currentProxyApi.superClass?.associatedProxyApi;
}
return superClassChain;
}