diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2021-06-16 19:17:27 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2021-08-05 17:47:29 +0100 |
commit | 3ec400b09fb15c9f7392b77b0c3fb324ee08beed (patch) | |
tree | 39776e85364d56a1b13c1a8773af6b771b6c14b3 /giscanner | |
parent | 700e8776b7942b204b86748d266c895b08d59823 (diff) | |
download | gobject-introspection-3ec400b09fb15c9f7392b77b0c3fb324ee08beed.tar.gz |
Add new annotations for property accessors
We introduce two new annotations:
- (set-property PROPERTY_NAME)
- (get-property PROPERTY_NAME)
These annotations are valid inside function blocks for methods on
objects and interfaces, and define whether a function is a property
accessor, e.g.:
/**
* gtk_widget_set_name: (set-property name)
* @self: ...
* @name: ...
*
* ...
*/
/**
* gtk_widget_get_name: (get-property name)
* @self: ...
*
* ...
*
* Returns: ...
*/
The annotations are transformed into the GIR data as attributes:
- glib:set-property="PROPERTY_NAME"
- glib:get-property="PROPERTY_NAME"
The underlying typelib data has had flags for setter and getter
functions for a while, but they have never been plugged into the GIR
data or the introspection scanner. Now they are; you can retrieve the
GIPropertyInfo from a GIFunctionInfo that has the GI_FUNCTION_IS_SETTER
or GI_FUNCTION_IS_GETTER flags set.
Fixes: #13
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/annotationparser.py | 35 | ||||
-rw-r--r-- | giscanner/ast.py | 2 | ||||
-rw-r--r-- | giscanner/girparser.py | 2 | ||||
-rw-r--r-- | giscanner/girwriter.py | 4 | ||||
-rw-r--r-- | giscanner/maintransformer.py | 17 |
5 files changed, 53 insertions, 7 deletions
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py index c0b30581..bf475d4c 100644 --- a/giscanner/annotationparser.py +++ b/giscanner/annotationparser.py @@ -196,6 +196,7 @@ ANN_CONSTRUCTOR = 'constructor' ANN_DESTROY = 'destroy' ANN_ELEMENT_TYPE = 'element-type' ANN_FOREIGN = 'foreign' +ANN_GET_PROPERTY = 'get-property' ANN_GET_VALUE_FUNC = 'get-value-func' ANN_IN = 'in' ANN_INOUT = 'inout' @@ -207,6 +208,7 @@ ANN_OUT = 'out' ANN_REF_FUNC = 'ref-func' ANN_RENAME_TO = 'rename-to' ANN_SCOPE = 'scope' +ANN_SET_PROPERTY = 'set-property' ANN_SET_VALUE_FUNC = 'set-value-func' ANN_SKIP = 'skip' ANN_TRANSFER = 'transfer' @@ -226,6 +228,7 @@ GI_ANNS = [ANN_ALLOW_NONE, ANN_DESTROY, ANN_ELEMENT_TYPE, ANN_FOREIGN, + ANN_GET_PROPERTY, ANN_GET_VALUE_FUNC, ANN_IN, ANN_INOUT, @@ -234,6 +237,7 @@ GI_ANNS = [ANN_ALLOW_NONE, ANN_REF_FUNC, ANN_RENAME_TO, ANN_SCOPE, + ANN_SET_PROPERTY, ANN_SET_VALUE_FUNC, ANN_SKIP, ANN_TRANSFER, @@ -812,6 +816,18 @@ class GtkDocAnnotatable(object): self._validate_annotation(position, ann_name, options, exact_n_options=0) + def _do_validate_get_property(self, position, ann_name, options): + ''' + Validate the ``(get-property)`` 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 + ''' + + self._validate_annotation(position, ann_name, options, exact_n_options=1) + def _do_validate_get_value_func(self, position, ann_name, options): ''' Validate the ``(value-func)`` annotation. @@ -947,6 +963,18 @@ class GtkDocAnnotatable(object): self._validate_annotation(position, ann_name, options, exact_n_options=1, choices=SCOPE_OPTIONS) + def _do_validate_set_property(self, position, ann_name, options): + ''' + Validate the ``(set-property)`` 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 + ''' + + self._validate_annotation(position, ann_name, options, exact_n_options=1) + def _do_validate_set_value_func(self, position, ann_name, options): ''' Validate the ``(value-func)`` annotation. @@ -1092,9 +1120,10 @@ class GtkDocCommentBlock(GtkDocAnnotatable): 'name', 'params', 'description', 'tags') #: Valid annotation names for the GTK-Doc comment block identifier part. - valid_annotations = (ANN_ATTRIBUTES, ANN_CONSTRUCTOR, ANN_FOREIGN, ANN_GET_VALUE_FUNC, - ANN_METHOD, ANN_REF_FUNC, ANN_RENAME_TO, ANN_SET_VALUE_FUNC, - ANN_SKIP, ANN_TRANSFER, ANN_TYPE, ANN_UNREF_FUNC, ANN_VALUE, ANN_VFUNC) + valid_annotations = (ANN_ATTRIBUTES, ANN_CONSTRUCTOR, ANN_FOREIGN, ANN_GET_PROPERTY, + ANN_GET_VALUE_FUNC, ANN_METHOD, ANN_REF_FUNC, ANN_RENAME_TO, + ANN_SET_PROPERTY, ANN_SET_VALUE_FUNC, ANN_SKIP, ANN_TRANSFER, + ANN_TYPE, ANN_UNREF_FUNC, ANN_VALUE, ANN_VFUNC) def __init__(self, name, position=None): GtkDocAnnotatable.__init__(self, position) diff --git a/giscanner/ast.py b/giscanner/ast.py index e11fc988..a85e8879 100644 --- a/giscanner/ast.py +++ b/giscanner/ast.py @@ -752,6 +752,8 @@ class Function(Callable): self.shadows = None # C symbol string self.moved_to = None # namespaced function name string self.internal_skipped = False # if True, this func will not be written to GIR + self.set_property = None # Property name + self.get_property = None # Property name def clone(self): clone = copy.copy(self) diff --git a/giscanner/girparser.py b/giscanner/girparser.py index 9f124d89..a20de210 100644 --- a/giscanner/girparser.py +++ b/giscanner/girparser.py @@ -382,6 +382,8 @@ class GIRParser(object): else: assert False + func.set_property = node.attrib.get(_glibns('set-property'), None) + func.get_property = node.attrib.get(_glibns('get-property'), None) func.shadows = node.attrib.get('shadows', None) func.shadowed_by = node.attrib.get('shadowed-by', None) func.moved_to = node.attrib.get('moved-to', None) diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py index d276e923..9551f18f 100644 --- a/giscanner/girwriter.py +++ b/giscanner/girwriter.py @@ -224,6 +224,10 @@ class GIRWriter(XMLWriter): attrs.append(('shadows', func.shadows)) if func.moved_to is not None: attrs.append(('moved-to', func.moved_to)) + if func.set_property is not None: + attrs.append(('glib:set-property', func.set_property)) + if func.get_property is not None: + attrs.append(('glib:get-property', func.get_property)) self._write_callable(func, tag_name, attrs) def _write_function_macro(self, macro): diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 9077a1d0..23073b4e 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -24,10 +24,11 @@ from . import message from .annotationparser import (TAG_DEPRECATED, TAG_SINCE, TAG_STABILITY, TAG_RETURNS) from .annotationparser import (ANN_ALLOW_NONE, ANN_ARRAY, ANN_ATTRIBUTES, ANN_CLOSURE, ANN_CONSTRUCTOR, ANN_DESTROY, ANN_ELEMENT_TYPE, ANN_FOREIGN, - ANN_GET_VALUE_FUNC, ANN_IN, ANN_INOUT, ANN_METHOD, ANN_OUT, - ANN_REF_FUNC, ANN_RENAME_TO, ANN_SCOPE, ANN_SET_VALUE_FUNC, - ANN_SKIP, ANN_TRANSFER, ANN_TYPE, ANN_UNREF_FUNC, ANN_VALUE, - ANN_VFUNC, ANN_NULLABLE, ANN_OPTIONAL, ANN_NOT) + ANN_GET_PROPERTY, ANN_GET_VALUE_FUNC, ANN_IN, ANN_INOUT, + ANN_METHOD, ANN_OUT, ANN_REF_FUNC, ANN_RENAME_TO, ANN_SCOPE, + ANN_SET_PROPERTY, ANN_SET_VALUE_FUNC, ANN_SKIP, ANN_TRANSFER, + ANN_TYPE, ANN_UNREF_FUNC, ANN_VALUE, ANN_VFUNC, ANN_NULLABLE, + ANN_OPTIONAL, ANN_NOT) from .annotationparser import (OPT_ARRAY_FIXED_SIZE, OPT_ARRAY_LENGTH, OPT_ARRAY_ZERO_TERMINATED, OPT_OUT_CALLEE_ALLOCATES, OPT_OUT_CALLER_ALLOCATES, OPT_TRANSFER_CONTAINER, OPT_TRANSFER_FLOATING, OPT_TRANSFER_NONE) @@ -773,6 +774,14 @@ class MainTransformer(object): if ANN_METHOD in block.annotations: node.is_method = True + set_property = block.annotations.get(ANN_SET_PROPERTY) + if set_property is not None and isinstance(node, ast.Function): + node.set_property = set_property[0] + + get_property = block.annotations.get(ANN_GET_PROPERTY) + if get_property is not None and isinstance(node, ast.Function): + node.get_property = get_property[0] + def _apply_annotations_alias(self, node, chain): block = self._get_block(node) self._apply_annotations_annotated(node, block) |