From 1b854d5910b4044d1fc7b81d1a7b7378be210115 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Sat, 18 May 2024 15:45:53 +0200 Subject: [PATCH] girwriter: Write default-value of properties --- codegen/valagirwriter.vala | 3 +++ tests/girwriter/GirTest-1.0.gir-expected | 4 ++-- tests/girwriter/girtest.vala | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala index 405f8a2e5..77388bb05 100644 --- a/codegen/valagirwriter.vala +++ b/codegen/valagirwriter.vala @@ -1488,6 +1488,9 @@ public class Vala.GIRWriter : CodeVisitor { } } } + if (prop.initializer != null && prop.initializer is Literal) { + buffer.append_printf (" default-value=\"%s\"", literal_expression_to_value_string (prop.initializer)); + } write_symbol_attributes (prop); buffer.append_printf (">\n"); indent++; diff --git a/tests/girwriter/GirTest-1.0.gir-expected b/tests/girwriter/GirTest-1.0.gir-expected index 786dd7784..0a22e2121 100644 --- a/tests/girwriter/GirTest-1.0.gir-expected +++ b/tests/girwriter/GirTest-1.0.gir-expected @@ -979,7 +979,7 @@ - + @@ -2458,7 +2458,7 @@ - + diff --git a/tests/girwriter/girtest.vala b/tests/girwriter/girtest.vala index 06a506505..20c87b746 100644 --- a/tests/girwriter/girtest.vala +++ b/tests/girwriter/girtest.vala @@ -130,7 +130,7 @@ namespace GirTest { } public interface InterfaceTest : Object { - public abstract int property { get; construct set; } + public abstract int property { get; construct set; default = 23; } internal abstract string internal_property { get; set; } public virtual void int8_in (int8 param) { } @@ -206,7 +206,7 @@ namespace GirTest { public string? nullable_field; - public string some_property { get; construct set; } + public string some_property { get; construct set; default = "foo"; } public string write_only_property { set; } -- 2.47.3