findLibrary method

  1. @override
LibraryMirror findLibrary(
  1. String libraryName
)
inherited

Returns a mirror of the given library library.

Implementation

@override
LibraryMirror findLibrary(String libraryName) {
  ReflectorData reflectorData = data[this]!;
  if (reflectorData.libraryMirrors == null) {
    throw NoSuchCapabilityError('Using `findLibrary` without capability. '
        'Try adding `libraryCapability`.');
  }
  // The specification says that an exception shall be thrown if there
  // is anything other than one library with a matching name.
  int matchCount = 0;
  LibraryMirror? matchingLibrary;
  for (LibraryMirror libraryMirror in reflectorData.libraryMirrors!) {
    if (libraryMirror.qualifiedName == libraryName) {
      matchCount++;
      matchingLibrary = libraryMirror;
    }
  }
  switch (matchCount) {
    case 0:
      throw ArgumentError('No such library: $libraryName');
    case 1:
      return matchingLibrary!;
    default:
      throw ArgumentError('Ambiguous library name: $libraryName');
  }
}