]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Move "blurb", "nick" and "notify" into Property
authorRico Tzschichholz <ricotz@ubuntu.com>
Fri, 11 Nov 2016 19:04:06 +0000 (20:04 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 11 Nov 2016 19:21:27 +0000 (20:21 +0100)
codegen/valaccodebasemodule.vala
codegen/valagtypemodule.vala
tests/Makefile.am
tests/annotations/description.vala [new file with mode: 0644]
vala/valaproperty.vala

index 4641aff08bae7eed20a54a46a15a81d890275c77..3e4da4006faa0f68bf14be13226be2c725ca8cb3 100644 (file)
@@ -1770,7 +1770,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                        // notify on property changes
                        if (is_gobject_property (prop) &&
-                           get_ccode_notify (prop) &&
+                           prop.notify &&
                            (acc.writable || acc.construction)) {
                                var notify_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_notify"));
                                notify_call.add_argument (new CCodeCastExpression (new CCodeIdentifier ("self"), "GObject *"));
@@ -6393,26 +6393,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                return get_ccode_attribute(m).sentinel;
        }
 
-       public static bool get_ccode_notify (Property prop) {
-               return prop.get_attribute_bool ("CCode", "notify", true);
-       }
-
-       public static string get_ccode_nick (Property prop) {
-               var nick = prop.get_attribute_string ("Description", "nick");
-               if (nick == null) {
-                       nick = prop.name.replace ("_", "-");
-               }
-               return nick;
-       }
-
-       public static string get_ccode_blurb (Property prop) {
-               var blurb = prop.get_attribute_string ("Description", "blurb");
-               if (blurb == null) {
-                       blurb = prop.name.replace ("_", "-");
-               }
-               return blurb;
-       }
-
        public CCodeDeclaratorSuffix? get_ccode_declarator_suffix (DataType type) {
                var array_type = type as ArrayType;
                if (array_type != null) {
index 1b5c2f1412f2aa844702901e1963a1edfadd0b91..af7a8a4811e57de9aaed182b74ab509e42fa63a5 100644 (file)
@@ -1713,10 +1713,8 @@ public class Vala.GTypeModule : GErrorModule {
        public override CCodeFunctionCall get_param_spec (Property prop) {
                var cspec = new CCodeFunctionCall ();
                cspec.add_argument (get_property_canonical_cconstant (prop));
-               var nick = get_ccode_nick (prop);
-               var blurb = get_ccode_blurb (prop);
-               cspec.add_argument (new CCodeConstant ("\"%s\"".printf (nick)));
-               cspec.add_argument (new CCodeConstant ("\"%s\"".printf (blurb)));
+               cspec.add_argument (new CCodeConstant ("\"%s\"".printf (prop.nick)));
+               cspec.add_argument (new CCodeConstant ("\"%s\"".printf (prop.blurb)));
 
 
                if (prop.property_type.data_type is Class || prop.property_type.data_type is Interface) {
index abd60f0fc60f496f1103505fb165e16b91e41719..1e6fd84c3b5a4961d318e62265009bd2706d189e 100644 (file)
@@ -245,6 +245,7 @@ TESTS = \
        gir/bug667751.test \
        gir/bug742012.test \
        annotations/deprecated.vala \
+       annotations/description.vala \
        $(NULL)
 
 check-TESTS: $(TESTS)
diff --git a/tests/annotations/description.vala b/tests/annotations/description.vala
new file mode 100644 (file)
index 0000000..3556bbb
--- /dev/null
@@ -0,0 +1,14 @@
+class Foo : Object {
+       [Description (nick = "foo's nick", blurb = "foo's blurb")]
+       public int foo { get; set; }
+}
+
+void main () {
+       var foo = new Foo ();
+       (unowned ParamSpec)[] properties = foo.get_class ().list_properties ();
+       foreach (unowned ParamSpec p in properties) {
+               assert (p.get_name () == "foo");
+               assert (p.get_nick () == "foo's nick");
+               assert (p.get_blurb () == "foo's blurb");
+       }
+}
index 19aad24be9de0ff727f9ef4feb0d471295a43c5c..bc6b18efc8cc1b04df6bae626e2b0a74389ac2c6 100644 (file)
@@ -107,6 +107,48 @@ public class Vala.Property : Symbol, Lockable {
         */
        public MemberBinding binding { get; set; default = MemberBinding.INSTANCE; }
 
+       /**
+        * The nick of this property
+        */
+       public string nick {
+               get {
+                       if (_nick == null) {
+                               _nick = get_attribute_string ("Description", "nick");
+                               if (_nick == null) {
+                                       _nick = name.replace ("_", "-");
+                               }
+                       }
+                       return _nick;
+               }
+       }
+
+       /**
+        * The blurb of this property
+        */
+       public string blurb {
+               get {
+                       if (_blurb == null) {
+                               _blurb = get_attribute_string ("Description", "blurb");
+                               if (_blurb == null) {
+                                       _blurb = name.replace ("_", "-");
+                               }
+                       }
+                       return _blurb;
+               }
+       }
+
+       /**
+        * Specifies whether this a property triggers a notify.
+        */
+       public bool notify {
+               get {
+                       if (_notify == null) {
+                               _notify = get_attribute_bool ("CCode", "notify", true);
+                       }
+                       return _notify;
+               }
+       }
+
        /**
         * Specifies the virtual or abstract property this property overrides.
         * Reference must be weak as virtual properties set base_property to
@@ -153,6 +195,9 @@ public class Vala.Property : Symbol, Lockable {
        private bool base_properties_valid;
        PropertyAccessor? _get_accessor;
        PropertyAccessor? _set_accessor;
+       private string? _nick;
+       private string? _blurb;
+       private bool? _notify;
 
        /**
         * Creates a new property.