Fixed Enum null check warnings
This commit is contained in:
parent
56e0e7a05a
commit
cf8d9814e8
3 changed files with 18 additions and 7 deletions
|
@ -249,7 +249,7 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
|
||||||
var args = <String, Expression>{};
|
var args = <String, Expression>{};
|
||||||
for (var field in ctx.effectiveFields) {
|
for (var field in ctx.effectiveFields) {
|
||||||
var fType = field.type;
|
var fType = field.type;
|
||||||
Reference type = convertTypeReference(field.type);
|
Reference type = convertTypeReference(fType);
|
||||||
if (isSpecialId(ctx, field)) {
|
if (isSpecialId(ctx, field)) {
|
||||||
type = refer('int');
|
type = refer('int');
|
||||||
}
|
}
|
||||||
|
@ -272,9 +272,16 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
|
||||||
expr = refer('mapToDouble').call([expr]);
|
expr = refer('mapToDouble').call([expr]);
|
||||||
} else if (fType is InterfaceType &&
|
} else if (fType is InterfaceType &&
|
||||||
fType.element is EnumElement) {
|
fType.element is EnumElement) {
|
||||||
|
/*
|
||||||
|
* fields.contains('type') ? row[3] == null ? null :
|
||||||
|
* EnumType.values[(row[3] as int)] : null,
|
||||||
|
*/
|
||||||
var isNull = expr.equalTo(literalNull);
|
var isNull = expr.equalTo(literalNull);
|
||||||
|
|
||||||
|
Reference enumType =
|
||||||
|
convertTypeReference(fType, ignoreNullabilityCheck: true);
|
||||||
expr = isNull.conditional(literalNull,
|
expr = isNull.conditional(literalNull,
|
||||||
type.property('values').index(expr.asA(refer('int'))));
|
enumType.property('values').index(expr.asA(refer('int'))));
|
||||||
} else if (fType.isDartCoreBool) {
|
} else if (fType.isDartCoreBool) {
|
||||||
// Generated Code: mapToBool(row[i])
|
// Generated Code: mapToBool(row[i])
|
||||||
expr = refer('mapToBool').call([expr]);
|
expr = refer('mapToBool').call([expr]);
|
||||||
|
@ -886,7 +893,7 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
|
||||||
|
|
||||||
if (fType is InterfaceType && fType.element is EnumElement) {
|
if (fType is InterfaceType && fType.element is EnumElement) {
|
||||||
var asInt = value.asA(refer('int'));
|
var asInt = value.asA(refer('int'));
|
||||||
var t = convertTypeReference(fType);
|
var t = convertTypeReference(fType, ignoreNullabilityCheck: true);
|
||||||
value = t.property('values').index(asInt);
|
value = t.property('values').index(asInt);
|
||||||
} else if (const TypeChecker.fromRuntime(List)
|
} else if (const TypeChecker.fromRuntime(List)
|
||||||
.isAssignableFromType(fType)) {
|
.isAssignableFromType(fType)) {
|
||||||
|
|
|
@ -3,7 +3,6 @@ import 'package:angel3_orm/angel3_orm.dart';
|
||||||
import 'package:angel3_serialize/angel3_serialize.dart';
|
import 'package:angel3_serialize/angel3_serialize.dart';
|
||||||
import 'package:optional/optional.dart';
|
import 'package:optional/optional.dart';
|
||||||
|
|
||||||
// import 'car.dart';
|
|
||||||
part 'has_car.g.dart';
|
part 'has_car.g.dart';
|
||||||
|
|
||||||
// Map _carToMap(Car car) => car.toJson();
|
// Map _carToMap(Car car) => car.toJson();
|
||||||
|
|
|
@ -38,13 +38,18 @@ Builder typescriptDefinitionBuilder(_) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a [DartType] to a [TypeReference].
|
/// Converts a [DartType] to a [TypeReference].
|
||||||
TypeReference convertTypeReference(DartType t, {bool forceNullable = false}) {
|
TypeReference convertTypeReference(DartType t,
|
||||||
|
{bool forceNullable = false, bool ignoreNullabilityCheck = false}) {
|
||||||
return TypeReference((b) {
|
return TypeReference((b) {
|
||||||
b.symbol = t.element?.displayName;
|
b.symbol = t.element?.displayName;
|
||||||
|
|
||||||
// Generate nullable type
|
// Generate nullable type
|
||||||
if (t.nullabilitySuffix == NullabilitySuffix.question || forceNullable) {
|
if (ignoreNullabilityCheck) {
|
||||||
b.isNullable = true;
|
b.isNullable = false;
|
||||||
|
} else {
|
||||||
|
if (t.nullabilitySuffix == NullabilitySuffix.question || forceNullable) {
|
||||||
|
b.isNullable = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t is InterfaceType) {
|
if (t is InterfaceType) {
|
||||||
|
|
Loading…
Reference in a new issue