getSymbolForPackage method

Future<List<Type>> getSymbolForPackage({
  1. required Package package,
})

Implementation

Future<List<Type>> getSymbolForPackage({required Package package}) async {
  final uri = _getUriFromPackage(package);

  if (uri == null) {
    throw _SymbolResolvingException(package);
  }

  final library = await analysisContextCollection.contexts.first.currentSession.getResolvedLibrary(uri);

  if (library is ResolvedLibraryResult) {
    return [
      for (var element in library.element.exportNamespace.definedNames.values)
        if (element is InterfaceElement)
          if (element.typeParameters case List(isEmpty: false) && final typeParameters)
            PolymorphicType(
              name: element.name,
              source: package,
              arguments: [
                for (final typeParameter in typeParameters) //
                  TypeParameterType(name: typeParameter.name),
              ],
            )
          else
            MonomorphicType(
              name: element.name,
              source: package,
            ),
    ];
  } else {
    throw _SymbolResolvingException(package);
  }
}