]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
libvaladoc: gir-reader: improve short descs
authorFlorian Brosch <flo.brosch@gmail.com>
Thu, 5 Jan 2012 21:28:30 +0000 (22:28 +0100)
committerFlorian Brosch <flo.brosch@gmail.com>
Thu, 5 Jan 2012 21:28:30 +0000 (22:28 +0100)
22 files changed:
src/libvaladoc/content/blockcontent.vala
src/libvaladoc/content/contentelement.vala
src/libvaladoc/content/embedded.vala
src/libvaladoc/content/headline.vala
src/libvaladoc/content/inlinecontent.vala
src/libvaladoc/content/inlinetaglet.vala
src/libvaladoc/content/link.vala
src/libvaladoc/content/list.vala
src/libvaladoc/content/sourcecode.vala
src/libvaladoc/content/symbollink.vala
src/libvaladoc/content/table.vala
src/libvaladoc/content/tablecell.vala
src/libvaladoc/content/tablerow.vala
src/libvaladoc/content/text.vala
src/libvaladoc/content/wikilink.vala
src/libvaladoc/documentation/gtkdoccommentparser.vala
src/libvaladoc/taglets/tagletdeprecated.vala
src/libvaladoc/taglets/tagletinheritdoc.vala
src/libvaladoc/taglets/tagletlink.vala
src/libvaladoc/taglets/tagletsee.vala
src/libvaladoc/taglets/tagletsince.vala
src/libvaladoc/taglets/tagletthrows.vala

index c3c55fdff1a7e3cda54884858f476026ee2fe255..e46617797867eb1eafa42d46f19cd9fca4c0425a 100755 (executable)
@@ -45,5 +45,15 @@ public abstract class Valadoc.Content.BlockContent : ContentElement {
                        element.accept (visitor);
                }
        }
+
+       public override bool is_empty () {
+               foreach (Block item in content) {
+                       if (!item.is_empty ()) {
+                               return false;
+                       }
+               }
+
+               return true;
+       }
 }
 
index 8886ca89eb2f1e7b51b9379560c7b1e8bb3d2452..427cf660719b4bc7ff402bf8019b2d597ac28a33 100755 (executable)
@@ -32,6 +32,8 @@ public abstract class Valadoc.Content.ContentElement : Object {
 
        public abstract void accept (ContentVisitor visitor);
 
+       public abstract bool is_empty ();
+
        public virtual void accept_children (ContentVisitor visitor) {
        }
 }
index e3be516d0d9a6baf68e7049a965838f2a8fe6884..f158800aaee933b0f28f14c84b6da6d98ee13729 100755 (executable)
@@ -53,4 +53,8 @@ public class Valadoc.Content.Embedded : ContentElement, Inline, StyleAttributes
        public override void accept (ContentVisitor visitor) {
                visitor.visit_embedded (this);
        }
+
+       public override bool is_empty () {
+               return false;
+       }
 }
index c644c71c49a8d3c628ad49ca3f420f2b1a388989..c7fcb29ce9f055a50867894765032d519e743500 100755 (executable)
@@ -42,5 +42,10 @@ public class Valadoc.Content.Headline : Block, InlineContent {
        public override void accept (ContentVisitor visitor) {
                visitor.visit_headline (this);
        }
+
+
+       public override bool is_empty () {
+               return false;
+       }
 }
 
index cdb2470369cd2e9a61026eb25e103f0f2a7d5baf..389c66b96b8b9913b138c8469a84662d51880275 100755 (executable)
@@ -46,5 +46,15 @@ public abstract class Valadoc.Content.InlineContent : ContentElement {
                        element.accept (visitor);
                }
        }
+
+       public override bool is_empty () {
+               foreach (Inline item in content) {
+                       if (!item.is_empty ()) {
+                               return false;
+                       }
+               }
+
+               return true;
+       }
 }
 
index 1ea92bbb434171269ec4062575fb5106376f76bb..813bcf339071f33e4cbb21845355b4b20eabf792 100755 (executable)
@@ -57,5 +57,10 @@ public abstract class Valadoc.Content.InlineTaglet : ContentElement, Taglet, Inl
                ContentElement element = get_content ();
                element.accept (visitor);
        }
+
+       public override bool is_empty () {
+               // taglets are not empty by default
+               return false;
+       }
 }
 
index 421039aa0137ff52f9aa602c86c4726a7989d547..e114e9694716fc71388053affdc5a3c7ee0c6adc 100755 (executable)
@@ -40,4 +40,8 @@ public class Valadoc.Content.Link : InlineContent, Inline {
        public override void accept (ContentVisitor visitor) {
                visitor.visit_link (this);
        }
+
+       public override bool is_empty () {
+               return false;
+       }
 }
index 256eb880588700d8070f8331fdb14552b711f5f6..c7bae59a85f7c5dbdac820231af6ee670fd15b5d 100755 (executable)
@@ -124,4 +124,8 @@ public class Valadoc.Content.List : ContentElement, Block {
                        element.accept (visitor);
                }
        }
+
+       public override bool is_empty () {
+               return _items.size == 0;
+       }
 }
index 574a09623f5fb5a11338e1c9c2849c95b1db7d89..fb2bd625e9a47780fad569a925b9bbe85531c5fd 100755 (executable)
@@ -70,4 +70,9 @@ public class Valadoc.Content.SourceCode : ContentElement, Inline{
        public override void accept (ContentVisitor visitor) {
                visitor.visit_source_code (this);
        }
+
+       public override bool is_empty () {
+               // empty source blocks are visible as well
+               return false;
+       }
 }
index 11d4d330f06396758634399c43eee234b32dec29..ef52b301017e7b95ca273daff10a64d901165428 100755 (executable)
@@ -42,5 +42,9 @@ public class Valadoc.Content.SymbolLink : ContentElement, Inline {
        public override void accept (ContentVisitor visitor) {
                visitor.visit_symbol_link (this);
        }
+
+       public override bool is_empty () {
+               return false;
+       }
 }
 
index 95feebe7aa3700c483f84cc6aff7e29559a957f6..dc232ae2086ddbffe3e0c9c0050cc868e7fed3e3 100755 (executable)
@@ -51,5 +51,9 @@ public class Valadoc.Content.Table : ContentElement, Block {
                        element.accept (visitor);
                }
        }
+
+       public override bool is_empty () {
+               return false;
+       }
 }
 
index dddd89f5e7b418d268a7204c9be2b51e76c6a78e..01e732f090a662c3379f24f7f97303ead08e52b4 100755 (executable)
@@ -44,5 +44,10 @@ public class Valadoc.Content.TableCell : InlineContent, StyleAttributes {
        public override void accept (ContentVisitor visitor) {
                visitor.visit_table_cell (this);
        }
+
+       public override bool is_empty () {
+               // empty cells are displayed as well
+               return false;
+       }
 }
 
index b2868cc9de3fca1e04e444446265f5784fd0af52..943c95f646d5faa76750b148ba9b4d1925eb8f0b 100755 (executable)
@@ -49,5 +49,9 @@ public class Valadoc.Content.TableRow : ContentElement {
                        element.accept (visitor);
                }
        }
+
+       public override bool is_empty () {
+               return false;
+       }
 }
 
index f4704e8430960a1c015f748c4e8e0aa32fcf1e5a..2b147235d52a41c49ac24e7be1a47fcb37f88a0f 100755 (executable)
@@ -42,5 +42,10 @@ public class Valadoc.Content.Text : ContentElement, Inline {
        public override void accept (ContentVisitor visitor) {
                visitor.visit_text (this);
        }
+
+
+       public override bool is_empty () {
+               return content == "";
+       }
 }
 
index 3833c47bbe73ab2e43a97c53798c7bd4ef9deaac..e88bc18f7198bc7cf9f9f40f4ded7bb89f8cdd45 100755 (executable)
@@ -45,4 +45,9 @@ public class Valadoc.Content.WikiLink : InlineContent, Inline {
        public override void accept (ContentVisitor visitor) {
                visitor.visit_wiki_link (this);
        }
+
+
+       public override bool is_empty () {
+               return false;
+       }
 }
index a376d400cb53975f7a95bf2941e7a2fb53d11844..984f56dff91140fab10a7bcbae2ec5289cce71d9 100644 (file)
@@ -54,6 +54,116 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
                this.stack.clear ();
        }
 
+       private inline Text? split_text (Text text) {
+               int offset = 0;
+               while ((offset = text.content.index_of_char ('.', offset)) >= 0) {
+                       if (offset >= 2) {
+                               // ignore e.g.
+                               unowned string cmp4 = ((string) (((char*) text.content) + offset - 2));
+                               if (cmp4.has_prefix (" e.g.") || cmp4.has_prefix ("(e.g.")) {
+                                       offset = offset + 3;
+                                       continue;
+                               }
+
+                               // ignore i.e.
+                               if (cmp4.has_prefix (" i.e.") || cmp4.has_prefix ("(i.e.")) {
+                                       offset = offset + 3;
+                                       continue;
+                               }
+                       }
+
+                       Text sec = factory.create_text (text.content.substring (offset+1, -1));
+                       text.content = text.content.substring (0, offset+1);
+                       return sec;
+               }
+
+               return null;
+       }
+
+       private inline Run? split_run (Run run) {
+               Run? sec = null;
+
+               Iterator<Inline> iter = run.content.iterator ();
+               for (bool has_next = iter.first (); has_next; has_next = iter.next ()) {
+                       Inline item = iter.get ();
+                       if (sec == null) {
+                               Inline? tmp = split_inline (item);
+                               if (tmp != null) {
+                                       sec = factory.create_run (run.style);
+                                       sec.content.add (tmp);
+                               }
+                       } else {
+                               sec.content.add (item);
+                               iter.remove ();
+                       }
+               }
+
+               return sec;
+       }
+
+       private inline Inline? split_inline (Inline item) {
+               if (item is Text) {
+                       return split_text ((Text) item);
+               } else if (item is Run) {
+                       return split_run ((Run) item);
+               }
+
+               return null;
+       }
+
+       private inline Paragraph? split_paragraph (Paragraph p) {
+               Paragraph? sec = null;
+
+               Iterator<Inline> iter = p.content.iterator ();
+               for (bool has_next = iter.first (); has_next; has_next = iter.next ()) {
+                       Inline item = iter.get ();
+                       if (sec == null) {
+                               Inline? tmp = split_inline (item);
+                               if (tmp != null) {
+                                       sec = factory.create_paragraph ();
+                                       sec.horizontal_align = p.horizontal_align;
+                                       sec.vertical_align = p.vertical_align;
+                                       sec.style = p.style;
+                                       sec.content.add (tmp);
+                               }
+                       } else {
+                               sec.content.add (item);
+                               iter.remove ();
+                       }
+               }
+
+               return sec;
+       }
+
+       private void extract_short_desc (Comment comment) {
+               if (comment.content.size == 0) {
+                       return ;
+               }
+
+               Paragraph? first_paragraph = comment.content[0] as Paragraph;
+               if (first_paragraph == null) {
+                       // add empty paragraph to avoid non-text as short descriptions
+                       comment.content.insert (1, factory.create_paragraph ());
+                       return ;
+               }
+
+
+               // avoid fancy stuff in short descriptions:
+               first_paragraph.horizontal_align = null;
+               first_paragraph.vertical_align = null;
+               first_paragraph.style = null;
+
+
+               Paragraph? second_paragraph = split_paragraph (first_paragraph);
+               if (second_paragraph == null) {
+                       return ;
+               }
+
+               if (second_paragraph.is_empty () == false) {
+                       comment.content.insert (1, second_paragraph);
+               }
+       }
+
        private void report_unexpected_token (Token got, string expected) {
                if (this.show_warnings) {
                        return ;
@@ -171,6 +281,8 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
                        return null;
                }
 
+               extract_short_desc (comment);
+
                return comment;
        }
 
index 4386571b0edef11cd1106f2b91fadd280ba570cb..f51adc174fae305557acb6d0105a457dc5f8d37a 100755 (executable)
@@ -35,4 +35,9 @@ public class Valadoc.Taglets.Deprecated : InlineContent, Taglet, Block {
        public override void accept (ContentVisitor visitor) {
                visitor.visit_taglet (this);
        }
+
+       public override bool is_empty () {
+               return false;
+       }
 }
+
index 4f4568faa658f7274601d3e1e0b54a45f05796ca..329db68696ca2aaea7a6674843611a395b1e144f 100755 (executable)
@@ -67,4 +67,8 @@ public class Valadoc.Taglets.InheritDoc : InlineTaglet {
                }
                return new Text ("");
        }
+
+       public override bool is_empty () {
+               return false;
+       }
 }
index 633fc4184a255a014b715d9ce12a8e4895b85ddf..3ebb6de3eb692bfc9a641c7157ea1f9430d3e689 100755 (executable)
@@ -100,4 +100,8 @@ public class Valadoc.Taglets.Link : InlineTaglet {
                        return link;
                }
        }
+
+       public override bool is_empty () {
+               return false;
+       }
 }
index d976688770383c20a73d2c47704613a252cf5c98..68ed636ed65cec28838a99afae5167f10269c776 100755 (executable)
@@ -58,4 +58,8 @@ public class Valadoc.Taglets.See : ContentElement, Taglet, Block {
        public override void accept (ContentVisitor visitor) {
                visitor.visit_taglet (this);
        }
+
+       public override bool is_empty () {
+               return false;
+       }
 }
index e28bf72a9689282f94c6d6bda0b44abe0abf1fa5..5b68ecfe828731f6ee0f72668be7b85a7fa57424 100755 (executable)
@@ -25,7 +25,7 @@ using Valadoc.Content;
 
 
 public class Valadoc.Taglets.Since : ContentElement, Taglet, Block {
-       public string version;
+       public string version { get; internal set; }
 
        public Rule? get_parser_rule (Rule run_rule) {
                Rule optional_spaces = Rule.option ({ Rule.many ({ TokenType.SPACE }) });
@@ -43,4 +43,8 @@ public class Valadoc.Taglets.Since : ContentElement, Taglet, Block {
        public override void accept (ContentVisitor visitor) {
                visitor.visit_taglet (this);
        }
+
+       public override bool is_empty () {
+               return false;
+       }
 }
index 79ae9c07e08399873b3094cb90724dea3f882fe9..b592f6ca1e76c725a3108e30ef2172843c054822 100755 (executable)
@@ -49,3 +49,4 @@ public class Valadoc.Taglets.Throws : InlineContent, Taglet, Block {
                visitor.visit_taglet (this);
        }
 }
+