[valadoc] libvaladoc: Avoid nullable enum as property-type



commit b947a9dd269e01318f7bd583f1c8f884e1527e5b
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Fri Jul 14 15:07:07 2017 +0200

    libvaladoc: Avoid nullable enum as property-type
    
    https://bugzilla.gnome.org/show_bug.cgi?id=784927

 src/libvaladoc/content/embedded.vala             |    4 +-
 src/libvaladoc/content/paragraph.vala            |    4 +-
 src/libvaladoc/content/sourcecode.vala           |   25 +++++---------
 src/libvaladoc/content/styleattributes.vala      |   40 ++++++++++------------
 src/libvaladoc/content/tablecell.vala            |    4 +-
 src/libvaladoc/documentation/importerhelper.vala |    4 +-
 src/libvaladoc/html/htmlrenderer.vala            |   29 ++++++----------
 7 files changed, 46 insertions(+), 64 deletions(-)
---
diff --git a/src/libvaladoc/content/embedded.vala b/src/libvaladoc/content/embedded.vala
index b1d7d95..311df16 100644
--- a/src/libvaladoc/content/embedded.vala
+++ b/src/libvaladoc/content/embedded.vala
@@ -35,12 +35,12 @@ public class Valadoc.Content.Embedded : ContentElement, Inline, StyleAttributes
                set;
        }
 
-       public HorizontalAlign? horizontal_align {
+       public HorizontalAlign horizontal_align {
                get;
                set;
        }
 
-       public VerticalAlign? vertical_align {
+       public VerticalAlign vertical_align {
                get;
                set;
        }
diff --git a/src/libvaladoc/content/paragraph.vala b/src/libvaladoc/content/paragraph.vala
index 6d474b9..e1838fe 100644
--- a/src/libvaladoc/content/paragraph.vala
+++ b/src/libvaladoc/content/paragraph.vala
@@ -25,12 +25,12 @@ using Gee;
 
 
 public class Valadoc.Content.Paragraph : InlineContent, Block, StyleAttributes {
-       public HorizontalAlign? horizontal_align {
+       public HorizontalAlign horizontal_align {
                get;
                set;
        }
 
-       public VerticalAlign? vertical_align {
+       public VerticalAlign vertical_align {
                get;
                set;
        }
diff --git a/src/libvaladoc/content/sourcecode.vala b/src/libvaladoc/content/sourcecode.vala
index 31803f0..3656757 100644
--- a/src/libvaladoc/content/sourcecode.vala
+++ b/src/libvaladoc/content/sourcecode.vala
@@ -25,63 +25,56 @@ using Gee;
 
 public class Valadoc.Content.SourceCode : ContentElement, Inline {
        public enum Language {
+               UNKNOWN,
                GENIE,
                VALA,
                XML,
                C;
 
-               public static Language? from_path (string path) {
+               public static Language from_path (string path) {
                        int pos = path.last_index_of (".");
                        if (pos < 0) {
-                               return null;
+                               return Language.UNKNOWN;
                        }
 
                        string ext = path.substring (pos + 1);
                        return from_string (ext, true);
                }
 
-               public static Language? from_string (string str, bool is_extension = false) {
+               public static Language from_string (string str, bool is_extension = false) {
                        switch (str) {
                        case "genie":
                                if (is_extension) {
-                                       return null;
+                                       return Language.UNKNOWN;
                                }
                                return Language.GENIE;
-
                        case "gs":
                                return Language.GENIE;
-
                        case "xml":
                                return Language.XML;
-
                        case "vala":
                                return Language.VALA;
-
                        case "c":
                        case "h":
                                return Language.C;
                        }
 
-                       return null;
+                       return Language.UNKNOWN;
                }
 
                public unowned string to_string () {
                        switch (this) {
                        case Language.GENIE:
                                return "genie";
-
                        case Language.VALA:
                                return "vala";
-
                        case Language.XML:
                                return "xml";
-
                        case Language.C:
                                return "c";
                        }
 
-                       assert (true);
-                       return "";
+                       assert_not_reached ();
                }
        }
 
@@ -96,7 +89,7 @@ public class Valadoc.Content.SourceCode : ContentElement, Inline {
                private set;
        }
 
-       public Language? language {
+       public Language language {
                get;
                set;
        }
@@ -191,7 +184,7 @@ public class Valadoc.Content.SourceCode : ContentElement, Inline {
                                string name = start._strip ().down ();
                                _language = Language.from_string (name);
                                code = splitted[1] ?? "";
-                               if (_language == null && name != "none") {
+                               if (_language == Language.UNKNOWN && name != "none") {
                                        string node_segment = (container is Api.Package)? "" : 
container.get_full_name () + ": ";
                                        reporter.simple_warning ("%s: %s{{{".printf (file_path, node_segment),
                                                "Unsupported programming language '%s'", name);
diff --git a/src/libvaladoc/content/styleattributes.vala b/src/libvaladoc/content/styleattributes.vala
index c24893a..c2ce515 100644
--- a/src/libvaladoc/content/styleattributes.vala
+++ b/src/libvaladoc/content/styleattributes.vala
@@ -24,86 +24,82 @@ using Gee;
 
 
 public enum Valadoc.Content.HorizontalAlign {
+       NONE,
        LEFT,
        RIGHT,
        CENTER;
 
-       public static HorizontalAlign? from_string (string str) {
+       public static HorizontalAlign from_string (string str) {
                switch (str) {
+               case "none":
+                       return HorizontalAlign.NONE;
                case "left":
                        return HorizontalAlign.LEFT;
-
                case "right":
                        return HorizontalAlign.RIGHT;
-
                case "center":
                        return HorizontalAlign.CENTER;
                }
-
-               return null;
+               assert_not_reached ();
        }
 
        public unowned string to_string () {
                switch (this) {
+               case HorizontalAlign.NONE:
+                       return "none";
                case HorizontalAlign.LEFT:
                        return "left";
-
                case HorizontalAlign.RIGHT:
                        return "right";
-
                case HorizontalAlign.CENTER:
                        return "center";
                }
-
-               assert (true);
-               return "";
+               assert_not_reached ();
        }
 }
 
 public enum Valadoc.Content.VerticalAlign {
+       NONE,
        TOP,
        MIDDLE,
        BOTTOM;
 
-       public static VerticalAlign? from_string (string str) {
+       public static VerticalAlign from_string (string str) {
                switch (str) {
+               case "none":
+                       return VerticalAlign.NONE;
                case "top":
                        return VerticalAlign.TOP;
-
                case "middle":
                        return VerticalAlign.MIDDLE;
-
                case "bottom":
                        return VerticalAlign.BOTTOM;
                }
-
-               return null;
+               assert_not_reached ();
        }
 
        public unowned string to_string () {
                switch (this) {
+               case VerticalAlign.NONE:
+                       return "none";
                case VerticalAlign.TOP:
                        return "top";
-
                case VerticalAlign.MIDDLE:
                        return "middle";
-
                case VerticalAlign.BOTTOM:
                        return "bottom";
                }
-
-               assert (true);
-               return "";
+               assert_not_reached ();
        }
 }
 
 public interface Valadoc.Content.StyleAttributes : ContentElement {
-       public abstract HorizontalAlign? horizontal_align {
+       public abstract HorizontalAlign horizontal_align {
                get;
                set;
        }
 
-       public abstract VerticalAlign? vertical_align {
+       public abstract VerticalAlign vertical_align {
                get;
                set;
        }
diff --git a/src/libvaladoc/content/tablecell.vala b/src/libvaladoc/content/tablecell.vala
index 50c7fd4..ef1094b 100644
--- a/src/libvaladoc/content/tablecell.vala
+++ b/src/libvaladoc/content/tablecell.vala
@@ -25,12 +25,12 @@ using Gee;
 
 
 public class Valadoc.Content.TableCell : InlineContent, StyleAttributes {
-       public HorizontalAlign? horizontal_align {
+       public HorizontalAlign horizontal_align {
                get;
                set;
        }
 
-       public VerticalAlign? vertical_align {
+       public VerticalAlign vertical_align {
                get;
                set;
        }
diff --git a/src/libvaladoc/documentation/importerhelper.vala 
b/src/libvaladoc/documentation/importerhelper.vala
index 3f75018..4f65acd 100644
--- a/src/libvaladoc/documentation/importerhelper.vala
+++ b/src/libvaladoc/documentation/importerhelper.vala
@@ -147,8 +147,8 @@ namespace Valadoc.ImporterHelper {
 
 
                // avoid fancy stuff in short descriptions:
-               first_paragraph.horizontal_align = null;
-               first_paragraph.vertical_align = null;
+               first_paragraph.horizontal_align = HorizontalAlign.NONE;
+               first_paragraph.vertical_align = VerticalAlign.NONE;
                first_paragraph.style = null;
 
 
diff --git a/src/libvaladoc/html/htmlrenderer.vala b/src/libvaladoc/html/htmlrenderer.vala
index bdd78a0..7af1546 100644
--- a/src/libvaladoc/html/htmlrenderer.vala
+++ b/src/libvaladoc/html/htmlrenderer.vala
@@ -422,23 +422,16 @@ public class Valadoc.Html.HtmlRenderer : ContentRenderer {
 
        public override void visit_paragraph (Paragraph element) {
                //FIXME: the extra-field is just a workarround for the current codegen ...
-               if (element.horizontal_align == null) {
+               switch (element.horizontal_align) {
+               case HorizontalAlign.CENTER:
+                       writer.start_tag ("p", {"style", "text-align: center;"});
+                       break;
+               case HorizontalAlign.RIGHT:
+                       writer.start_tag ("p", {"style", "text-align: right;"});
+                       break;
+               default:
                        writer.start_tag ("p");
-               } else {
-                       HorizontalAlign tmp = element.horizontal_align;
-                       switch (tmp) {
-                       case HorizontalAlign.CENTER:
-                               writer.start_tag ("p", {"style", "text-align: center;"});
-                               break;
-
-                       case HorizontalAlign.RIGHT:
-                               writer.start_tag ("p", {"style", "text-align: right;"});
-                               break;
-
-                       default:
-                               writer.start_tag ("p");
-                               break;
-                       }
+                       break;
                }
                element.accept_children (this);
                writer.end_tag ("p");
@@ -568,11 +561,11 @@ public class Valadoc.Html.HtmlRenderer : ContentRenderer {
        public override void visit_table_cell (TableCell element) {
                string style = "";
 
-               if (element.horizontal_align != null) {
+               if (element.horizontal_align != HorizontalAlign.NONE) {
                        style += "text-align: "+element.horizontal_align.to_string ()+"; ";
                }
 
-               if (element.vertical_align != null) {
+               if (element.vertical_align != VerticalAlign.NONE) {
                        style += "vertical-align: "+element.vertical_align.to_string ()+"; ";
                }
 


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