@@ -459,6 +459,10 @@ class _MarkdownCommentReference {
459459 // conflicts are allowed, but an instance field is allowed to have the
460460 // same name as a named constructor.
461461 _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,
462466 // Prefer the Dart analyzer's resolution of comment references. We
463467 // can't start from this because of the differences in Dartdoc
464468 // canonicalization.
@@ -547,6 +551,14 @@ class _MarkdownCommentReference {
547551 }
548552 }
549553
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+
550562 void _findTypeParameters () {
551563 if (element is TypeParameters ) {
552564 results.addAll ((element as TypeParameters ).typeParameters.where ((p) =>
@@ -648,7 +660,7 @@ class _MarkdownCommentReference {
648660 prefixToLibrary[codeRefChompedParts.first]? .forEach ((l) => l
649661 .modelElementsNameMap[lookup]
650662 ? .map (_convertConstructors)
651- ? .forEach ((m) => _addCanonicalResult (m, _getPreferredClass (m) )));
663+ ? .forEach ((m) => _addCanonicalResult (m)));
652664 }
653665 }
654666 }
@@ -660,8 +672,7 @@ class _MarkdownCommentReference {
660672 if (codeRefChomped == modelElement.fullyQualifiedNameWithoutLibrary ||
661673 (modelElement is Library &&
662674 codeRefChomped == modelElement.fullyQualifiedName)) {
663- _addCanonicalResult (
664- _convertConstructors (modelElement), preferredClass);
675+ _addCanonicalResult (_convertConstructors (modelElement));
665676 }
666677 }
667678 }
@@ -671,7 +682,7 @@ class _MarkdownCommentReference {
671682 // Only look for partially qualified matches if we didn't find a fully qualified one.
672683 if (library.modelElementsNameMap.containsKey (codeRefChomped)) {
673684 for (final modelElement in library.modelElementsNameMap[codeRefChomped]) {
674- _addCanonicalResult (_convertConstructors (modelElement), preferredClass );
685+ _addCanonicalResult (_convertConstructors (modelElement));
675686 }
676687 }
677688 }
@@ -684,15 +695,7 @@ class _MarkdownCommentReference {
684695 packageGraph.findRefElementCache.containsKey (codeRefChomped)) {
685696 for (var modelElement
686697 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));
696699 }
697700 }
698701 }
@@ -785,9 +788,8 @@ class _MarkdownCommentReference {
785788 }
786789
787790 // 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);
791793 }
792794
793795 /// _getResultsForClass assumes codeRefChomped might be a member of tryClass (inherited or not)
@@ -804,7 +806,7 @@ class _MarkdownCommentReference {
804806 } else {
805807 // People like to use 'this' in docrefs too.
806808 if (codeRef == 'this' ) {
807- _addCanonicalResult (tryClass, null );
809+ _addCanonicalResult (tryClass);
808810 } else {
809811 // TODO(jcollins-g): get rid of reimplementation of identifier resolution
810812 // or integrate into ModelElement in a simpler way.
@@ -816,7 +818,7 @@ class _MarkdownCommentReference {
816818 // Fortunately superChains are short, but optimize this if it matters.
817819 superChain.addAll (tryClass.superChain.map ((t) => t.element));
818820 for (final c in superChain) {
819- _getResultsForSuperChainElement (c, tryClass );
821+ _getResultsForSuperChainElement (c);
820822 if (results.isNotEmpty) break ;
821823 }
822824 }
@@ -825,20 +827,20 @@ class _MarkdownCommentReference {
825827
826828 /// Get any possible results for this class in the superChain. Returns
827829 /// true if we found something.
828- void _getResultsForSuperChainElement (Class c, Class tryClass ) {
830+ void _getResultsForSuperChainElement (Class c) {
829831 var membersToCheck = (c.allModelElementsByNamePart[codeRefChomped] ?? [])
830832 .map (_convertConstructors);
831833 for (var modelElement in membersToCheck) {
832834 // [thing], a member of this class
833- _addCanonicalResult (modelElement, tryClass );
835+ _addCanonicalResult (modelElement);
834836 }
835837 if (codeRefChompedParts.length < 2 ||
836838 codeRefChompedParts[codeRefChompedParts.length - 2 ] == c.name) {
837839 membersToCheck =
838840 (c.allModelElementsByNamePart[codeRefChompedParts.last] ??
839841 < ModelElement > [])
840842 .map (_convertConstructors);
841- membersToCheck.forEach ((m) => _addCanonicalResult (m, tryClass ));
843+ membersToCheck.forEach ((m) => _addCanonicalResult (m));
842844 }
843845 results.remove (null );
844846 if (results.isNotEmpty) return ;
0 commit comments