diff --git a/lib/src/model/model_element.dart b/lib/src/model/model_element.dart index 0b01fa554d..f9577733b8 100644 --- a/lib/src/model/model_element.dart +++ b/lib/src/model/model_element.dart @@ -509,11 +509,15 @@ abstract class ModelElement // This is not accurate if we are still constructing the Package. assert(packageGraph.allLibrariesAdded); - var definingLibraryIsLocalPublic = - packageGraph.localPublicLibraries.contains(library); - var possibleCanonicalLibrary = definingLibraryIsLocalPublic - ? library - : canonicalLibraryCandidate(this); + var isLocalLibrary = packageGraph.localLibraries.contains(library); + if (!isLocalLibrary && !config.linkToRemote) { + return null; + } + + var definingLibraryIsPublic = + packageGraph.publicLibraries.contains(library); + var possibleCanonicalLibrary = + definingLibraryIsPublic ? library : canonicalLibraryCandidate(this); if (possibleCanonicalLibrary != null) return possibleCanonicalLibrary; @@ -831,16 +835,6 @@ extension on Element { } } -// Copied from analyzer's `lib/src/dart/element/extensions.dart`. Re-use that -// extension if it becomes public. -extension on Element { - /// Whether this Element is annotated with a `Deprecated` annotation with a - /// `_DeprecationKind` of [kind]. - bool isDeprecatedWithKind(String kind) => metadata.annotations - .where((e) => e.isDeprecated) - .any((e) => e.deprecationKind == kind); -} - // Copied from analyzer's `lib/src/dart/element/extensions.dart`. Re-use that // extension if it becomes public. extension ElementAnnotationExtension on ElementAnnotation { diff --git a/lib/src/model/package_graph.dart b/lib/src/model/package_graph.dart index c87e5d32d0..8329c9f9c5 100644 --- a/lib/src/model/package_graph.dart +++ b/lib/src/model/package_graph.dart @@ -653,7 +653,7 @@ class PackageGraph with CommentReferable, Nameable { return libraries.wherePublic.toSet(); }(); - late final List _localLibraries = () { + late final List localLibraries = () { assert(allLibrariesAdded); return localPackages.expand((p) => p.libraries).toList(growable: false) ..sort(); @@ -661,7 +661,7 @@ class PackageGraph with CommentReferable, Nameable { late final Set localPublicLibraries = () { assert(allLibrariesAdded); - return _localLibraries.wherePublic.toSet(); + return localLibraries.wherePublic.toSet(); }(); /// The String name representing the `Object` type. diff --git a/test/end2end/model_test.dart b/test/end2end/model_test.dart index bcda54076c..4068e0600b 100644 --- a/test/end2end/model_test.dart +++ b/test/end2end/model_test.dart @@ -1836,7 +1836,7 @@ void main() async { group('Class', () { late final List classes; - late final Class Apple, B, Cat, Dog, F, Dep, SpecialList; + late final Class Apple, B, Cat, Dog, F, Helper, SpecialList; late final Class ExtendingClass, CatString; setUpAll(() { @@ -1846,7 +1846,7 @@ void main() async { Cat = classes.named('Cat'); Dog = classes.named('Dog'); F = classes.named('F'); - Dep = classes.named('Deprecated'); + Helper = classes.named('Helper'); SpecialList = fakeLibrary.classes.named('SpecialList'); ExtendingClass = twoExportsLib.classes.named('ExtendingClass'); CatString = exLibrary.classes.named('CatString'); @@ -1881,7 +1881,7 @@ void main() async { }); test('correctly finds all the classes', () { - expect(classes, hasLength(34)); + expect(classes, hasLength(33)); }); test('abstract', () { @@ -1984,10 +1984,9 @@ void main() async { }); test('exported class should have hrefs from the current library', () { - expect( - Dep.href, equals('${htmlBasePlaceholder}ex/Deprecated-class.html')); - expect(Dep.instanceMethods.named('toString').href, - equals('${htmlBasePlaceholder}ex/Deprecated/toString.html')); + expect(Helper.href, equals('${htmlBasePlaceholder}ex/Helper-class.html')); + expect(Helper.instanceMethods.named('toString').href, + equals('${htmlBasePlaceholder}ex/Helper/toString.html')); }); test('F has a single instance method', () { diff --git a/test/packages_test.dart b/test/packages_test.dart index c6861a8f43..ef15937e50 100644 --- a/test/packages_test.dart +++ b/test/packages_test.dart @@ -263,6 +263,7 @@ library bar; .writeAsStringSync(''' /// Documentation comment. library one; +export 'some_other_lib.dart' show Exported; class One {} '''); @@ -276,6 +277,10 @@ library script; class Script {} '''); + packageOneRoot + .getChildAssumingFolder('lib') + .getChildAssumingFile('some_other_lib.dart') + .writeAsStringSync('''class Exported {}'''); packageTwoRoot = utils.writePackage('two', resourceProvider, packageConfigProvider); @@ -316,6 +321,12 @@ dartdoc: expect(packageOne.documentedWhere, equals(DocumentLocation.remote)); expect(classOne.href, equals('https://mypub.topdomain/one/0.0.1/one/One-class.html')); + // Validate that canonicalization takes place for remote packages. + var exported = libraryOne.classes.named('Exported'); + expect( + exported.href, + equals( + 'https://mypub.topdomain/one/0.0.1/some_other_lib/Exported-class.html')); }); test(