1
+ import 'package:analyzer/dart/element/element.dart' ;
1
2
import 'package:args/args.dart' ;
2
3
import 'package:crypto/crypto.dart' as crypto;
3
4
import 'package:dartdoc/src/model/documentable.dart' ;
@@ -37,6 +38,9 @@ final _htmlInjectRegExp = RegExp(r'<dartdoc-html>([a-f0-9]+)</dartdoc-html>');
37
38
/// entrypoints.
38
39
mixin DocumentationComment
39
40
on Documentable , Warnable , Locatable , SourceCodeMixin {
41
+ @override
42
+ Element get element;
43
+
40
44
List <DocumentationComment >? _documentationFrom;
41
45
42
46
/// The [ModelElement] (s) from which we will get documentation.
@@ -56,7 +60,7 @@ mixin DocumentationComment
56
60
if (! hasDocumentationComment && self.overriddenElement != null ) {
57
61
return self.overriddenElement! .documentationFrom;
58
62
} else if (self.isInherited) {
59
- return modelBuilder.fromElement (element! ).documentationFrom;
63
+ return modelBuilder.fromElement (element).documentationFrom;
60
64
} else {
61
65
return [this ];
62
66
}
@@ -71,15 +75,15 @@ mixin DocumentationComment
71
75
72
76
/// The rawest form of the documentation comment, including comment delimiters
73
77
/// like `///` , `//` , `/*` , `*/` .
74
- String get documentationComment;
78
+ String get documentationComment => element.documentationComment ?? '' ;
75
79
76
80
/// True if [this] has a synthetic/inherited or local documentation
77
81
/// comment. False otherwise.
78
- bool get hasDocumentationComment;
82
+ bool get hasDocumentationComment => element.documentationComment != null ;
79
83
80
84
/// Returns true if the raw documentation comment has a 'nodoc' indication.
81
85
late final bool hasNodoc = () {
82
- if (packageGraph.configSetsNodocFor (element! .source! .fullName)) {
86
+ if (packageGraph.configSetsNodocFor (element.source! .fullName)) {
83
87
return true ;
84
88
}
85
89
if (! hasDocumentationComment) {
@@ -331,7 +335,7 @@ mixin DocumentationComment
331
335
replacement = replacement.replaceFirst ('```' , '```$lang ' );
332
336
}
333
337
} else {
334
- var filePath = element! .source! .fullName.substring (dirPath.length + 1 );
338
+ var filePath = element.source! .fullName.substring (dirPath.length + 1 );
335
339
336
340
// TODO(srawlins): If a file exists at the location without the
337
341
// appended 'md' extension, note this.
@@ -753,20 +757,28 @@ mixin DocumentationComment
753
757
}
754
758
}
755
759
756
- /// Returns the documentation for this literal element unless
757
- /// [config.dropTextFrom] indicates it should not be returned. Macro
758
- /// definitions are stripped, but macros themselves are not injected. This
759
- /// is a two stage process to avoid ordering problems.
760
- String ? _documentationLocal;
760
+ bool _documentationLocalIsSet = false ;
761
761
762
- String ? get documentationLocal =>
763
- _documentationLocal ?? = _buildDocumentationLocal ();
762
+ /// Returns the documentation for this literal element unless
763
+ /// `config.dropTextFrom` indicates it should not be returned. Macro
764
+ /// definitions are stripped, but macros themselves are not injected. This is
765
+ /// a two stage process to avoid ordering problems.
766
+ late final String _documentationLocal;
767
+
768
+ String get documentationLocal {
769
+ if (! _documentationLocalIsSet) {
770
+ _documentationLocal = _buildDocumentationBaseSync ();
771
+ _documentationLocalIsSet = true ;
772
+ }
773
+ return _documentationLocal;
774
+ }
764
775
765
776
/// Unconditionally precache local documentation.
766
777
///
767
778
/// Use only in factory for [PackageGraph] .
768
779
Future <void > precacheLocalDocs () async {
769
780
_documentationLocal = await _buildDocumentationBase ();
781
+ _documentationLocalIsSet = true ;
770
782
}
771
783
772
784
late final bool _hasNodoc;
@@ -833,35 +845,31 @@ mixin DocumentationComment
833
845
834
846
String ? _rawDocs;
835
847
836
- String ? _buildDocumentationLocal () => _buildDocumentationBaseSync ();
837
-
838
848
/// Override this to add more features to the documentation builder in a
839
849
/// subclass.
840
850
String buildDocumentationAddition (String docs) => docs;
841
851
842
- /// Separate from [_buildDocumentationLocal] for overriding.
843
- String ? _buildDocumentationBaseSync () {
852
+ String _buildDocumentationBaseSync () {
844
853
assert (_rawDocs == null ,
845
854
'reentrant calls to _buildDocumentation* not allowed' );
846
855
// Do not use the sync method if we need to evaluate tools or templates.
847
856
assert (! isCanonical || ! needsPrecache);
848
857
String rawDocs;
849
- if (config.dropTextFrom.contains (element! .library! .name)) {
858
+ if (config.dropTextFrom.contains (element.library! .name)) {
850
859
rawDocs = '' ;
851
860
} else {
852
861
rawDocs = _processCommentWithoutTools (documentationComment);
853
862
}
854
863
return _rawDocs = buildDocumentationAddition (rawDocs);
855
864
}
856
865
857
- /// Separate from [_buildDocumentationLocal] for overriding. Can only be
858
- /// used as part of [PackageGraph.setUpPackageGraph] .
859
- Future <String ?> _buildDocumentationBase () async {
866
+ /// Can only be used as part of `PackageGraph.setUpPackageGraph` .
867
+ Future <String > _buildDocumentationBase () async {
860
868
assert (_rawDocs == null ,
861
869
'reentrant calls to _buildDocumentation* not allowed' );
862
870
String rawDocs;
863
871
// Do not use the sync method if we need to evaluate tools or templates.
864
- if (config.dropTextFrom.contains (element! .library! .name)) {
872
+ if (config.dropTextFrom.contains (element.library! .name)) {
865
873
rawDocs = '' ;
866
874
} else {
867
875
rawDocs = await processComment (documentationComment);
0 commit comments