[vala/staging: 4/6] libvaladoc: Avoid nullable enum as property-type
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 4/6] libvaladoc: Avoid nullable enum as property-type
- Date: Fri, 14 Jul 2017 15:18:23 +0000 (UTC)
commit 42946e3a9962795d51dd01fa7116a8610c28d9bf
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/sourcecode.vala | 25 ++++++----------
libvaladoc/content/styleattributes.vala | 40 +++++++++++--------------
libvaladoc/content/tablecell.vala | 4 +-
libvaladoc/documentation/importerhelper.vala | 4 +-
libvaladoc/html/htmlrenderer.vala | 29 +++++++-----------
7 files changed, 46 insertions(+), 64 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/sourcecode.vala b/libvaladoc/content/sourcecode.vala
index a9c4935..a9b74b5 100644
--- a/libvaladoc/content/sourcecode.vala
+++ b/libvaladoc/content/sourcecode.vala
@@ -24,63 +24,56 @@
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 ();
}
}
@@ -95,7 +88,7 @@ public class Valadoc.Content.SourceCode : ContentElement, Inline {
private set;
}
- public Language? language {
+ public Language language {
get;
set;
}
@@ -190,7 +183,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/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]