]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
doclets/gtkdoclet: Support error-domains annotation
authorLuca Bruno <lethalman88@gmail.com>
Tue, 4 May 2010 20:05:29 +0000 (22:05 +0200)
committerFlorian Brosch <flo.brosch@gmail.com>
Tue, 4 May 2010 20:05:29 +0000 (22:05 +0200)
src/doclets/gtkdoc/gcomment.vala
src/doclets/gtkdoc/generator.vala

index 3238abe0abf309b9c6097330b53d2b57df81ee4a..c1af81913817d2022546a0a46c52f2f554f1bc2e 100644 (file)
@@ -45,11 +45,8 @@ public class Gtkdoc.GComment {
                var builder = new StringBuilder ();
 
                builder.append_printf ("/**\n * %s", symbol);
-               if (symbol_annotations != null) {
-                       if (symbol_annotations.length > 0) {
-                               builder.append_c (':');
-                       }
-
+               if (symbol_annotations != null && symbol_annotations.length > 0) {
+                       builder.append_c (':');
                        foreach (var annotation in symbol_annotations) {
                                builder.append_printf (" (%s)", annotation);
                        }
@@ -57,14 +54,11 @@ public class Gtkdoc.GComment {
 
                foreach (var header in headers) {
                        builder.append_printf ("\n * %s:", header.name);
-                       if (header.annotations != null) {
+                       if (header.annotations != null && header.annotations.length > 0) {
                                foreach (var annotation in header.annotations) {
                                        builder.append_printf (" (%s)", annotation);
                                }
-
-                               if (header.annotations.length > 0) {
-                                       builder.append_c (':');
-                               }
+                               builder.append_c (':');
                        }
 
                        if (header.value != null) {
index 4152ea7fbef9e55165394a6a1f8fd8587ab7bd94..c0766e53c3b53d191d79df14780899ab31f434f8 100644 (file)
@@ -179,20 +179,21 @@ public class Gtkdoc.Generator : Api.Visitor {
                }
        }
 
-       private void add_manual_header (string name, string? comment, string[]? annotations = null) {
+       private Header? add_manual_header (string name, string? comment, string[]? annotations = null) {
                if (comment == null && annotations == null) {
-                       return;
+                       return null;
                }
 
                var header = new Header ("@"+name);
                header.annotations = annotations;
                header.value = comment;
                current_headers.add (header);
+               return header;
        }
 
-       private void add_header (string name, Comment? comment, string[]? annotations = null) {
+       private Header? add_header (string name, Comment? comment, string[]? annotations = null) {
                if (comment == null) {
-                       return;
+                       return null;
                }
 
                var converter = new Gtkdoc.CommentConverter ();
@@ -209,6 +210,7 @@ public class Gtkdoc.Generator : Api.Visitor {
 
                header.annotations = annotations;
                current_headers.add (header);
+               return header;
        }
 
        public override void visit_tree (Api.Tree tree) {
@@ -290,13 +292,21 @@ public class Gtkdoc.Generator : Api.Visitor {
        public override void visit_error_domain (Api.ErrorDomain edomain) {
                if (current_method != null || current_delegate != null) {
                        // method throws error
+                       Header? param_header = null;
                        foreach (var header in current_headers) {
                                if (header.name == "error") {
-                                       // we already commented the error parameter
-                                       return;
+                                       param_header = header;
+                                       break;
                                }
                        }
-                       add_manual_header ("error", "location to store the error occuring, or %NULL to ignore", {"out"});
+                       if (param_header == null) {
+                               add_manual_header ("error", "location to store the error occuring, or %NULL to ignore", {"error-domains %s".printf (edomain.get_cname ())});
+                       } else {
+                               // assume the only annotation is error-domains
+                               var annotation = param_header.annotations[0];
+                               annotation += " %s".printf (edomain.get_cname ());
+                               param_header.annotations[0] = annotation;
+                       }
                } else {
                        // error domain definition
                        var old_headers = current_headers;
@@ -387,7 +397,7 @@ public class Gtkdoc.Generator : Api.Visitor {
                // gtkdoc maps parameters by their ordering, so let's manually add the first parameter
                add_manual_header (to_lower_case (((Api.Node)sig.parent).name), "", null);
                sig.accept_all_children (this);
-               var name = sig.get_cname ().replace ("_", "-");
+               var name = sig.get_cname().replace ("_", "-");
                add_comment (sig.get_filename(), "%s::%s".printf (current_cname, name), sig.documentation);
 
                current_headers = old_headers;
@@ -457,7 +467,7 @@ public class Gtkdoc.Generator : Api.Visitor {
 
                if (param.parameter_type.data_type is Api.Array) {
                        annotations += "array length=%s".printf (param.name+"_length1");
-               } 
+               }
 
                if (param.documentation != null) {
                        add_header (param.name, param.documentation, annotations);