Skip to content

Commit 422a1ae

Browse files
committed
Merge branch 'main' into fix-wildcards
2 parents 10700c7 + 4a6062e commit 422a1ae

15 files changed

+109
-35
lines changed

lib/resources/docs.dart.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/model/canonicalization.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ final class Canonicalization {
7474
scoredCandidate._alterScore(1.0, _Reason.packageName);
7575
}
7676

77+
// Same idea as the above, for the Dart SDK.
78+
if (library.name == 'dart:core') {
79+
scoredCandidate._alterScore(0.9, _Reason.packageName);
80+
}
81+
7782
// Give a tiny boost for libraries with long names, assuming they're
7883
// more specific (and therefore more likely to be the owner of this symbol).
7984
scoredCandidate._alterScore(

lib/src/model/container.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ abstract class Container extends ModelElement
238238
String get sidebarPath;
239239

240240
@override
241-
String get aboveSidebarPath => library.sidebarPath;
241+
String get aboveSidebarPath => canonicalLibraryOrThrow.sidebarPath;
242242

243243
@override
244244
String get belowSidebarPath => sidebarPath;

lib/src/model/model_element.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,22 @@ abstract class ModelElement
394394
!(enclosingElement as Extension).isPublic) {
395395
return false;
396396
}
397+
398+
if (element case LibraryElement(:var identifier, :var source)) {
399+
// Private Dart SDK libraries are not public.
400+
if (identifier.startsWith('dart:_') ||
401+
identifier.startsWith('dart:nativewrappers/') ||
402+
'dart:nativewrappers' == identifier) {
403+
return false;
404+
}
405+
// Package-private libraries are not public.
406+
var elementUri = source.uri;
407+
if (elementUri.scheme == 'package' &&
408+
elementUri.pathSegments[1] == 'src') {
409+
return false;
410+
}
411+
}
412+
397413
return !element.hasPrivateName && !hasNodoc;
398414
}();
399415

@@ -518,6 +534,7 @@ abstract class ModelElement
518534
final candidateLibraries = thisAndExported.where((l) {
519535
if (!l.isPublic) return false;
520536
if (l.package.documentedWhere == DocumentLocation.missing) return false;
537+
if (this is Library) return true;
521538
var lookup = l.element.exportNamespace.definedNames[topLevelElementName];
522539
return topLevelElement ==
523540
(lookup is PropertyAccessorElement ? lookup.variable2 : lookup);

lib/src/model/model_function.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ModelFunctionTyped extends ModelElement with TypeParameters {
5151
String get filePath => '${canonicalLibrary?.dirName}/$fileName';
5252

5353
@override
54-
String get aboveSidebarPath => enclosingElement.sidebarPath;
54+
String get aboveSidebarPath => canonicalLibraryOrThrow.sidebarPath;
5555

5656
@override
5757
String? get belowSidebarPath => null;

lib/src/model/package_graph.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class PackageGraph with CommentReferable, Nameable {
195195
// that might not _have_ a canonical [ModelElement], too.
196196
if (element.isCanonical ||
197197
element.canonicalModelElement == null ||
198+
element is Library ||
198199
element.enclosingElement!.isCanonical) {
199200
for (var d in element.documentationFrom
200201
.where((d) => d.hasDocumentationComment)) {
@@ -771,6 +772,8 @@ class PackageGraph with CommentReferable, Nameable {
771772
if (canonicalClass != null) preferredClass = canonicalClass;
772773
}
773774
var lib = modelElement.canonicalLibrary;
775+
if (modelElement is Library) return lib;
776+
774777
if (lib == null && preferredClass != null) {
775778
lib = preferredClass.canonicalLibrary;
776779
}

lib/src/model/top_level_variable.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class TopLevelVariable extends ModelElement
4545
String get filePath => '${canonicalLibraryOrThrow.dirName}/$fileName';
4646

4747
@override
48-
String get aboveSidebarPath => enclosingElement.sidebarPath;
48+
String get aboveSidebarPath => canonicalLibraryOrThrow.sidebarPath;
4949

5050
@override
5151
String? get belowSidebarPath => null;

lib/src/model/typedef.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ abstract class Typedef extends ModelElement
3535
String get filePath => '${canonicalLibraryOrThrow.dirName}/$fileName';
3636

3737
@override
38-
String get aboveSidebarPath => enclosingElement.sidebarPath;
38+
String get aboveSidebarPath => canonicalLibraryOrThrow.sidebarPath;
3939

4040
@override
4141
String? get belowSidebarPath => null;

lib/src/model_utils.dart

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,6 @@ extension ElementExtension on Element {
7272
return true;
7373
}
7474
}
75-
if (self is LibraryElement) {
76-
if (self.identifier.startsWith('dart:_') ||
77-
self.identifier.startsWith('dart:nativewrappers/') ||
78-
'dart:nativewrappers' == self.identifier) {
79-
return true;
80-
}
81-
var elementUri = self.source.uri;
82-
// TODO(jcollins-g): Implement real cross package detection.
83-
if (elementUri.scheme == 'package' &&
84-
elementUri.pathSegments[1] == 'src') {
85-
return true;
86-
}
87-
}
8875
return false;
8976
}
9077
}

lib/src/search.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ class IndexItem {
130130
EnclosedBy? enclosedBy;
131131
if (data['enclosedBy'] != null) {
132132
final map = data['enclosedBy'] as Map<String, dynamic>;
133+
assert(
134+
map['href'] != null,
135+
"'enclosedBy' element expected to have a non-null 'href', "
136+
"but was null: '${data['qualifiedName']}', "
137+
"enclosed by the ${Kind.values[map['kind'] as int]} '${map['name']}' "
138+
"('${map['qualifiedName']}')",
139+
);
133140
enclosedBy = EnclosedBy._(
134141
name: map['name'] as String,
135142
kind: Kind.values[map['kind'] as int],

0 commit comments

Comments
 (0)