[valadoc] Allow to inherit from imported docs



commit 58e527fbe2020611a1f2596d5cffe8ad4a0cc240
Author: Florian Brosch <flo brosch gmail com>
Date:   Sat Aug 23 20:09:08 2014 +0200

    Allow to inherit from imported docs

 src/libvaladoc/api/node.vala                       |    2 +-
 src/libvaladoc/api/tree.vala                       |   47 ++++++++++++--------
 src/libvaladoc/content/comment.vala                |   10 ----
 .../documentation/documentationparser.vala         |   21 ++++++++-
 src/libvaladoc/documentation/wiki.vala             |    6 +--
 src/libvaladoc/taglets/tagletinheritdoc.vala       |   21 +++------
 src/libvaladoc/taglets/tagletlink.vala             |    2 +
 src/valadoc/valadoc.vala                           |   20 +++++---
 8 files changed, 69 insertions(+), 60 deletions(-)
---
diff --git a/src/libvaladoc/api/node.vala b/src/libvaladoc/api/node.vala
index 2cbfe7c..d3ed2bd 100644
--- a/src/libvaladoc/api/node.vala
+++ b/src/libvaladoc/api/node.vala
@@ -28,7 +28,7 @@ using Gee;
  * Represents a node in the api tree.
  */
 public abstract class Valadoc.Api.Node : Item, Browsable, Documentation, Comparable<Node> {
-       protected bool do_document { private set; get; default = false; }
+       protected bool do_document = false;
        private SourceFile file;
 
        /**
diff --git a/src/libvaladoc/api/tree.vala b/src/libvaladoc/api/tree.vala
index e217701..59f87d3 100644
--- a/src/libvaladoc/api/tree.vala
+++ b/src/libvaladoc/api/tree.vala
@@ -29,7 +29,7 @@ using Gee;
  * The root of the code tree.
  */
 public class Valadoc.Api.Tree {
-       private Deque<Node> unbrowsable_documentation_dependencies = new LinkedList<Node>();
+       private Deque<InheritDocContainer> inheritdocs = new LinkedList<InheritDocContainer> ();
        private ArrayList<string> external_c_files = new ArrayList<string>();
        private ArrayList<Package> packages = new ArrayList<Package>();
        private Package source_package = null;
@@ -38,6 +38,18 @@ public class Valadoc.Api.Tree {
        private CTypeResolver _cresolver = null;
        private Package _source_package;
 
+
+       private class InheritDocContainer {
+               public unowned Taglets.InheritDoc taglet;
+               public unowned Api.Node taglet_container;
+
+               public InheritDocContainer (Api.Node taglet_container, Taglets.InheritDoc taglet) {
+                       this.taglet_container = taglet_container;
+                       this.taglet = taglet;
+               }
+       }
+
+
        public void add_package(Package package) {
                this.packages.add (package);
        }
@@ -78,10 +90,6 @@ public class Valadoc.Api.Tree {
                return this.packages.read_only_view;
        }
 
-       internal bool push_unbrowsable_documentation_dependency (Api.Node node) {
-               return unbrowsable_documentation_dependencies.offer_head (node);
-       }
-
        private void add_dependencies_to_source_package () {
                if ( this.source_package != null ) {
                        ArrayList<Package> deplst = new ArrayList<Package> ();
@@ -246,11 +254,6 @@ public class Valadoc.Api.Tree {
                return _source_package;
        }
 
-       public void process_comments (DocumentationParser docparser) {
-               parse_comments (docparser);
-               check_comments (docparser);
-       }
-
        private void parse_wiki (DocumentationParser docparser) {
                this.wikitree = new WikiPageTree ();
                var pkg = get_source_package ();
@@ -260,13 +263,13 @@ public class Valadoc.Api.Tree {
        }
 
        private void check_wiki (DocumentationParser docparser) {
-               var pkg = get_source_package ();
+               Package pkg = get_source_package ();
                if (pkg != null) {
                        wikitree.check (settings, docparser, pkg);
                }
        }
 
-       private void parse_comments (DocumentationParser docparser) {
+       public void parse_comments (DocumentationParser docparser) {
                parse_wiki (docparser);
 
                foreach (Package pkg in this.packages) {
@@ -276,24 +279,30 @@ public class Valadoc.Api.Tree {
                }
        }
 
-       private void check_comments (DocumentationParser docparser) {
+       public void check_comments (DocumentationParser docparser) {
                check_wiki (docparser);
 
                foreach (Package pkg in this.packages) {
                        if (pkg.is_browsable (settings)) {
                                pkg.check_comments (settings, docparser);
+                               postprocess_inheritdoc (docparser);
                        }
                }
+       }
 
+       internal void register_inheritdoc (Api.Node container, Taglets.InheritDoc taglet) {
+               inheritdocs.add (new InheritDocContainer (container, taglet));
+       }
+
+       private void postprocess_inheritdoc (DocumentationParser docparser) {
+               while (!this.inheritdocs.is_empty) {
+                       InheritDocContainer container = this.inheritdocs.poll_head ();
 
-               // Parse & check inherited non-public comments:
-               while (!this.unbrowsable_documentation_dependencies.is_empty) {
-                       var node = this.unbrowsable_documentation_dependencies.poll_head ();
-                       node.parse_comments (settings, docparser);
-                       node.check_comments (settings, docparser);
+                       docparser.transform_inheritdoc (container.taglet_container, container.taglet);
                }
        }
 
+
        /**
         * Import documentation from various sources
         *
@@ -301,7 +310,7 @@ public class Valadoc.Api.Tree {
         * @param packages sources
         * @param import_directories List of directories where to find the files
         */
-       public void import_documentation (DocumentationImporter[] importers, string[] packages,
+       public void import_comments (DocumentationImporter[] importers, string[] packages,
                                                                          string[] import_directories)
        {
                HashSet<string> processed = new HashSet<string> ();
diff --git a/src/libvaladoc/content/comment.vala b/src/libvaladoc/content/comment.vala
index f1f1d41..f4ba4a0 100644
--- a/src/libvaladoc/content/comment.vala
+++ b/src/libvaladoc/content/comment.vala
@@ -26,8 +26,6 @@ using Gee;
 
 
 public class Valadoc.Content.Comment : BlockContent {
-       private Gee.LinkedList<InheritDoc> inheritdocs = new Gee.LinkedList<InheritDoc> ();
-
        public Gee.List<Taglet> taglets { get { return _taglets; } }
        private Gee.List<Taglet> _taglets;
 
@@ -39,10 +37,6 @@ public class Valadoc.Content.Comment : BlockContent {
                _taglets = new ArrayList<Taglet> ();
        }
 
-       internal void register_inheritdoc (InheritDoc taglet) {
-               inheritdocs.add (taglet);
-       }
-
        public override void configure (Settings settings, ResourceLocator locator) {
        }
 
@@ -62,10 +56,6 @@ public class Valadoc.Content.Comment : BlockContent {
                        element.parent = this;
                        element.check (api_root, container, file_path, reporter, settings);
                }
-
-               foreach (InheritDoc element in inheritdocs) {
-                       element.transform (api_root, container, file_path, reporter, settings);
-               }
        }
 
        public override void accept (ContentVisitor visitor) {
diff --git a/src/libvaladoc/documentation/documentationparser.vala 
b/src/libvaladoc/documentation/documentationparser.vala
index d94af81..3dde0b8 100644
--- a/src/libvaladoc/documentation/documentationparser.vala
+++ b/src/libvaladoc/documentation/documentationparser.vala
@@ -138,8 +138,25 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
                comment.check (_tree, element, element.get_source_file ().get_name (), _reporter, _settings);
        }
 
-       public void check_wikipage (Api.Package package, Page page) {
-               page.check (_tree, package, package.get_source_file ().get_name (), _reporter, _settings);
+       public void check_wikipage (Api.Package package, WikiPage page) {
+               page.documentation.check (_tree, package, page.get_filename (), _reporter, _settings);
+       }
+
+       public void transform_inheritdoc (Api.Node taglet_owner, Taglets.InheritDoc taglet) {
+               if (taglet.inherited == null) {
+                       return ;
+               }
+
+
+               taglet.inherited.parse_comments (_settings, this);
+               if (taglet.inherited.documentation == null) {
+                       return ;
+               }
+
+
+               taglet.inherited.check_comments (_settings, this);
+
+               taglet.transform (_tree, taglet_owner, taglet_owner.get_source_file ().get_name (), 
_reporter, _settings);
        }
 
        private GirMetaData get_metadata_for_comment (Api.GirSourceComment gir_comment) {
diff --git a/src/libvaladoc/documentation/wiki.vala b/src/libvaladoc/documentation/wiki.vala
index 56227a4..fac10e5 100644
--- a/src/libvaladoc/documentation/wiki.vala
+++ b/src/libvaladoc/documentation/wiki.vala
@@ -79,10 +79,6 @@ public class Valadoc.WikiPage : Object, Documentation {
        public void parse (DocumentationParser docparser, Api.Package pkg) {
                documentation = docparser.parse_wikipage (pkg, this);
        }
-
-       public void check (DocumentationParser docparser, Api.Package pkg) {
-               docparser.check_wikipage (pkg, documentation);
-       }
 }
 
 
@@ -155,7 +151,7 @@ public class Valadoc.WikiPageTree : Object {
                }
 
                foreach (WikiPage page in this.wikipages) {
-                       page.check (docparser, pkg);
+                       docparser.check_wikipage (pkg, page);
                }
        }
 }
diff --git a/src/libvaladoc/taglets/tagletinheritdoc.vala b/src/libvaladoc/taglets/tagletinheritdoc.vala
index 54c90d7..1f32bad 100644
--- a/src/libvaladoc/taglets/tagletinheritdoc.vala
+++ b/src/libvaladoc/taglets/tagletinheritdoc.vala
@@ -26,18 +26,13 @@ using Valadoc.Content;
 
 public class Valadoc.Taglets.InheritDoc : InlineTaglet {
        private Taglet? parent_taglet = null;
-       private Api.Node? _inherited;
-
-       private Comment root {
-               get {
-                       ContentElement pos;
-                       for (pos = this; pos.parent != null; pos = pos.parent);
-                       // inheritDoc is only allowed in source comments
-                       assert (pos is Comment);
-                       return (Comment) pos;
-               }
+
+       public Api.Node? inherited {
+               private set;
+               get;
        }
 
+
        public override Rule? get_parser_rule (Rule run_rule) {
                return null;
        }
@@ -72,13 +67,9 @@ public class Valadoc.Taglets.InheritDoc : InlineTaglet {
                        _inherited = (Api.Node) ((Api.Struct) container).base_type.data_type;
                }
 
-               if (_inherited != null) {
-                       api_root.push_unbrowsable_documentation_dependency (_inherited);
-               }
-
                parent_taglet = find_parent_taglet ();
-               if (parent_taglet == null && _inherited != null && _inherited.documentation != null) {
-                       root.register_inheritdoc (this);
+               if (parent_taglet == null && _inherited != null) {
+                       api_root.register_inheritdoc (container, this);
                }
 
 
diff --git a/src/libvaladoc/taglets/tagletlink.vala b/src/libvaladoc/taglets/tagletlink.vala
index 72ed12a..82a41ba 100644
--- a/src/libvaladoc/taglets/tagletlink.vala
+++ b/src/libvaladoc/taglets/tagletlink.vala
@@ -176,6 +176,8 @@ public class Valadoc.Taglets.Link : InlineTaglet {
                link.locator = locator;
 
                link.symbol_name = symbol_name;
+               link.c_accept_plural = c_accept_plural;
+               link.c_is_plural = c_is_plural;
                link._context = _context;
                link._symbol = _symbol;
 
diff --git a/src/valadoc/valadoc.vala b/src/valadoc/valadoc.vala
index 9f6256f..9d7a982 100644
--- a/src/valadoc/valadoc.vala
+++ b/src/valadoc/valadoc.vala
@@ -1,7 +1,6 @@
 /* valadoc.vala
  *
- * Copyright (C) 2008-2009 Florian Brosch
- * Copyright (C) 2011      Florian Brosch
+ * Copyright (C) 2008-2014 Florian Brosch
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -265,17 +264,22 @@ public class ValaDoc : Object {
                        return quit (reporter);
                }
 
-               doctree.process_comments (docparser);
-               if (reporter.errors > 0) {
-                       return quit (reporter);
-               }
-
                DocumentationImporter[] importers = {
                        new ValadocDocumentationImporter (doctree, docparser, modules, settings, reporter),
                        new GirDocumentationImporter (doctree, docparser, modules, settings, reporter)
                };
 
-               doctree.import_documentation (importers, import_packages, import_directories);
+               doctree.parse_comments (docparser);
+               if (reporter.errors > 0) {
+                       return quit (reporter);
+               }
+
+               doctree.import_comments (importers, import_packages, import_directories);
+               if (reporter.errors > 0) {
+                       return quit (reporter);
+               }
+
+               doctree.check_comments (docparser);
                if (reporter.errors > 0) {
                        return quit (reporter);
                }


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