Skip to content

Commit 5e6ec89

Browse files
authored
Continuing the crushing down of documentation handling (#2818)
* Straight move * Partial * delete experiment * rebuild * moved computeDocumentationComment and documentationComment * Move more documentation comment handling * remove ??= from a cut and paste * Documentation comment move for combos * better as a getter
1 parent c476d64 commit 5e6ec89

9 files changed

+208
-163
lines changed

lib/src/generator/templates.runtime_renderers.dart

Lines changed: 120 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ class _Renderer_Accessor extends RendererBase<Accessor> {
6868
getters: _invisibleGetters['GetterSetterCombo']);
6969
},
7070
),
71+
'documentationComment': Property(
72+
getValue: (CT_ c) => c.documentationComment,
73+
renderVariable:
74+
(CT_ c, Property<CT_> self, List<String> remainingNames) {
75+
if (remainingNames.isEmpty) {
76+
return self.getValue(c).toString();
77+
}
78+
var name = remainingNames.first;
79+
var nextProperty =
80+
_Renderer_String.propertyMap().getValue(name);
81+
return nextProperty.renderVariable(self.getValue(c),
82+
nextProperty, [...remainingNames.skip(1)]);
83+
},
84+
isNullValue: (CT_ c) => c.documentationComment == null,
85+
renderValue: (CT_ c, RendererBase<CT_> r,
86+
List<MustachioNode> ast, StringSink sink) {
87+
_render_String(
88+
c.documentationComment, ast, r.template, sink,
89+
parent: r);
90+
},
91+
),
7192
'element': Property(
7293
getValue: (CT_ c) => c.element,
7394
renderVariable: (CT_ c, Property<CT_> self,
@@ -3907,6 +3928,26 @@ class _Renderer_DocumentationComment
39073928
_propertyMapCache.putIfAbsent(
39083929
CT_,
39093930
() => {
3931+
'documentationAsHtml': Property(
3932+
getValue: (CT_ c) => c.documentationAsHtml,
3933+
renderVariable:
3934+
(CT_ c, Property<CT_> self, List<String> remainingNames) {
3935+
if (remainingNames.isEmpty) {
3936+
return self.getValue(c).toString();
3937+
}
3938+
var name = remainingNames.first;
3939+
var nextProperty =
3940+
_Renderer_String.propertyMap().getValue(name);
3941+
return nextProperty.renderVariable(self.getValue(c),
3942+
nextProperty, [...remainingNames.skip(1)]);
3943+
},
3944+
isNullValue: (CT_ c) => c.documentationAsHtml == null,
3945+
renderValue: (CT_ c, RendererBase<CT_> r,
3946+
List<MustachioNode> ast, StringSink sink) {
3947+
_render_String(c.documentationAsHtml, ast, r.template, sink,
3948+
parent: r);
3949+
},
3950+
),
39103951
'documentationComment': Property(
39113952
getValue: (CT_ c) => c.documentationComment,
39123953
renderVariable:
@@ -3928,6 +3969,20 @@ class _Renderer_DocumentationComment
39283969
parent: r);
39293970
},
39303971
),
3972+
'documentationFrom': Property(
3973+
getValue: (CT_ c) => c.documentationFrom,
3974+
renderVariable: (CT_ c, Property<CT_> self,
3975+
List<String> remainingNames) =>
3976+
self.renderSimpleVariable(
3977+
c, remainingNames, 'List<DocumentationComment>'),
3978+
renderIterable: (CT_ c, RendererBase<CT_> r,
3979+
List<MustachioNode> ast, StringSink sink) {
3980+
return c.documentationFrom.map((e) => renderSimple(
3981+
e, ast, r.template, sink,
3982+
parent: r,
3983+
getters: _invisibleGetters['DocumentationComment']));
3984+
},
3985+
),
39313986
'documentationLocal': Property(
39323987
getValue: (CT_ c) => c.documentationLocal,
39333988
renderVariable:
@@ -3948,6 +4003,19 @@ class _Renderer_DocumentationComment
39484003
parent: r);
39494004
},
39504005
),
4006+
'elementDocumentation': Property(
4007+
getValue: (CT_ c) => c.elementDocumentation,
4008+
renderVariable: (CT_ c, Property<CT_> self,
4009+
List<String> remainingNames) =>
4010+
self.renderSimpleVariable(
4011+
c, remainingNames, 'Documentation'),
4012+
isNullValue: (CT_ c) => c.elementDocumentation == null,
4013+
renderValue: (CT_ c, RendererBase<CT_> r,
4014+
List<MustachioNode> ast, StringSink sink) {
4015+
renderSimple(c.elementDocumentation, ast, r.template, sink,
4016+
parent: r, getters: _invisibleGetters['Documentation']);
4017+
},
4018+
),
39514019
'fullyQualifiedNameWithoutLibrary': Property(
39524020
getValue: (CT_ c) => c.fullyQualifiedNameWithoutLibrary,
39534021
renderVariable:
@@ -5865,17 +5933,39 @@ class _Renderer_GetterSetterCombo extends RendererBase<GetterSetterCombo> {
58655933
parent: r);
58665934
},
58675935
),
5936+
'documentationComment': Property(
5937+
getValue: (CT_ c) => c.documentationComment,
5938+
renderVariable:
5939+
(CT_ c, Property<CT_> self, List<String> remainingNames) {
5940+
if (remainingNames.isEmpty) {
5941+
return self.getValue(c).toString();
5942+
}
5943+
var name = remainingNames.first;
5944+
var nextProperty =
5945+
_Renderer_String.propertyMap().getValue(name);
5946+
return nextProperty.renderVariable(self.getValue(c),
5947+
nextProperty, [...remainingNames.skip(1)]);
5948+
},
5949+
isNullValue: (CT_ c) => c.documentationComment == null,
5950+
renderValue: (CT_ c, RendererBase<CT_> r,
5951+
List<MustachioNode> ast, StringSink sink) {
5952+
_render_String(
5953+
c.documentationComment, ast, r.template, sink,
5954+
parent: r);
5955+
},
5956+
),
58685957
'documentationFrom': Property(
58695958
getValue: (CT_ c) => c.documentationFrom,
58705959
renderVariable: (CT_ c, Property<CT_> self,
58715960
List<String> remainingNames) =>
58725961
self.renderSimpleVariable(
5873-
c, remainingNames, 'List<ModelElement>'),
5962+
c, remainingNames, 'List<DocumentationComment>'),
58745963
renderIterable: (CT_ c, RendererBase<CT_> r,
58755964
List<MustachioNode> ast, StringSink sink) {
5876-
return c.documentationFrom.map((e) => _render_ModelElement(
5965+
return c.documentationFrom.map((e) => renderSimple(
58775966
e, ast, r.template, sink,
5878-
parent: r));
5967+
parent: r,
5968+
getters: _invisibleGetters['DocumentationComment']));
58795969
},
58805970
),
58815971
'enclosingElement': Property(
@@ -5926,28 +6016,6 @@ class _Renderer_GetterSetterCombo extends RendererBase<GetterSetterCombo> {
59266016
self.renderSimpleVariable(c, remainingNames, 'bool'),
59276017
getBool: (CT_ c) => c.getterSetterBothAvailable == true,
59286018
),
5929-
'getterSetterDocumentationComment': Property(
5930-
getValue: (CT_ c) => c.getterSetterDocumentationComment,
5931-
renderVariable:
5932-
(CT_ c, Property<CT_> self, List<String> remainingNames) {
5933-
if (remainingNames.isEmpty) {
5934-
return self.getValue(c).toString();
5935-
}
5936-
var name = remainingNames.first;
5937-
var nextProperty =
5938-
_Renderer_String.propertyMap().getValue(name);
5939-
return nextProperty.renderVariable(self.getValue(c),
5940-
nextProperty, [...remainingNames.skip(1)]);
5941-
},
5942-
isNullValue: (CT_ c) =>
5943-
c.getterSetterDocumentationComment == null,
5944-
renderValue: (CT_ c, RendererBase<CT_> r,
5945-
List<MustachioNode> ast, StringSink sink) {
5946-
_render_String(c.getterSetterDocumentationComment, ast,
5947-
r.template, sink,
5948-
parent: r);
5949-
},
5950-
),
59516019
'hasAccessorsWithDocs': Property(
59526020
getValue: (CT_ c) => c.hasAccessorsWithDocs,
59536021
renderVariable: (CT_ c, Property<CT_> self,
@@ -9397,19 +9465,6 @@ class _Renderer_ModelElement extends RendererBase<ModelElement> {
93979465
getters: _invisibleGetters['CompilationUnitElement']);
93989466
},
93999467
),
9400-
'computeDocumentationFrom': Property(
9401-
getValue: (CT_ c) => c.computeDocumentationFrom,
9402-
renderVariable: (CT_ c, Property<CT_> self,
9403-
List<String> remainingNames) =>
9404-
self.renderSimpleVariable(
9405-
c, remainingNames, 'List<ModelElement>'),
9406-
renderIterable: (CT_ c, RendererBase<CT_> r,
9407-
List<MustachioNode> ast, StringSink sink) {
9408-
return c.computeDocumentationFrom.map((e) =>
9409-
_render_ModelElement(e, ast, r.template, sink,
9410-
parent: r));
9411-
},
9412-
),
94139468
'config': Property(
94149469
getValue: (CT_ c) => c.config,
94159470
renderVariable: (CT_ c, Property<CT_> self,
@@ -9476,8 +9531,8 @@ class _Renderer_ModelElement extends RendererBase<ModelElement> {
94769531
parent: r);
94779532
},
94789533
),
9479-
'documentationAsHtml': Property(
9480-
getValue: (CT_ c) => c.documentationAsHtml,
9534+
'documentationComment': Property(
9535+
getValue: (CT_ c) => c.documentationComment,
94819536
renderVariable:
94829537
(CT_ c, Property<CT_> self, List<String> remainingNames) {
94839538
if (remainingNames.isEmpty) {
@@ -9489,26 +9544,14 @@ class _Renderer_ModelElement extends RendererBase<ModelElement> {
94899544
return nextProperty.renderVariable(self.getValue(c),
94909545
nextProperty, [...remainingNames.skip(1)]);
94919546
},
9492-
isNullValue: (CT_ c) => c.documentationAsHtml == null,
9547+
isNullValue: (CT_ c) => c.documentationComment == null,
94939548
renderValue: (CT_ c, RendererBase<CT_> r,
94949549
List<MustachioNode> ast, StringSink sink) {
9495-
_render_String(c.documentationAsHtml, ast, r.template, sink,
9550+
_render_String(
9551+
c.documentationComment, ast, r.template, sink,
94969552
parent: r);
94979553
},
94989554
),
9499-
'documentationFrom': Property(
9500-
getValue: (CT_ c) => c.documentationFrom,
9501-
renderVariable: (CT_ c, Property<CT_> self,
9502-
List<String> remainingNames) =>
9503-
self.renderSimpleVariable(
9504-
c, remainingNames, 'List<ModelElement>'),
9505-
renderIterable: (CT_ c, RendererBase<CT_> r,
9506-
List<MustachioNode> ast, StringSink sink) {
9507-
return c.documentationFrom.map((e) => _render_ModelElement(
9508-
e, ast, r.template, sink,
9509-
parent: r));
9510-
},
9511-
),
95129555
'element': Property(
95139556
getValue: (CT_ c) => c.element,
95149557
renderVariable: (CT_ c, Property<CT_> self,
@@ -15207,6 +15250,27 @@ const _invisibleGetters = {
1520715250
'useBaseHref'
1520815251
},
1520915252
'DocumentLocation': {'hashCode', 'runtimeType', 'index'},
15253+
'Documentation': {
15254+
'hashCode',
15255+
'runtimeType',
15256+
'hasExtendedDocs',
15257+
'asHtml',
15258+
'asOneLiner',
15259+
'commentRefs'
15260+
},
15261+
'DocumentationComment': {
15262+
'documentationFrom',
15263+
'documentationAsHtml',
15264+
'elementDocumentation',
15265+
'documentationComment',
15266+
'hasNodoc',
15267+
'sourceFileName',
15268+
'fullyQualifiedNameWithoutLibrary',
15269+
'pathContext',
15270+
'modelElementRenderer',
15271+
'documentationLocal',
15272+
'needsPrecache'
15273+
},
1521015274
'Element': {
1521115275
'hashCode',
1521215276
'runtimeType',
@@ -15415,7 +15479,7 @@ const _invisibleGetters = {
1541515479
'hasAccessorsWithDocs',
1541615480
'getterSetterBothAvailable',
1541715481
'oneLineDoc',
15418-
'getterSetterDocumentationComment',
15482+
'documentationComment',
1541915483
'modelType',
1542015484
'isCallable',
1542115485
'hasParameters',

lib/src/model/accessor.dart

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,29 @@ class Accessor extends ModelElement implements EnclosedElement {
7272
return _sourceCode;
7373
}
7474

75+
bool _documentationCommentComputed = false;
76+
String _documentationComment;
7577
@override
76-
String computeDocumentationComment() {
77-
if (isSynthetic) {
78-
// If we're a setter, only display something if we have something different than the getter.
79-
// TODO(jcollins-g): modify analyzer to do this itself?
80-
if (isGetter ||
81-
definingCombo.hasNodoc ||
82-
(isSetter &&
83-
definingCombo.hasGetter &&
84-
definingCombo.getter.documentationComment !=
85-
definingCombo.documentationComment)) {
86-
return stripComments(definingCombo.documentationComment);
87-
} else {
88-
return '';
89-
}
90-
}
91-
return stripComments(super.computeDocumentationComment());
92-
}
78+
String get documentationComment => _documentationCommentComputed
79+
? _documentationComment
80+
: _documentationComment ??= () {
81+
_documentationCommentComputed = true;
82+
if (isSynthetic) {
83+
// If we're a setter, only display something if we have something different than the getter.
84+
// TODO(jcollins-g): modify analyzer to do this itself?
85+
if (isGetter ||
86+
definingCombo.hasNodoc ||
87+
(isSetter &&
88+
definingCombo.hasGetter &&
89+
definingCombo.getter.documentationComment !=
90+
definingCombo.documentationComment)) {
91+
return stripComments(definingCombo.documentationComment);
92+
} else {
93+
return '';
94+
}
95+
}
96+
return stripComments(super.documentationComment);
97+
}();
9398

9499
@override
95100
void warn(PackageWarning kind,

lib/src/model/container_member.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ mixin ContainerMember on ModelElement implements EnclosedElement {
7373
// TODO(jcollins-g): split Field documentation up between accessors
7474
// and resolve the pieces with different scopes. dart-lang/dartdoc#2693.
7575
// Until then, just pretend we're handling this correctly.
76-
yield documentationFrom.first.definingLibrary;
76+
yield (documentationFrom.first as ModelElement).definingLibrary;
7777
// TODO(jcollins-g): Wean users off of depending on canonical library
7878
// resolution. dart-lang/dartdoc#2696
7979
if (canonicalLibrary != null) yield canonicalLibrary;

0 commit comments

Comments
 (0)