Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions lib/src/model/prefix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'package:dartdoc/src/model/model.dart';
/// Like [Parameter], it doesn't have doc pages, but participates in lookups.
/// Forwards to its referenced library if referred to directly.
class Prefix extends ModelElement with HasNoPage {

@override
final PrefixElement2 element;

Expand All @@ -27,15 +26,21 @@ class Prefix extends ModelElement with HasNoPage {
// TODO(jcollins-g): consider connecting PrefixElement to the imported library
// in analyzer?
late final Library associatedLibrary =
getModelForElement(_getImportedLibraryElement()!) as Library;
getModelForElement(_importedLibraryElement) as Library;

LibraryElement2? _getImportedLibraryElement() {
LibraryElement2 get _importedLibraryElement {
final importLists =
library.element.fragments.map((fragment) => fragment.libraryImports2);
return importLists
var libraryImport = importLists
.expand((import) => import)
.firstWhere((i) => i.prefix2?.element == element)
.importedLibrary2;
.firstWhere((i) => i.prefix2?.element == element);
var importedLibrary = libraryImport.importedLibrary2;
if (importedLibrary == null) {
throw StateError(
'Unexpected null LibraryElement2 for imported library at '
'${libraryImport.uri}');
}
return importedLibrary;
}

@override
Expand Down