@@ -174,25 +174,24 @@ final List<md.BlockSyntax> _markdownBlockSyntaxes = [
174174final RegExp _hideSchemes = RegExp ('^(http|https)://' );
175175
176176class MatchingLinkResult {
177- final ModelElement modelElement ;
177+ final CommentReferable commentReferable ;
178178 final bool warn;
179179
180- MatchingLinkResult (this .modelElement , {this .warn = true });
180+ MatchingLinkResult (this .commentReferable , {this .warn = true });
181181
182182 @override
183183 bool operator == (Object other) {
184184 return other is MatchingLinkResult &&
185- modelElement == other.modelElement &&
185+ commentReferable == other.commentReferable &&
186186 warn == other.warn;
187187 }
188188
189189 @override
190- int get hashCode => hash2 (modelElement , warn);
190+ int get hashCode => hash2 (commentReferable , warn);
191191
192192 bool isEquivalentTo (MatchingLinkResult other) {
193- if (this == other) return true ;
194- var compareThis = modelElement;
195- var compareOther = other.modelElement;
193+ var compareThis = commentReferable;
194+ var compareOther = other.commentReferable;
196195
197196 if (compareThis is Accessor ) {
198197 compareThis = (compareThis as Accessor ).enclosingCombo;
@@ -202,8 +201,16 @@ class MatchingLinkResult {
202201 compareOther = (compareOther as Accessor ).enclosingCombo;
203202 }
204203
205- if (compareThis? .canonicalModelElement ==
206- compareOther? .canonicalModelElement) return true ;
204+ if (compareThis is ModelElement &&
205+ compareThis.canonicalModelElement != null ) {
206+ compareThis = (compareThis as ModelElement ).canonicalModelElement;
207+ }
208+ if (compareOther is ModelElement &&
209+ compareOther.canonicalModelElement != null ) {
210+ compareOther = (compareOther as ModelElement ).canonicalModelElement;
211+ }
212+ if (compareThis == compareOther) return true ;
213+
207214 // The old implementation just throws away Parameter matches to avoid
208215 // problems with warning unnecessarily at higher levels of the code.
209216 // I'd like to fix this at a different layer with the new lookup, so treat
@@ -221,12 +228,13 @@ class MatchingLinkResult {
221228 if (compareThis is TypeParameter && compareOther == null ) {
222229 return true ;
223230 }
231+
224232 return false ;
225233 }
226234
227235 @override
228236 String toString () {
229- return 'element: [${modelElement is Constructor ? 'new ' : '' }${modelElement ?.fullyQualifiedName }] warn: $warn ' ;
237+ return 'element: [${commentReferable is Constructor ? 'new ' : '' }${commentReferable ?.fullyQualifiedName }] warn: $warn ' ;
230238 }
231239}
232240
@@ -354,12 +362,6 @@ MatchingLinkResult _getMatchingLinkElementCommentReferable(
354362 var lookupResult =
355363 warnable.referenceBy (commentReference.referenceBy, filter: filter);
356364
357- // TODO(jcollins-g): Referring to packages or other non-[ModelElement]s
358- // might be needed here. Determine if that's the case.
359- if (! (lookupResult is ModelElement )) {
360- lookupResult = null ;
361- }
362-
363365 // TODO(jcollins-g): Consider prioritizing analyzer resolution before custom.
364366 return MatchingLinkResult (lookupResult);
365367}
@@ -1001,11 +1003,11 @@ const _referenceLookupWarnings = {
10011003md.Node _makeLinkNode (String codeRef, Warnable warnable) {
10021004 var result = getMatchingLinkElement (warnable, codeRef);
10031005 var textContent = htmlEscape.convert (codeRef);
1004- var linkedElement = result.modelElement ;
1006+ var linkedElement = result.commentReferable ;
10051007 if (linkedElement != null ) {
10061008 if (linkedElement.href != null ) {
10071009 var anchor = md.Element .text ('a' , textContent);
1008- if (linkedElement.isDeprecated) {
1010+ if (linkedElement is ModelElement && linkedElement .isDeprecated) {
10091011 anchor.attributes['class' ] = 'deprecated' ;
10101012 }
10111013 anchor.attributes['href' ] = linkedElement.href;
@@ -1041,11 +1043,11 @@ MatchingLinkResult getMatchingLinkElement(Warnable warnable, String codeRef,
10411043 if (doComparison) {
10421044 resultNew = _getMatchingLinkElementCommentReferable (codeRef, warnable);
10431045 resultOld = _getMatchingLinkElementLegacy (codeRef, warnable);
1044- if (resultNew.modelElement != null ) {
1046+ if (resultNew.commentReferable != null ) {
10451047 markdownStats.resolvedNewLookupReferences++ ;
10461048 }
10471049 result = experimentalReferenceLookup ? resultNew : resultOld;
1048- if (resultOld.modelElement != null ) {
1050+ if (resultOld.commentReferable != null ) {
10491051 markdownStats.resolvedOldLookupReferences++ ;
10501052 }
10511053 } else {
@@ -1059,12 +1061,13 @@ MatchingLinkResult getMatchingLinkElement(Warnable warnable, String codeRef,
10591061 if (resultOld.isEquivalentTo (resultNew)) {
10601062 markdownStats.resolvedEquivalentlyReferences++ ;
10611063 } else {
1062- if (resultNew.modelElement == null && resultOld.modelElement != null ) {
1064+ if (resultNew.commentReferable == null &&
1065+ resultOld.commentReferable != null ) {
10631066 warnable.warn (PackageWarning .referenceLookupMissingWithNew,
10641067 message: '[$codeRef ] => ' + resultOld.toString (),
10651068 referredFrom: warnable.documentationFrom);
1066- } else if (resultNew.modelElement != null &&
1067- resultOld.modelElement == null ) {
1069+ } else if (resultNew.commentReferable != null &&
1070+ resultOld.commentReferable == null ) {
10681071 warnable.warn (PackageWarning .referenceLookupFoundWithNew,
10691072 message: '[$codeRef ] => ' + resultNew.toString (),
10701073 referredFrom: warnable.documentationFrom);
@@ -1077,7 +1080,7 @@ MatchingLinkResult getMatchingLinkElement(Warnable warnable, String codeRef,
10771080 }
10781081 }
10791082 markdownStats.totalReferences++ ;
1080- if (result.modelElement != null ) markdownStats.resolvedReferences++ ;
1083+ if (result.commentReferable != null ) markdownStats.resolvedReferences++ ;
10811084 return result;
10821085}
10831086
@@ -1095,16 +1098,21 @@ final RegExp allAfterLastNewline = RegExp(r'\n.*$', multiLine: true);
10951098// https://github.com/dart-lang/dartdoc/issues/1250#issuecomment-269257942
10961099void showWarningsForGenericsOutsideSquareBracketsBlocks (
10971100 String text, Warnable element) {
1098- for (var position in findFreeHangingGenericsPositions (text)) {
1099- var priorContext =
1100- '${text .substring (max (position - maxPriorContext , 0 ), position )}' ;
1101- var postContext =
1102- '${text .substring (position , min (position + maxPostContext , text .length ))}' ;
1103- priorContext = priorContext.replaceAll (allBeforeFirstNewline, '' );
1104- postContext = postContext.replaceAll (allAfterLastNewline, '' );
1105- var errorMessage = '$priorContext $postContext ' ;
1106- // TODO(jcollins-g): allow for more specific error location inside comments
1107- element.warn (PackageWarning .typeAsHtml, message: errorMessage);
1101+ // Skip this if not warned for performance and for dart-lang/sdk#46419.
1102+ if (element.config.packageWarningOptions
1103+ .warningModes[PackageWarning .typeAsHtml] !=
1104+ PackageWarningMode .ignore) {
1105+ for (var position in findFreeHangingGenericsPositions (text)) {
1106+ var priorContext =
1107+ '${text .substring (max (position - maxPriorContext , 0 ), position )}' ;
1108+ var postContext =
1109+ '${text .substring (position , min (position + maxPostContext , text .length ))}' ;
1110+ priorContext = priorContext.replaceAll (allBeforeFirstNewline, '' );
1111+ postContext = postContext.replaceAll (allAfterLastNewline, '' );
1112+ var errorMessage = '$priorContext $postContext ' ;
1113+ // TODO(jcollins-g): allow for more specific error location inside comments
1114+ element.warn (PackageWarning .typeAsHtml, message: errorMessage);
1115+ }
11081116 }
11091117}
11101118
0 commit comments