Skip to content

Commit d07dcfa

Browse files
astashovkeertip
authored andcommitted
Use only canonical elements when resolving unresolved refs in comments (#1329)
If we don't do that, dartdoc will think there's ambiguity if several libs export the same elements (like in Flutter, e.g. `widgets` exports `Flexible` and `material` exports `Flexible`). And we won't get links for these references and will get warnings about ambiguity in stderr. Testing: Generated Flutter docs, made sure `fit` from `Flexible` class resolves correctly and doesn't produce a warning Fixes #1328
1 parent 1661b0e commit d07dcfa

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/src/markdown_processor.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ MatchingLinkResult _findRefElementInLibrary(String codeRef, ModelElement element
139139
final Package package = library.package;
140140
final Map<String, ModelElement> result = {};
141141

142-
for (final modelElement in package.allModelElements) {
142+
for (final modelElement in package.allCanonicalModelElements) {
143143
if (codeRef == modelElement.fullyQualifiedName) {
144144
result[modelElement.fullyQualifiedName] = modelElement;
145145
}
146146
}
147147

148148
// Only look for partially qualified matches if we didn't find a fully qualified one.
149149
if (result.isEmpty) {
150-
for (final modelElement in library.allModelElements) {
150+
for (final modelElement in library.allCanonicalModelElements) {
151151
if (codeRef == modelElement.fullyQualifiedNameWithoutLibrary) {
152152
result[modelElement.fullyQualifiedName] = modelElement;
153153
}

lib/src/model.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ class Library extends ModelElement {
12841284
}
12851285

12861286
List<ModelElement> _allModelElements;
1287-
List<ModelElement> get allModelElements {
1287+
Iterable<ModelElement> get allModelElements {
12881288
if (_allModelElements == null) {
12891289
final List<ModelElement> results = [];
12901290
results
@@ -1308,6 +1308,11 @@ class Library extends ModelElement {
13081308

13091309
return _allModelElements;
13101310
}
1311+
1312+
List<ModelElement> _allCanonicalModelElements;
1313+
Iterable<ModelElement> get allCanonicalModelElements {
1314+
return (_allCanonicalModelElements ??= allModelElements.where((e) => e.isCanonical).toList());
1315+
}
13111316
}
13121317

13131318
class Method extends ModelElement
@@ -2303,7 +2308,7 @@ class Package implements Nameable, Documentable {
23032308
}
23042309

23052310
List<ModelElement> _allModelElements;
2306-
List<ModelElement> get allModelElements {
2311+
Iterable<ModelElement> get allModelElements {
23072312
if (_allModelElements == null) {
23082313
_allModelElements = [];
23092314
this.libraries.forEach((library) {
@@ -2313,6 +2318,11 @@ class Package implements Nameable, Documentable {
23132318
return _allModelElements;
23142319
}
23152320

2321+
List<ModelElement> _allCanonicalModelElements;
2322+
Iterable<ModelElement> get allCanonicalModelElements {
2323+
return (_allCanonicalModelElements ??= allModelElements.where((e) => e.isCanonical).toList());
2324+
}
2325+
23162326
ExportGraph _exportGraph;
23172327
ExportGraph get exportGraph {
23182328
return (_exportGraph ??= new ExportGraph(libraries.map((l) => l.element as LibraryElement)));

0 commit comments

Comments
 (0)