Some improvements related to generator error recovery

This commit is contained in:
Simon Binder 2020-07-07 23:01:02 +02:00
parent 6f0fa9cde1
commit 7ff91a620a
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
6 changed files with 30 additions and 9 deletions

View File

@ -34,7 +34,7 @@ class AnalyzeDartStep extends AnalyzingStep {
affectedElement: accessor.fromClass, affectedElement: accessor.fromClass,
message: msg.toString(), message: msg.toString(),
)); ));
} catch (e) { } on Exception catch (e) {
// unknown error while sorting // unknown error while sorting
reportError(ErrorInDartCode( reportError(ErrorInDartCode(
severity: Severity.warning, severity: Severity.warning,
@ -43,6 +43,9 @@ class AnalyzeDartStep extends AnalyzingStep {
)); ));
} }
// Just to have something in case the above breaks.
availableEntities ??= const [];
final availableQueries = transitiveImports final availableQueries = transitiveImports
.map((f) => f.currentResult) .map((f) => f.currentResult)
.whereType<ParsedMoorFile>() .whereType<ParsedMoorFile>()

View File

@ -1,3 +1,4 @@
import 'package:moor_generator/moor_generator.dart' show MoorColumn;
import 'package:sqlparser/sqlparser.dart'; import 'package:sqlparser/sqlparser.dart';
import '../query_handler.dart'; import '../query_handler.dart';
@ -119,10 +120,17 @@ class _LintingVisitor extends RecursiveVisitor<void, void> {
); );
// second, check that no required columns are left out // second, check that no required columns are left out
final specifiedTable = linter.mapper.tableToMoor(e.table.resolved as Table); final resolved = e.table.resolved;
final required = specifiedTable.columns List<MoorColumn> required;
.where(specifiedTable.isColumnRequiredForInsert) if (resolved is Table) {
.toList(); final specifiedTable =
linter.mapper.tableToMoor(e.table.resolved as Table);
required = specifiedTable.columns
.where(specifiedTable.isColumnRequiredForInsert)
.toList();
} else {
required = const [];
}
if (required.isNotEmpty && e.source is DefaultValues) { if (required.isNotEmpty && e.source is DefaultValues) {
linter.lints.add(AnalysisError( linter.lints.add(AnalysisError(

View File

@ -9,6 +9,9 @@ abstract class MoorSchemaEntity implements HasDeclaration {
/// For tables, this can be contents of a `REFERENCES` clause. For triggers, /// For tables, this can be contents of a `REFERENCES` clause. For triggers,
/// it would be the tables watched. /// it would be the tables watched.
/// ///
/// If an entity contains an (invalid) null reference, that should not be
/// included in [references].
///
/// The generator will verify that the graph of entities and [references] /// The generator will verify that the graph of entities and [references]
/// is acyclic and sort them topologically. /// is acyclic and sort them topologically.
Iterable<MoorSchemaEntity> get references; Iterable<MoorSchemaEntity> get references;

View File

@ -36,5 +36,10 @@ class MoorIndex extends MoorSchemaEntity {
String get displayName => name; String get displayName => name;
@override @override
Iterable<MoorSchemaEntity> get references => [table]; Iterable<MoorSchemaEntity> get references {
if (table == null) {
return const Iterable.empty();
}
return [table];
}
} }

View File

@ -356,8 +356,10 @@ class Parser extends ParserBase
as = _consumeIdentifier('Expected a name of the result class').identifier; as = _consumeIdentifier('Expected a name of the result class').identifier;
} }
final colon = final colon = _consume(
_consume(TokenType.colon, 'Expected a colon (:) followed by a query'); TokenType.colon,
'Expected a colon (:) followed by a query. Imports and CREATE '
'statements must appear before the first query.');
final stmt = _crud(); final stmt = _crud();
if (stmt == null) { if (stmt == null) {

View File

@ -499,7 +499,7 @@ class KeywordToken extends Token {
IdentifierToken convertToIdentifier() { IdentifierToken convertToIdentifier() {
isIdentifier = true; isIdentifier = true;
return IdentifierToken(false, span, synthetic: false); return IdentifierToken(false, span, synthetic: true);
} }
} }