[vala/wip/ricotz: 3/3] Move "blurb", "nick" and "notify" into Property
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/ricotz: 3/3] Move "blurb", "nick" and "notify" into Property
- Date: Fri, 11 Nov 2016 19:26:36 +0000 (UTC)
commit a9677aa57de0fe0fd5eb23938f562e4ba9b0556b
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Fri Nov 11 20:04:06 2016 +0100
Move "blurb", "nick" and "notify" into Property
codegen/valaccodebasemodule.vala | 22 +----------------
codegen/valagtypemodule.vala | 6 +---
tests/Makefile.am | 1 +
tests/annotations/description.vala | 14 +++++++++++
vala/valaproperty.vala | 45 ++++++++++++++++++++++++++++++++++++
5 files changed, 63 insertions(+), 25 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 4641aff..3e4da40 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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) {
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 1b5c2f1..af7a8a4 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -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) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index abd60f0..1e6fd84 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
index 0000000..3556bbb
--- /dev/null
+++ b/tests/annotations/description.vala
@@ -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");
+ }
+}
diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala
index 19aad24..bc6b18e 100644
--- a/vala/valaproperty.vala
+++ b/vala/valaproperty.vala
@@ -108,6 +108,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
* themselves.
@@ -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.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]