[vala/staging] libvaladoc: Avoid nullable enum as property-type
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] libvaladoc: Avoid nullable enum as property-type
- Date: Fri, 14 Jul 2017 14:38:19 +0000 (UTC)
commit 1f07ba4cc1fe00a3bed8dc96549f62c0a9482659
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
libvaladoc/content/embedded.vala | 4 +-
libvaladoc/content/paragraph.vala | 4 +-
libvaladoc/content/styleattributes.vala | 40 +++++++++++--------------
libvaladoc/content/tablecell.vala | 4 +-
libvaladoc/documentation/importerhelper.vala | 4 +-
libvaladoc/html/htmlrenderer.vala | 29 +++++++-----------
6 files changed, 37 insertions(+), 48 deletions(-)
---
diff --git a/libvaladoc/content/embedded.vala b/libvaladoc/content/embedded.vala
index 2666cd8..8eed77c 100644
--- a/libvaladoc/content/embedded.vala
+++ b/libvaladoc/content/embedded.vala
@@ -33,12 +33,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/libvaladoc/content/paragraph.vala b/libvaladoc/content/paragraph.vala
index 548c03f..2c8fbef 100644
--- a/libvaladoc/content/paragraph.vala
+++ b/libvaladoc/content/paragraph.vala
@@ -23,12 +23,12 @@
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/libvaladoc/content/styleattributes.vala b/libvaladoc/content/styleattributes.vala
index 69fdb83..7ee404e 100644
--- a/libvaladoc/content/styleattributes.vala
+++ b/libvaladoc/content/styleattributes.vala
@@ -22,86 +22,82 @@
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/libvaladoc/content/tablecell.vala b/libvaladoc/content/tablecell.vala
index 9bc1208..a0a806a 100644
--- a/libvaladoc/content/tablecell.vala
+++ b/libvaladoc/content/tablecell.vala
@@ -23,12 +23,12 @@
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/libvaladoc/documentation/importerhelper.vala b/libvaladoc/documentation/importerhelper.vala
index 76888d7..952db70 100644
--- a/libvaladoc/documentation/importerhelper.vala
+++ b/libvaladoc/documentation/importerhelper.vala
@@ -145,8 +145,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/libvaladoc/html/htmlrenderer.vala b/libvaladoc/html/htmlrenderer.vala
index d26d606..9a8c171 100644
--- a/libvaladoc/html/htmlrenderer.vala
+++ b/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]