summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2016-11-11 20:04:06 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2016-11-11 20:21:27 +0100
commita9677aa57de0fe0fd5eb23938f562e4ba9b0556b (patch)
treeff0e7bca89d907c3b2f6eb566bcc464e418e6a84
parentcccf2ad9f2c6d3bb96af755bbb325bc27f232c10 (diff)
downloadvala-a9677aa57de0fe0fd5eb23938f562e4ba9b0556b.tar.gz
Move "blurb", "nick" and "notify" into Property
-rw-r--r--codegen/valaccodebasemodule.vala22
-rw-r--r--codegen/valagtypemodule.vala6
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/annotations/description.vala14
-rw-r--r--vala/valaproperty.vala45
5 files changed, 63 insertions, 25 deletions
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 4641aff08..3e4da4006 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 1b5c2f141..af7a8a481 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 abd60f0fc..1e6fd84c3 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 000000000..3556bbb6a
--- /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 19aad24be..bc6b18efc 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.