diff options
author | Johan Dahlin <jdahlin@litl.com> | 2010-05-10 19:00:14 -0300 |
---|---|---|
committer | Johan Dahlin <johan@gnome.org> | 2010-05-27 10:13:33 -0300 |
commit | e0d017ac04190d8f5dac65005b69132bbeeb35dd (patch) | |
tree | 70a9b41c8fb1961794e1de303f0767788c7696f0 | |
parent | 15cfa49be6976c0d8a5574164feca6b0212a7f4a (diff) | |
download | gobject-introspection-e0d017ac04190d8f5dac65005b69132bbeeb35dd.tar.gz |
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
-rw-r--r-- | giscanner/annotationparser.py | 4 | ||||
-rw-r--r-- | tests/scanner/annotation-1.0-expected.gir | 3 | ||||
-rw-r--r-- | tests/scanner/annotation-1.0-expected.tgir | 3 | ||||
-rw-r--r-- | tests/scanner/annotation.c | 16 |
4 files changed, 26 insertions, 0 deletions
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py index 180de6be..ef60179b 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 25216d1a..ed3c3b97 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 94e8e85e..4f74b27c 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 e1376e4c..29e8b370 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)); } |