[gobject-introspection/ebassi/property-annotation: 17/19] Improve getter function matching heuristic
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection/ebassi/property-annotation: 17/19] Improve getter function matching heuristic
- Date: Wed, 28 Jul 2021 15:32:02 +0000 (UTC)
commit 03059895809eb7061175b90bf8231096ac59fdc8
Author: Emmanuele Bassi <ebassi gnome org>
Date: Tue Jul 27 11:43:06 2021 +0100
Improve getter function matching heuristic
Some readonly boolean properties in the form of 'has-foo' or 'is-bar'
expose a getter function in the form of `get_has_foo()` or
`get_is_bar()`, according to extant coding practices. We should ensure
we still check for those.
giscanner/maintransformer.py | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
---
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index b4d44d52..4e4a5573 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -1466,20 +1466,25 @@ method or constructor of some type."""
def _pair_property_accessors(self, node):
"""Look for accessor methods for class properties"""
for prop in node.properties:
- setter = prop.setter
- if setter is None:
+ if prop.setter is None:
normalized_name = prop.name.replace('-', '_')
if prop.writable and not prop.construct_only:
setter = 'set_' + normalized_name
- getter = prop.getter
- if getter is None:
+ else:
+ setter = None
+ else:
+ setter = prop.setter
+ if prop.getter is None:
if prop.readable:
+ getter = ['get_' + normalized_name]
# Heuristic: read-only properties can have getters that are
# just the property name, like: gtk_widget_has_focus()
if not prop.writable and prop.type.is_equiv(ast.TYPE_BOOLEAN):
- getter = normalized_name
- else:
- getter = 'get_' + normalized_name
+ getter.append(normalized_name)
+ else:
+ getter = []
+ else:
+ getter = [prop.getter]
for method in node.methods:
if setter is not None and method.name == setter:
if method.set_property is None:
@@ -1492,7 +1497,7 @@ method or constructor of some type."""
method.set_property = prop.name
prop.setter = method.name
continue
- if getter is not None and method.name == getter:
+ if getter is not [] and method.name in getter:
if method.get_property is None:
method.get_property = prop.name
elif method.get_property != prop.name:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]