Skip to content

Commit

Permalink
remove true definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
tshedor committed Aug 24, 2024
1 parent efaec65 commit 38fe229
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/brick_build/lib/src/utils/shared_checker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ class SharedChecker<_SiblingModel extends Model> {
if (classElement.supertype?.typeArguments == null ||
classElement.supertype!.typeArguments.isEmpty) {
throw InvalidGenerationSourceError(
'Type argument for ${targetType.getDisplayString()}${targetType.nullabilitySuffix == NullabilitySuffix.question ? '?' : ''} is undefined.',
'Type argument for ${targetType.getDisplayString()} is undefined.',
todo:
'Define the type on class ${targetType.element}, e.g. `extends ${classElement.supertype!.getDisplayString(withNullability: false)}<int>`',
'Define the type on class ${targetType.element}, e.g. `extends ${classElement.supertype!.getDisplayString().replaceAll('?', '')}<int>`',
element: targetType.element,
);
}
Expand Down
5 changes: 2 additions & 3 deletions packages/brick_json_generators/lib/json_deserialize.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/nullability_suffix.dart';
import 'package:brick_build/generators.dart';
import 'package:brick_core/core.dart';
import 'package:brick_core/field_serializable.dart';
Expand Down Expand Up @@ -95,7 +94,7 @@ mixin JsonDeserialize<TModel extends Model, Annotation extends FieldSerializable
final nullableSuffix = checker.isNullable ? '?' : '';

return '''$fieldValue$nullableSuffix.map(
(d) => ${klass.displayName}.fromJson(d as ${parameterType.getDisplayString()}${parameterType.nullabilitySuffix == NullabilitySuffix.question ? '?' : ''})
(d) => ${klass.displayName}.fromJson(d as ${parameterType.getDisplayString()})
)$castIterable$defaultValue''';
}

Expand Down Expand Up @@ -139,7 +138,7 @@ mixin JsonDeserialize<TModel extends Model, Annotation extends FieldSerializable
final parameterType = checker.fromJsonConstructor!.parameters.first.type;

final output =
'${klass.displayName}.fromJson($fieldValue as ${parameterType.getDisplayString()}${parameterType.nullabilitySuffix == NullabilitySuffix.question ? '?' : ''})';
'${klass.displayName}.fromJson($fieldValue as ${parameterType.getDisplayString()})';
if (checker.isNullable) return '$fieldValue != null ? $output : null';
return output;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ class OfflineFirstSqliteDeserialize extends SqliteDeserialize {
if (argTypeChecker.hasSerdes) {
final doesHaveConstructor = hasConstructor(checker.argType);
if (doesHaveConstructor) {
final serializableType =
argTypeChecker.superClassTypeArgs.last.getDisplayString(withNullability: true);
final serializableType = argTypeChecker.superClassTypeArgs.last.getDisplayString();
return '''
jsonDecode($fieldValue).map(
(c) => $argType.$constructorName(c as $serializableType)
Expand All @@ -106,8 +105,7 @@ class OfflineFirstSqliteDeserialize extends SqliteDeserialize {
if ((checker as OfflineFirstChecker).hasSerdes) {
final doesHaveConstructor = hasConstructor(field.type);
if (doesHaveConstructor) {
final serializableType =
checker.superClassTypeArgs.last.getDisplayString(withNullability: true);
final serializableType = checker.superClassTypeArgs.last.getDisplayString();
return '${SharedChecker.withoutNullability(field.type)}.$constructorName($fieldValue as $serializableType)';
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/nullability_suffix.dart';
import 'package:brick_build/generators.dart' show SerdesGenerator, SharedChecker;
import 'package:brick_sqlite/brick_sqlite.dart';
import 'package:brick_sqlite/db.dart' show InsertTable, InsertForeignKey;
Expand Down Expand Up @@ -138,7 +137,7 @@ class SqliteDeserialize<_Model extends SqliteModel> extends SqliteSerdesGenerato
final discoveredByIndex =
'jsonDecode($fieldValue).map((d) => d as int > -1 ? ${SharedChecker.withoutNullability(argType)}.values[d] : null)';
final nullableSuffix = checker.isNullable ? '?' : '';
return '$discoveredByIndex$nullableSuffix.whereType<${argType.getDisplayString()}${argType.nullabilitySuffix == NullabilitySuffix.question ? '?' : ''}>()$castIterable';
return '$discoveredByIndex$nullableSuffix.whereType<${argType.getDisplayString()}>()$castIterable';
}

// Iterable<bool>
Expand All @@ -153,7 +152,7 @@ class SqliteDeserialize<_Model extends SqliteModel> extends SqliteSerdesGenerato
final nullableSuffix = checker.isNullable ? " ?? '[]'" : '';

return '''jsonDecode($fieldValue$nullableSuffix).map(
(d) => ${klass.displayName}.fromJson(d as ${parameterType.getDisplayString()}${parameterType.nullabilitySuffix == NullabilitySuffix.question ? '?' : ''})
(d) => ${klass.displayName}.fromJson(d as ${parameterType.getDisplayString()})
)$castIterable$defaultValue''';
}

Expand Down Expand Up @@ -211,7 +210,7 @@ class SqliteDeserialize<_Model extends SqliteModel> extends SqliteSerdesGenerato
} else if (checker.fromJsonConstructor != null) {
final klass = checker.targetType.element as ClassElement;
final parameterType = checker.fromJsonConstructor!.parameters.first.type;
return '${klass.displayName}.fromJson(jsonDecode($fieldValue as String) as ${parameterType.getDisplayString()}${parameterType.nullabilitySuffix == NullabilitySuffix.question ? '?' : ''})';
return '${klass.displayName}.fromJson(jsonDecode($fieldValue as String) as ${parameterType.getDisplayString()})';
}

return null;
Expand Down

0 comments on commit 38fe229

Please sign in to comment.