typeRefer function Null safety

Reference typeRefer(
  1. ImportableType type,
  2. [Uri? targetFile,
  3. bool withNullabilitySuffix = true]
)

Implementation

Reference typeRefer(ImportableType type,
    [Uri? targetFile, bool withNullabilitySuffix = true]) {
  final relativeImport = targetFile == null
      ? ImportableTypeResolver.resolveAssetImport(type.import)
      : ImportableTypeResolver.relative(type.import, targetFile);
  return TypeReference((reference) {
    reference
      ..symbol = type.name
      ..url = relativeImport
      ..isNullable = withNullabilitySuffix && type.isNullable;
    if (type.typeArguments.isNotEmpty) {
      reference.types.addAll(
        type.typeArguments.map((e) => typeRefer(e, targetFile)),
      );
    }
  });
}