Skip to content

Commit

Permalink
Make getters and setters actually look like their declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins committed Aug 30, 2024
1 parent b47a0c2 commit e5d9ba7
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 34 deletions.
47 changes: 16 additions & 31 deletions lib/src/generator/templates.aot_renderers_for_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5195,7 +5195,6 @@ String _deduplicated_lib_templates__accessor_getter_html(
buffer.writeln();
buffer.write('''
<section id="getter">
<section class="multi-line-signature">
''');
buffer.write(
Expand All @@ -5206,6 +5205,7 @@ String _deduplicated_lib_templates__accessor_getter_html(
<span class="returntype">''');
buffer.write(context1.modelType.returnType.linkedName);
buffer.write('''</span>
get
''');
buffer.write(
__deduplicated_lib_templates__accessor_getter_html_partial_name_summary_1(
Expand Down Expand Up @@ -5344,29 +5344,32 @@ String _deduplicated_lib_templates__accessor_setter_html(
context1));
buffer.writeln();
buffer.write('''
<span class="returntype">void</span>
''');
buffer.write(
__deduplicated_lib_templates__accessor_setter_html_partial_name_summary_1(
context1));
buffer.write('''<span class="signature">(<wbr>''');
set
<span class="name ''');
if (context1.isDeprecated) {
buffer.write('''deprecated''');
}
buffer.write('''">''');
buffer.writeEscaped(context1.definingCombo.name);
buffer.write('''</span>
<span class="signature">(<wbr>''');
buffer.write(context1.linkedParamsNoMetadata);
buffer.write(''')</span>
''');
buffer.write(
__deduplicated_lib_templates__accessor_setter_html_partial_attributes_2(
__deduplicated_lib_templates__accessor_setter_html_partial_attributes_1(
context1));
buffer.writeln();
buffer.write('''
</section>
''');
buffer.write(
__deduplicated_lib_templates__accessor_setter_html_partial_documentation_3(
__deduplicated_lib_templates__accessor_setter_html_partial_documentation_2(
context1));
buffer.write('\n ');
buffer.write(
__deduplicated_lib_templates__accessor_setter_html_partial_source_code_4(
__deduplicated_lib_templates__accessor_setter_html_partial_source_code_3(
context1));
buffer.writeln();
buffer.write('''
Expand Down Expand Up @@ -5402,25 +5405,7 @@ String __deduplicated_lib_templates__accessor_setter_html_partial_annotations_0(
return buffer.toString();
}

String
__deduplicated_lib_templates__accessor_setter_html_partial_name_summary_1(
Accessor context1) {
final buffer = StringBuffer();
if (context1.isConst) {
buffer.write('''const ''');
}
buffer.write('''<span class="name ''');
if (context1.isDeprecated) {
buffer.write('''deprecated''');
}
buffer.write('''">''');
buffer.writeEscaped(context1.name);
buffer.write('''</span>''');

return buffer.toString();
}

String __deduplicated_lib_templates__accessor_setter_html_partial_attributes_2(
String __deduplicated_lib_templates__accessor_setter_html_partial_attributes_1(
Accessor context1) {
final buffer = StringBuffer();
if (context1.hasAttributes) {
Expand All @@ -5434,7 +5419,7 @@ String __deduplicated_lib_templates__accessor_setter_html_partial_attributes_2(
}

String
__deduplicated_lib_templates__accessor_setter_html_partial_documentation_3(
__deduplicated_lib_templates__accessor_setter_html_partial_documentation_2(
Accessor context1) {
final buffer = StringBuffer();
if (context1.hasDocumentation) {
Expand All @@ -5452,7 +5437,7 @@ String
return buffer.toString();
}

String __deduplicated_lib_templates__accessor_setter_html_partial_source_code_4(
String __deduplicated_lib_templates__accessor_setter_html_partial_source_code_3(
Accessor context1) {
final buffer = StringBuffer();
if (context1.hasSourceCode) {
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/_accessor_getter.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{ #getter }}
<section id="getter">

<section class="multi-line-signature">
{{ >annotations }}
<span class="returntype">{{{ modelType.returnType.linkedName }}}</span>
get
{{ >name_summary }}
{{ >attributes }}
</section>
Expand Down
5 changes: 3 additions & 2 deletions lib/templates/_accessor_setter.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

<section class="multi-line-signature">
{{ >annotations }}
<span class="returntype">void</span>
{{ >name_summary }}<span class="signature">(<wbr>{{{ linkedParamsNoMetadata }}})</span>
set
<span class="name {{#isDeprecated}}deprecated{{/isDeprecated}}">{{ definingCombo.name }}</span>
<span class="signature">(<wbr>{{{ linkedParamsNoMetadata }}})</span>
{{ >attributes }}
</section>

Expand Down
87 changes: 87 additions & 0 deletions test/templates/field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,93 @@ extension type ET(
);
}

void test_getter_signature() async {
await createPackageWithLibrary('''
class C {
int get f1 => 1;
}
''');
var f1Lines = readLines(['lib', 'C', 'f1.html']);
f1Lines.expectMainContentContainsAllInOrder(
[
matches('<h1><span class="kind-property">f1</span> property'),
matches('<section class="multi-line-signature">'),
matches('<span class="returntype">int</span>'),
matches('get'),
matches('<span class="name ">f1</span>'),
],
);
}

void test_getter_overridingProperty_signature() async {
await createPackageWithLibrary('''
class C {
int f1 = 0;
}
class D extends C {
@override
int get f1 => 1;
}
''');
var f1Lines = readLines(['lib', 'D', 'f1.html']);
f1Lines.expectMainContentContainsAllInOrder(
[
matches('<h1><span class="kind-property">f1</span> property'),
matches('<section class="multi-line-signature">'),
matches('<span class="returntype">int</span>'),
matches('get'),
matches('<span class="name ">f1</span>'),
],
);
}

void test_setter_signature() async {
await createPackageWithLibrary('''
class C {
set f1(int value) {}
}
''');
var f1Lines = readLines(['lib', 'C', 'f1.html']);
f1Lines.expectMainContentContainsAllInOrder(
[
matches('<section class="multi-line-signature">'),
matches('set'),
matches('<span class="name ">f1</span>'),
matches(r'<span class="signature">\('
'<wbr><span class="parameter" id="f1=-param-value">'
'<span class="type-annotation">int</span> '
'<span class="parameter-name">value</span>'
r'</span>\)'
'</span>'),
],
);
}

void test_setter_overridingProperty_signature() async {
await createPackageWithLibrary('''
class C {
int f1 = 0;
}
class D extends C {
set f1(int value) {}
}
''');
var f1Lines = readLines(['lib', 'D', 'f1.html']);
f1Lines.expectMainContentContainsAllInOrder(
[
matches('<section class="multi-line-signature">'),
matches('set'),
matches('<span class="name ">f1</span>'),
matches(r'<span class="signature">\('
'<wbr><span class="parameter" id="f1=-param-value">'
'<span class="type-annotation">int</span> '
'<span class="parameter-name">value</span>'
r'</span>\)'
'</span>'),
],
);
}

// TODO(srawlins): Add rendering tests:
// * how inherited fields look on subclass page ('inherited' feature)
// * static fields
Expand Down

0 comments on commit e5d9ba7

Please sign in to comment.