@@ -119,19 +119,44 @@ const validHtmlTags = [
119
119
final RegExp nonHTML =
120
120
RegExp ("</?(?!(${validHtmlTags .join ("|" )})[> ])\\ w+[> ]" );
121
121
122
- // Type parameters and other things to ignore at the end of doc references.
123
- final RegExp trailingIgnoreStuff = RegExp (r'(<.*>|\(.*\))$' );
124
-
125
- // Things to ignore at the beginning of doc references
126
- final RegExp leadingIgnoreStuff =
122
+ /// Things to ignore at the end of a doc reference.
123
+ ///
124
+ /// This is intended to catch type parameters/arguments, and function call
125
+ /// parentheses.
126
+ final _trailingIgnorePattern = RegExp (r'(<.*>|\(.*\)|\?|!)$' );
127
+
128
+ @Deprecated ('Public variable intended to be private; will be removed as early '
129
+ 'as Dartdoc 1.0.0' )
130
+ RegExp get trailingIgnoreStuff => _trailingIgnorePattern;
131
+
132
+ /// Things to ignore at the beginning of a doc reference.
133
+ ///
134
+ /// This is intended to catch various keywords that a developer may include in
135
+ /// front of a variable name.
136
+ // TODO(srawlins): I cannot find any tests asserting we can resolve such
137
+ // references.
138
+ final _leadingIgnorePattern =
127
139
RegExp (r'^(const|final|var)[\s]+' , multiLine: true );
128
140
129
- // If found, this may be intended as a reference to a constructor.
130
- final RegExp isConstructor = RegExp (r'(^new[\s]+|\(\)$)' , multiLine: true );
131
-
132
- // This is probably not really intended as a doc reference, so don't try or
133
- // warn about them.
134
- // Covers anything with leading digits/symbols, empty string, weird punctuation, spaces.
141
+ @Deprecated ('Public variable intended to be private; will be removed as early '
142
+ 'as Dartdoc 1.0.0' )
143
+ RegExp get leadingIgnoreStuff => _leadingIgnorePattern;
144
+
145
+ /// If found, this pattern may indicate a reference to a constructor.
146
+ final _constructorIndicationPattern =
147
+ RegExp (r'(^new[\s]+|\(\)$)' , multiLine: true );
148
+
149
+ @Deprecated ('Public variable intended to be private; will be removed as early '
150
+ 'as Dartdoc 1.0.0' )
151
+ RegExp get isConstructor => _constructorIndicationPattern;
152
+
153
+ /// A pattern indicating that text which looks like a doc reference is not
154
+ /// intended to be.
155
+ ///
156
+ /// This covers anything with leading digits/symbols, empty strings, weird
157
+ /// punctuation, spaces.
158
+ ///
159
+ /// The idea is to catch such cases and not produce warnings about the contents.
135
160
final RegExp notARealDocReference = RegExp (r'''(^[^\w]|^[\d]|[,"'/]|^$)''' );
136
161
137
162
final RegExp operatorPrefix = RegExp (r'^operator[ ]*' );
@@ -194,7 +219,7 @@ ModelElement _getPreferredClass(ModelElement modelElement) {
194
219
/// Returns null if element is a parameter.
195
220
MatchingLinkResult _getMatchingLinkElement (
196
221
String codeRef, Warnable element, List <ModelCommentReference > commentRefs) {
197
- if (! codeRef.contains (isConstructor ) &&
222
+ if (! codeRef.contains (_constructorIndicationPattern ) &&
198
223
codeRef.contains (notARealDocReference)) {
199
224
// Don't waste our time on things we won't ever find.
200
225
return MatchingLinkResult (null , warn: false );
@@ -314,7 +339,7 @@ class _MarkdownCommentReference {
314
339
assert (element != null );
315
340
assert (element.packageGraph.allLibrariesAdded);
316
341
317
- codeRefChomped = codeRef.replaceAll (isConstructor , '' );
342
+ codeRefChomped = codeRef.replaceAll (_constructorIndicationPattern , '' );
318
343
library =
319
344
element is ModelElement ? (element as ModelElement ).library : null ;
320
345
packageGraph = library.packageGraph;
@@ -342,7 +367,7 @@ class _MarkdownCommentReference {
342
367
String get _impliedDefaultConstructor {
343
368
if (! __impliedDefaultConstructorIsSet) {
344
369
__impliedDefaultConstructorIsSet = true ;
345
- if (codeRef.contains (isConstructor ) ||
370
+ if (codeRef.contains (_constructorIndicationPattern ) ||
346
371
(codeRefChompedParts.length >= 2 &&
347
372
codeRefChompedParts[codeRefChompedParts.length - 1 ] ==
348
373
codeRefChompedParts[codeRefChompedParts.length - 2 ])) {
@@ -362,35 +387,40 @@ class _MarkdownCommentReference {
362
387
/// are more than one, but does not warn otherwise.
363
388
ModelElement computeReferredElement () {
364
389
results = {};
365
- // TODO(jcollins-g): A complex package winds up spending a lot of cycles in here. Optimize.
390
+ // TODO(jcollins-g): A complex package winds up spending a lot of cycles in
391
+ // here. Optimize.
366
392
for (var findMethod in [
367
393
// This might be an operator. Strip the operator prefix and try again.
368
394
_findWithoutOperatorPrefix,
369
395
// Oh, and someone might have thrown on a 'const' or 'final' in front.
370
396
_findWithoutLeadingIgnoreStuff,
371
397
// Maybe this ModelElement has parameters, and this is one of them.
372
- // We don't link these, but this keeps us from emitting warnings. Be sure to
373
- // get members of parameters too.
398
+ // We don't link these, but this keeps us from emitting warnings. Be sure
399
+ // to get members of parameters too.
374
400
_findParameters,
375
401
// Maybe this ModelElement has type parameters, and this is one of them.
376
402
_findTypeParameters,
377
403
// This could be local to the class, look there first.
378
404
_findWithinTryClasses,
379
405
// This could be a reference to a renamed library.
380
406
_findReferenceFromPrefixes,
381
- // We now need the ref element cache to keep from repeatedly searching [Package.allModelElements].
382
- // But if not, look for a fully qualified match. (That only makes sense
383
- // if the codeRef might be qualified, and contains periods.)
407
+ // We now need the ref element cache to keep from repeatedly searching
408
+ // [Package.allModelElements]. But if not, look for a fully qualified
409
+ // match. (That only makes sense if the code reference might be
410
+ // qualified, and contains periods.)
384
411
_findWithinRefElementCache,
385
- // Only look for partially qualified matches if we didn't find a fully qualified one.
412
+ // Only look for partially qualified matches if we didn't find a fully
413
+ // qualified one.
386
414
_findPartiallyQualifiedMatches,
387
- // Only look for partially qualified matches if we didn't find a fully qualified one.
415
+ // Only look for partially qualified matches if we didn't find a fully
416
+ // qualified one.
388
417
_findGlobalWithinRefElementCache,
389
- // This could conceivably be a reference to an enum member. They don't show up in allModelElements.
418
+ // This could conceivably be a reference to an enum member. They don't
419
+ // show up in [allModelElements].
390
420
_findEnumReferences,
391
421
// Oh, and someone might have some type parameters or other garbage.
392
- // After finding within classes because sometimes parentheses are used
393
- // to imply constructors.
422
+ // After finding within classes because sometimes parentheses are used to
423
+ // imply constructors.
394
424
_findWithoutTrailingIgnoreStuff,
395
425
// Use the analyzer to resolve a comment reference.
396
426
_findAnalyzerReferences,
@@ -514,17 +544,17 @@ class _MarkdownCommentReference {
514
544
}
515
545
516
546
void _findWithoutLeadingIgnoreStuff () {
517
- if (codeRef.contains (leadingIgnoreStuff )) {
518
- var newCodeRef = codeRef.replaceFirst (leadingIgnoreStuff , '' );
547
+ if (codeRef.contains (_leadingIgnorePattern )) {
548
+ var newCodeRef = codeRef.replaceFirst (_leadingIgnorePattern , '' );
519
549
results.add (_MarkdownCommentReference (
520
550
newCodeRef, element, commentRefs, preferredClass)
521
551
.computeReferredElement ());
522
552
}
523
553
}
524
554
525
555
void _findWithoutTrailingIgnoreStuff () {
526
- if (codeRef.contains (trailingIgnoreStuff )) {
527
- var newCodeRef = codeRef.replaceFirst (trailingIgnoreStuff , '' );
556
+ if (codeRef.contains (_trailingIgnorePattern )) {
557
+ var newCodeRef = codeRef.replaceFirst (_trailingIgnorePattern , '' );
528
558
results.add (_MarkdownCommentReference (
529
559
newCodeRef, element, commentRefs, preferredClass)
530
560
.computeReferredElement ());
0 commit comments