[gobject-introspection/ebassi/property-annotation: 18/24] scanner: Add an heuristic for property getters




commit 194088c24796792fc13622d0f74a8b0ee819135b
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Jun 17 18:10:51 2021 +0100

    scanner: Add an heuristic for property getters
    
    If a property is boolean and read-only, the getter method can be the
    same as the property name, for instance:
    
      - gtk_widget_has_focus()
      - gtk_media_stream_has_audio()

 giscanner/maintransformer.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
---
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index dc8bd3c2..bca69697 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -1472,7 +1472,12 @@ method or constructor of some type."""
             else:
                 setter = 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
             else:
                 getter = None
             for method in node.methods:


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