@@ -459,6 +459,10 @@ class _MarkdownCommentReference {
459
459
// conflicts are allowed, but an instance field is allowed to have the
460
460
// same name as a named constructor.
461
461
_reducePreferConstructorViaIndicators,
462
+ // Prefer Fields/TopLevelVariables to accessors.
463
+ // TODO(jcollins-g): Remove after fixing dart-lang/dartdoc#2396 or
464
+ // exclude Accessors from all lookup tables.
465
+ _reducePreferCombos,
462
466
// Prefer the Dart analyzer's resolution of comment references. We
463
467
// can't start from this because of the differences in Dartdoc
464
468
// canonicalization.
@@ -547,6 +551,14 @@ class _MarkdownCommentReference {
547
551
}
548
552
}
549
553
554
+ void _reducePreferCombos () {
555
+ var accessors = results.whereType <Accessor >().toList ();
556
+ accessors.forEach ((a) {
557
+ results.remove (a);
558
+ results.add (a.enclosingCombo);
559
+ });
560
+ }
561
+
550
562
void _findTypeParameters () {
551
563
if (element is TypeParameters ) {
552
564
results.addAll ((element as TypeParameters ).typeParameters.where ((p) =>
@@ -648,7 +660,7 @@ class _MarkdownCommentReference {
648
660
prefixToLibrary[codeRefChompedParts.first]? .forEach ((l) => l
649
661
.modelElementsNameMap[lookup]
650
662
? .map (_convertConstructors)
651
- ? .forEach ((m) => _addCanonicalResult (m, _getPreferredClass (m) )));
663
+ ? .forEach ((m) => _addCanonicalResult (m)));
652
664
}
653
665
}
654
666
}
@@ -660,8 +672,7 @@ class _MarkdownCommentReference {
660
672
if (codeRefChomped == modelElement.fullyQualifiedNameWithoutLibrary ||
661
673
(modelElement is Library &&
662
674
codeRefChomped == modelElement.fullyQualifiedName)) {
663
- _addCanonicalResult (
664
- _convertConstructors (modelElement), preferredClass);
675
+ _addCanonicalResult (_convertConstructors (modelElement));
665
676
}
666
677
}
667
678
}
@@ -671,7 +682,7 @@ class _MarkdownCommentReference {
671
682
// Only look for partially qualified matches if we didn't find a fully qualified one.
672
683
if (library.modelElementsNameMap.containsKey (codeRefChomped)) {
673
684
for (final modelElement in library.modelElementsNameMap[codeRefChomped]) {
674
- _addCanonicalResult (_convertConstructors (modelElement), preferredClass );
685
+ _addCanonicalResult (_convertConstructors (modelElement));
675
686
}
676
687
}
677
688
}
@@ -684,15 +695,7 @@ class _MarkdownCommentReference {
684
695
packageGraph.findRefElementCache.containsKey (codeRefChomped)) {
685
696
for (var modelElement
686
697
in packageGraph.findRefElementCache[codeRefChomped]) {
687
- // For fully qualified matches, the original preferredClass passed
688
- // might make no sense. Instead, use the enclosing class from the
689
- // element in [packageGraph.findRefElementCache], because that element's
690
- // enclosing class will be preferred from [codeRefChomped]'s perspective.
691
- _addCanonicalResult (
692
- _convertConstructors (modelElement),
693
- modelElement.enclosingElement is Class
694
- ? modelElement.enclosingElement
695
- : null );
698
+ _addCanonicalResult (_convertConstructors (modelElement));
696
699
}
697
700
}
698
701
}
@@ -785,9 +788,8 @@ class _MarkdownCommentReference {
785
788
}
786
789
787
790
// Add a result, but make it canonical.
788
- void _addCanonicalResult (ModelElement modelElement, Container tryClass) {
789
- results.add (packageGraph.findCanonicalModelElementFor (modelElement.element,
790
- preferredClass: tryClass));
791
+ void _addCanonicalResult (ModelElement modelElement) {
792
+ results.add (modelElement.canonicalModelElement);
791
793
}
792
794
793
795
/// _getResultsForClass assumes codeRefChomped might be a member of tryClass (inherited or not)
@@ -804,7 +806,7 @@ class _MarkdownCommentReference {
804
806
} else {
805
807
// People like to use 'this' in docrefs too.
806
808
if (codeRef == 'this' ) {
807
- _addCanonicalResult (tryClass, null );
809
+ _addCanonicalResult (tryClass);
808
810
} else {
809
811
// TODO(jcollins-g): get rid of reimplementation of identifier resolution
810
812
// or integrate into ModelElement in a simpler way.
@@ -816,7 +818,7 @@ class _MarkdownCommentReference {
816
818
// Fortunately superChains are short, but optimize this if it matters.
817
819
superChain.addAll (tryClass.superChain.map ((t) => t.element));
818
820
for (final c in superChain) {
819
- _getResultsForSuperChainElement (c, tryClass );
821
+ _getResultsForSuperChainElement (c);
820
822
if (results.isNotEmpty) break ;
821
823
}
822
824
}
@@ -825,20 +827,20 @@ class _MarkdownCommentReference {
825
827
826
828
/// Get any possible results for this class in the superChain. Returns
827
829
/// true if we found something.
828
- void _getResultsForSuperChainElement (Class c, Class tryClass ) {
830
+ void _getResultsForSuperChainElement (Class c) {
829
831
var membersToCheck = (c.allModelElementsByNamePart[codeRefChomped] ?? [])
830
832
.map (_convertConstructors);
831
833
for (var modelElement in membersToCheck) {
832
834
// [thing], a member of this class
833
- _addCanonicalResult (modelElement, tryClass );
835
+ _addCanonicalResult (modelElement);
834
836
}
835
837
if (codeRefChompedParts.length < 2 ||
836
838
codeRefChompedParts[codeRefChompedParts.length - 2 ] == c.name) {
837
839
membersToCheck =
838
840
(c.allModelElementsByNamePart[codeRefChompedParts.last] ??
839
841
< ModelElement > [])
840
842
.map (_convertConstructors);
841
- membersToCheck.forEach ((m) => _addCanonicalResult (m, tryClass ));
843
+ membersToCheck.forEach ((m) => _addCanonicalResult (m));
842
844
}
843
845
results.remove (null );
844
846
if (results.isNotEmpty) return ;
0 commit comments