@@ -15,6 +15,7 @@ import 'package:dartdoc/src/tuple.dart';
15
15
import 'package:dartdoc/src/warnings.dart' ;
16
16
import 'package:html/parser.dart' show parse;
17
17
import 'package:markdown/markdown.dart' as md;
18
+ import 'package:quiver/iterables.dart' as quiverIterables;
18
19
19
20
const validHtmlTags = const [
20
21
"a" ,
@@ -547,8 +548,7 @@ class _MarkdownCommentReference {
547
548
if (codeRefChomped == modelElement.fullyQualifiedNameWithoutLibrary ||
548
549
(modelElement is Library &&
549
550
codeRefChomped == modelElement.fullyQualifiedName)) {
550
- results.add (
551
- packageGraph.findCanonicalModelElementFor (modelElement.element));
551
+ _addCanonicalResult (modelElement, null );
552
552
}
553
553
}
554
554
}
@@ -559,9 +559,7 @@ class _MarkdownCommentReference {
559
559
if (library.modelElementsNameMap.containsKey (codeRefChomped)) {
560
560
for (final modelElement in library.modelElementsNameMap[codeRefChomped]) {
561
561
if (! _ConsiderIfConstructor (modelElement)) continue ;
562
- results.add (packageGraph.findCanonicalModelElementFor (
563
- modelElement.element,
564
- preferredClass: preferredClass));
562
+ _addCanonicalResult (modelElement, preferredClass);
565
563
}
566
564
}
567
565
}
@@ -579,11 +577,11 @@ class _MarkdownCommentReference {
579
577
// might make no sense. Instead, use the enclosing class from the
580
578
// element in [packageGraph.findRefElementCache], because that element's
581
579
// enclosing class will be preferred from [codeRefChomped]'s perspective.
582
- results. add (packageGraph. findCanonicalModelElementFor (
583
- modelElement.element ,
584
- preferredClass : modelElement.enclosingElement is Class
580
+ _addCanonicalResult (
581
+ modelElement,
582
+ modelElement.enclosingElement is Class
585
583
? modelElement.enclosingElement
586
- : null )) ;
584
+ : null );
587
585
}
588
586
}
589
587
}
@@ -639,6 +637,12 @@ class _MarkdownCommentReference {
639
637
}
640
638
}
641
639
640
+ // Add a result, but make it canonical.
641
+ void _addCanonicalResult (ModelElement modelElement, Class tryClass) {
642
+ results.add (packageGraph.findCanonicalModelElementFor (modelElement.element,
643
+ preferredClass: tryClass));
644
+ }
645
+
642
646
/// _getResultsForClass assumes codeRefChomped might be a member of tryClass (inherited or not)
643
647
/// and will add to [results]
644
648
void _getResultsForClass (Class tryClass) {
@@ -653,8 +657,7 @@ class _MarkdownCommentReference {
653
657
} else {
654
658
// People like to use 'this' in docrefs too.
655
659
if (codeRef == 'this' ) {
656
- results
657
- .add (packageGraph.findCanonicalModelElementFor (tryClass.element));
660
+ _addCanonicalResult (tryClass, null );
658
661
} else {
659
662
// TODO(jcollins-g): get rid of reimplementation of identifier resolution
660
663
// or integrate into ModelElement in a simpler way.
@@ -666,62 +669,42 @@ class _MarkdownCommentReference {
666
669
// Fortunately superChains are short, but optimize this if it matters.
667
670
superChain.addAll (tryClass.superChain.map ((t) => t.element as Class ));
668
671
for (final c in superChain) {
669
- // TODO(jcollins-g): add a hash-map-enabled lookup function to Class?
670
- for (final modelElement in c.allModelElements) {
671
- if (! _ConsiderIfConstructor (modelElement)) continue ;
672
- String namePart = modelElement.fullyQualifiedName.split ('.' ).last;
673
- if (modelElement is Accessor ) {
674
- // TODO(jcollins-g): Individual classes should be responsible for
675
- // this name comparison munging.
676
- namePart = namePart.split ('=' ).first;
677
- }
678
- // TODO(jcollins-g): fix operators so we can use 'name' here or similar.
679
- if (codeRefChomped == namePart) {
680
- results.add (packageGraph.findCanonicalModelElementFor (
681
- modelElement.element,
682
- preferredClass: tryClass));
683
- continue ;
684
- }
685
- // Handle non-documented class documentation being imported into a
686
- // documented class when it refers to itself (with help from caller's
687
- // iteration on tryClasses).
688
- // TODO(jcollins-g): Fix partial qualifications in _findRefElementInLibrary so it can tell
689
- // when it is referenced from a non-documented element?
690
- // TODO(jcollins-g): We could probably check this early.
691
- if (codeRefChompedParts.first == c.name &&
692
- codeRefChompedParts.last == namePart) {
693
- results.add (packageGraph.findCanonicalModelElementFor (
694
- modelElement.element,
695
- preferredClass: tryClass));
696
- continue ;
697
- }
698
- if (modelElement is Constructor ) {
699
- // Constructor names don't include the class, so we might miss them in the above search.
700
- if (codeRefChompedParts.length > 1 ) {
701
- String codeRefClass =
702
- codeRefChompedParts[codeRefChompedParts.length - 2 ];
703
- String codeRefConstructor = codeRefChompedParts.last;
704
- if (codeRefClass == c.name &&
705
- codeRefConstructor ==
706
- modelElement.fullyQualifiedName.split ('.' ).last) {
707
- results.add (packageGraph.findCanonicalModelElementFor (
708
- modelElement.element,
709
- preferredClass: tryClass));
710
- continue ;
711
- }
712
- }
713
- }
714
- }
715
- results.remove (null );
672
+ _getResultsForSuperChainElement (c, tryClass);
716
673
if (results.isNotEmpty) break ;
717
- if (c.fullyQualifiedNameWithoutLibrary == codeRefChomped) {
718
- results.add (c);
719
- break ;
720
- }
721
674
}
722
675
}
723
676
}
724
677
}
678
+
679
+ /// Get any possible results for this class in the superChain. Returns
680
+ /// true if we found something.
681
+ void _getResultsForSuperChainElement (Class c, Class tryClass) {
682
+ Iterable <ModelElement > membersToCheck;
683
+ membersToCheck = (c.allModelElementsByNamePart[codeRefChomped] ?? [])
684
+ .where ((m) => _ConsiderIfConstructor (m));
685
+ for (final ModelElement modelElement in membersToCheck) {
686
+ // [thing], a member of this class
687
+ _addCanonicalResult (modelElement, tryClass);
688
+ }
689
+ membersToCheck = (c.allModelElementsByNamePart[codeRefChompedParts.last] ??
690
+ < ModelElement > [])
691
+ .where ((m) => _ConsiderIfConstructor (m));
692
+ if (codeRefChompedParts.first == c.name) {
693
+ // [Foo...thing], a member of this class (possibly a parameter).
694
+ membersToCheck.map ((m) => _addCanonicalResult (m, tryClass));
695
+ } else if (codeRefChompedParts.length > 1 &&
696
+ codeRefChompedParts[codeRefChompedParts.length - 2 ] == c.name) {
697
+ // [....Foo.thing], a member of this class partially specified.
698
+ membersToCheck
699
+ .whereType <Constructor >()
700
+ .map ((m) => _addCanonicalResult (m, tryClass));
701
+ }
702
+ results.remove (null );
703
+ if (results.isNotEmpty) return ;
704
+ if (c.fullyQualifiedNameWithoutLibrary == codeRefChomped) {
705
+ results.add (c);
706
+ }
707
+ }
725
708
}
726
709
727
710
String _linkDocReference (String codeRef, Warnable warnable,
0 commit comments