getUriFromPackage method

String? getUriFromPackage(
  1. Package package
)

Implementation

String? getUriFromPackage(Package package) {
  switch (package) {
    case DartSdkPackage(:final name):
      return sdk.mapDartUri('dart:$name')?.fullName;
    case ExternalPackage(:final name):
      final parts = name.split('/');
      final package = parts.first;

      final String file;

      if (parts.length == 1) {
        file = '$package.dart';
      } else {
        file = '${parts.skip(1).join('/')}.dart';
      }

      final folder = _packages[package]?.libFolder;

      return folder == null ? null : '$folder/$file';
    case CurrentPackage():
      return '.';
  }
}