]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girwriter: Write default-value of properties
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 18 May 2024 13:45:53 +0000 (15:45 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 18 May 2024 13:50:05 +0000 (15:50 +0200)
codegen/valagirwriter.vala
tests/girwriter/GirTest-1.0.gir-expected
tests/girwriter/girtest.vala

index 405f8a2e52f9a22041e80f2e8979dff7a2275038..77388bb0559c491ce7ea9b02d9b549923be431f7 100644 (file)
@@ -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++;
index 786dd7784e0f9368a1c8732c992dfa75222ec490..0a22e2121d03eb715356aae2093a06850d40559c 100644 (file)
                                </parameter>
                        </parameters>
                </virtual-method>
-               <property name="some-property" writable="1" construct="1">
+               <property name="some-property" writable="1" construct="1" default-value="foo">
                        <type name="utf8" c:type="gchar*"/>
                </property>
                <method name="get_some_property" c:identifier="gir_test_object_test_get_some_property">
                                <type name="none" c:type="void"/>
                        </return-value>
                </function>
-               <property name="property" writable="1" construct="1">
+               <property name="property" writable="1" construct="1" default-value="23">
                        <type name="gint" c:type="gint"/>
                </property>
                <method name="get_property" c:identifier="gir_test_interface_test_get_property">
index 06a5065052257e0585e6d0821c5b39a49fdfa505..20c87b74671226b2336998551f05fc214e7ffb26 100644 (file)
@@ -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; }