[gobject-introspection] Add type annotation for properties



commit e0d017ac04190d8f5dac65005b69132bbeeb35dd
Author: Johan Dahlin <jdahlin litl com>
Date:   Mon May 10 19:00:14 2010 -0300

    Add type annotation for properties
    
    Add type annotation syntax for GObject properties. This makes
    it possible to override the type of a property. For instance,
    this will allow function pointers with a G_TYPE_POINTER type set
    to be used from a language binding which reads the typelib information
    in addition g_object_class_find_property.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=618318

 giscanner/annotationparser.py              |    4 ++++
 tests/scanner/annotation-1.0-expected.gir  |    3 +++
 tests/scanner/annotation-1.0-expected.tgir |    3 +++
 tests/scanner/annotation.c                 |   16 ++++++++++++++++
 4 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index 180de6b..ef60179 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -52,6 +52,7 @@ TAG_RETURNS = 'returns'
 TAG_RETURNS_ALT = 'return value'
 TAG_ATTRIBUTES = 'attributes'
 TAG_RENAME_TO = 'rename to'
+TAG_TYPE = 'type'
 
 # Options - annotations for parameters and return values
 OPT_ALLOW_NONE = 'allow-none'
@@ -409,6 +410,9 @@ class AnnotationApplier(object):
         self._parse_node_common(prop, block)
         if block:
             prop.doc = block.comment
+        type_tag = self._get_tag(block, TAG_TYPE)
+        if type_tag:
+            prop.type = self._resolve(type_tag.value, prop.type)
 
     def _parse_callback(self, callback):
         block = self._blocks.get(callback.ctype)
diff --git a/tests/scanner/annotation-1.0-expected.gir b/tests/scanner/annotation-1.0-expected.gir
index 25216d1..ed3c3b9 100644
--- a/tests/scanner/annotation-1.0-expected.gir
+++ b/tests/scanner/annotation-1.0-expected.gir
@@ -484,6 +484,9 @@ type.">
           <type name="none" c:type="void"/>
         </return-value>
       </method>
+      <property name="function-property" writable="1" construct="1">
+        <type name="Callback" c:type="gpointer"/>
+      </property>
       <property name="string-property"
                 version="1.0"
                 deprecated="Use better-string-property instead"
diff --git a/tests/scanner/annotation-1.0-expected.tgir b/tests/scanner/annotation-1.0-expected.tgir
index 94e8e85..4f74b27 100644
--- a/tests/scanner/annotation-1.0-expected.tgir
+++ b/tests/scanner/annotation-1.0-expected.tgir
@@ -356,6 +356,9 @@
           <type name="none"/>
         </return-value>
       </method>
+      <property name="function-property" writable="1" construct="1">
+        <type name="Callback"/>
+      </property>
       <property name="string-property" writable="1" construct="1">
         <type name="utf8"/>
       </property>
diff --git a/tests/scanner/annotation.c b/tests/scanner/annotation.c
index e1376e4..29e8b37 100644
--- a/tests/scanner/annotation.c
+++ b/tests/scanner/annotation.c
@@ -7,6 +7,7 @@ G_DEFINE_TYPE (AnnotationObject, annotation_object, G_TYPE_OBJECT);
 enum {
   PROP_0,
   PROP_STRING_PROPERTY,
+  PROP_FUNCTION_PROPERTY
 };
 
 enum {
@@ -28,6 +29,8 @@ annotation_object_set_property (GObject         *object,
     {
     case PROP_STRING_PROPERTY:
       break;
+    case PROP_FUNCTION_PROPERTY:
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -44,6 +47,8 @@ annotation_object_get_property (GObject         *object,
     {
     case PROP_STRING_PROPERTY:
       break;
+    case PROP_FUNCTION_PROPERTY:
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -128,6 +133,17 @@ annotation_object_class_init (AnnotationObjectClass *klass)
                                                         "This property is a string",
                                                         NULL,
                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+  /**
+   * AnnotationObject:function-property:
+   *
+   * Type: AnnotationCallback
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_FUNCTION_PROPERTY,
+                                   g_param_spec_pointer ("function-property",
+                                                         "Function property",
+                                                         "This property is a function pointer",
+                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]