[valadoc] libvaladoc: gir-reader: improve short descs



commit ca2ba9131b10c5927172505f89f79cc0088dca3f
Author: Florian Brosch <flo brosch gmail com>
Date:   Thu Jan 5 22:28:30 2012 +0100

    libvaladoc: gir-reader: improve short descs

 src/libvaladoc/content/blockcontent.vala           |   10 ++
 src/libvaladoc/content/contentelement.vala         |    2 +
 src/libvaladoc/content/embedded.vala               |    4 +
 src/libvaladoc/content/headline.vala               |    5 +
 src/libvaladoc/content/inlinecontent.vala          |   10 ++
 src/libvaladoc/content/inlinetaglet.vala           |    5 +
 src/libvaladoc/content/link.vala                   |    4 +
 src/libvaladoc/content/list.vala                   |    4 +
 src/libvaladoc/content/sourcecode.vala             |    5 +
 src/libvaladoc/content/symbollink.vala             |    4 +
 src/libvaladoc/content/table.vala                  |    4 +
 src/libvaladoc/content/tablecell.vala              |    5 +
 src/libvaladoc/content/tablerow.vala               |    4 +
 src/libvaladoc/content/text.vala                   |    5 +
 src/libvaladoc/content/wikilink.vala               |    5 +
 .../documentation/gtkdoccommentparser.vala         |  112 ++++++++++++++++++++
 src/libvaladoc/taglets/tagletdeprecated.vala       |    5 +
 src/libvaladoc/taglets/tagletinheritdoc.vala       |    4 +
 src/libvaladoc/taglets/tagletlink.vala             |    4 +
 src/libvaladoc/taglets/tagletsee.vala              |    4 +
 src/libvaladoc/taglets/tagletsince.vala            |    6 +-
 src/libvaladoc/taglets/tagletthrows.vala           |    1 +
 22 files changed, 211 insertions(+), 1 deletions(-)
---
diff --git a/src/libvaladoc/content/blockcontent.vala b/src/libvaladoc/content/blockcontent.vala
index c3c55fd..e466177 100755
--- a/src/libvaladoc/content/blockcontent.vala
+++ b/src/libvaladoc/content/blockcontent.vala
@@ -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;
+	}
 }
 
diff --git a/src/libvaladoc/content/contentelement.vala b/src/libvaladoc/content/contentelement.vala
index 8886ca8..427cf66 100755
--- a/src/libvaladoc/content/contentelement.vala
+++ b/src/libvaladoc/content/contentelement.vala
@@ -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) {
 	}
 }
diff --git a/src/libvaladoc/content/embedded.vala b/src/libvaladoc/content/embedded.vala
index e3be516..f158800 100755
--- a/src/libvaladoc/content/embedded.vala
+++ b/src/libvaladoc/content/embedded.vala
@@ -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;
+	}
 }
diff --git a/src/libvaladoc/content/headline.vala b/src/libvaladoc/content/headline.vala
index c644c71..c7fcb29 100755
--- a/src/libvaladoc/content/headline.vala
+++ b/src/libvaladoc/content/headline.vala
@@ -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;
+	}
 }
 
diff --git a/src/libvaladoc/content/inlinecontent.vala b/src/libvaladoc/content/inlinecontent.vala
index cdb2470..389c66b 100755
--- a/src/libvaladoc/content/inlinecontent.vala
+++ b/src/libvaladoc/content/inlinecontent.vala
@@ -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;
+	}
 }
 
diff --git a/src/libvaladoc/content/inlinetaglet.vala b/src/libvaladoc/content/inlinetaglet.vala
index 1ea92bb..813bcf3 100755
--- a/src/libvaladoc/content/inlinetaglet.vala
+++ b/src/libvaladoc/content/inlinetaglet.vala
@@ -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;
+	}
 }
 
diff --git a/src/libvaladoc/content/link.vala b/src/libvaladoc/content/link.vala
index 421039a..e114e96 100755
--- a/src/libvaladoc/content/link.vala
+++ b/src/libvaladoc/content/link.vala
@@ -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;
+	}
 }
diff --git a/src/libvaladoc/content/list.vala b/src/libvaladoc/content/list.vala
index 256eb88..c7bae59 100755
--- a/src/libvaladoc/content/list.vala
+++ b/src/libvaladoc/content/list.vala
@@ -124,4 +124,8 @@ public class Valadoc.Content.List : ContentElement, Block {
 			element.accept (visitor);
 		}
 	}
+
+	public override bool is_empty () {
+		return _items.size == 0;
+	}
 }
diff --git a/src/libvaladoc/content/sourcecode.vala b/src/libvaladoc/content/sourcecode.vala
index 574a096..fb2bd62 100755
--- a/src/libvaladoc/content/sourcecode.vala
+++ b/src/libvaladoc/content/sourcecode.vala
@@ -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;
+	}
 }
diff --git a/src/libvaladoc/content/symbollink.vala b/src/libvaladoc/content/symbollink.vala
index 11d4d33..ef52b30 100755
--- a/src/libvaladoc/content/symbollink.vala
+++ b/src/libvaladoc/content/symbollink.vala
@@ -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;
+	}
 }
 
diff --git a/src/libvaladoc/content/table.vala b/src/libvaladoc/content/table.vala
index 95feebe..dc232ae 100755
--- a/src/libvaladoc/content/table.vala
+++ b/src/libvaladoc/content/table.vala
@@ -51,5 +51,9 @@ public class Valadoc.Content.Table : ContentElement, Block {
 			element.accept (visitor);
 		}
 	}
+
+	public override bool is_empty () {
+		return false;
+	}
 }
 
diff --git a/src/libvaladoc/content/tablecell.vala b/src/libvaladoc/content/tablecell.vala
index dddd89f..01e732f 100755
--- a/src/libvaladoc/content/tablecell.vala
+++ b/src/libvaladoc/content/tablecell.vala
@@ -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;
+	}
 }
 
diff --git a/src/libvaladoc/content/tablerow.vala b/src/libvaladoc/content/tablerow.vala
index b2868cc..943c95f 100755
--- a/src/libvaladoc/content/tablerow.vala
+++ b/src/libvaladoc/content/tablerow.vala
@@ -49,5 +49,9 @@ public class Valadoc.Content.TableRow : ContentElement {
 			element.accept (visitor);
 		}
 	}
+
+	public override bool is_empty () {
+		return false;
+	}
 }
 
diff --git a/src/libvaladoc/content/text.vala b/src/libvaladoc/content/text.vala
index f4704e8..2b14723 100755
--- a/src/libvaladoc/content/text.vala
+++ b/src/libvaladoc/content/text.vala
@@ -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 == "";
+	}
 }
 
diff --git a/src/libvaladoc/content/wikilink.vala b/src/libvaladoc/content/wikilink.vala
index 3833c47..e88bc18 100755
--- a/src/libvaladoc/content/wikilink.vala
+++ b/src/libvaladoc/content/wikilink.vala
@@ -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;
+	}
 }
diff --git a/src/libvaladoc/documentation/gtkdoccommentparser.vala b/src/libvaladoc/documentation/gtkdoccommentparser.vala
index a376d40..984f56d 100644
--- a/src/libvaladoc/documentation/gtkdoccommentparser.vala
+++ b/src/libvaladoc/documentation/gtkdoccommentparser.vala
@@ -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;
 	}
 
diff --git a/src/libvaladoc/taglets/tagletdeprecated.vala b/src/libvaladoc/taglets/tagletdeprecated.vala
index 4386571..f51adc1 100755
--- a/src/libvaladoc/taglets/tagletdeprecated.vala
+++ b/src/libvaladoc/taglets/tagletdeprecated.vala
@@ -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;
+	}
 }
+
diff --git a/src/libvaladoc/taglets/tagletinheritdoc.vala b/src/libvaladoc/taglets/tagletinheritdoc.vala
index 4f4568f..329db68 100755
--- a/src/libvaladoc/taglets/tagletinheritdoc.vala
+++ b/src/libvaladoc/taglets/tagletinheritdoc.vala
@@ -67,4 +67,8 @@ public class Valadoc.Taglets.InheritDoc : InlineTaglet {
 		}
 		return new Text ("");
 	}
+
+	public override bool is_empty () {
+		return false;
+	}
 }
diff --git a/src/libvaladoc/taglets/tagletlink.vala b/src/libvaladoc/taglets/tagletlink.vala
index 633fc41..3ebb6de 100755
--- a/src/libvaladoc/taglets/tagletlink.vala
+++ b/src/libvaladoc/taglets/tagletlink.vala
@@ -100,4 +100,8 @@ public class Valadoc.Taglets.Link : InlineTaglet {
 			return link;
 		}
 	}
+
+	public override bool is_empty () {
+		return false;
+	}
 }
diff --git a/src/libvaladoc/taglets/tagletsee.vala b/src/libvaladoc/taglets/tagletsee.vala
index d976688..68ed636 100755
--- a/src/libvaladoc/taglets/tagletsee.vala
+++ b/src/libvaladoc/taglets/tagletsee.vala
@@ -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;
+	}
 }
diff --git a/src/libvaladoc/taglets/tagletsince.vala b/src/libvaladoc/taglets/tagletsince.vala
index e28bf72..5b68ecf 100755
--- a/src/libvaladoc/taglets/tagletsince.vala
+++ b/src/libvaladoc/taglets/tagletsince.vala
@@ -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;
+	}
 }
diff --git a/src/libvaladoc/taglets/tagletthrows.vala b/src/libvaladoc/taglets/tagletthrows.vala
index 79ae9c0..b592f6c 100755
--- a/src/libvaladoc/taglets/tagletthrows.vala
+++ b/src/libvaladoc/taglets/tagletthrows.vala
@@ -49,3 +49,4 @@ public class Valadoc.Taglets.Throws : InlineContent, Taglet, Block {
 		visitor.visit_taglet (this);
 	}
 }
+



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