]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Allow specifying the nick of enum values ba1258de7cc9e1dcd5c8068f04da245c13c0e6b2
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 8 Mar 2017 15:25:23 +0000 (16:25 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 17 May 2018 12:29:32 +0000 (14:29 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=625209

codegen/valaccodebasemodule.vala
codegen/valatyperegisterfunction.vala
tests/annotations/description.vala
vala/valaenumvalue.vala

index 0752a020937afa0602a71558c8954034736f13d8..4c1e60685c666c59f51408f8515dd6c3df56b033 100644 (file)
@@ -6311,10 +6311,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                return new CCodeConstant ("\"%s%s\"".printf (get_ccode_name (sig), (detail != null ? "::%s".printf (detail) : "")));
        }
 
-       public static CCodeConstant get_enum_value_canonical_cconstant (EnumValue ev) {
-               return new CCodeConstant ("\"%s\"".printf (ev.name.down ().replace ("_", "-")));
-       }
-
        public bool get_signal_has_emitter (Signal sig) {
                return sig.get_attribute ("HasEmitter") != null;
        }
index 8894117fcb4162fc4bcdab65e1c890ce9140ca04..9b7c46a2ff7bcb440011ef37c84c17f187c85ab5 100644 (file)
@@ -163,8 +163,8 @@ public abstract class Vala.TypeRegisterFunction {
                        foreach (EnumValue ev in en.get_values ()) {
                                clist_ev = new CCodeInitializerList ();
                                clist_ev.append (new CCodeConstant (get_ccode_name (ev)));
-                               clist_ev.append (new CCodeIdentifier ("\"%s\"".printf (get_ccode_name (ev))));
-                               clist_ev.append (CCodeBaseModule.get_enum_value_canonical_cconstant (ev));
+                               clist_ev.append (new CCodeConstant ("\"%s\"".printf (get_ccode_name (ev))));
+                               clist_ev.append (new CCodeConstant ("\"%s\"".printf (ev.nick)));
                                clist.append (clist_ev);
                        }
 
index 3556bbb6a477a6af69be2cdd005e8d281a716204..b30489598aa9ddcc3ee7b3dc8ef2bb16ec1c8ee8 100644 (file)
@@ -3,6 +3,11 @@ class Foo : Object {
        public int foo { get; set; }
 }
 
+enum Bar {
+       [Description (nick = "foo's nick")]
+       FOO
+}
+
 void main () {
        var foo = new Foo ();
        (unowned ParamSpec)[] properties = foo.get_class ().list_properties ();
@@ -11,4 +16,6 @@ void main () {
                assert (p.get_nick () == "foo's nick");
                assert (p.get_blurb () == "foo's blurb");
        }
+
+       assert (((EnumClass) typeof (Bar).class_ref ()).get_value_by_name (Bar.FOO.to_string ()).value_nick == "foo's nick");
 }
index 6d2f35bb16cb3675c8c62f86f40d0b44a0eb00b8..1352e6b031fe7ba3c77ab6d50993eb82a39cfb20 100644 (file)
@@ -26,6 +26,23 @@ using GLib;
  * Represents an enum member in the source code.
  */
 public class Vala.EnumValue : Constant {
+       /**
+        * The nick of this enum-value
+        */
+       public string nick {
+               get {
+                       if (_nick == null) {
+                               _nick = get_attribute_string ("Description", "nick");
+                               if (_nick == null) {
+                                       _nick = name.down ().replace ("_", "-");
+                               }
+                       }
+                       return _nick;
+               }
+       }
+
+       private string? _nick = null;
+
        /**
         * Creates a new enum value with the specified numerical representation.
         *