[gnome-taquin] Compile with --experimental-non-null.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-taquin] Compile with --experimental-non-null.
- Date: Mon, 21 Jan 2019 06:11:39 +0000 (UTC)
commit 4d0f42a3615df951ad3a4b23363e2ea7e92ed924
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon Jan 14 10:21:24 2019 +0100
Compile with --experimental-non-null.
That helps when using nullable variables.
src/game-view.vala | 16 ++++++++--------
src/game-window.vala | 6 ++++--
src/meson.build | 3 ++-
src/taquin-game.vala | 18 ++++++++++++------
src/taquin-main.vala | 45 +++++++++++++++++++++++----------------------
src/taquin-view.vala | 47 +++++++++++++++++++++++++++++------------------
6 files changed, 78 insertions(+), 57 deletions(-)
---
diff --git a/src/game-view.vala b/src/game-view.vala
index c71c664..5b1c90f 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -46,15 +46,15 @@ private class GameView : Stack
{
/* Translators: when configuring a new game, label of the blue Start button (with a mnemonic
that appears pressing Alt) */
start_game_button = new Button.with_mnemonic (_("_Start Game"));
- start_game_button.width_request = 222;
- start_game_button.height_request = 60;
- start_game_button.halign = Align.CENTER;
- start_game_button.set_action_name ("ui.start-game");
+ ((!) start_game_button).width_request = 222;
+ ((!) start_game_button).height_request = 60;
+ ((!) start_game_button).halign = Align.CENTER;
+ ((!) start_game_button).set_action_name ("ui.start-game");
/* Translators: when configuring a new game, tooltip text of the blue Start button */
// start_game_button.set_tooltip_text (_("Start a new game as configured"));
- ((StyleContext) start_game_button.get_style_context ()).add_class ("suggested-action");
- start_game_button.show ();
- new_game_box.pack_end (start_game_button, false, false, 0);
+ ((StyleContext) ((!) start_game_button).get_style_context ()).add_class ("suggested-action");
+ ((!) start_game_button).show ();
+ new_game_box.pack_end ((!) start_game_button, false, false, 0);
}
game_content = content;
@@ -68,7 +68,7 @@ private class GameView : Stack
{
set_visible_child (new_game_box);
if (grab_focus && start_game_button != null)
- start_game_button.grab_focus ();
+ ((!) start_game_button).grab_focus ();
// TODO else if (!grabs_focus && start_game_button == null)
}
diff --git a/src/game-window.vala b/src/game-window.vala
index ebf120f..e4fcd0b 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -55,8 +55,10 @@ private class GameWindow : ApplicationWindow
if (css_resource != null)
{
CssProvider css_provider = new CssProvider ();
- css_provider.load_from_resource (css_resource);
- StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), css_provider,
STYLE_PROVIDER_PRIORITY_APPLICATION);
+ css_provider.load_from_resource ((!) css_resource);
+ Gdk.Screen? gdk_screen = Gdk.Screen.get_default ();
+ if (gdk_screen != null) // else..?
+ StyleContext.add_provider_for_screen ((!) gdk_screen, css_provider,
STYLE_PROVIDER_PRIORITY_APPLICATION);
}
/* window actions */
diff --git a/src/meson.build b/src/meson.build
index b508172..53e83b4 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -14,7 +14,8 @@ executable(meson.project_name(),[
'-include', 'config.h'
],
vala_args: [
- '--vapidir', join_paths(meson.current_source_dir(), 'vapi')
+ '--vapidir', join_paths(meson.current_source_dir(), 'vapi'),
+ '--enable-experimental-non-null'
],
dependencies: [
glib_dependency,
diff --git a/src/taquin-game.vala b/src/taquin-game.vala
index 481ff54..2a318fb 100644
--- a/src/taquin-game.vala
+++ b/src/taquin-game.vala
@@ -105,7 +105,12 @@ public class Game : Object
/* Now construct the game description */
for (var j = 0; j < ntiles; j++)
- tiles[j % size, j / size] = line[j];
+ {
+ int? line_j = line[j];
+ if (line_j == null)
+ assert_not_reached ();
+ tiles[j % size, j / size] = (!) line_j;
+ }
}
public string to_string ()
@@ -266,12 +271,12 @@ public class Game : Object
return;
if (game_type == GameType.FIFTEEN)
- fifteen_move (state.x, state.y, true);
+ fifteen_move (((!) state).x, ((!) state).y, true);
else
- sixteen_move (state.x, state.y, true);
+ sixteen_move (((!) state).x, ((!) state).y, true);
state = previous_state;
- previous_state = state == null ? null : state.previous;
+ previous_state = state == null ? null : ((!) state).previous;
if (state == null)
cannot_undo_more ();
@@ -281,7 +286,8 @@ public class Game : Object
{
previous_state = state == null ? null : state;
state = UndoItem () { x = x_gap, y = y_gap, next = null, previous = previous_state };
- if (previous_state != null)
- previous_state.next = state;
+ if (previous_state == null)
+ return;
+ previous_state = UndoItem () { x = ((!) previous_state).x, y = ((!) previous_state).y, next = state,
previous = ((!) previous_state).previous };
}
}
diff --git a/src/taquin-main.vala b/src/taquin-main.vala
index 5adf371..2623f28 100644
--- a/src/taquin-main.vala
+++ b/src/taquin-main.vala
@@ -43,7 +43,7 @@ public class Taquin : Gtk.Application
private Game? game = null;
List<string> theme_dirlist;
- private static const OptionEntry[] option_entries =
+ private const OptionEntry [] option_entries =
{
/* Translators: command-line option description, see 'gnome-taquin --help' */
{ "fifteen", 0, 0, OptionArg.NONE, null, N_("Play the classical 1880s’ 15-puzzle"), null},
@@ -65,10 +65,10 @@ public class Taquin : Gtk.Application
/* Translators: command-line option description, see 'gnome-taquin --help' */
/* { "no-gtk", 0, 0, OptionArg.NONE, null, N_("Begins a console game"), null}, TODO */
- { null }
+ {}
};
- private const GLib.ActionEntry app_actions[] =
+ private const GLib.ActionEntry [] action_entries =
{
/* TODO SimpleActionChangeStateCallback is deprecated...
{"change-size", null, "s", null, null, change_size_cb},
http://valadoc.org/#!api=gio-2.0/GLib.SimpleActionChangeStateCallback
@@ -133,11 +133,11 @@ public class Taquin : Gtk.Application
settings = new GLib.Settings ("org.gnome.Taquin");
if (sound != null)
- settings.set_boolean ("sound", sound);
+ settings.set_boolean ("sound", (!) sound);
if (tmp_size > 1)
settings.set_int ("size", tmp_size);
if (tmp_type != null)
- settings.set_string ("type", tmp_type.to_string()); // TODO better?
+ settings.set_string ("type", ((!) tmp_type).to_string ()); // TODO better?
/* UI parts */
view = new TaquinView ();
@@ -184,7 +184,7 @@ public class Taquin : Gtk.Application
});
update_theme (settings.get_string ("theme"));
- add_action_entries (app_actions, this);
+ add_action_entries (action_entries, this);
add_action (settings.create_action ("sound"));
add_action (settings.create_action ("type")); // TODO window action?
// TODO window.add_action (settings.create_action ("size")); // Problem: cannot use this way
for an integer from a menu; works for radiobuttons in Iagno
@@ -212,12 +212,12 @@ public class Taquin : Gtk.Application
private void start_game ()
{
if (game != null)
- SignalHandler.disconnect_by_func (game, null, this);
+ SignalHandler.disconnect_by_func ((!) game, null, this);
GameType type = (GameType) settings.get_enum ("type");
int size = settings.get_int ("size");
game = new Game (type, size);
- view.game = game;
+ view.game = (!) game;
string filename = "";
var dirlist = theme_dirlist.copy ();
@@ -231,10 +231,10 @@ public class Taquin : Gtk.Application
view.theme = Path.build_filename (DATA_DIRECTORY, "themes", settings.get_string ("theme"), filename);
view.realize (); // TODO does that help?
- game.complete.connect (game_complete_cb);
- game.cannot_move.connect (cannot_move_cb);
- game.cannot_undo_more.connect (window.cannot_undo_more);
- game.move.connect (move_cb);
+ ((!) game).complete.connect (game_complete_cb);
+ ((!) game).cannot_move.connect (cannot_move_cb);
+ ((!) game).cannot_undo_more.connect (window.cannot_undo_more);
+ ((!) game).move.connect (move_cb);
}
/*\
@@ -243,16 +243,15 @@ public class Taquin : Gtk.Application
private void about_cb ()
{
- string[] authors = { "Arnaud Bonatti", null };
+ string[] authors = { "Arnaud Bonatti" };
string[] artists = { "Abelard (Wikimedia)",
"Alvesgaspar (Wikimedia)",
"Mueller-rech.muenchen (Wikimedia)",
"Ruskis (Wikimedia)",
"Toyah (Wikimedia)",
/* Translators: about dialog text; in the Credits, text at the end of the
"Artwork by" section */
- _("(see COPYING.themes for informations)"),
- null };
- string[] documenters = { "Arnaud Bonatti", null };
+ _("(see COPYING.themes for informations)") };
+ string[] documenters = { "Arnaud Bonatti" };
show_about_dialog (window,
"name", PROGRAM_NAME,
"version", VERSION,
@@ -266,8 +265,7 @@ public class Taquin : Gtk.Application
/* Translators: about dialog text; this string should be replaced by a text
crediting yourselves and your translation team, or should be left empty. Do not translate literally! */
"translator-credits", _("translator-credits"),
"logo-icon-name", "org.gnome.Taquin",
- "website", "https://wiki.gnome.org/Apps/Taquin",
- null);
+ "website", "https://wiki.gnome.org/Apps/Taquin");
}
private void help_cb ()
@@ -287,8 +285,9 @@ public class Taquin : Gtk.Application
\*/
private void undo_cb ()
+ requires (game != null)
{
- game.undo ();
+ ((!) game).undo ();
play_sound ("sliding-1");
}
@@ -323,9 +322,10 @@ public class Taquin : Gtk.Application
\*/
private void change_size_cb (SimpleAction action, Variant? variant)
+ requires (variant != null)
{
size_changed = true;
- int size = int.parse (variant.get_string ());
+ int size = int.parse (((!) variant).get_string ());
update_size_button_label (size);
settings.set_int ("size", size);
}
@@ -336,9 +336,10 @@ public class Taquin : Gtk.Application
}
private void change_theme_cb (SimpleAction action, Variant? variant)
+ requires (variant != null)
{
theme_changed = true;
- string name = variant.get_string ();
+ string name = ((!) variant).get_string ();
update_theme (name);
settings.set_string ("theme", name);
}
@@ -365,7 +366,7 @@ public class Taquin : Gtk.Application
var filename = dir.read_name ();
if (filename == null)
break;
- theme_dirlist.append (filename);
+ theme_dirlist.append ((!) filename);
}
}
catch (FileError e)
diff --git a/src/taquin-view.vala b/src/taquin-view.vala
index 769bf36..87f3b01 100644
--- a/src/taquin-view.vala
+++ b/src/taquin-view.vala
@@ -81,13 +81,18 @@ public class TaquinView : Gtk.DrawingArea
}
private Game? _game = null;
- public Game? game
+ public Game game
{
- get { return _game; }
+ get { if (_game == null) assert_not_reached (); return (!) _game; }
set
{
if (_game != null)
SignalHandler.disconnect_by_func (_game, null, this);
+
+ _game = value;
+ if (_game == null)
+ assert_not_reached ();
+
animate = false;
finished = false;
animate_end = false;
@@ -95,24 +100,30 @@ public class TaquinView : Gtk.DrawingArea
draw_lights = false;
x_arrow = 0;
y_arrow = 0;
- _game = value;
- _game.move.connect (move_cb);
- _game.complete.connect (complete_cb);
+ ((!) _game).move.connect (move_cb);
+ ((!) _game).complete.connect (complete_cb);
queue_draw ();
}
}
private string? _theme = null;
- public string? theme
+ public string theme
{
- get { return _theme; }
- set { _theme = value; tiles_pattern = null; queue_draw (); }
+ get { if (_theme == null) assert_not_reached (); return (!) _theme; }
+ set
+ {
+ _theme = value;
+ if (_theme == null)
+ assert_not_reached ();
+ tiles_pattern = null;
+ queue_draw ();
+ }
}
public override bool draw (Cairo.Context cr)
{
- if (game == null)
- return false;
+// if (game == null)
+// return false;
calculate ();
@@ -175,8 +186,8 @@ public class TaquinView : Gtk.DrawingArea
var matrix = Cairo.Matrix.identity ();
matrix.translate (texture_x - tile_x, texture_y - tile_y);
- tiles_pattern.set_matrix (matrix);
- cr.set_source (tiles_pattern);
+ ((!) tiles_pattern).set_matrix (matrix);
+ cr.set_source ((!) tiles_pattern);
cr.rectangle (tile_x, tile_y, tile_size - GRID_SPACING, tile_size - GRID_SPACING);
cr.fill ();
@@ -186,8 +197,8 @@ public class TaquinView : Gtk.DrawingArea
matrix = Cairo.Matrix.identity ();
matrix.translate (texture_x - tile_x, texture_y - tile_y);
- tiles_pattern.set_matrix (matrix);
- cr.set_source (tiles_pattern);
+ ((!) tiles_pattern).set_matrix (matrix);
+ cr.set_source ((!) tiles_pattern);
cr.rectangle (tile_x, tile_y, tile_size - GRID_SPACING, tile_size - GRID_SPACING);
cr.fill ();
}
@@ -225,8 +236,8 @@ public class TaquinView : Gtk.DrawingArea
var matrix = Cairo.Matrix.identity ();
matrix.translate (texture_x - tile_x, texture_y - tile_y);
- tiles_pattern.set_matrix (matrix);
- cr.set_source (tiles_pattern);
+ ((!) tiles_pattern).set_matrix (matrix);
+ cr.set_source ((!) tiles_pattern);
cr.rectangle (tile_x, tile_y, tile_size - GRID_SPACING, tile_size - GRID_SPACING);
cr.fill ();
}
@@ -238,7 +249,7 @@ public class TaquinView : Gtk.DrawingArea
if (animation_end_offset >= 1)
animation_end_offset = 1;
var matrix = Cairo.Matrix.identity ();
- tiles_pattern.set_matrix (matrix);
+ ((!) tiles_pattern).set_matrix (matrix);
cr.paint_with_alpha (animation_end_offset);
if (animation_end_offset != 1)
queue_draw ();
@@ -416,7 +427,7 @@ public class TaquinView : Gtk.DrawingArea
{
if (finished)
return false;
- string k_name = Gdk.keyval_name (event.keyval);
+ string k_name = (!) (Gdk.keyval_name (event.keyval) ?? "");
if (game.game_type == GameType.SIXTEEN && ((event.state & ModifierType.SHIFT_MASK) > 0 ||
(event.state & ModifierType.CONTROL_MASK) > 0))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]