From e5d9ba75b3811d4d8614ece107b4afcdf56ec484 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Fri, 30 Aug 2024 06:11:03 -0700 Subject: [PATCH] Make getters and setters actually look like their declarations --- .../templates.aot_renderers_for_html.dart | 47 ++++------ lib/templates/_accessor_getter.html | 2 +- lib/templates/_accessor_setter.html | 5 +- test/templates/field_test.dart | 87 +++++++++++++++++++ 4 files changed, 107 insertions(+), 34 deletions(-) diff --git a/lib/src/generator/templates.aot_renderers_for_html.dart b/lib/src/generator/templates.aot_renderers_for_html.dart index 51a555c35b..887dbb129e 100644 --- a/lib/src/generator/templates.aot_renderers_for_html.dart +++ b/lib/src/generator/templates.aot_renderers_for_html.dart @@ -5195,7 +5195,6 @@ String _deduplicated_lib_templates__accessor_getter_html( buffer.writeln(); buffer.write('''
-
'''); buffer.write( @@ -5206,6 +5205,7 @@ String _deduplicated_lib_templates__accessor_getter_html( '''); buffer.write(context1.modelType.returnType.linkedName); buffer.write(''' + get '''); buffer.write( __deduplicated_lib_templates__accessor_getter_html_partial_name_summary_1( @@ -5344,17 +5344,20 @@ String _deduplicated_lib_templates__accessor_setter_html( context1)); buffer.writeln(); buffer.write(''' - void - '''); - buffer.write( - __deduplicated_lib_templates__accessor_setter_html_partial_name_summary_1( - context1)); - buffer.write('''('''); + set + '''); + buffer.writeEscaped(context1.definingCombo.name); + buffer.write(''' + ('''); buffer.write(context1.linkedParamsNoMetadata); buffer.write(''') '''); 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(''' @@ -5362,11 +5365,11 @@ String _deduplicated_lib_templates__accessor_setter_html( '''); 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(''' @@ -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(''''''); - buffer.writeEscaped(context1.name); - buffer.write(''''''); - - 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) { @@ -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) { @@ -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) { diff --git a/lib/templates/_accessor_getter.html b/lib/templates/_accessor_getter.html index ac0cf538df..bced920ae0 100644 --- a/lib/templates/_accessor_getter.html +++ b/lib/templates/_accessor_getter.html @@ -1,9 +1,9 @@ {{ #getter }}
-
{{ >annotations }} {{{ modelType.returnType.linkedName }}} + get {{ >name_summary }} {{ >attributes }}
diff --git a/lib/templates/_accessor_setter.html b/lib/templates/_accessor_setter.html index 5b7c89c22b..4365ee2843 100644 --- a/lib/templates/_accessor_setter.html +++ b/lib/templates/_accessor_setter.html @@ -3,8 +3,9 @@
{{ >annotations }} - void - {{ >name_summary }}({{{ linkedParamsNoMetadata }}}) + set + {{ definingCombo.name }} + ({{{ linkedParamsNoMetadata }}}) {{ >attributes }}
diff --git a/test/templates/field_test.dart b/test/templates/field_test.dart index 34c9dd8148..15519a85af 100644 --- a/test/templates/field_test.dart +++ b/test/templates/field_test.dart @@ -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('

f1 property'), + matches('
'), + matches('int'), + matches('get'), + matches('f1'), + ], + ); + } + + 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('

f1 property'), + matches('
'), + matches('int'), + matches('get'), + matches('f1'), + ], + ); + } + + void test_setter_signature() async { + await createPackageWithLibrary(''' +class C { + set f1(int value) {} +} +'''); + var f1Lines = readLines(['lib', 'C', 'f1.html']); + f1Lines.expectMainContentContainsAllInOrder( + [ + matches('
'), + matches('set'), + matches('f1'), + matches(r'\(' + '' + 'int ' + 'value' + r'\)' + ''), + ], + ); + } + + 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('
'), + matches('set'), + matches('f1'), + matches(r'\(' + '' + 'int ' + 'value' + r'\)' + ''), + ], + ); + } + // TODO(srawlins): Add rendering tests: // * how inherited fields look on subclass page ('inherited' feature) // * static fields