@@ -174,25 +174,24 @@ final List<md.BlockSyntax> _markdownBlockSyntaxes = [
174
174
final RegExp _hideSchemes = RegExp ('^(http|https)://' );
175
175
176
176
class MatchingLinkResult {
177
- final ModelElement modelElement ;
177
+ final CommentReferable commentReferable ;
178
178
final bool warn;
179
179
180
- MatchingLinkResult (this .modelElement , {this .warn = true });
180
+ MatchingLinkResult (this .commentReferable , {this .warn = true });
181
181
182
182
@override
183
183
bool operator == (Object other) {
184
184
return other is MatchingLinkResult &&
185
- modelElement == other.modelElement &&
185
+ commentReferable == other.commentReferable &&
186
186
warn == other.warn;
187
187
}
188
188
189
189
@override
190
- int get hashCode => hash2 (modelElement , warn);
190
+ int get hashCode => hash2 (commentReferable , warn);
191
191
192
192
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;
196
195
197
196
if (compareThis is Accessor ) {
198
197
compareThis = (compareThis as Accessor ).enclosingCombo;
@@ -202,8 +201,16 @@ class MatchingLinkResult {
202
201
compareOther = (compareOther as Accessor ).enclosingCombo;
203
202
}
204
203
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
+
207
214
// The old implementation just throws away Parameter matches to avoid
208
215
// problems with warning unnecessarily at higher levels of the code.
209
216
// I'd like to fix this at a different layer with the new lookup, so treat
@@ -221,12 +228,13 @@ class MatchingLinkResult {
221
228
if (compareThis is TypeParameter && compareOther == null ) {
222
229
return true ;
223
230
}
231
+
224
232
return false ;
225
233
}
226
234
227
235
@override
228
236
String toString () {
229
- return 'element: [${modelElement is Constructor ? 'new ' : '' }${modelElement ?.fullyQualifiedName }] warn: $warn ' ;
237
+ return 'element: [${commentReferable is Constructor ? 'new ' : '' }${commentReferable ?.fullyQualifiedName }] warn: $warn ' ;
230
238
}
231
239
}
232
240
@@ -354,12 +362,6 @@ MatchingLinkResult _getMatchingLinkElementCommentReferable(
354
362
var lookupResult =
355
363
warnable.referenceBy (commentReference.referenceBy, filter: filter);
356
364
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
-
363
365
// TODO(jcollins-g): Consider prioritizing analyzer resolution before custom.
364
366
return MatchingLinkResult (lookupResult);
365
367
}
@@ -1001,11 +1003,11 @@ const _referenceLookupWarnings = {
1001
1003
md.Node _makeLinkNode (String codeRef, Warnable warnable) {
1002
1004
var result = getMatchingLinkElement (warnable, codeRef);
1003
1005
var textContent = htmlEscape.convert (codeRef);
1004
- var linkedElement = result.modelElement ;
1006
+ var linkedElement = result.commentReferable ;
1005
1007
if (linkedElement != null ) {
1006
1008
if (linkedElement.href != null ) {
1007
1009
var anchor = md.Element .text ('a' , textContent);
1008
- if (linkedElement.isDeprecated) {
1010
+ if (linkedElement is ModelElement && linkedElement .isDeprecated) {
1009
1011
anchor.attributes['class' ] = 'deprecated' ;
1010
1012
}
1011
1013
anchor.attributes['href' ] = linkedElement.href;
@@ -1041,11 +1043,11 @@ MatchingLinkResult getMatchingLinkElement(Warnable warnable, String codeRef,
1041
1043
if (doComparison) {
1042
1044
resultNew = _getMatchingLinkElementCommentReferable (codeRef, warnable);
1043
1045
resultOld = _getMatchingLinkElementLegacy (codeRef, warnable);
1044
- if (resultNew.modelElement != null ) {
1046
+ if (resultNew.commentReferable != null ) {
1045
1047
markdownStats.resolvedNewLookupReferences++ ;
1046
1048
}
1047
1049
result = experimentalReferenceLookup ? resultNew : resultOld;
1048
- if (resultOld.modelElement != null ) {
1050
+ if (resultOld.commentReferable != null ) {
1049
1051
markdownStats.resolvedOldLookupReferences++ ;
1050
1052
}
1051
1053
} else {
@@ -1059,12 +1061,13 @@ MatchingLinkResult getMatchingLinkElement(Warnable warnable, String codeRef,
1059
1061
if (resultOld.isEquivalentTo (resultNew)) {
1060
1062
markdownStats.resolvedEquivalentlyReferences++ ;
1061
1063
} else {
1062
- if (resultNew.modelElement == null && resultOld.modelElement != null ) {
1064
+ if (resultNew.commentReferable == null &&
1065
+ resultOld.commentReferable != null ) {
1063
1066
warnable.warn (PackageWarning .referenceLookupMissingWithNew,
1064
1067
message: '[$codeRef ] => ' + resultOld.toString (),
1065
1068
referredFrom: warnable.documentationFrom);
1066
- } else if (resultNew.modelElement != null &&
1067
- resultOld.modelElement == null ) {
1069
+ } else if (resultNew.commentReferable != null &&
1070
+ resultOld.commentReferable == null ) {
1068
1071
warnable.warn (PackageWarning .referenceLookupFoundWithNew,
1069
1072
message: '[$codeRef ] => ' + resultNew.toString (),
1070
1073
referredFrom: warnable.documentationFrom);
@@ -1077,7 +1080,7 @@ MatchingLinkResult getMatchingLinkElement(Warnable warnable, String codeRef,
1077
1080
}
1078
1081
}
1079
1082
markdownStats.totalReferences++ ;
1080
- if (result.modelElement != null ) markdownStats.resolvedReferences++ ;
1083
+ if (result.commentReferable != null ) markdownStats.resolvedReferences++ ;
1081
1084
return result;
1082
1085
}
1083
1086
@@ -1095,16 +1098,21 @@ final RegExp allAfterLastNewline = RegExp(r'\n.*$', multiLine: true);
1095
1098
// https://github.com/dart-lang/dartdoc/issues/1250#issuecomment-269257942
1096
1099
void showWarningsForGenericsOutsideSquareBracketsBlocks (
1097
1100
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
+ }
1108
1116
}
1109
1117
}
1110
1118
0 commit comments