Skip to content

Commit

Permalink
girwriter: Write default-value of properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ricotz committed May 18, 2024
1 parent 5245a38 commit 1b854d5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions codegen/valagirwriter.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
4 changes: 2 additions & 2 deletions tests/girwriter/GirTest-1.0.gir-expected
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@
</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">
Expand Down Expand Up @@ -2458,7 +2458,7 @@
<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">
Expand Down
4 changes: 2 additions & 2 deletions tests/girwriter/girtest.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
Expand Down Expand Up @@ -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; }

Expand Down

0 comments on commit 1b854d5

Please sign in to comment.