resolvePrefixes static method
Implementation
static Set<ImportableType> resolvePrefixes(Set<ImportableType> importableTypes) {
var registeredImports = <ImportableType>{};
var importsWithPrefixes = <String?, ImportableType>{};
for (var iType in importableTypes.where((e) => e.import != null)) {
if (registeredImports.any((e) => e.name == iType.name)) {
var prefix = Uri.parse(iType.import!).pathSegments.first;
var prefixesWithSameNameCount = importsWithPrefixes.values.where((e) => e.prefix!.startsWith(prefix)).length;
prefix += (prefixesWithSameNameCount > 0 ? prefixesWithSameNameCount.toString() : '');
importsWithPrefixes[iType.import] = iType.copyWith(prefix: prefix);
registeredImports.add(iType);
} else {
registeredImports.add(iType);
}
}
return importableTypes
.where((e) => e.import != null)
.map((e) =>
importsWithPrefixes[e.import] == null
? e
: e.copyWith(prefix: importsWithPrefixes[e.import]!.prefix))
.toSet();
}