summaryrefslogtreecommitdiff
path: root/vala/valacodenode.vala
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2021-12-15 21:42:53 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2021-12-15 21:42:53 +0100
commit92b2e9315f9946fdc1821570ee017d9afa6582a3 (patch)
treea9b0b8cccf41e556afecb4ee55a4e008c47cc6af /vala/valacodenode.vala
parent52c225d65cf0bb9d26040170e965a09c6d231da7 (diff)
downloadvala-92b2e9315f9946fdc1821570ee017d9afa6582a3.tar.gz
girparser: Avoid possibily creating duplicated attributes
Don't append an attribute without checking if there is an existing one. In case the attribute already exists append the new key/value pairs.
Diffstat (limited to 'vala/valacodenode.vala')
-rw-r--r--vala/valacodenode.vala17
1 files changed, 17 insertions, 0 deletions
diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala
index 05ba53a0a..4ca44c8d9 100644
--- a/vala/valacodenode.vala
+++ b/vala/valacodenode.vala
@@ -120,6 +120,23 @@ public abstract class Vala.CodeNode {
return null;
}
+ /**
+ * Add attribute and append key/value pairs to an existing one.
+ *
+ * @param a an attribute to add
+ */
+ public void add_attribute (Attribute a) {
+ unowned Attribute? old_a = get_attribute (a.name);
+ if (old_a == null) {
+ attributes.append (a);
+ } else {
+ var it = a.args.map_iterator ();
+ while (it.next ()) {
+ old_a.args.set (it.get_key (), it.get_value ());
+ }
+ }
+ }
+
unowned Attribute get_or_create_attribute (string name) {
unowned Attribute? a = get_attribute (name);
if (a == null) {