diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2023-01-08 14:31:41 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2023-01-08 14:36:47 +0000 |
commit | 8c6dc5fa17874a9b6fefee07a8b69e4430975101 (patch) | |
tree | ed25107c79733390f297f8b4ed7d94a84b71d4a4 | |
parent | 790bd8a474c2820564afc57a60f20f3deb4e0d42 (diff) | |
download | gobject-introspection-8c6dc5fa17874a9b6fefee07a8b69e4430975101.tar.gz |
Add `default-value` annotation
An escape hatch to specify a freeform string for the default value of a
property.
Fixes: #4
-rw-r--r-- | docs/website/annotations/giannotations.rst | 4 | ||||
-rw-r--r-- | giscanner/annotationparser.py | 16 | ||||
-rw-r--r-- | giscanner/maintransformer.py | 4 | ||||
-rw-r--r-- | tests/scanner/Regress-1.0-expected.gir | 10 | ||||
-rw-r--r-- | tests/scanner/regress.c | 10 |
5 files changed, 37 insertions, 7 deletions
diff --git a/docs/website/annotations/giannotations.rst b/docs/website/annotations/giannotations.rst index 3e4bfa92..8099bd5b 100644 --- a/docs/website/annotations/giannotations.rst +++ b/docs/website/annotations/giannotations.rst @@ -129,6 +129,10 @@ Support for GObject objects - identifier (only applies to methods) - This signal is emitted by the given method - + * - ``(default-value VALUE)`` + - identifier (only applies to properties) + - The default value of a GObject property, as a freeform string + - :issue:`4` Support for GObject closures diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py index bce99804..3952b24b 100644 --- a/giscanner/annotationparser.py +++ b/giscanner/annotationparser.py @@ -193,6 +193,7 @@ ANN_ARRAY = 'array' ANN_ATTRIBUTES = 'attributes' ANN_CLOSURE = 'closure' ANN_CONSTRUCTOR = 'constructor' +ANN_DEFAULT_VALUE = 'default-value' ANN_DESTROY = 'destroy' ANN_ELEMENT_TYPE = 'element-type' ANN_EMITTER = 'emitter' @@ -228,6 +229,7 @@ GI_ANNS = [ANN_ALLOW_NONE, ANN_ATTRIBUTES, ANN_CLOSURE, ANN_CONSTRUCTOR, + ANN_DEFAULT_VALUE, ANN_DESTROY, ANN_ELEMENT_TYPE, ANN_EMITTER, @@ -788,6 +790,19 @@ class GtkDocAnnotatable(object): self._validate_annotation(position, ann_name, options, exact_n_options=0) + def _do_validate_default_value(self, position, ann_name, options): + ''' + Validate the ``(default-value)`` annotation. + + :param position: :class:`giscanner.message.Position` of the line in the source file + containing the annotation to be validated + :param ann_name: name of the annotation holding the options to validate + :param options: annotation options to validate + ''' + + # The 'default-value' annotation allows free form annotations. + pass + def _do_validate_destroy(self, position, ann_name, options): ''' Validate the ``(destroy)`` annotation. @@ -1167,6 +1182,7 @@ class GtkDocCommentBlock(GtkDocAnnotatable): valid_annotations = ( ANN_ATTRIBUTES, ANN_CONSTRUCTOR, + ANN_DEFAULT_VALUE, ANN_EMITTER, ANN_FOREIGN, ANN_GET_PROPERTY, diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 2004d254..285712c7 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -28,6 +28,7 @@ from .annotationparser import ( ANN_ATTRIBUTES, ANN_CLOSURE, ANN_CONSTRUCTOR, + ANN_DEFAULT_VALUE, ANN_DESTROY, ANN_ELEMENT_TYPE, ANN_EMITTER, @@ -963,6 +964,9 @@ class MainTransformer(object): getter = block.annotations.get(ANN_GETTER) if getter: prop.getter = getter[0] + default_value = block.annotations.get(ANN_DEFAULT_VALUE) + if default_value: + prop.default_value = default_value[0] def _apply_annotations_signal(self, parent, signal): names = [] diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir index 608f120c..d6ca9dc6 100644 --- a/tests/scanner/Regress-1.0-expected.gir +++ b/tests/scanner/Regress-1.0-expected.gir @@ -4870,7 +4870,10 @@ raise an error.</doc> default-value="1.000000"> <type name="gfloat" c:type="gfloat"/> </property> - <property name="gtype" writable="1" transfer-ownership="none"> + <property name="gtype" + writable="1" + transfer-ownership="none" + default-value="G_TYPE_INVALID"> <type name="GType" c:type="GType"/> </property> <property name="hash-table" writable="1" transfer-ownership="container"> @@ -4893,7 +4896,10 @@ raise an error.</doc> default-value="0"> <type name="gint" c:type="gint"/> </property> - <property name="list" writable="1" transfer-ownership="none"> + <property name="list" + writable="1" + transfer-ownership="none" + default-value="NULL"> <type name="GLib.List" c:type="gpointer"> <type name="utf8"/> </type> diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c index e21997de..15430bd1 100644 --- a/tests/scanner/regress.c +++ b/tests/scanner/regress.c @@ -2643,7 +2643,7 @@ regress_test_obj_class_init (RegressTestObjClass *klass) pspec); /** - * RegressTestObj:list: (type GLib.List(utf8)) (transfer none) + * RegressTestObj:list: (type GLib.List(utf8)) (transfer none) (default-value NULL) */ pspec = g_param_spec_pointer ("list", "GList property", @@ -2745,7 +2745,7 @@ regress_test_obj_class_init (RegressTestObjClass *klass) /** - * TestObj:gtype: + * RegressTestObj:gtype: (default-value G_TYPE_INVALID) */ pspec = g_param_spec_gtype ("gtype", "GType property", @@ -2757,7 +2757,7 @@ regress_test_obj_class_init (RegressTestObjClass *klass) pspec); /** - * TestObj:name-conflict: + * RegressTestObj:name-conflict: */ pspec = g_param_spec_int ("name-conflict", "name-conflict property", @@ -2771,7 +2771,7 @@ regress_test_obj_class_init (RegressTestObjClass *klass) pspec); /** - * TestObj:byte-array: + * RegressTestObj:byte-array: */ pspec = g_param_spec_boxed ("byte-array", "GByteArray property", @@ -2783,7 +2783,7 @@ regress_test_obj_class_init (RegressTestObjClass *klass) pspec); /** - * TestObj:write-only: + * RegressTestObj:write-only: */ pspec = g_param_spec_boolean ("write-only", "Write-only property", "A write-only bool property that resets the value of TestObj:int to 0 when true", |