Skip to content

Commit e5d9ba7

Browse files
committed
Make getters and setters actually look like their declarations
1 parent b47a0c2 commit e5d9ba7

File tree

4 files changed

+107
-34
lines changed

4 files changed

+107
-34
lines changed

lib/src/generator/templates.aot_renderers_for_html.dart

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5195,7 +5195,6 @@ String _deduplicated_lib_templates__accessor_getter_html(
51955195
buffer.writeln();
51965196
buffer.write('''
51975197
<section id="getter">
5198-
51995198
<section class="multi-line-signature">
52005199
''');
52015200
buffer.write(
@@ -5206,6 +5205,7 @@ String _deduplicated_lib_templates__accessor_getter_html(
52065205
<span class="returntype">''');
52075206
buffer.write(context1.modelType.returnType.linkedName);
52085207
buffer.write('''</span>
5208+
get
52095209
''');
52105210
buffer.write(
52115211
__deduplicated_lib_templates__accessor_getter_html_partial_name_summary_1(
@@ -5344,29 +5344,32 @@ String _deduplicated_lib_templates__accessor_setter_html(
53445344
context1));
53455345
buffer.writeln();
53465346
buffer.write('''
5347-
<span class="returntype">void</span>
5348-
''');
5349-
buffer.write(
5350-
__deduplicated_lib_templates__accessor_setter_html_partial_name_summary_1(
5351-
context1));
5352-
buffer.write('''<span class="signature">(<wbr>''');
5347+
set
5348+
<span class="name ''');
5349+
if (context1.isDeprecated) {
5350+
buffer.write('''deprecated''');
5351+
}
5352+
buffer.write('''">''');
5353+
buffer.writeEscaped(context1.definingCombo.name);
5354+
buffer.write('''</span>
5355+
<span class="signature">(<wbr>''');
53535356
buffer.write(context1.linkedParamsNoMetadata);
53545357
buffer.write(''')</span>
53555358
''');
53565359
buffer.write(
5357-
__deduplicated_lib_templates__accessor_setter_html_partial_attributes_2(
5360+
__deduplicated_lib_templates__accessor_setter_html_partial_attributes_1(
53585361
context1));
53595362
buffer.writeln();
53605363
buffer.write('''
53615364
</section>
53625365
53635366
''');
53645367
buffer.write(
5365-
__deduplicated_lib_templates__accessor_setter_html_partial_documentation_3(
5368+
__deduplicated_lib_templates__accessor_setter_html_partial_documentation_2(
53665369
context1));
53675370
buffer.write('\n ');
53685371
buffer.write(
5369-
__deduplicated_lib_templates__accessor_setter_html_partial_source_code_4(
5372+
__deduplicated_lib_templates__accessor_setter_html_partial_source_code_3(
53705373
context1));
53715374
buffer.writeln();
53725375
buffer.write('''
@@ -5402,25 +5405,7 @@ String __deduplicated_lib_templates__accessor_setter_html_partial_annotations_0(
54025405
return buffer.toString();
54035406
}
54045407

5405-
String
5406-
__deduplicated_lib_templates__accessor_setter_html_partial_name_summary_1(
5407-
Accessor context1) {
5408-
final buffer = StringBuffer();
5409-
if (context1.isConst) {
5410-
buffer.write('''const ''');
5411-
}
5412-
buffer.write('''<span class="name ''');
5413-
if (context1.isDeprecated) {
5414-
buffer.write('''deprecated''');
5415-
}
5416-
buffer.write('''">''');
5417-
buffer.writeEscaped(context1.name);
5418-
buffer.write('''</span>''');
5419-
5420-
return buffer.toString();
5421-
}
5422-
5423-
String __deduplicated_lib_templates__accessor_setter_html_partial_attributes_2(
5408+
String __deduplicated_lib_templates__accessor_setter_html_partial_attributes_1(
54245409
Accessor context1) {
54255410
final buffer = StringBuffer();
54265411
if (context1.hasAttributes) {
@@ -5434,7 +5419,7 @@ String __deduplicated_lib_templates__accessor_setter_html_partial_attributes_2(
54345419
}
54355420

54365421
String
5437-
__deduplicated_lib_templates__accessor_setter_html_partial_documentation_3(
5422+
__deduplicated_lib_templates__accessor_setter_html_partial_documentation_2(
54385423
Accessor context1) {
54395424
final buffer = StringBuffer();
54405425
if (context1.hasDocumentation) {
@@ -5452,7 +5437,7 @@ String
54525437
return buffer.toString();
54535438
}
54545439

5455-
String __deduplicated_lib_templates__accessor_setter_html_partial_source_code_4(
5440+
String __deduplicated_lib_templates__accessor_setter_html_partial_source_code_3(
54565441
Accessor context1) {
54575442
final buffer = StringBuffer();
54585443
if (context1.hasSourceCode) {

lib/templates/_accessor_getter.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{{ #getter }}
22
<section id="getter">
3-
43
<section class="multi-line-signature">
54
{{ >annotations }}
65
<span class="returntype">{{{ modelType.returnType.linkedName }}}</span>
6+
get
77
{{ >name_summary }}
88
{{ >attributes }}
99
</section>

lib/templates/_accessor_setter.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
<section class="multi-line-signature">
55
{{ >annotations }}
6-
<span class="returntype">void</span>
7-
{{ >name_summary }}<span class="signature">(<wbr>{{{ linkedParamsNoMetadata }}})</span>
6+
set
7+
<span class="name {{#isDeprecated}}deprecated{{/isDeprecated}}">{{ definingCombo.name }}</span>
8+
<span class="signature">(<wbr>{{{ linkedParamsNoMetadata }}})</span>
89
{{ >attributes }}
910
</section>
1011

test/templates/field_test.dart

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,93 @@ extension type ET(
9191
);
9292
}
9393

94+
void test_getter_signature() async {
95+
await createPackageWithLibrary('''
96+
class C {
97+
int get f1 => 1;
98+
}
99+
''');
100+
var f1Lines = readLines(['lib', 'C', 'f1.html']);
101+
f1Lines.expectMainContentContainsAllInOrder(
102+
[
103+
matches('<h1><span class="kind-property">f1</span> property'),
104+
matches('<section class="multi-line-signature">'),
105+
matches('<span class="returntype">int</span>'),
106+
matches('get'),
107+
matches('<span class="name ">f1</span>'),
108+
],
109+
);
110+
}
111+
112+
void test_getter_overridingProperty_signature() async {
113+
await createPackageWithLibrary('''
114+
class C {
115+
int f1 = 0;
116+
}
117+
class D extends C {
118+
@override
119+
int get f1 => 1;
120+
}
121+
''');
122+
var f1Lines = readLines(['lib', 'D', 'f1.html']);
123+
f1Lines.expectMainContentContainsAllInOrder(
124+
[
125+
matches('<h1><span class="kind-property">f1</span> property'),
126+
matches('<section class="multi-line-signature">'),
127+
matches('<span class="returntype">int</span>'),
128+
matches('get'),
129+
matches('<span class="name ">f1</span>'),
130+
],
131+
);
132+
}
133+
134+
void test_setter_signature() async {
135+
await createPackageWithLibrary('''
136+
class C {
137+
set f1(int value) {}
138+
}
139+
''');
140+
var f1Lines = readLines(['lib', 'C', 'f1.html']);
141+
f1Lines.expectMainContentContainsAllInOrder(
142+
[
143+
matches('<section class="multi-line-signature">'),
144+
matches('set'),
145+
matches('<span class="name ">f1</span>'),
146+
matches(r'<span class="signature">\('
147+
'<wbr><span class="parameter" id="f1=-param-value">'
148+
'<span class="type-annotation">int</span> '
149+
'<span class="parameter-name">value</span>'
150+
r'</span>\)'
151+
'</span>'),
152+
],
153+
);
154+
}
155+
156+
void test_setter_overridingProperty_signature() async {
157+
await createPackageWithLibrary('''
158+
class C {
159+
int f1 = 0;
160+
}
161+
class D extends C {
162+
set f1(int value) {}
163+
}
164+
''');
165+
var f1Lines = readLines(['lib', 'D', 'f1.html']);
166+
f1Lines.expectMainContentContainsAllInOrder(
167+
[
168+
matches('<section class="multi-line-signature">'),
169+
matches('set'),
170+
matches('<span class="name ">f1</span>'),
171+
matches(r'<span class="signature">\('
172+
'<wbr><span class="parameter" id="f1=-param-value">'
173+
'<span class="type-annotation">int</span> '
174+
'<span class="parameter-name">value</span>'
175+
r'</span>\)'
176+
'</span>'),
177+
],
178+
);
179+
}
180+
94181
// TODO(srawlins): Add rendering tests:
95182
// * how inherited fields look on subclass page ('inherited' feature)
96183
// * static fields

0 commit comments

Comments
 (0)