From 5510a90583a852af0f5d2148d8222731438fd9a6 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 9 Oct 2019 19:48:52 +0200 Subject: [PATCH] Fix warnings (2.6-dev SDK), escape \r, constant workaround --- moor/CHANGELOG.md | 3 ++- moor/example/example.g.dart | 2 +- moor/example_web/lib/widgets/create_entry_bar.dart | 2 +- moor/example_web/lib/widgets/entry_list.dart | 2 +- moor/lib/src/runtime/database.dart | 4 ++-- moor/lib/src/runtime/statements/delete.dart | 2 +- moor/lib/src/runtime/statements/select.dart | 4 ++-- moor/lib/src/types/type_system.dart | 6 ++++++ moor/test/data/tables/custom_tables.g.dart | 3 +-- moor/test/data/tables/todos.g.dart | 2 +- moor/test/database_test.dart | 2 +- moor/test/expressions/datetime_expression_test.dart | 2 +- moor/test/types/sql_type_test.dart | 2 +- moor_flutter/example/lib/widgets/add_category_dialog.dart | 2 +- moor_flutter/example/lib/widgets/categories_drawer.dart | 4 ++-- moor_flutter/example/lib/widgets/todo_edit_dialog.dart | 4 ++-- moor_flutter/example/pubspec.yaml | 4 ++-- moor_generator/CHANGELOG.md | 5 +++++ moor_generator/lib/src/utils/string_escaper.dart | 1 + moor_generator/lib/src/writer/database_writer.dart | 2 +- 20 files changed, 35 insertions(+), 23 deletions(-) diff --git a/moor/CHANGELOG.md b/moor/CHANGELOG.md index edf526a9..ee1663b4 100644 --- a/moor/CHANGELOG.md +++ b/moor/CHANGELOG.md @@ -4,7 +4,8 @@ to check values for both an upper and lower bound - Automatically map `BOOLEAN` and `DATETIME` columns declared in a sql file to the appropriate type (both used to be `double` before). -- __Breaking__: Remove the type parameter from `Insertable.createCompanion`. +- __Breaking__: Remove the type parameter from `Insertable.createCompanion` (it was declared as an + internal method) ## 2.0.0 This is the first major update after the initial release and moor and we have a lot to cover: diff --git a/moor/example/example.g.dart b/moor/example/example.g.dart index b0005c20..64b3caa2 100644 --- a/moor/example/example.g.dart +++ b/moor/example/example.g.dart @@ -831,7 +831,7 @@ class $IngredientInRecipesTable extends IngredientInRecipes } abstract class _$Database extends GeneratedDatabase { - _$Database(QueryExecutor e) : super(const SqlTypeSystem.withDefaults(), e); + _$Database(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e); $CategoriesTable _categories; $CategoriesTable get categories => _categories ??= $CategoriesTable(this); $RecipesTable _recipes; diff --git a/moor/example_web/lib/widgets/create_entry_bar.dart b/moor/example_web/lib/widgets/create_entry_bar.dart index e51f2cfa..be5a2414 100644 --- a/moor/example_web/lib/widgets/create_entry_bar.dart +++ b/moor/example_web/lib/widgets/create_entry_bar.dart @@ -24,7 +24,7 @@ class _CreateEntryBarState extends State { child: TextField( controller: _controller, onSubmitted: (_) => _submit(), - decoration: InputDecoration( + decoration: const InputDecoration( border: OutlineInputBorder(), ), ), diff --git a/moor/example_web/lib/widgets/entry_list.dart b/moor/example_web/lib/widgets/entry_list.dart index e5f7df9a..b3c23f8c 100644 --- a/moor/example_web/lib/widgets/entry_list.dart +++ b/moor/example_web/lib/widgets/entry_list.dart @@ -45,7 +45,7 @@ class _EntryCard extends StatelessWidget { mainAxisSize: MainAxisSize.max, children: [ Text(entry.content), - Spacer(), + const Spacer(), Checkbox( value: entry.done, onChanged: (checked) { diff --git a/moor/lib/src/runtime/database.dart b/moor/lib/src/runtime/database.dart index 35586014..7c803248 100644 --- a/moor/lib/src/runtime/database.dart +++ b/moor/lib/src/runtime/database.dart @@ -124,8 +124,8 @@ mixin QueryEngine on DatabaseConnectionUser { bool get topLevel => false; /// We can detect when a user called methods on the wrong [QueryEngine] - /// (e.g. calling [GeneratedDatabase.into] in a transaction, where - /// [Transaction.into] should have been called instead). See the documentation + /// (e.g. calling [QueryEngine.into] in a transaction, where + /// [QueryEngine.into] should have been called instead). See the documentation /// of [topLevel] on how this works. QueryEngine get _resolvedEngine { if (!topLevel) { diff --git a/moor/lib/src/runtime/statements/delete.dart b/moor/lib/src/runtime/statements/delete.dart index 6fcb359f..f2d87900 100644 --- a/moor/lib/src/runtime/statements/delete.dart +++ b/moor/lib/src/runtime/statements/delete.dart @@ -8,7 +8,7 @@ import 'package:moor/src/runtime/structure/table_info.dart'; /// A `DELETE` statement in sql class DeleteStatement extends Query with SingleTableQueryMixin { - /// This constructor should be called by [GeneratedDatabase.delete] for you. + /// This constructor should be called by [QueryEngine.delete] for you. DeleteStatement(QueryEngine database, TableInfo table) : super(database, table); diff --git a/moor/lib/src/runtime/statements/select.dart b/moor/lib/src/runtime/statements/select.dart index 10bb1840..60b75b10 100644 --- a/moor/lib/src/runtime/statements/select.dart +++ b/moor/lib/src/runtime/statements/select.dart @@ -223,8 +223,8 @@ class SimpleSelectStatement /// See also: /// - [innerJoin], [leftOuterJoin] and [crossJoin], which can be used to /// construct a [Join]. - /// - [GeneratedDatabase.alias], which can be used to build statements that - /// refer to the same table multiple times. + /// - [DatabaseConnectionUser.alias], which can be used to build statements + /// that refer to the same table multiple times. JoinedSelectStatement join(List joins) { final statement = JoinedSelectStatement(database, table, joins); diff --git a/moor/lib/src/types/type_system.dart b/moor/lib/src/types/type_system.dart index e7843be7..a7b7b3ac 100644 --- a/moor/lib/src/types/type_system.dart +++ b/moor/lib/src/types/type_system.dart @@ -20,6 +20,12 @@ class SqlTypeSystem { RealType(), ]); + /// Constant field of [SqlTypeSystem.withDefaults()]. This field exists as a + /// workaround for an analyzer bug: https://dartbug.com/38658 + /// + /// Used internally by generated code. + static const defaultInstance = SqlTypeSystem.withDefaults(); + /// Returns the appropriate sql type for the dart type provided as the /// generic parameter. SqlType forDartType() { diff --git a/moor/test/data/tables/custom_tables.g.dart b/moor/test/data/tables/custom_tables.g.dart index e6df0fcf..a2a13f6d 100644 --- a/moor/test/data/tables/custom_tables.g.dart +++ b/moor/test/data/tables/custom_tables.g.dart @@ -876,8 +876,7 @@ class Mytable extends Table with TableInfo { } abstract class _$CustomTablesDb extends GeneratedDatabase { - _$CustomTablesDb(QueryExecutor e) - : super(const SqlTypeSystem.withDefaults(), e); + _$CustomTablesDb(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e); NoIds _noIds; NoIds get noIds => _noIds ??= NoIds(this); WithDefaults _withDefaults; diff --git a/moor/test/data/tables/todos.g.dart b/moor/test/data/tables/todos.g.dart index 9b4b7e47..57d1e58e 100644 --- a/moor/test/data/tables/todos.g.dart +++ b/moor/test/data/tables/todos.g.dart @@ -1286,7 +1286,7 @@ class $PureDefaultsTable extends PureDefaults } abstract class _$TodoDb extends GeneratedDatabase { - _$TodoDb(QueryExecutor e) : super(const SqlTypeSystem.withDefaults(), e); + _$TodoDb(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e); $TodosTableTable _todosTable; $TodosTableTable get todosTable => _todosTable ??= $TodosTableTable(this); $CategoriesTable _categories; diff --git a/moor/test/database_test.dart b/moor/test/database_test.dart index df77a773..7d13427e 100644 --- a/moor/test/database_test.dart +++ b/moor/test/database_test.dart @@ -47,7 +47,7 @@ void main() { setUp(() { executor = MockExecutor(); queryExecutor = MockQueryExecutor(); - db = _FakeDb(const SqlTypeSystem.withDefaults(), executor); + db = _FakeDb(SqlTypeSystem.defaultInstance, executor); }); test('onCreate', () async { diff --git a/moor/test/expressions/datetime_expression_test.dart b/moor/test/expressions/datetime_expression_test.dart index da57ef53..3744cd11 100644 --- a/moor/test/expressions/datetime_expression_test.dart +++ b/moor/test/expressions/datetime_expression_test.dart @@ -20,7 +20,7 @@ void main() { expectedResults.forEach((key, value) { test('should extract field', () { - final ctx = GenerationContext(const SqlTypeSystem.withDefaults(), null); + final ctx = GenerationContext(SqlTypeSystem.defaultInstance, null); key(column).writeInto(ctx); expect(ctx.sql, value); diff --git a/moor/test/types/sql_type_test.dart b/moor/test/types/sql_type_test.dart index b8c78e4c..9bf41d45 100644 --- a/moor/test/types/sql_type_test.dart +++ b/moor/test/types/sql_type_test.dart @@ -3,7 +3,7 @@ import 'package:test/test.dart'; void main() { test('types map null values to null', () { - final typeSystem = const SqlTypeSystem.withDefaults(); + const typeSystem = SqlTypeSystem.defaultInstance; for (var type in typeSystem.types) { expect(type.mapToSqlVariable(null), isNull, diff --git a/moor_flutter/example/lib/widgets/add_category_dialog.dart b/moor_flutter/example/lib/widgets/add_category_dialog.dart index 295f8ed7..aaa735f2 100644 --- a/moor_flutter/example/lib/widgets/add_category_dialog.dart +++ b/moor_flutter/example/lib/widgets/add_category_dialog.dart @@ -27,7 +27,7 @@ class _AddCategoryDialogState extends State { TextField( controller: _controller, autofocus: true, - decoration: InputDecoration( + decoration: const InputDecoration( labelText: 'Name of the category', ), onSubmitted: (_) => _addEntry(), diff --git a/moor_flutter/example/lib/widgets/categories_drawer.dart b/moor_flutter/example/lib/widgets/categories_drawer.dart index 63defceb..3aad0a40 100644 --- a/moor_flutter/example/lib/widgets/categories_drawer.dart +++ b/moor_flutter/example/lib/widgets/categories_drawer.dart @@ -35,7 +35,7 @@ class CategoriesDrawer extends StatelessWidget { }, ), ), - Spacer(), + const Spacer(), Row( children: [ FlatButton( @@ -89,7 +89,7 @@ class _CategoryDrawerEntry extends StatelessWidget { // also show a delete button if the category can be deleted if (category != null) { rowContent.addAll([ - Spacer(), + const Spacer(), IconButton( icon: const Icon(Icons.delete_outline), color: Colors.red, diff --git a/moor_flutter/example/lib/widgets/todo_edit_dialog.dart b/moor_flutter/example/lib/widgets/todo_edit_dialog.dart index 02bc499b..a6b7e406 100644 --- a/moor_flutter/example/lib/widgets/todo_edit_dialog.dart +++ b/moor_flutter/example/lib/widgets/todo_edit_dialog.dart @@ -45,7 +45,7 @@ class _TodoEditDialogState extends State { children: [ TextField( controller: textController, - decoration: InputDecoration( + decoration: const InputDecoration( hintText: 'What needs to be done?', helperText: 'Content of entry', ), @@ -53,7 +53,7 @@ class _TodoEditDialogState extends State { Row( children: [ Text(formattedDate), - Spacer(), + const Spacer(), IconButton( icon: const Icon(Icons.calendar_today), onPressed: () async { diff --git a/moor_flutter/example/pubspec.yaml b/moor_flutter/example/pubspec.yaml index 8f8a45fc..b9075301 100644 --- a/moor_flutter/example/pubspec.yaml +++ b/moor_flutter/example/pubspec.yaml @@ -12,11 +12,11 @@ dependencies: intl: cupertino_icons: ^0.1.2 rxdart: 0.21.0 - moor_flutter: ^1.4.0 + moor_flutter: ^2.0.0 dev_dependencies: build_runner: - moor_generator: ^1.4.0 + moor_generator: ^2.0.0 flutter_test: sdk: flutter diff --git a/moor_generator/CHANGELOG.md b/moor_generator/CHANGELOG.md index 0a40e255..2214918f 100644 --- a/moor_generator/CHANGELOG.md +++ b/moor_generator/CHANGELOG.md @@ -1,3 +1,8 @@ +## upcoming release + +- Escape `\r` characters in generated Dart literals +- Fix for [an analyzer bug on constant expressions](https://dartbug.com/38658) in generated code + ## 1.7.1 - Drop support for analyzer versions `<0.36.4`. They weren't supported in version 1.7.0 either, but the `pubspec.yaml` did not specify this correctly. diff --git a/moor_generator/lib/src/utils/string_escaper.dart b/moor_generator/lib/src/utils/string_escaper.dart index 17df4baf..c2fc418a 100644 --- a/moor_generator/lib/src/utils/string_escaper.dart +++ b/moor_generator/lib/src/utils/string_escaper.dart @@ -7,5 +7,6 @@ String escapeForDart(String value) { return value .replaceAll("'", "\\'") .replaceAll('\$', '\\\$') + .replaceAll('\r', '\\r') .replaceAll('\n', '\\n'); } diff --git a/moor_generator/lib/src/writer/database_writer.dart b/moor_generator/lib/src/writer/database_writer.dart index 583f8bd8..5352d30f 100644 --- a/moor_generator/lib/src/writer/database_writer.dart +++ b/moor_generator/lib/src/writer/database_writer.dart @@ -23,7 +23,7 @@ class DatabaseWriter { final className = '_\$${db.fromClass.name}'; dbScope.leaf().write( 'abstract class $className extends GeneratedDatabase {\n' - '$className(QueryExecutor e) : super(const SqlTypeSystem.withDefaults(), e); \n'); + '$className(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e); \n'); final tableGetters = [];