Skip to content
Merged
176 changes: 120 additions & 56 deletions lib/src/generator/templates.runtime_renderers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,27 @@ class _Renderer_Accessor extends RendererBase<Accessor> {
getters: _invisibleGetters['GetterSetterCombo']);
},
),
'documentationComment': Property(
getValue: (CT_ c) => c.documentationComment,
renderVariable:
(CT_ c, Property<CT_> self, List<String> remainingNames) {
if (remainingNames.isEmpty) {
return self.getValue(c).toString();
}
var name = remainingNames.first;
var nextProperty =
_Renderer_String.propertyMap().getValue(name);
return nextProperty.renderVariable(self.getValue(c),
nextProperty, [...remainingNames.skip(1)]);
},
isNullValue: (CT_ c) => c.documentationComment == null,
renderValue: (CT_ c, RendererBase<CT_> r,
List<MustachioNode> ast, StringSink sink) {
_render_String(
c.documentationComment, ast, r.template, sink,
parent: r);
},
),
'element': Property(
getValue: (CT_ c) => c.element,
renderVariable: (CT_ c, Property<CT_> self,
Expand Down Expand Up @@ -3907,6 +3928,26 @@ class _Renderer_DocumentationComment
_propertyMapCache.putIfAbsent(
CT_,
() => {
'documentationAsHtml': Property(
getValue: (CT_ c) => c.documentationAsHtml,
renderVariable:
(CT_ c, Property<CT_> self, List<String> remainingNames) {
if (remainingNames.isEmpty) {
return self.getValue(c).toString();
}
var name = remainingNames.first;
var nextProperty =
_Renderer_String.propertyMap().getValue(name);
return nextProperty.renderVariable(self.getValue(c),
nextProperty, [...remainingNames.skip(1)]);
},
isNullValue: (CT_ c) => c.documentationAsHtml == null,
renderValue: (CT_ c, RendererBase<CT_> r,
List<MustachioNode> ast, StringSink sink) {
_render_String(c.documentationAsHtml, ast, r.template, sink,
parent: r);
},
),
'documentationComment': Property(
getValue: (CT_ c) => c.documentationComment,
renderVariable:
Expand All @@ -3928,6 +3969,20 @@ class _Renderer_DocumentationComment
parent: r);
},
),
'documentationFrom': Property(
getValue: (CT_ c) => c.documentationFrom,
renderVariable: (CT_ c, Property<CT_> self,
List<String> remainingNames) =>
self.renderSimpleVariable(
c, remainingNames, 'List<DocumentationComment>'),
renderIterable: (CT_ c, RendererBase<CT_> r,
List<MustachioNode> ast, StringSink sink) {
return c.documentationFrom.map((e) => renderSimple(
e, ast, r.template, sink,
parent: r,
getters: _invisibleGetters['DocumentationComment']));
},
),
'documentationLocal': Property(
getValue: (CT_ c) => c.documentationLocal,
renderVariable:
Expand All @@ -3948,6 +4003,19 @@ class _Renderer_DocumentationComment
parent: r);
},
),
'elementDocumentation': Property(
getValue: (CT_ c) => c.elementDocumentation,
renderVariable: (CT_ c, Property<CT_> self,
List<String> remainingNames) =>
self.renderSimpleVariable(
c, remainingNames, 'Documentation'),
isNullValue: (CT_ c) => c.elementDocumentation == null,
renderValue: (CT_ c, RendererBase<CT_> r,
List<MustachioNode> ast, StringSink sink) {
renderSimple(c.elementDocumentation, ast, r.template, sink,
parent: r, getters: _invisibleGetters['Documentation']);
},
),
'fullyQualifiedNameWithoutLibrary': Property(
getValue: (CT_ c) => c.fullyQualifiedNameWithoutLibrary,
renderVariable:
Expand Down Expand Up @@ -5865,17 +5933,39 @@ class _Renderer_GetterSetterCombo extends RendererBase<GetterSetterCombo> {
parent: r);
},
),
'documentationComment': Property(
getValue: (CT_ c) => c.documentationComment,
renderVariable:
(CT_ c, Property<CT_> self, List<String> remainingNames) {
if (remainingNames.isEmpty) {
return self.getValue(c).toString();
}
var name = remainingNames.first;
var nextProperty =
_Renderer_String.propertyMap().getValue(name);
return nextProperty.renderVariable(self.getValue(c),
nextProperty, [...remainingNames.skip(1)]);
},
isNullValue: (CT_ c) => c.documentationComment == null,
renderValue: (CT_ c, RendererBase<CT_> r,
List<MustachioNode> ast, StringSink sink) {
_render_String(
c.documentationComment, ast, r.template, sink,
parent: r);
},
),
'documentationFrom': Property(
getValue: (CT_ c) => c.documentationFrom,
renderVariable: (CT_ c, Property<CT_> self,
List<String> remainingNames) =>
self.renderSimpleVariable(
c, remainingNames, 'List<ModelElement>'),
c, remainingNames, 'List<DocumentationComment>'),
renderIterable: (CT_ c, RendererBase<CT_> r,
List<MustachioNode> ast, StringSink sink) {
return c.documentationFrom.map((e) => _render_ModelElement(
return c.documentationFrom.map((e) => renderSimple(
e, ast, r.template, sink,
parent: r));
parent: r,
getters: _invisibleGetters['DocumentationComment']));
},
),
'enclosingElement': Property(
Expand Down Expand Up @@ -5926,28 +6016,6 @@ class _Renderer_GetterSetterCombo extends RendererBase<GetterSetterCombo> {
self.renderSimpleVariable(c, remainingNames, 'bool'),
getBool: (CT_ c) => c.getterSetterBothAvailable == true,
),
'getterSetterDocumentationComment': Property(
getValue: (CT_ c) => c.getterSetterDocumentationComment,
renderVariable:
(CT_ c, Property<CT_> self, List<String> remainingNames) {
if (remainingNames.isEmpty) {
return self.getValue(c).toString();
}
var name = remainingNames.first;
var nextProperty =
_Renderer_String.propertyMap().getValue(name);
return nextProperty.renderVariable(self.getValue(c),
nextProperty, [...remainingNames.skip(1)]);
},
isNullValue: (CT_ c) =>
c.getterSetterDocumentationComment == null,
renderValue: (CT_ c, RendererBase<CT_> r,
List<MustachioNode> ast, StringSink sink) {
_render_String(c.getterSetterDocumentationComment, ast,
r.template, sink,
parent: r);
},
),
'hasAccessorsWithDocs': Property(
getValue: (CT_ c) => c.hasAccessorsWithDocs,
renderVariable: (CT_ c, Property<CT_> self,
Expand Down Expand Up @@ -9397,19 +9465,6 @@ class _Renderer_ModelElement extends RendererBase<ModelElement> {
getters: _invisibleGetters['CompilationUnitElement']);
},
),
'computeDocumentationFrom': Property(
getValue: (CT_ c) => c.computeDocumentationFrom,
renderVariable: (CT_ c, Property<CT_> self,
List<String> remainingNames) =>
self.renderSimpleVariable(
c, remainingNames, 'List<ModelElement>'),
renderIterable: (CT_ c, RendererBase<CT_> r,
List<MustachioNode> ast, StringSink sink) {
return c.computeDocumentationFrom.map((e) =>
_render_ModelElement(e, ast, r.template, sink,
parent: r));
},
),
'config': Property(
getValue: (CT_ c) => c.config,
renderVariable: (CT_ c, Property<CT_> self,
Expand Down Expand Up @@ -9476,8 +9531,8 @@ class _Renderer_ModelElement extends RendererBase<ModelElement> {
parent: r);
},
),
'documentationAsHtml': Property(
getValue: (CT_ c) => c.documentationAsHtml,
'documentationComment': Property(
getValue: (CT_ c) => c.documentationComment,
renderVariable:
(CT_ c, Property<CT_> self, List<String> remainingNames) {
if (remainingNames.isEmpty) {
Expand All @@ -9489,26 +9544,14 @@ class _Renderer_ModelElement extends RendererBase<ModelElement> {
return nextProperty.renderVariable(self.getValue(c),
nextProperty, [...remainingNames.skip(1)]);
},
isNullValue: (CT_ c) => c.documentationAsHtml == null,
isNullValue: (CT_ c) => c.documentationComment == null,
renderValue: (CT_ c, RendererBase<CT_> r,
List<MustachioNode> ast, StringSink sink) {
_render_String(c.documentationAsHtml, ast, r.template, sink,
_render_String(
c.documentationComment, ast, r.template, sink,
parent: r);
},
),
'documentationFrom': Property(
getValue: (CT_ c) => c.documentationFrom,
renderVariable: (CT_ c, Property<CT_> self,
List<String> remainingNames) =>
self.renderSimpleVariable(
c, remainingNames, 'List<ModelElement>'),
renderIterable: (CT_ c, RendererBase<CT_> r,
List<MustachioNode> ast, StringSink sink) {
return c.documentationFrom.map((e) => _render_ModelElement(
e, ast, r.template, sink,
parent: r));
},
),
'element': Property(
getValue: (CT_ c) => c.element,
renderVariable: (CT_ c, Property<CT_> self,
Expand Down Expand Up @@ -15207,6 +15250,27 @@ const _invisibleGetters = {
'useBaseHref'
},
'DocumentLocation': {'hashCode', 'runtimeType', 'index'},
'Documentation': {
'hashCode',
'runtimeType',
'hasExtendedDocs',
'asHtml',
'asOneLiner',
'commentRefs'
},
'DocumentationComment': {
'documentationFrom',
'documentationAsHtml',
'elementDocumentation',
'documentationComment',
'hasNodoc',
'sourceFileName',
'fullyQualifiedNameWithoutLibrary',
'pathContext',
'modelElementRenderer',
'documentationLocal',
'needsPrecache'
},
'Element': {
'hashCode',
'runtimeType',
Expand Down Expand Up @@ -15415,7 +15479,7 @@ const _invisibleGetters = {
'hasAccessorsWithDocs',
'getterSetterBothAvailable',
'oneLineDoc',
'getterSetterDocumentationComment',
'documentationComment',
'modelType',
'isCallable',
'hasParameters',
Expand Down
39 changes: 22 additions & 17 deletions lib/src/model/accessor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,29 @@ class Accessor extends ModelElement implements EnclosedElement {
return _sourceCode;
}

bool _documentationCommentComputed = false;
String _documentationComment;
@override
String computeDocumentationComment() {
if (isSynthetic) {
// If we're a setter, only display something if we have something different than the getter.
// TODO(jcollins-g): modify analyzer to do this itself?
if (isGetter ||
definingCombo.hasNodoc ||
(isSetter &&
definingCombo.hasGetter &&
definingCombo.getter.documentationComment !=
definingCombo.documentationComment)) {
return stripComments(definingCombo.documentationComment);
} else {
return '';
}
}
return stripComments(super.computeDocumentationComment());
}
String get documentationComment => _documentationCommentComputed
? _documentationComment
: _documentationComment ??= () {
_documentationCommentComputed = true;
if (isSynthetic) {
// If we're a setter, only display something if we have something different than the getter.
// TODO(jcollins-g): modify analyzer to do this itself?
if (isGetter ||
definingCombo.hasNodoc ||
(isSetter &&
definingCombo.hasGetter &&
definingCombo.getter.documentationComment !=
definingCombo.documentationComment)) {
return stripComments(definingCombo.documentationComment);
} else {
return '';
}
}
return stripComments(super.documentationComment);
}();

@override
void warn(PackageWarning kind,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/container_member.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ mixin ContainerMember on ModelElement implements EnclosedElement {
// TODO(jcollins-g): split Field documentation up between accessors
// and resolve the pieces with different scopes. dart-lang/dartdoc#2693.
// Until then, just pretend we're handling this correctly.
yield documentationFrom.first.definingLibrary;
yield (documentationFrom.first as ModelElement).definingLibrary;
// TODO(jcollins-g): Wean users off of depending on canonical library
// resolution. dart-lang/dartdoc#2696
if (canonicalLibrary != null) yield canonicalLibrary;
Expand Down
Loading