[gobject-introspection] giscanner: Test fixups for field annotations and documentation



commit 288b339edf262f1dba4e87a9faef46cc79749bd5
Author: Stef Walter <stefw gnome org>
Date:   Mon Oct 28 22:13:47 2013 +0100

    giscanner: Test fixups for field annotations and documentation
    
    Related to: https://bugzilla.gnome.org/show_bug.cgi?id=710561

 giscanner/girparser.py                             |   19 +++++++++-----
 .../Regress.AnnotationFields.page                  |   25 ++++++++++++++++++++
 .../Regress.AnnotationFields.page                  |   25 ++++++++++++++++++++
 tests/scanner/Utility-1.0-expected.gir             |    1 +
 4 files changed, 63 insertions(+), 7 deletions(-)
---
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index d01e753..25e9035 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -331,7 +331,7 @@ class GIRParser(object):
             for i, paramnode in enumerate(self._find_children(parameters_node,
                                                               _corens('parameter'))):
                 param = parameters[i]
-                self._parse_type_second_pass(func, paramnode, param.type)
+                self._parse_type_array_length(parameters, paramnode, param.type)
                 closure = paramnode.attrib.get('closure')
                 if closure:
                     idx = int(closure)
@@ -343,7 +343,7 @@ class GIRParser(object):
                     assert idx < len(parameters), "%d >= %d" % (idx, len(parameters))
                     param.destroy_name = parameters[idx].argname
 
-        self._parse_type_second_pass(func, returnnode, retval.type)
+        self._parse_type_array_length(parameters, returnnode, retval.type)
 
         self._parse_generic_attribs(node, func)
 
@@ -375,6 +375,9 @@ class GIRParser(object):
                 func = self._parse_function_common(method, ast.Function, compound)
                 func.is_method = True
                 compound.methods.append(func)
+            for i, fieldnode in enumerate(self._find_children(node, _corens('field'))):
+                field = compound.fields[i]
+                self._parse_type_array_length(compound.fields, fieldnode, field.type)
             for func in self._find_children(node, _corens('function')):
                 compound.static_methods.append(
                     self._parse_function_common(func, ast.Function, compound))
@@ -456,8 +459,8 @@ class GIRParser(object):
                 return self._parse_type_simple(typenode)
         assert False, "Failed to parse toplevel type"
 
-    def _parse_type_second_pass(self, parent, node, typeval):
-        """A hack necessary to handle the integer parameter indexes on
+    def _parse_type_array_length(self, siblings, node, typeval):
+        """A hack necessary to handle the integer parameter/field indexes on
            array types."""
         typenode = node.find(_corens('array'))
         if typenode is None:
@@ -465,9 +468,11 @@ class GIRParser(object):
         lenidx = typenode.attrib.get('length')
         if lenidx is not None:
             idx = int(lenidx)
-            assert idx < len(parent.parameters), "%r %d >= %d" % (parent, idx,
-                                                                  len(parent.parameters))
-            typeval.length_param_name = parent.parameters[idx].argname
+            assert idx < len(siblings), "%r %d >= %d" % (parent, idx, len(siblings))
+            if isinstance(siblings[idx], ast.Field):
+                typeval.length_param_name = siblings[idx].name
+            else:
+                typeval.length_param_name = siblings[idx].argname
 
     def _parse_boxed(self, node):
         obj = ast.Boxed(node.attrib[_glibns('name')],
diff --git a/tests/scanner/Regress-1.0-Gjs-expected/Regress.AnnotationFields.page 
b/tests/scanner/Regress-1.0-Gjs-expected/Regress.AnnotationFields.page
new file mode 100644
index 0000000..5323454
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Gjs-expected/Regress.AnnotationFields.page
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<page id="Regress.AnnotationFields"
+      type="guide"
+      style="record"
+      xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
+      xmlns:ui="http://projectmallard.org/1.0/ui/";>
+  <info>
+    
+      <link xref="index" group="record" type="guide"/>
+    
+  </info>
+  <title>Regress.AnnotationFields</title>
+  
+  
+  
+    <p>This is a struct for testing field documentation and annotations</p>
+  
+  
+  
+  
+  
+  
+  
+</page>
diff --git a/tests/scanner/Regress-1.0-Python-expected/Regress.AnnotationFields.page 
b/tests/scanner/Regress-1.0-Python-expected/Regress.AnnotationFields.page
new file mode 100644
index 0000000..5323454
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Python-expected/Regress.AnnotationFields.page
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<page id="Regress.AnnotationFields"
+      type="guide"
+      style="record"
+      xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
+      xmlns:ui="http://projectmallard.org/1.0/ui/";>
+  <info>
+    
+      <link xref="index" group="record" type="guide"/>
+    
+  </info>
+  <title>Regress.AnnotationFields</title>
+  
+  
+  
+    <p>This is a struct for testing field documentation and annotations</p>
+  
+  
+  
+  
+  
+  
+  
+</page>
diff --git a/tests/scanner/Utility-1.0-expected.gir b/tests/scanner/Utility-1.0-expected.gir
index 1936fd2..0bd3829 100644
--- a/tests/scanner/Utility-1.0-expected.gir
+++ b/tests/scanner/Utility-1.0-expected.gir
@@ -19,6 +19,7 @@ and/or use gtk-doc annotations.  -->
     </alias>
     <record name="Buffer" c:type="UtilityBuffer">
       <field name="data" writable="1">
+        <doc xml:space="preserve">the data</doc>
         <type name="gpointer"/>
       </field>
       <field name="length" writable="1">


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