]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
libvaladoc: .valadoc-importer: Add support for ::append and ::prepend
authorFlorian Brosch <flo.brosch@gmail.com>
Fri, 16 Nov 2012 18:49:01 +0000 (19:49 +0100)
committerFlorian Brosch <flo.brosch@gmail.com>
Sat, 17 Nov 2012 00:35:03 +0000 (01:35 +0100)
src/libvaladoc/importer/valadocdocumentationimporter.vala

index 4f63d48cce200bcee3226bae2e8f72bca607cbb1..b005217f78b8da5059b61c7f89965bab3cfb8331 100644 (file)
@@ -115,9 +115,28 @@ public class Valadoc.Importer.ValadocDocumentationImporter : DocumentationImport
                _parser.set_root_rule (file);
        }
 
-       private void add_documentation (string symbol_name, StringBuilder? comment, string filename, SourceLocation src_ref) {
+       private enum InsertionMode {
+               APPEND,
+               PREPEND,
+               REPLACE
+       }
+
+       private void add_documentation (string _symbol_name, StringBuilder? comment, string filename, SourceLocation src_ref) {
                Api.Node? symbol = null;
 
+               InsertionMode insertion_mode;
+               string symbol_name;
+               if (_symbol_name.has_suffix ("::append")) {
+                       symbol_name = _symbol_name.substring (0, _symbol_name.length - 8);
+                       insertion_mode = InsertionMode.APPEND;
+               } else if (_symbol_name.has_suffix ("::prepend")) {
+                       symbol_name = _symbol_name.substring (0, _symbol_name.length - 9);
+                       insertion_mode = InsertionMode.PREPEND;
+               } else {
+                       symbol_name = _symbol_name;
+                       insertion_mode = InsertionMode.REPLACE;
+               }
+
                if (symbol_name.has_prefix ("c::")) {
                        symbol = tree.search_symbol_cstr (null, symbol_name.substring (3));
                } else {
@@ -135,11 +154,28 @@ public class Valadoc.Importer.ValadocDocumentationImporter : DocumentationImport
                if (comment != null) {
                        var docu = _doc_parser.parse_comment_str (symbol, comment.str, filename, src_ref.line, src_ref.column);
                        if (docu != null) {
-                               symbol.documentation = docu;
+                               if (symbol.documentation == null || insertion_mode == InsertionMode.REPLACE) {
+                                       if (insertion_mode == InsertionMode.APPEND) {
+                                               docu.content.insert (0, factory.create_paragraph ());
+                                       }
+                                       symbol.documentation = docu;
+                               } else if (insertion_mode == InsertionMode.APPEND) {
+                                       symbol.documentation.content.add_all (docu.content);
+                                       merge_taglets (symbol.documentation, docu);
+                               } else if (insertion_mode == InsertionMode.PREPEND) {
+                                       symbol.documentation.content.insert_all (0, docu.content);
+                                       merge_taglets (symbol.documentation, docu);
+                               }
                        }
                }
        }
 
+       private void merge_taglets (Comment comment, Comment imported) {
+               foreach (Taglet taglet in imported.taglets) {
+                       imported.taglets.add (taglet);
+               }
+       }
+
        public override void process (string filename) {
                try {
                        _filename = filename;