@@ -126,10 +126,6 @@ final RegExp nonHTML =
126
126
/// parentheses.
127
127
final _trailingIgnorePattern = RegExp (r'(<.*>|\(.*\)|\?|!)$' );
128
128
129
- @Deprecated ('Public variable intended to be private; will be removed as early '
130
- 'as Dartdoc 1.0.0' )
131
- RegExp get trailingIgnoreStuff => _trailingIgnorePattern;
132
-
133
129
/// Things to ignore at the beginning of a doc reference.
134
130
///
135
131
/// This is intended to catch various keywords that a developer may include in
@@ -139,18 +135,10 @@ RegExp get trailingIgnoreStuff => _trailingIgnorePattern;
139
135
final _leadingIgnorePattern =
140
136
RegExp (r'^(const|final|var)[\s]+' , multiLine: true );
141
137
142
- @Deprecated ('Public variable intended to be private; will be removed as early '
143
- 'as Dartdoc 1.0.0' )
144
- RegExp get leadingIgnoreStuff => _leadingIgnorePattern;
145
-
146
138
/// If found, this pattern may indicate a reference to a constructor.
147
139
final _constructorIndicationPattern =
148
140
RegExp (r'(^new[\s]+|\(\)$)' , multiLine: true );
149
141
150
- @Deprecated ('Public variable intended to be private; will be removed as early '
151
- 'as Dartdoc 1.0.0' )
152
- RegExp get isConstructor => _constructorIndicationPattern;
153
-
154
142
/// A pattern indicating that text which looks like a doc reference is not
155
143
/// intended to be.
156
144
///
@@ -288,8 +276,8 @@ ModelElement _getPreferredClass(ModelElement modelElement) {
288
276
}
289
277
290
278
/// Implements _getMatchingLinkElement via [CommentReferable.referenceBy] .
291
- MatchingLinkResult _getMatchingLinkElementCommentReferable (String codeRef,
292
- Warnable warnable, List < ModelCommentReference > commentRefs ) {
279
+ MatchingLinkResult _getMatchingLinkElementCommentReferable (
280
+ String codeRef, Warnable warnable ) {
293
281
if (! codeRef.contains (_constructorIndicationPattern) &&
294
282
codeRef.contains (notARealDocReference)) {
295
283
// Don't waste our time on things we won't ever find.
@@ -304,8 +292,8 @@ MatchingLinkResult _getMatchingLinkElementCommentReferable(String codeRef,
304
292
}
305
293
306
294
/// Returns null if element is a parameter.
307
- MatchingLinkResult _getMatchingLinkElementLegacy (String codeRef,
308
- Warnable warnable, List < ModelCommentReference > commentRefs ) {
295
+ MatchingLinkResult _getMatchingLinkElementLegacy (
296
+ String codeRef, Warnable warnable ) {
309
297
if (! codeRef.contains (_constructorIndicationPattern) &&
310
298
codeRef.contains (notARealDocReference)) {
311
299
// Don't waste our time on things we won't ever find.
@@ -322,9 +310,9 @@ MatchingLinkResult _getMatchingLinkElementLegacy(String codeRef,
322
310
message:
323
311
'Comment reference resolution inside extension methods is not yet implemented' );
324
312
} else {
325
- refModelElement = _MarkdownCommentReference (
326
- codeRef, warnable, commentRefs , preferredClass)
327
- .computeReferredElement ();
313
+ refModelElement =
314
+ _MarkdownCommentReference ( codeRef, warnable, preferredClass)
315
+ .computeReferredElement ();
328
316
}
329
317
}
330
318
@@ -368,27 +356,28 @@ MatchingLinkResult _getMatchingLinkElementLegacy(String codeRef,
368
356
return MatchingLinkResult (refModelElement);
369
357
}
370
358
371
- /// Given a set of commentRefs, return the one whose name matches the codeRef.
372
- Element _getRefElementFromCommentRefs (
373
- List <ModelCommentReference > commentRefs, String codeRef) {
374
- if (commentRefs != null ) {
375
- for (var ref in commentRefs) {
376
- if (ref.name == codeRef) {
377
- var isConstrElement = ref.staticElement is ConstructorElement ;
378
- // Constructors are now handled by library search.
379
- if (! isConstrElement) {
380
- var refElement = ref.staticElement;
381
- if (refElement is PropertyAccessorElement ) {
382
- // yay we found an accessor that wraps a const, but we really
383
- // want the top-level field itself
384
- refElement = (refElement as PropertyAccessorElement ).variable;
385
- }
386
- if (refElement is PrefixElement ) {
387
- // We found a prefix element, but what we really want is the library element.
388
- refElement = (refElement as PrefixElement ).enclosingElement;
389
- }
390
- return refElement;
359
+ /// Get the element referred by the [codeRef] in analyzer.
360
+ /// Deletes constructors and otherwise messes with the output for the rest
361
+ /// of the heuristics.
362
+ Element _getRefElementFromCommentRefs (Warnable element, String codeRef) {
363
+ if (element.commentRefs != null ) {
364
+ var ref = element.commentRefs[codeRef];
365
+ // ref can be null here if the analyzer failed to recognize this as a
366
+ // comment reference (e.g. [Foo.operator []]).
367
+ if (ref != null ) {
368
+ // Constructors are now handled by library search.
369
+ if (ref.staticElement is ! ConstructorElement ) {
370
+ var refElement = ref.staticElement;
371
+ if (refElement is PropertyAccessorElement ) {
372
+ // yay we found an accessor that wraps a const, but we really
373
+ // want the top-level field itself
374
+ refElement = (refElement as PropertyAccessorElement ).variable;
391
375
}
376
+ if (refElement is PrefixElement ) {
377
+ // We found a prefix element, but what we really want is the library element.
378
+ refElement = (refElement as PrefixElement ).enclosingElement;
379
+ }
380
+ return refElement;
392
381
}
393
382
}
394
383
}
@@ -403,9 +392,6 @@ class _MarkdownCommentReference {
403
392
/// The element containing the code reference.
404
393
final Warnable element;
405
394
406
- /// A list of [ModelCommentReference] s for this element.
407
- final List <ModelCommentReference > commentRefs;
408
-
409
395
/// Disambiguate inheritance with this class.
410
396
final Class preferredClass;
411
397
@@ -421,8 +407,7 @@ class _MarkdownCommentReference {
421
407
/// PackageGraph associated with this element.
422
408
PackageGraph packageGraph;
423
409
424
- _MarkdownCommentReference (
425
- this .codeRef, this .element, this .commentRefs, this .preferredClass) {
410
+ _MarkdownCommentReference (this .codeRef, this .element, this .preferredClass) {
426
411
assert (element != null );
427
412
assert (element.packageGraph.allLibrariesAdded);
428
413
@@ -589,7 +574,7 @@ class _MarkdownCommentReference {
589
574
_codeRefChompedParts ?? = codeRefChomped.split ('.' );
590
575
591
576
void _reducePreferAnalyzerResolution () {
592
- var refElement = _getRefElementFromCommentRefs (commentRefs , codeRef);
577
+ var refElement = _getRefElementFromCommentRefs (element , codeRef);
593
578
if (results.any ((me) => me.element == refElement)) {
594
579
results.removeWhere ((me) => me.element != refElement);
595
580
}
@@ -663,26 +648,23 @@ class _MarkdownCommentReference {
663
648
void _findWithoutLeadingIgnoreStuff () {
664
649
if (codeRef.contains (_leadingIgnorePattern)) {
665
650
var newCodeRef = codeRef.replaceFirst (_leadingIgnorePattern, '' );
666
- results.add (_MarkdownCommentReference (
667
- newCodeRef, element, commentRefs, preferredClass)
651
+ results.add (_MarkdownCommentReference (newCodeRef, element, preferredClass)
668
652
.computeReferredElement ());
669
653
}
670
654
}
671
655
672
656
void _findWithoutTrailingIgnoreStuff () {
673
657
if (codeRef.contains (_trailingIgnorePattern)) {
674
658
var newCodeRef = codeRef.replaceFirst (_trailingIgnorePattern, '' );
675
- results.add (_MarkdownCommentReference (
676
- newCodeRef, element, commentRefs, preferredClass)
659
+ results.add (_MarkdownCommentReference (newCodeRef, element, preferredClass)
677
660
.computeReferredElement ());
678
661
}
679
662
}
680
663
681
664
void _findWithoutOperatorPrefix () {
682
665
if (codeRef.startsWith (operatorPrefix)) {
683
666
var newCodeRef = codeRef.replaceFirst (operatorPrefix, '' );
684
- results.add (_MarkdownCommentReference (
685
- newCodeRef, element, commentRefs, preferredClass)
667
+ results.add (_MarkdownCommentReference (newCodeRef, element, preferredClass)
686
668
.computeReferredElement ());
687
669
}
688
670
}
@@ -826,7 +808,7 @@ class _MarkdownCommentReference {
826
808
}
827
809
828
810
void _findAnalyzerReferences () {
829
- var refElement = _getRefElementFromCommentRefs (commentRefs , codeRef);
811
+ var refElement = _getRefElementFromCommentRefs (element , codeRef);
830
812
if (refElement == null ) return ;
831
813
832
814
ModelElement refModelElement;
@@ -943,9 +925,8 @@ const _referenceLookupWarnings = {
943
925
PackageWarning .referenceLookupMissingWithNew,
944
926
};
945
927
946
- md.Node _makeLinkNode (String codeRef, Warnable warnable,
947
- List <ModelCommentReference > commentRefs) {
948
- var result = _getMatchingLinkElement (warnable, codeRef, commentRefs);
928
+ md.Node _makeLinkNode (String codeRef, Warnable warnable) {
929
+ var result = _getMatchingLinkElement (warnable, codeRef);
949
930
var textContent = htmlEscape.convert (codeRef);
950
931
var linkedElement = result.modelElement;
951
932
if (linkedElement != null ) {
@@ -974,18 +955,16 @@ md.Node _makeLinkNode(String codeRef, Warnable warnable,
974
955
return md.Element .text ('code' , textContent);
975
956
}
976
957
977
- MatchingLinkResult _getMatchingLinkElement (Warnable warnable, String codeRef,
978
- List <ModelCommentReference > commentRefs) {
958
+ MatchingLinkResult _getMatchingLinkElement (Warnable warnable, String codeRef) {
979
959
MatchingLinkResult result, resultOld, resultNew;
980
960
// Do a comparison between result types only if the warnings for them are
981
961
// enabled, because there's a significant performance penalty.
982
962
var doComparison = warnable.config.packageWarningOptions.warningModes.entries
983
963
.where ((entry) => _referenceLookupWarnings.contains (entry.key))
984
964
.any ((entry) => entry.value != PackageWarningMode .ignore);
985
965
if (doComparison) {
986
- resultNew =
987
- _getMatchingLinkElementCommentReferable (codeRef, warnable, commentRefs);
988
- resultOld = _getMatchingLinkElementLegacy (codeRef, warnable, commentRefs);
966
+ resultNew = _getMatchingLinkElementCommentReferable (codeRef, warnable);
967
+ resultOld = _getMatchingLinkElementLegacy (codeRef, warnable);
989
968
if (resultNew.modelElement != null ) {
990
969
markdownStats.resolvedNewLookupReferences++ ;
991
970
}
@@ -996,10 +975,9 @@ MatchingLinkResult _getMatchingLinkElement(Warnable warnable, String codeRef,
996
975
}
997
976
} else {
998
977
if (warnable.config.experimentalReferenceLookup) {
999
- result = _getMatchingLinkElementCommentReferable (
1000
- codeRef, warnable, commentRefs);
978
+ result = _getMatchingLinkElementCommentReferable (codeRef, warnable);
1001
979
} else {
1002
- result = _getMatchingLinkElementLegacy (codeRef, warnable, commentRefs );
980
+ result = _getMatchingLinkElementLegacy (codeRef, warnable);
1003
981
}
1004
982
}
1005
983
if (doComparison) {
@@ -1084,13 +1062,12 @@ Iterable<int> findFreeHangingGenericsPositions(String string) sync* {
1084
1062
}
1085
1063
1086
1064
class MarkdownDocument extends md.Document {
1087
- factory MarkdownDocument .withElementLinkResolver (
1088
- Canonicalization element, List <ModelCommentReference > commentRefs) {
1065
+ factory MarkdownDocument .withElementLinkResolver (Canonicalization element) {
1089
1066
md.Node /*?*/ linkResolver (String name, [String /*?*/ _]) {
1090
1067
if (name.isEmpty) {
1091
1068
return null ;
1092
1069
}
1093
- return _makeLinkNode (name, element, commentRefs );
1070
+ return _makeLinkNode (name, element);
1094
1071
}
1095
1072
1096
1073
return MarkdownDocument (
0 commit comments