[gobject-introspection/gir-docbook] g-ir-doctool: Add annotations (some)



commit 62d306b024921e6bfb48562a34a4e21b1f497bde
Author: Tomeu Vizoso <tomeu vizoso collabora co uk>
Date:   Fri Aug 12 17:16:35 2011 +0200

    g-ir-doctool: Add annotations (some)

 giscanner/docbookwriter.py                  |   38 ++++++++++++++++++++++++---
 tests/doctool/GIRepository-2.0-expected.xml |   20 ++++++++++++++
 2 files changed, 54 insertions(+), 4 deletions(-)
---
diff --git a/giscanner/docbookwriter.py b/giscanner/docbookwriter.py
index 222942f..d391076 100644
--- a/giscanner/docbookwriter.py
+++ b/giscanner/docbookwriter.py
@@ -147,15 +147,34 @@ class DocBookFormatter(object):
         self._render_parameters(method, method.parameters)
         self._writer.enable_whitespace()
 
+    def _get_annotations(self, argument):
+        annotations = {}
+
+        if hasattr(argument.type, 'element_type') and \
+           argument.type.element_type is not None:
+            annotations['element-type'] = argument.type.element_type
+
+        if argument.transfer is not None and argument.transfer != 'none':
+            annotations['transfer'] = argument.transfer
+
+        if hasattr(argument, 'allow_none') and argument.allow_none:
+            annotations['allow-none'] = None
+
+        return annotations
+
     def render_param_list(self, entity):
         method = entity.get_ast()
 
-        self._render_param(method.parent_class.name.lower(), 'instance')
+        self._render_param(method.parent_class.name.lower(), 'instance', [])
+
         for param in method.parameters:
-            self._render_param(param.argname, param.doc)
-        self._render_param('Returns', method.retval.doc)
+            self._render_param(param.argname, param.doc,
+                               self._get_annotations(param))
+
+        self._render_param('Returns', method.retval.doc,
+                           self._get_annotations(method.retval))
 
-    def _render_param(self, argname, doc):
+    def _render_param(self, argname, doc, annotations):
         with self._writer.tagcontext('varlistentry'):
             with self._writer.tagcontext('term'):
                 self._writer.disable_whitespace()
@@ -170,6 +189,17 @@ class DocBookFormatter(object):
                 with self._writer.tagcontext('listitem'):
                     with self._writer.tagcontext('simpara'):
                         self._writer.write_line(doc)
+                        if annotations:
+                            with self._writer.tagcontext('emphasis', [('role', 'annotation')]):
+                                for key, value in annotations.iteritems():
+                                    self._writer.disable_whitespace()
+                                    try:
+                                        self._writer.write_line('[%s' % key)
+                                        if value is not None:
+                                            self._writer.write_line(' %s' % value)
+                                        self._writer.write_line(']')
+                                    finally:
+                                        self._writer.enable_whitespace()
 
     def render_property(self, entity, link=False):
         prop = entity.get_ast()
diff --git a/tests/doctool/GIRepository-2.0-expected.xml b/tests/doctool/GIRepository-2.0-expected.xml
index e6097dd..08e140e 100644
--- a/tests/doctool/GIRepository-2.0-expected.xml
+++ b/tests/doctool/GIRepository-2.0-expected.xml
@@ -384,6 +384,8 @@ while (g_base_info_iterate_attributes (info, &amp;iter, &amp;name, &amp;value))
             <listitem>
               <simpara>
                 the same @info.
+                <emphasis role="annotation">
+[transfer full]                </emphasis>
               </simpara>
             </listitem>
           </varlistentry>
@@ -507,6 +509,8 @@ available) for @namespace_ in this @repository.</para>
             <listitem>
               <simpara>
                 the array of versions.
+                <emphasis role="annotation">
+[element-type utf8][transfer full]                </emphasis>
               </simpara>
             </listitem>
           </varlistentry>
@@ -552,6 +556,8 @@ when you know the GType to originate from be from a loaded namespace.</para>
             <listitem>
               <simpara>
                 #GIBaseInfo representing metadata about @type, or %NULL
+                <emphasis role="annotation">
+[transfer full]                </emphasis>
               </simpara>
             </listitem>
           </varlistentry>
@@ -605,6 +611,8 @@ ensure the namespace has already been loaded.</para>
             <listitem>
               <simpara>
                 #GIBaseInfo representing metadata about @name, or %NULL
+                <emphasis role="annotation">
+[transfer full]                </emphasis>
               </simpara>
             </listitem>
           </varlistentry>
@@ -690,6 +698,8 @@ such as #g_irepository_require before calling this function.</para>
             <listitem>
               <simpara>
                 Zero-terminated string array of versioned dependencies
+                <emphasis role="annotation">
+[element-type utf8][transfer full]                </emphasis>
               </simpara>
             </listitem>
           </varlistentry>
@@ -744,6 +754,8 @@ entries.</para>
             <listitem>
               <simpara>
                 #GIBaseInfo containing metadata
+                <emphasis role="annotation">
+[transfer full]                </emphasis>
               </simpara>
             </listitem>
           </varlistentry>
@@ -774,6 +786,8 @@ entries.</para>
             <listitem>
               <simpara>
                 List of namespaces
+                <emphasis role="annotation">
+[element-type utf8][transfer full]                </emphasis>
               </simpara>
             </listitem>
           </varlistentry>
@@ -991,6 +1005,8 @@ quickly as this function will if it has already been loaded.</para>
             <listitem>
               <simpara>
                 Required version, may be %NULL for latest
+                <emphasis role="annotation">
+[allow-none]                </emphasis>
               </simpara>
             </listitem>
           </varlistentry>
@@ -1081,6 +1097,8 @@ not specified, the latest will be used.</para>
             <listitem>
               <simpara>
                 Version of namespace, may be %NULL for latest
+                <emphasis role="annotation">
+[allow-none]                </emphasis>
               </simpara>
             </listitem>
           </varlistentry>
@@ -1155,6 +1173,8 @@ not specified, the latest will be used.</para>
             <listitem>
               <simpara>
                 Version of namespace, may be %NULL for latest
+                <emphasis role="annotation">
+[allow-none]                </emphasis>
               </simpara>
             </listitem>
           </varlistentry>



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