diff --git a/examples/drift/.gitignore b/examples/drift/.gitignore index b94efff6..adce9480 100644 --- a/examples/drift/.gitignore +++ b/examples/drift/.gitignore @@ -11,3 +11,4 @@ pubspec.lock # Example !*.g.dart +!*.auto_mappr.dart diff --git a/examples/drift/lib/mappr.g.dart b/examples/drift/lib/mappr.auto_mappr.dart similarity index 82% rename from examples/drift/lib/mappr.g.dart rename to examples/drift/lib/mappr.auto_mappr.dart index 5b8a0208..341c1c79 100644 --- a/examples/drift/lib/mappr.g.dart +++ b/examples/drift/lib/mappr.auto_mappr.dart @@ -1,26 +1,26 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'mappr.dart'; - // ************************************************************************** // AutoMapprGenerator // ************************************************************************** -// ignore_for_file: non_constant_identifier_names, prefer_const_constructors -// ignore_for_file: prefer_const_literals_to_create_immutables -// ignore_for_file: require_trailing_commas, unnecessary_const -// ignore_for_file: unnecessary_lambdas, unnecessary_parenthesis -// ignore_for_file: unnecessary_raw_strings +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:auto_mappr_annotation/auto_mappr_annotation.dart' as _i1; + +import 'db.dart' as _i2; +import 'mappr.dart' as _i3; /// {@template package:examples_drift/mappr.dart} /// Available mappings: /// - `Todo` → `TodoItem`. /// {@endtemplate} -class $Mappr implements AutoMapprInterface { +class $Mappr implements _i1.AutoMapprInterface { const $Mappr(); Type _typeOf() => T; - List get _modules => const []; + List<_i1.AutoMapprInterface> get _delegates => const []; /// {@macro AutoMapprInterface:canConvert} /// {@macro package:examples_drift/mappr.dart} @@ -28,13 +28,14 @@ class $Mappr implements AutoMapprInterface { bool canConvert({bool recursive = true}) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.Todo>() || + sourceTypeOf == _typeOf<_i2.Todo?>()) && + (targetTypeOf == _typeOf<_i3.TodoItem>() || + targetTypeOf == _typeOf<_i3.TodoItem?>())) { return true; } if (recursive) { - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return true; } @@ -50,7 +51,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return _convert(model)!; } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convert(model)!; } @@ -69,7 +70,7 @@ class $Mappr implements AutoMapprInterface { canReturnNull: true, ); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvert(model); } @@ -85,7 +86,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return model.map((item) => _convert(item)!); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertIterable(model); } @@ -105,7 +106,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return model.map((item) => _convert(item, canReturnNull: true)); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertIterable(model); } @@ -121,7 +122,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return convertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertList(model); } @@ -140,7 +141,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return tryConvertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertList(model); } @@ -156,7 +157,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return convertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertSet(model); } @@ -175,7 +176,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return tryConvertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertSet(model); } @@ -190,25 +191,26 @@ class $Mappr implements AutoMapprInterface { }) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.Todo>() || + sourceTypeOf == _typeOf<_i2.Todo?>()) && + (targetTypeOf == _typeOf<_i3.TodoItem>() || + targetTypeOf == _typeOf<_i3.TodoItem?>())) { if (canReturnNull && model == null) { return null; } - return (_map__Todo__To__TodoItem((model as Todo?)) as TARGET); + return (_map___i2$Todo__To___i3$TodoItem((model as _i2.Todo?)) as TARGET); } throw Exception('No ${model.runtimeType} -> $targetTypeOf mapping.'); } - TodoItem _map__Todo__To__TodoItem(Todo? input) { + _i3.TodoItem _map___i2$Todo__To___i3$TodoItem(_i2.Todo? input) { final model = input; if (model == null) { throw Exception( r'Mapping Todo → TodoItem failed because Todo was null, and no default value was provided. ' r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); } - return TodoItem( + return _i3.TodoItem( id: model.id, title: model.title, ); diff --git a/examples/drift/lib/mappr.dart b/examples/drift/lib/mappr.dart index a996efc6..567df05a 100644 --- a/examples/drift/lib/mappr.dart +++ b/examples/drift/lib/mappr.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:examples_drift/db.dart'; -part 'mappr.g.dart'; +import 'package:examples_drift/mappr.auto_mappr.dart'; class TodoItem { final int id; diff --git a/examples/drift/pubspec.yaml b/examples/drift/pubspec.yaml index b642eea2..10ff61c0 100644 --- a/examples/drift/pubspec.yaml +++ b/examples/drift/pubspec.yaml @@ -15,5 +15,5 @@ dev_dependencies: auto_mappr: ^1.6.0 build_runner: ^2.0.0 drift_dev: ^2.7.0 - netglade_analysis: ^4.0.0 + netglade_analysis: ^4.2.0 test: ^1.16.0 diff --git a/examples/example/.gitignore b/examples/example/.gitignore index b94efff6..adce9480 100644 --- a/examples/example/.gitignore +++ b/examples/example/.gitignore @@ -11,3 +11,4 @@ pubspec.lock # Example !*.g.dart +!*.auto_mappr.dart diff --git a/examples/example/lib/enum.g.dart b/examples/example/lib/enum.auto_mappr.dart similarity index 71% rename from examples/example/lib/enum.g.dart rename to examples/example/lib/enum.auto_mappr.dart index 6cdd3e9e..97bbe7e9 100644 --- a/examples/example/lib/enum.g.dart +++ b/examples/example/lib/enum.auto_mappr.dart @@ -1,16 +1,15 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'enum.dart'; - // ************************************************************************** // AutoMapprGenerator // ************************************************************************** -// ignore_for_file: non_constant_identifier_names, prefer_const_constructors -// ignore_for_file: prefer_const_literals_to_create_immutables -// ignore_for_file: require_trailing_commas, unnecessary_const -// ignore_for_file: unnecessary_lambdas, unnecessary_parenthesis -// ignore_for_file: unnecessary_raw_strings +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:auto_mappr_annotation/auto_mappr_annotation.dart' as _i1; + +import 'enum.dart' as _i2; /// {@template package:examples_example/enum.dart} /// Available mappings: @@ -18,11 +17,11 @@ part of 'enum.dart'; /// - `Vehicle` → `Vehicle`. /// - `Vehicle` → `VehicleX`. /// {@endtemplate} -class $Mappr implements AutoMapprInterface { +class $Mappr implements _i1.AutoMapprInterface { const $Mappr(); Type _typeOf() => T; - List get _modules => const []; + List<_i1.AutoMapprInterface> get _delegates => const []; /// {@macro AutoMapprInterface:canConvert} /// {@macro package:examples_example/enum.dart} @@ -30,26 +29,26 @@ class $Mappr implements AutoMapprInterface { bool canConvert({bool recursive = true}) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.UserType>() || + sourceTypeOf == _typeOf<_i2.UserType?>()) && + (targetTypeOf == _typeOf<_i2.PersonType>() || + targetTypeOf == _typeOf<_i2.PersonType?>())) { return true; } - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.Vehicle>() || + sourceTypeOf == _typeOf<_i2.Vehicle?>()) && + (targetTypeOf == _typeOf<_i2.Vehicle>() || + targetTypeOf == _typeOf<_i2.Vehicle?>())) { return true; } - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.Vehicle>() || + sourceTypeOf == _typeOf<_i2.Vehicle?>()) && + (targetTypeOf == _typeOf<_i2.VehicleX>() || + targetTypeOf == _typeOf<_i2.VehicleX?>())) { return true; } if (recursive) { - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return true; } @@ -65,7 +64,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return _convert(model)!; } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convert(model)!; } @@ -84,7 +83,7 @@ class $Mappr implements AutoMapprInterface { canReturnNull: true, ); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvert(model); } @@ -100,7 +99,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return model.map((item) => _convert(item)!); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertIterable(model); } @@ -120,7 +119,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return model.map((item) => _convert(item, canReturnNull: true)); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertIterable(model); } @@ -136,7 +135,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return convertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertList(model); } @@ -155,7 +154,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return tryConvertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertList(model); } @@ -171,7 +170,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return convertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertSet(model); } @@ -190,7 +189,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return tryConvertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertSet(model); } @@ -205,63 +204,66 @@ class $Mappr implements AutoMapprInterface { }) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.UserType>() || + sourceTypeOf == _typeOf<_i2.UserType?>()) && + (targetTypeOf == _typeOf<_i2.PersonType>() || + targetTypeOf == _typeOf<_i2.PersonType?>())) { if (canReturnNull && model == null) { return null; } - return (_map__UserType__To__PersonType((model as UserType?)) as TARGET); + return (_map___i2$UserType__To___i2$PersonType((model as _i2.UserType?)) + as TARGET); } - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.Vehicle>() || + sourceTypeOf == _typeOf<_i2.Vehicle?>()) && + (targetTypeOf == _typeOf<_i2.Vehicle>() || + targetTypeOf == _typeOf<_i2.Vehicle?>())) { if (canReturnNull && model == null) { return null; } - return (_map__Vehicle__To__Vehicle((model as Vehicle?)) as TARGET); + return (_map___i2$Vehicle__To___i2$Vehicle((model as _i2.Vehicle?)) + as TARGET); } - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.Vehicle>() || + sourceTypeOf == _typeOf<_i2.Vehicle?>()) && + (targetTypeOf == _typeOf<_i2.VehicleX>() || + targetTypeOf == _typeOf<_i2.VehicleX?>())) { if (canReturnNull && model == null) { return null; } - return (_map__Vehicle__To__VehicleX((model as Vehicle?)) as TARGET); + return (_map___i2$Vehicle__To___i2$VehicleX((model as _i2.Vehicle?)) + as TARGET); } throw Exception('No ${model.runtimeType} -> $targetTypeOf mapping.'); } - PersonType _map__UserType__To__PersonType(UserType? input) { + _i2.PersonType _map___i2$UserType__To___i2$PersonType(_i2.UserType? input) { final model = input; if (model == null) { throw Exception( r'Mapping UserType → PersonType failed because UserType was null, and no default value was provided. ' r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); } - return PersonType.values.firstWhere((x) => x.name == model.name); + return _i2.PersonType.values.firstWhere((x) => x.name == model.name); } - Vehicle _map__Vehicle__To__Vehicle(Vehicle? input) { + _i2.Vehicle _map___i2$Vehicle__To___i2$Vehicle(_i2.Vehicle? input) { final model = input; if (model == null) { throw Exception( r'Mapping Vehicle → Vehicle failed because Vehicle was null, and no default value was provided. ' r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); } - return Vehicle.values.firstWhere((x) => x.name == model.name); + return _i2.Vehicle.values.firstWhere((x) => x.name == model.name); } - VehicleX _map__Vehicle__To__VehicleX(Vehicle? input) { + _i2.VehicleX _map___i2$Vehicle__To___i2$VehicleX(_i2.Vehicle? input) { final model = input; if (model == null) { throw Exception( r'Mapping Vehicle → VehicleX failed because Vehicle was null, and no default value was provided. ' r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); } - return VehicleX.values.firstWhere((x) => x.name == model.name); + return _i2.VehicleX.values.firstWhere((x) => x.name == model.name); } } diff --git a/examples/example/lib/enum.dart b/examples/example/lib/enum.dart index 670a1438..ee44c3cb 100644 --- a/examples/example/lib/enum.dart +++ b/examples/example/lib/enum.dart @@ -1,6 +1,6 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; -part 'enum.g.dart'; +import 'package:examples_example/enum.auto_mappr.dart'; enum UserType { student, admin, parent } diff --git a/examples/example/lib/equatable.g.dart b/examples/example/lib/equatable.auto_mappr.dart similarity index 82% rename from examples/example/lib/equatable.g.dart rename to examples/example/lib/equatable.auto_mappr.dart index d4ce6859..5fa12e51 100644 --- a/examples/example/lib/equatable.g.dart +++ b/examples/example/lib/equatable.auto_mappr.dart @@ -1,26 +1,25 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'equatable.dart'; - // ************************************************************************** // AutoMapprGenerator // ************************************************************************** -// ignore_for_file: non_constant_identifier_names, prefer_const_constructors -// ignore_for_file: prefer_const_literals_to_create_immutables -// ignore_for_file: require_trailing_commas, unnecessary_const -// ignore_for_file: unnecessary_lambdas, unnecessary_parenthesis -// ignore_for_file: unnecessary_raw_strings +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:auto_mappr_annotation/auto_mappr_annotation.dart' as _i1; + +import 'equatable.dart' as _i2; /// {@template package:examples_example/equatable.dart} /// Available mappings: /// - `UserDto` → `User`. /// {@endtemplate} -class $Mappr implements AutoMapprInterface { +class $Mappr implements _i1.AutoMapprInterface { const $Mappr(); Type _typeOf() => T; - List get _modules => const []; + List<_i1.AutoMapprInterface> get _delegates => const []; /// {@macro AutoMapprInterface:canConvert} /// {@macro package:examples_example/equatable.dart} @@ -28,13 +27,14 @@ class $Mappr implements AutoMapprInterface { bool canConvert({bool recursive = true}) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.UserDto>() || + sourceTypeOf == _typeOf<_i2.UserDto?>()) && + (targetTypeOf == _typeOf<_i2.User>() || + targetTypeOf == _typeOf<_i2.User?>())) { return true; } if (recursive) { - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return true; } @@ -50,7 +50,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return _convert(model)!; } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convert(model)!; } @@ -69,7 +69,7 @@ class $Mappr implements AutoMapprInterface { canReturnNull: true, ); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvert(model); } @@ -85,7 +85,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return model.map((item) => _convert(item)!); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertIterable(model); } @@ -105,7 +105,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return model.map((item) => _convert(item, canReturnNull: true)); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertIterable(model); } @@ -121,7 +121,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return convertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertList(model); } @@ -140,7 +140,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return tryConvertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertList(model); } @@ -156,7 +156,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return convertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertSet(model); } @@ -175,7 +175,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return tryConvertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertSet(model); } @@ -190,25 +190,27 @@ class $Mappr implements AutoMapprInterface { }) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.UserDto>() || + sourceTypeOf == _typeOf<_i2.UserDto?>()) && + (targetTypeOf == _typeOf<_i2.User>() || + targetTypeOf == _typeOf<_i2.User?>())) { if (canReturnNull && model == null) { return null; } - return (_map__UserDto__To__User((model as UserDto?)) as TARGET); + return (_map___i2$UserDto__To___i2$User((model as _i2.UserDto?)) + as TARGET); } throw Exception('No ${model.runtimeType} -> $targetTypeOf mapping.'); } - User _map__UserDto__To__User(UserDto? input) { + _i2.User _map___i2$UserDto__To___i2$User(_i2.UserDto? input) { final model = input; if (model == null) { throw Exception( r'Mapping UserDto → User failed because UserDto was null, and no default value was provided. ' r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); } - return User( + return _i2.User( id: model.id, name: model.name, tag: null, diff --git a/examples/example/lib/equatable.dart b/examples/example/lib/equatable.dart index 29fee030..ac72afd4 100644 --- a/examples/example/lib/equatable.dart +++ b/examples/example/lib/equatable.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'equatable.g.dart'; +import 'package:examples_example/equatable.auto_mappr.dart'; @AutoMappr([ MapType(), diff --git a/examples/example/lib/nested.g.dart b/examples/example/lib/nested.auto_mappr.dart similarity index 69% rename from examples/example/lib/nested.g.dart rename to examples/example/lib/nested.auto_mappr.dart index f50fa375..d7c10103 100644 --- a/examples/example/lib/nested.g.dart +++ b/examples/example/lib/nested.auto_mappr.dart @@ -1,16 +1,15 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'nested.dart'; - // ************************************************************************** // AutoMapprGenerator // ************************************************************************** -// ignore_for_file: non_constant_identifier_names, prefer_const_constructors -// ignore_for_file: prefer_const_literals_to_create_immutables -// ignore_for_file: require_trailing_commas, unnecessary_const -// ignore_for_file: unnecessary_lambdas, unnecessary_parenthesis -// ignore_for_file: unnecessary_raw_strings +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:auto_mappr_annotation/auto_mappr_annotation.dart' as _i1; + +import 'nested.dart' as _i2; /// {@template package:examples_example/nested.dart} /// Available mappings: @@ -18,11 +17,11 @@ part of 'nested.dart'; /// - `NestedDto` → `Nested`. /// - `NestedTagDto` → `NestedTag`. /// {@endtemplate} -class $Mappr implements AutoMapprInterface { +class $Mappr implements _i1.AutoMapprInterface { const $Mappr(); Type _typeOf() => T; - List get _modules => const []; + List<_i1.AutoMapprInterface> get _delegates => const []; /// {@macro AutoMapprInterface:canConvert} /// {@macro package:examples_example/nested.dart} @@ -30,25 +29,26 @@ class $Mappr implements AutoMapprInterface { bool canConvert({bool recursive = true}) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.UserDto>() || + sourceTypeOf == _typeOf<_i2.UserDto?>()) && + (targetTypeOf == _typeOf<_i2.User>() || + targetTypeOf == _typeOf<_i2.User?>())) { return true; } - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.NestedDto>() || + sourceTypeOf == _typeOf<_i2.NestedDto?>()) && + (targetTypeOf == _typeOf<_i2.Nested>() || + targetTypeOf == _typeOf<_i2.Nested?>())) { return true; } - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.NestedTagDto>() || + sourceTypeOf == _typeOf<_i2.NestedTagDto?>()) && + (targetTypeOf == _typeOf<_i2.NestedTag>() || + targetTypeOf == _typeOf<_i2.NestedTag?>())) { return true; } if (recursive) { - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return true; } @@ -64,7 +64,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return _convert(model)!; } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convert(model)!; } @@ -83,7 +83,7 @@ class $Mappr implements AutoMapprInterface { canReturnNull: true, ); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvert(model); } @@ -99,7 +99,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return model.map((item) => _convert(item)!); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertIterable(model); } @@ -119,7 +119,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return model.map((item) => _convert(item, canReturnNull: true)); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertIterable(model); } @@ -135,7 +135,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return convertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertList(model); } @@ -154,7 +154,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return tryConvertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertList(model); } @@ -170,7 +170,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return convertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertSet(model); } @@ -189,7 +189,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return tryConvertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertSet(model); } @@ -204,99 +204,105 @@ class $Mappr implements AutoMapprInterface { }) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.UserDto>() || + sourceTypeOf == _typeOf<_i2.UserDto?>()) && + (targetTypeOf == _typeOf<_i2.User>() || + targetTypeOf == _typeOf<_i2.User?>())) { if (canReturnNull && model == null) { return null; } - return (_map__UserDto__To__User((model as UserDto?)) as TARGET); + return (_map___i2$UserDto__To___i2$User((model as _i2.UserDto?)) + as TARGET); } - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.NestedDto>() || + sourceTypeOf == _typeOf<_i2.NestedDto?>()) && + (targetTypeOf == _typeOf<_i2.Nested>() || + targetTypeOf == _typeOf<_i2.Nested?>())) { if (canReturnNull && model == null) { return null; } - return (_map__NestedDto__To__Nested((model as NestedDto?)) as TARGET); + return (_map___i2$NestedDto__To___i2$Nested((model as _i2.NestedDto?)) + as TARGET); } - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.NestedTagDto>() || + sourceTypeOf == _typeOf<_i2.NestedTagDto?>()) && + (targetTypeOf == _typeOf<_i2.NestedTag>() || + targetTypeOf == _typeOf<_i2.NestedTag?>())) { if (canReturnNull && model == null) { return null; } - return (_map__NestedTagDto__To__NestedTag((model as NestedTagDto?)) - as TARGET); + return (_map___i2$NestedTagDto__To___i2$NestedTag( + (model as _i2.NestedTagDto?)) as TARGET); } throw Exception('No ${model.runtimeType} -> $targetTypeOf mapping.'); } - User _map__UserDto__To__User(UserDto? input) { + _i2.User _map___i2$UserDto__To___i2$User(_i2.UserDto? input) { final model = input; if (model == null) { throw Exception( r'Mapping UserDto → User failed because UserDto was null, and no default value was provided. ' r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); } - return User( + return _i2.User( id: model.id, - name: _map__NestedDto__To__Nested(model.name), - nestedItems: - model.nestedItems.map(_map__NestedDto__To__Nested).toList(), + name: _map___i2$NestedDto__To___i2$Nested(model.name), + nestedItems: model.nestedItems + .map<_i2.Nested>(_map___i2$NestedDto__To___i2$Nested) + .toList(), nestedItemsNullable: model.nestedItemsNullable - ?.map(_map__NestedDto__To__Nested) + ?.map<_i2.Nested>(_map___i2$NestedDto__To___i2$Nested) .toList() ?? - [], + <_i2.Nested>[], nestedItemsNullable2: model.nestedItemsNullable2 - .map(_map__NestedDto__To__Nested) + .map<_i2.Nested>(_map___i2$NestedDto__To___i2$Nested) .toList(), itemsWithNullableItem: model.itemsWithNullableItem .whereNotNull() - .map(_map__NestedDto__To__Nested) + .map<_i2.Nested>(_map___i2$NestedDto__To___i2$Nested) .toList(), itemsWithNullableItem2: model.itemsWithNullableItem2 - .map(_map__NestedDto__To__Nested_Nullable) + .map<_i2.Nested?>(_map___i2$NestedDto__To___i2$Nested_Nullable) .toList(), tag: null, ); } - Nested _map__NestedDto__To__Nested(NestedDto? input) { + _i2.Nested _map___i2$NestedDto__To___i2$Nested(_i2.NestedDto? input) { final model = input; if (model == null) { throw Exception( r'Mapping NestedDto → Nested failed because NestedDto was null, and no default value was provided. ' r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); } - return Nested( + return _i2.Nested( id: model.id, name: model.name, - tag: _map__NestedTagDto__To__NestedTag(model.tag), + tag: _map___i2$NestedTagDto__To___i2$NestedTag(model.tag), ); } - NestedTag _map__NestedTagDto__To__NestedTag(NestedTagDto? input) { + _i2.NestedTag _map___i2$NestedTagDto__To___i2$NestedTag( + _i2.NestedTagDto? input) { final model = input; if (model == null) { throw Exception( r'Mapping NestedTagDto → NestedTag failed because NestedTagDto was null, and no default value was provided. ' r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); } - return NestedTag(); + return _i2.NestedTag(); } - Nested? _map__NestedDto__To__Nested_Nullable(NestedDto? input) { + _i2.Nested? _map___i2$NestedDto__To___i2$Nested_Nullable( + _i2.NestedDto? input) { final model = input; if (model == null) { return null; } - return Nested( + return _i2.Nested( id: model.id, name: model.name, - tag: _map__NestedTagDto__To__NestedTag(model.tag), + tag: _map___i2$NestedTagDto__To___i2$NestedTag(model.tag), ); } } diff --git a/examples/example/lib/nested.dart b/examples/example/lib/nested.dart index 68a83b79..cbd79836 100644 --- a/examples/example/lib/nested.dart +++ b/examples/example/lib/nested.dart @@ -3,7 +3,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'nested.g.dart'; +import 'package:examples_example/nested.auto_mappr.dart'; @AutoMappr([ MapType(), diff --git a/examples/example/lib/nullable.g.dart b/examples/example/lib/nullable.auto_mappr.dart similarity index 74% rename from examples/example/lib/nullable.g.dart rename to examples/example/lib/nullable.auto_mappr.dart index e2c9cf1f..e78d8190 100644 --- a/examples/example/lib/nullable.g.dart +++ b/examples/example/lib/nullable.auto_mappr.dart @@ -1,27 +1,26 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'nullable.dart'; - // ************************************************************************** // AutoMapprGenerator // ************************************************************************** -// ignore_for_file: non_constant_identifier_names, prefer_const_constructors -// ignore_for_file: prefer_const_literals_to_create_immutables -// ignore_for_file: require_trailing_commas, unnecessary_const -// ignore_for_file: unnecessary_lambdas, unnecessary_parenthesis -// ignore_for_file: unnecessary_raw_strings +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:auto_mappr_annotation/auto_mappr_annotation.dart' as _i2; + +import 'nullable.dart' as _i1; /// {@template package:examples_example/nullable.dart} /// Available mappings: /// - `UserDto` → `User` -- With default value. /// - `NestedDto` → `Nested`. /// {@endtemplate} -class $Mappr implements AutoMapprInterface { +class $Mappr implements _i2.AutoMapprInterface { const $Mappr(); Type _typeOf() => T; - List get _modules => const []; + List<_i2.AutoMapprInterface> get _delegates => const []; /// {@macro AutoMapprInterface:canConvert} /// {@macro package:examples_example/nullable.dart} @@ -29,19 +28,20 @@ class $Mappr implements AutoMapprInterface { bool canConvert({bool recursive = true}) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i1.UserDto>() || + sourceTypeOf == _typeOf<_i1.UserDto?>()) && + (targetTypeOf == _typeOf<_i1.User>() || + targetTypeOf == _typeOf<_i1.User?>())) { return true; } - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i1.NestedDto>() || + sourceTypeOf == _typeOf<_i1.NestedDto?>()) && + (targetTypeOf == _typeOf<_i1.Nested>() || + targetTypeOf == _typeOf<_i1.Nested?>())) { return true; } if (recursive) { - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return true; } @@ -57,7 +57,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return _convert(model)!; } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convert(model)!; } @@ -76,7 +76,7 @@ class $Mappr implements AutoMapprInterface { canReturnNull: true, ); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvert(model); } @@ -92,7 +92,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return model.map((item) => _convert(item)!); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertIterable(model); } @@ -112,7 +112,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return model.map((item) => _convert(item, canReturnNull: true)); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertIterable(model); } @@ -128,7 +128,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return convertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertList(model); } @@ -147,7 +147,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return tryConvertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertList(model); } @@ -163,7 +163,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return convertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertSet(model); } @@ -182,7 +182,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return tryConvertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertSet(model); } @@ -197,60 +197,63 @@ class $Mappr implements AutoMapprInterface { }) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i1.UserDto>() || + sourceTypeOf == _typeOf<_i1.UserDto?>()) && + (targetTypeOf == _typeOf<_i1.User>() || + targetTypeOf == _typeOf<_i1.User?>())) { if (canReturnNull && model == null) { - return (const User( + return (const _i1.User( id: 1, - tag: Nested( + tag: _i1.Nested( id: 1, name: r'default', ), ) as TARGET); } - return (_map__UserDto__To__User((model as UserDto?)) as TARGET); + return (_map___i1$UserDto__To___i1$User((model as _i1.UserDto?)) + as TARGET); } - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i1.NestedDto>() || + sourceTypeOf == _typeOf<_i1.NestedDto?>()) && + (targetTypeOf == _typeOf<_i1.Nested>() || + targetTypeOf == _typeOf<_i1.Nested?>())) { if (canReturnNull && model == null) { return null; } - return (_map__NestedDto__To__Nested((model as NestedDto?)) as TARGET); + return (_map___i1$NestedDto__To___i1$Nested((model as _i1.NestedDto?)) + as TARGET); } throw Exception('No ${model.runtimeType} -> $targetTypeOf mapping.'); } - User _map__UserDto__To__User(UserDto? input) { + _i1.User _map___i1$UserDto__To___i1$User(_i1.UserDto? input) { final model = input; if (model == null) { - return const User( + return const _i1.User( id: 1, - tag: Nested( + tag: _i1.Nested( id: 1, name: r'default', ), ); } - return User( + return _i1.User( id: model.id, tag: model.tag == null - ? Mappr.defaultNested() - : _map__NestedDto__To__Nested(model.tag), - name: _map__NestedDto__To__Nested(model.name), + ? _i1.Mappr.defaultNested() + : _map___i1$NestedDto__To___i1$Nested(model.tag), + name: _map___i1$NestedDto__To___i1$Nested(model.name), ); } - Nested _map__NestedDto__To__Nested(NestedDto? input) { + _i1.Nested _map___i1$NestedDto__To___i1$Nested(_i1.NestedDto? input) { final model = input; if (model == null) { throw Exception( r'Mapping NestedDto → Nested failed because NestedDto was null, and no default value was provided. ' r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); } - return Nested( + return _i1.Nested( id: model.id, name: model.name, ); diff --git a/examples/example/lib/nullable.dart b/examples/example/lib/nullable.dart index 42ee90e5..04eb4fc7 100644 --- a/examples/example/lib/nullable.dart +++ b/examples/example/lib/nullable.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'nullable.g.dart'; +import 'package:examples_example/nullable.auto_mappr.dart'; @AutoMappr([ MapType( diff --git a/examples/example/lib/rename.g.dart b/examples/example/lib/rename.auto_mappr.dart similarity index 82% rename from examples/example/lib/rename.g.dart rename to examples/example/lib/rename.auto_mappr.dart index 89de1b19..7c3cd1af 100644 --- a/examples/example/lib/rename.g.dart +++ b/examples/example/lib/rename.auto_mappr.dart @@ -1,26 +1,25 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'rename.dart'; - // ************************************************************************** // AutoMapprGenerator // ************************************************************************** -// ignore_for_file: non_constant_identifier_names, prefer_const_constructors -// ignore_for_file: prefer_const_literals_to_create_immutables -// ignore_for_file: require_trailing_commas, unnecessary_const -// ignore_for_file: unnecessary_lambdas, unnecessary_parenthesis -// ignore_for_file: unnecessary_raw_strings +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:auto_mappr_annotation/auto_mappr_annotation.dart' as _i1; + +import 'rename.dart' as _i2; /// {@template package:examples_example/rename.dart} /// Available mappings: /// - `UserDto` → `User`. /// {@endtemplate} -class $Mappr implements AutoMapprInterface { +class $Mappr implements _i1.AutoMapprInterface { const $Mappr(); Type _typeOf() => T; - List get _modules => const []; + List<_i1.AutoMapprInterface> get _delegates => const []; /// {@macro AutoMapprInterface:canConvert} /// {@macro package:examples_example/rename.dart} @@ -28,13 +27,14 @@ class $Mappr implements AutoMapprInterface { bool canConvert({bool recursive = true}) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.UserDto>() || + sourceTypeOf == _typeOf<_i2.UserDto?>()) && + (targetTypeOf == _typeOf<_i2.User>() || + targetTypeOf == _typeOf<_i2.User?>())) { return true; } if (recursive) { - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return true; } @@ -50,7 +50,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return _convert(model)!; } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convert(model)!; } @@ -69,7 +69,7 @@ class $Mappr implements AutoMapprInterface { canReturnNull: true, ); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvert(model); } @@ -85,7 +85,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return model.map((item) => _convert(item)!); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertIterable(model); } @@ -105,7 +105,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return model.map((item) => _convert(item, canReturnNull: true)); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertIterable(model); } @@ -121,7 +121,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return convertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertList(model); } @@ -140,7 +140,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return tryConvertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertList(model); } @@ -156,7 +156,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return convertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertSet(model); } @@ -175,7 +175,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return tryConvertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertSet(model); } @@ -190,25 +190,27 @@ class $Mappr implements AutoMapprInterface { }) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.UserDto>() || + sourceTypeOf == _typeOf<_i2.UserDto?>()) && + (targetTypeOf == _typeOf<_i2.User>() || + targetTypeOf == _typeOf<_i2.User?>())) { if (canReturnNull && model == null) { return null; } - return (_map__UserDto__To__User((model as UserDto?)) as TARGET); + return (_map___i2$UserDto__To___i2$User((model as _i2.UserDto?)) + as TARGET); } throw Exception('No ${model.runtimeType} -> $targetTypeOf mapping.'); } - User _map__UserDto__To__User(UserDto? input) { + _i2.User _map___i2$UserDto__To___i2$User(_i2.UserDto? input) { final model = input; if (model == null) { throw Exception( r'Mapping UserDto → User failed because UserDto was null, and no default value was provided. ' r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); } - return User( + return _i2.User( id: model.id, name: model.xname, ); diff --git a/examples/example/lib/rename.dart b/examples/example/lib/rename.dart index 9def8c16..59b1bf8c 100644 --- a/examples/example/lib/rename.dart +++ b/examples/example/lib/rename.dart @@ -1,6 +1,6 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; -part 'rename.g.dart'; +import 'package:examples_example/rename.auto_mappr.dart'; @AutoMappr([ MapType( diff --git a/examples/example/pubspec.yaml b/examples/example/pubspec.yaml index 64aa0f2d..d4a1ae55 100644 --- a/examples/example/pubspec.yaml +++ b/examples/example/pubspec.yaml @@ -13,5 +13,5 @@ dependencies: dev_dependencies: auto_mappr: ^1.3.0 build_runner: ^2.0.0 - netglade_analysis: ^4.0.0 + netglade_analysis: ^4.2.0 test: ^1.16.0 diff --git a/examples/freezed/.gitignore b/examples/freezed/.gitignore index b94efff6..adce9480 100644 --- a/examples/freezed/.gitignore +++ b/examples/freezed/.gitignore @@ -11,3 +11,4 @@ pubspec.lock # Example !*.g.dart +!*.auto_mappr.dart diff --git a/examples/freezed/lib/freezed_example.g.dart b/examples/freezed/lib/freezed_example.auto_mappr.dart similarity index 81% rename from examples/freezed/lib/freezed_example.g.dart rename to examples/freezed/lib/freezed_example.auto_mappr.dart index 625fc49e..2502248b 100644 --- a/examples/freezed/lib/freezed_example.g.dart +++ b/examples/freezed/lib/freezed_example.auto_mappr.dart @@ -1,26 +1,25 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'freezed_example.dart'; - // ************************************************************************** // AutoMapprGenerator // ************************************************************************** -// ignore_for_file: non_constant_identifier_names, prefer_const_constructors -// ignore_for_file: prefer_const_literals_to_create_immutables -// ignore_for_file: require_trailing_commas, unnecessary_const -// ignore_for_file: unnecessary_lambdas, unnecessary_parenthesis -// ignore_for_file: unnecessary_raw_strings +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:auto_mappr_annotation/auto_mappr_annotation.dart' as _i1; + +import 'freezed_example.dart' as _i2; /// {@template package:examples_freezed/freezed_example.dart} /// Available mappings: /// - `UserInfo` → `UserInfoCompanion`. /// {@endtemplate} -class $Mappr implements AutoMapprInterface { +class $Mappr implements _i1.AutoMapprInterface { const $Mappr(); Type _typeOf() => T; - List get _modules => const []; + List<_i1.AutoMapprInterface> get _delegates => const []; /// {@macro AutoMapprInterface:canConvert} /// {@macro package:examples_freezed/freezed_example.dart} @@ -28,14 +27,14 @@ class $Mappr implements AutoMapprInterface { bool canConvert({bool recursive = true}) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.UserInfo>() || + sourceTypeOf == _typeOf<_i2.UserInfo?>()) && + (targetTypeOf == _typeOf<_i2.UserInfoCompanion>() || + targetTypeOf == _typeOf<_i2.UserInfoCompanion?>())) { return true; } if (recursive) { - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return true; } @@ -51,7 +50,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return _convert(model)!; } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convert(model)!; } @@ -70,7 +69,7 @@ class $Mappr implements AutoMapprInterface { canReturnNull: true, ); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvert(model); } @@ -86,7 +85,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return model.map((item) => _convert(item)!); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertIterable(model); } @@ -106,7 +105,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return model.map((item) => _convert(item, canReturnNull: true)); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertIterable(model); } @@ -122,7 +121,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return convertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertList(model); } @@ -141,7 +140,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return tryConvertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertList(model); } @@ -157,7 +156,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return convertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertSet(model); } @@ -176,7 +175,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return tryConvertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertSet(model); } @@ -191,27 +190,28 @@ class $Mappr implements AutoMapprInterface { }) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.UserInfo>() || + sourceTypeOf == _typeOf<_i2.UserInfo?>()) && + (targetTypeOf == _typeOf<_i2.UserInfoCompanion>() || + targetTypeOf == _typeOf<_i2.UserInfoCompanion?>())) { if (canReturnNull && model == null) { return null; } - return (_map__UserInfo__To__UserInfoCompanion((model as UserInfo?)) - as TARGET); + return (_map___i2$UserInfo__To___i2$UserInfoCompanion( + (model as _i2.UserInfo?)) as TARGET); } throw Exception('No ${model.runtimeType} -> $targetTypeOf mapping.'); } - UserInfoCompanion _map__UserInfo__To__UserInfoCompanion(UserInfo? input) { + _i2.UserInfoCompanion _map___i2$UserInfo__To___i2$UserInfoCompanion( + _i2.UserInfo? input) { final model = input; if (model == null) { throw Exception( r'Mapping UserInfo → UserInfoCompanion failed because UserInfo was null, and no default value was provided. ' r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); } - return UserInfoCompanion( + return _i2.UserInfoCompanion( email: model.email, loginIdentifier: model.loginIdentifier, updatedAt: model.updatedAt, diff --git a/examples/freezed/lib/freezed_example.dart b/examples/freezed/lib/freezed_example.dart index 9861f228..86270d48 100644 --- a/examples/freezed/lib/freezed_example.dart +++ b/examples/freezed/lib/freezed_example.dart @@ -1,8 +1,8 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; +import 'package:examples_freezed/freezed_example.auto_mappr.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'freezed_example.freezed.dart'; -part 'freezed_example.g.dart'; @freezed class UserInfoUnion with _$UserInfoUnion { diff --git a/examples/freezed/pubspec.yaml b/examples/freezed/pubspec.yaml index b9f6c438..2faceeac 100644 --- a/examples/freezed/pubspec.yaml +++ b/examples/freezed/pubspec.yaml @@ -15,5 +15,5 @@ dev_dependencies: auto_mappr: ^1.6.0 build_runner: ^2.0.0 freezed: ^2.3.2 - netglade_analysis: ^4.0.0 + netglade_analysis: ^4.2.0 test: ^1.16.0 diff --git a/examples/injectable/.gitignore b/examples/injectable/.gitignore index b94efff6..adce9480 100644 --- a/examples/injectable/.gitignore +++ b/examples/injectable/.gitignore @@ -11,3 +11,4 @@ pubspec.lock # Example !*.g.dart +!*.auto_mappr.dart diff --git a/examples/injectable/lib/mappr.g.dart b/examples/injectable/lib/mappr.auto_mappr.dart similarity index 82% rename from examples/injectable/lib/mappr.g.dart rename to examples/injectable/lib/mappr.auto_mappr.dart index 3cdd617f..961b48f8 100644 --- a/examples/injectable/lib/mappr.g.dart +++ b/examples/injectable/lib/mappr.auto_mappr.dart @@ -1,26 +1,25 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'mappr.dart'; - // ************************************************************************** // AutoMapprGenerator // ************************************************************************** -// ignore_for_file: non_constant_identifier_names, prefer_const_constructors -// ignore_for_file: prefer_const_literals_to_create_immutables -// ignore_for_file: require_trailing_commas, unnecessary_const -// ignore_for_file: unnecessary_lambdas, unnecessary_parenthesis -// ignore_for_file: unnecessary_raw_strings +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:auto_mappr_annotation/auto_mappr_annotation.dart' as _i1; + +import 'mappr.dart' as _i2; /// {@template package:examples_injectable/mappr.dart} /// Available mappings: /// - `UserDto` → `User`. /// {@endtemplate} -class $Mappr implements AutoMapprInterface { +class $Mappr implements _i1.AutoMapprInterface { const $Mappr(); Type _typeOf() => T; - List get _modules => const []; + List<_i1.AutoMapprInterface> get _delegates => const []; /// {@macro AutoMapprInterface:canConvert} /// {@macro package:examples_injectable/mappr.dart} @@ -28,13 +27,14 @@ class $Mappr implements AutoMapprInterface { bool canConvert({bool recursive = true}) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.UserDto>() || + sourceTypeOf == _typeOf<_i2.UserDto?>()) && + (targetTypeOf == _typeOf<_i2.User>() || + targetTypeOf == _typeOf<_i2.User?>())) { return true; } if (recursive) { - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return true; } @@ -50,7 +50,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return _convert(model)!; } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convert(model)!; } @@ -69,7 +69,7 @@ class $Mappr implements AutoMapprInterface { canReturnNull: true, ); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvert(model); } @@ -85,7 +85,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return model.map((item) => _convert(item)!); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertIterable(model); } @@ -105,7 +105,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return model.map((item) => _convert(item, canReturnNull: true)); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertIterable(model); } @@ -121,7 +121,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return convertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertList(model); } @@ -140,7 +140,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return tryConvertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertList(model); } @@ -156,7 +156,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return convertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertSet(model); } @@ -175,7 +175,7 @@ class $Mappr implements AutoMapprInterface { if (canConvert(recursive: false)) { return tryConvertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertSet(model); } @@ -190,25 +190,27 @@ class $Mappr implements AutoMapprInterface { }) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.UserDto>() || + sourceTypeOf == _typeOf<_i2.UserDto?>()) && + (targetTypeOf == _typeOf<_i2.User>() || + targetTypeOf == _typeOf<_i2.User?>())) { if (canReturnNull && model == null) { return null; } - return (_map__UserDto__To__User((model as UserDto?)) as TARGET); + return (_map___i2$UserDto__To___i2$User((model as _i2.UserDto?)) + as TARGET); } throw Exception('No ${model.runtimeType} -> $targetTypeOf mapping.'); } - User _map__UserDto__To__User(UserDto? input) { + _i2.User _map___i2$UserDto__To___i2$User(_i2.UserDto? input) { final model = input; if (model == null) { throw Exception( r'Mapping UserDto → User failed because UserDto was null, and no default value was provided. ' r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); } - return User( + return _i2.User( id: model.id, name: model.name, ); diff --git a/examples/injectable/lib/mappr.dart b/examples/injectable/lib/mappr.dart index 696257ba..44acf6a1 100644 --- a/examples/injectable/lib/mappr.dart +++ b/examples/injectable/lib/mappr.dart @@ -1,8 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; +import 'package:examples_injectable/mappr.auto_mappr.dart'; import 'package:injectable/injectable.dart'; -part 'mappr.g.dart'; - class User { final int id; final String name; diff --git a/examples/injectable/pubspec.yaml b/examples/injectable/pubspec.yaml index 65cb9f49..b6963415 100644 --- a/examples/injectable/pubspec.yaml +++ b/examples/injectable/pubspec.yaml @@ -16,5 +16,5 @@ dev_dependencies: auto_mappr: ^1.6.0 build_runner: ^2.0.0 injectable_generator: ^2.1.5 - netglade_analysis: ^4.0.0 + netglade_analysis: ^4.2.0 test: ^1.16.0 diff --git a/examples/json_serializable/.gitignore b/examples/json_serializable/.gitignore index b94efff6..adce9480 100644 --- a/examples/json_serializable/.gitignore +++ b/examples/json_serializable/.gitignore @@ -11,3 +11,4 @@ pubspec.lock # Example !*.g.dart +!*.auto_mappr.dart diff --git a/examples/json_serializable/build.yaml b/examples/json_serializable/build.yaml index 0a0ad92b..1fd05e48 100644 --- a/examples/json_serializable/build.yaml +++ b/examples/json_serializable/build.yaml @@ -3,3 +3,5 @@ targets: builders: auto_mappr: enabled: true + json_serializable: + enabled: true diff --git a/examples/json_serializable/lib/serializable.auto_mappr.dart b/examples/json_serializable/lib/serializable.auto_mappr.dart new file mode 100644 index 00000000..195b3a0e --- /dev/null +++ b/examples/json_serializable/lib/serializable.auto_mappr.dart @@ -0,0 +1,246 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ************************************************************************** +// AutoMapprGenerator +// ************************************************************************** + +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:auto_mappr_annotation/auto_mappr_annotation.dart' as _i1; + +import 'serializable.dart' as _i2; + +/// {@template package:examples_json_serializable/serializable.dart} +/// Available mappings: +/// - `UserDto` → `User`. +/// - `ValueHolderDto` → `ValueHolder`. +/// {@endtemplate} +class $Mappr implements _i1.AutoMapprInterface { + const $Mappr(); + + Type _typeOf() => T; + List<_i1.AutoMapprInterface> get _delegates => const []; + + /// {@macro AutoMapprInterface:canConvert} + /// {@macro package:examples_json_serializable/serializable.dart} + @override + bool canConvert({bool recursive = true}) { + final sourceTypeOf = _typeOf(); + final targetTypeOf = _typeOf(); + if ((sourceTypeOf == _typeOf<_i2.UserDto>() || + sourceTypeOf == _typeOf<_i2.UserDto?>()) && + (targetTypeOf == _typeOf<_i2.User>() || + targetTypeOf == _typeOf<_i2.User?>())) { + return true; + } + if ((sourceTypeOf == _typeOf<_i2.ValueHolderDto>() || + sourceTypeOf == _typeOf<_i2.ValueHolderDto?>()) && + (targetTypeOf == _typeOf<_i2.ValueHolder>() || + targetTypeOf == _typeOf<_i2.ValueHolder?>())) { + return true; + } + if (recursive) { + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return true; + } + } + } + return false; + } + + /// {@macro AutoMapprInterface:convert} + /// {@macro package:examples_json_serializable/serializable.dart} + @override + TARGET convert(SOURCE? model) { + if (canConvert(recursive: false)) { + return _convert(model)!; + } + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return mappr.convert(model)!; + } + } + + throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); + } + + /// {@macro AutoMapprInterface:tryConvert} + /// {@macro package:examples_json_serializable/serializable.dart} + @override + TARGET? tryConvert(SOURCE? model) { + if (canConvert(recursive: false)) { + return _convert( + model, + canReturnNull: true, + ); + } + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return mappr.tryConvert(model); + } + } + + return null; + } + + /// {@macro AutoMapprInterface:convertIterable} + /// {@macro package:examples_json_serializable/serializable.dart} + @override + Iterable convertIterable(Iterable model) { + if (canConvert(recursive: false)) { + return model.map((item) => _convert(item)!); + } + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return mappr.convertIterable(model); + } + } + + throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); + } + + /// For iterable items, converts from SOURCE to TARGET if such mapping is configured, into Iterable. + /// + /// When an item in the source iterable is null, uses `whenSourceIsNull` if defined or null + /// + /// {@macro package:examples_json_serializable/serializable.dart} + @override + Iterable tryConvertIterable( + Iterable model) { + if (canConvert(recursive: false)) { + return model.map((item) => _convert(item, canReturnNull: true)); + } + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return mappr.tryConvertIterable(model); + } + } + + throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); + } + + /// {@macro AutoMapprInterface:convertList} + /// {@macro package:examples_json_serializable/serializable.dart} + @override + List convertList(Iterable model) { + if (canConvert(recursive: false)) { + return convertIterable(model).toList(); + } + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return mappr.convertList(model); + } + } + + throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); + } + + /// For iterable items, converts from SOURCE to TARGET if such mapping is configured, into List. + /// + /// When an item in the source iterable is null, uses `whenSourceIsNull` if defined or null + /// + /// {@macro package:examples_json_serializable/serializable.dart} + @override + List tryConvertList(Iterable model) { + if (canConvert(recursive: false)) { + return tryConvertIterable(model).toList(); + } + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return mappr.tryConvertList(model); + } + } + + throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); + } + + /// {@macro AutoMapprInterface:convertSet} + /// {@macro package:examples_json_serializable/serializable.dart} + @override + Set convertSet(Iterable model) { + if (canConvert(recursive: false)) { + return convertIterable(model).toSet(); + } + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return mappr.convertSet(model); + } + } + + throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); + } + + /// For iterable items, converts from SOURCE to TARGET if such mapping is configured, into Set. + /// + /// When an item in the source iterable is null, uses `whenSourceIsNull` if defined or null + /// + /// {@macro package:examples_json_serializable/serializable.dart} + @override + Set tryConvertSet(Iterable model) { + if (canConvert(recursive: false)) { + return tryConvertIterable(model).toSet(); + } + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return mappr.tryConvertSet(model); + } + } + + throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); + } + + TARGET? _convert( + SOURCE? model, { + bool canReturnNull = false, + }) { + final sourceTypeOf = _typeOf(); + final targetTypeOf = _typeOf(); + if ((sourceTypeOf == _typeOf<_i2.UserDto>() || + sourceTypeOf == _typeOf<_i2.UserDto?>()) && + (targetTypeOf == _typeOf<_i2.User>() || + targetTypeOf == _typeOf<_i2.User?>())) { + if (canReturnNull && model == null) { + return null; + } + return (_map___i2$UserDto__To___i2$User((model as _i2.UserDto?)) + as TARGET); + } + if ((sourceTypeOf == _typeOf<_i2.ValueHolderDto>() || + sourceTypeOf == _typeOf<_i2.ValueHolderDto?>()) && + (targetTypeOf == _typeOf<_i2.ValueHolder>() || + targetTypeOf == _typeOf<_i2.ValueHolder?>())) { + if (canReturnNull && model == null) { + return null; + } + return (_map___i2$ValueHolderDto__To___i2$ValueHolder( + (model as _i2.ValueHolderDto?)) as TARGET); + } + throw Exception('No ${model.runtimeType} -> $targetTypeOf mapping.'); + } + + _i2.User _map___i2$UserDto__To___i2$User(_i2.UserDto? input) { + final model = input; + if (model == null) { + throw Exception( + r'Mapping UserDto → User failed because UserDto was null, and no default value was provided. ' + r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); + } + return _i2.User( + firstName: model.firstName, + lastName: model.lastName, + ); + } + + _i2.ValueHolder _map___i2$ValueHolderDto__To___i2$ValueHolder( + _i2.ValueHolderDto? input) { + final model = input; + if (model == null) { + throw Exception( + r'Mapping ValueHolderDto → ValueHolder failed because ValueHolderDto was null, and no default value was provided. ' + r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); + } + return _i2.ValueHolder(model.json); + } +} diff --git a/examples/json_serializable/lib/serializable.dart b/examples/json_serializable/lib/serializable.dart index ac32698a..61325968 100644 --- a/examples/json_serializable/lib/serializable.dart +++ b/examples/json_serializable/lib/serializable.dart @@ -1,4 +1,5 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; +import 'package:examples_json_serializable/serializable.auto_mappr.dart'; import 'package:json_annotation/json_annotation.dart'; part 'serializable.g.dart'; diff --git a/examples/json_serializable/lib/serializable.g.dart b/examples/json_serializable/lib/serializable.g.dart index 69c429dc..532b7555 100644 --- a/examples/json_serializable/lib/serializable.g.dart +++ b/examples/json_serializable/lib/serializable.g.dart @@ -2,246 +2,6 @@ part of 'serializable.dart'; -// ************************************************************************** -// AutoMapprGenerator -// ************************************************************************** - -// ignore_for_file: non_constant_identifier_names, prefer_const_constructors -// ignore_for_file: prefer_const_literals_to_create_immutables -// ignore_for_file: require_trailing_commas, unnecessary_const -// ignore_for_file: unnecessary_lambdas, unnecessary_parenthesis -// ignore_for_file: unnecessary_raw_strings - -/// {@template package:examples_json_serializable/serializable.dart} -/// Available mappings: -/// - `UserDto` → `User`. -/// - `ValueHolderDto` → `ValueHolder`. -/// {@endtemplate} -class $Mappr implements AutoMapprInterface { - const $Mappr(); - - Type _typeOf() => T; - List get _modules => const []; - - /// {@macro AutoMapprInterface:canConvert} - /// {@macro package:examples_json_serializable/serializable.dart} - @override - bool canConvert({bool recursive = true}) { - final sourceTypeOf = _typeOf(); - final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || targetTypeOf == _typeOf())) { - return true; - } - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { - return true; - } - if (recursive) { - for (final mappr in _modules) { - if (mappr.canConvert()) { - return true; - } - } - } - return false; - } - - /// {@macro AutoMapprInterface:convert} - /// {@macro package:examples_json_serializable/serializable.dart} - @override - TARGET convert(SOURCE? model) { - if (canConvert(recursive: false)) { - return _convert(model)!; - } - for (final mappr in _modules) { - if (mappr.canConvert()) { - return mappr.convert(model)!; - } - } - - throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); - } - - /// {@macro AutoMapprInterface:tryConvert} - /// {@macro package:examples_json_serializable/serializable.dart} - @override - TARGET? tryConvert(SOURCE? model) { - if (canConvert(recursive: false)) { - return _convert( - model, - canReturnNull: true, - ); - } - for (final mappr in _modules) { - if (mappr.canConvert()) { - return mappr.tryConvert(model); - } - } - - return null; - } - - /// {@macro AutoMapprInterface:convertIterable} - /// {@macro package:examples_json_serializable/serializable.dart} - @override - Iterable convertIterable(Iterable model) { - if (canConvert(recursive: false)) { - return model.map((item) => _convert(item)!); - } - for (final mappr in _modules) { - if (mappr.canConvert()) { - return mappr.convertIterable(model); - } - } - - throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); - } - - /// For iterable items, converts from SOURCE to TARGET if such mapping is configured, into Iterable. - /// - /// When an item in the source iterable is null, uses `whenSourceIsNull` if defined or null - /// - /// {@macro package:examples_json_serializable/serializable.dart} - @override - Iterable tryConvertIterable( - Iterable model) { - if (canConvert(recursive: false)) { - return model.map((item) => _convert(item, canReturnNull: true)); - } - for (final mappr in _modules) { - if (mappr.canConvert()) { - return mappr.tryConvertIterable(model); - } - } - - throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); - } - - /// {@macro AutoMapprInterface:convertList} - /// {@macro package:examples_json_serializable/serializable.dart} - @override - List convertList(Iterable model) { - if (canConvert(recursive: false)) { - return convertIterable(model).toList(); - } - for (final mappr in _modules) { - if (mappr.canConvert()) { - return mappr.convertList(model); - } - } - - throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); - } - - /// For iterable items, converts from SOURCE to TARGET if such mapping is configured, into List. - /// - /// When an item in the source iterable is null, uses `whenSourceIsNull` if defined or null - /// - /// {@macro package:examples_json_serializable/serializable.dart} - @override - List tryConvertList(Iterable model) { - if (canConvert(recursive: false)) { - return tryConvertIterable(model).toList(); - } - for (final mappr in _modules) { - if (mappr.canConvert()) { - return mappr.tryConvertList(model); - } - } - - throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); - } - - /// {@macro AutoMapprInterface:convertSet} - /// {@macro package:examples_json_serializable/serializable.dart} - @override - Set convertSet(Iterable model) { - if (canConvert(recursive: false)) { - return convertIterable(model).toSet(); - } - for (final mappr in _modules) { - if (mappr.canConvert()) { - return mappr.convertSet(model); - } - } - - throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); - } - - /// For iterable items, converts from SOURCE to TARGET if such mapping is configured, into Set. - /// - /// When an item in the source iterable is null, uses `whenSourceIsNull` if defined or null - /// - /// {@macro package:examples_json_serializable/serializable.dart} - @override - Set tryConvertSet(Iterable model) { - if (canConvert(recursive: false)) { - return tryConvertIterable(model).toSet(); - } - for (final mappr in _modules) { - if (mappr.canConvert()) { - return mappr.tryConvertSet(model); - } - } - - throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); - } - - TARGET? _convert( - SOURCE? model, { - bool canReturnNull = false, - }) { - final sourceTypeOf = _typeOf(); - final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || targetTypeOf == _typeOf())) { - if (canReturnNull && model == null) { - return null; - } - return (_map__UserDto__To__User((model as UserDto?)) as TARGET); - } - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { - if (canReturnNull && model == null) { - return null; - } - return (_map__ValueHolderDto__To__ValueHolder((model as ValueHolderDto?)) - as TARGET); - } - throw Exception('No ${model.runtimeType} -> $targetTypeOf mapping.'); - } - - User _map__UserDto__To__User(UserDto? input) { - final model = input; - if (model == null) { - throw Exception( - r'Mapping UserDto → User failed because UserDto was null, and no default value was provided. ' - r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); - } - return User( - firstName: model.firstName, - lastName: model.lastName, - ); - } - - ValueHolder _map__ValueHolderDto__To__ValueHolder(ValueHolderDto? input) { - final model = input; - if (model == null) { - throw Exception( - r'Mapping ValueHolderDto → ValueHolder failed because ValueHolderDto was null, and no default value was provided. ' - r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); - } - return ValueHolder(model.json); - } -} - // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** diff --git a/examples/json_serializable/pubspec.yaml b/examples/json_serializable/pubspec.yaml index ab88881e..de12a25c 100644 --- a/examples/json_serializable/pubspec.yaml +++ b/examples/json_serializable/pubspec.yaml @@ -14,5 +14,5 @@ dev_dependencies: auto_mappr: ^1.6.0 build_runner: ^2.0.0 json_serializable: ^6.6.1 - netglade_analysis: ^4.0.0 + netglade_analysis: ^4.2.0 test: ^1.16.0 diff --git a/examples/json_serializable/test/fixture/json_serializable.auto_mappr.dart b/examples/json_serializable/test/fixture/json_serializable.auto_mappr.dart new file mode 100644 index 00000000..d93e4e43 --- /dev/null +++ b/examples/json_serializable/test/fixture/json_serializable.auto_mappr.dart @@ -0,0 +1,246 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ************************************************************************** +// AutoMapprGenerator +// ************************************************************************** + +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:auto_mappr_annotation/auto_mappr_annotation.dart' as _i1; + +import 'json_serializable.dart' as _i2; + +/// {@template asset:examples_json_serializable/test/fixture/json_serializable.dart} +/// Available mappings: +/// - `UserDto` → `User`. +/// - `ValueHolderDto` → `ValueHolder`. +/// {@endtemplate} +class $Mappr implements _i1.AutoMapprInterface { + const $Mappr(); + + Type _typeOf() => T; + List<_i1.AutoMapprInterface> get _delegates => const []; + + /// {@macro AutoMapprInterface:canConvert} + /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} + @override + bool canConvert({bool recursive = true}) { + final sourceTypeOf = _typeOf(); + final targetTypeOf = _typeOf(); + if ((sourceTypeOf == _typeOf<_i2.UserDto>() || + sourceTypeOf == _typeOf<_i2.UserDto?>()) && + (targetTypeOf == _typeOf<_i2.User>() || + targetTypeOf == _typeOf<_i2.User?>())) { + return true; + } + if ((sourceTypeOf == _typeOf<_i2.ValueHolderDto>() || + sourceTypeOf == _typeOf<_i2.ValueHolderDto?>()) && + (targetTypeOf == _typeOf<_i2.ValueHolder>() || + targetTypeOf == _typeOf<_i2.ValueHolder?>())) { + return true; + } + if (recursive) { + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return true; + } + } + } + return false; + } + + /// {@macro AutoMapprInterface:convert} + /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} + @override + TARGET convert(SOURCE? model) { + if (canConvert(recursive: false)) { + return _convert(model)!; + } + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return mappr.convert(model)!; + } + } + + throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); + } + + /// {@macro AutoMapprInterface:tryConvert} + /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} + @override + TARGET? tryConvert(SOURCE? model) { + if (canConvert(recursive: false)) { + return _convert( + model, + canReturnNull: true, + ); + } + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return mappr.tryConvert(model); + } + } + + return null; + } + + /// {@macro AutoMapprInterface:convertIterable} + /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} + @override + Iterable convertIterable(Iterable model) { + if (canConvert(recursive: false)) { + return model.map((item) => _convert(item)!); + } + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return mappr.convertIterable(model); + } + } + + throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); + } + + /// For iterable items, converts from SOURCE to TARGET if such mapping is configured, into Iterable. + /// + /// When an item in the source iterable is null, uses `whenSourceIsNull` if defined or null + /// + /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} + @override + Iterable tryConvertIterable( + Iterable model) { + if (canConvert(recursive: false)) { + return model.map((item) => _convert(item, canReturnNull: true)); + } + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return mappr.tryConvertIterable(model); + } + } + + throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); + } + + /// {@macro AutoMapprInterface:convertList} + /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} + @override + List convertList(Iterable model) { + if (canConvert(recursive: false)) { + return convertIterable(model).toList(); + } + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return mappr.convertList(model); + } + } + + throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); + } + + /// For iterable items, converts from SOURCE to TARGET if such mapping is configured, into List. + /// + /// When an item in the source iterable is null, uses `whenSourceIsNull` if defined or null + /// + /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} + @override + List tryConvertList(Iterable model) { + if (canConvert(recursive: false)) { + return tryConvertIterable(model).toList(); + } + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return mappr.tryConvertList(model); + } + } + + throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); + } + + /// {@macro AutoMapprInterface:convertSet} + /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} + @override + Set convertSet(Iterable model) { + if (canConvert(recursive: false)) { + return convertIterable(model).toSet(); + } + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return mappr.convertSet(model); + } + } + + throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); + } + + /// For iterable items, converts from SOURCE to TARGET if such mapping is configured, into Set. + /// + /// When an item in the source iterable is null, uses `whenSourceIsNull` if defined or null + /// + /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} + @override + Set tryConvertSet(Iterable model) { + if (canConvert(recursive: false)) { + return tryConvertIterable(model).toSet(); + } + for (final mappr in _delegates) { + if (mappr.canConvert()) { + return mappr.tryConvertSet(model); + } + } + + throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); + } + + TARGET? _convert( + SOURCE? model, { + bool canReturnNull = false, + }) { + final sourceTypeOf = _typeOf(); + final targetTypeOf = _typeOf(); + if ((sourceTypeOf == _typeOf<_i2.UserDto>() || + sourceTypeOf == _typeOf<_i2.UserDto?>()) && + (targetTypeOf == _typeOf<_i2.User>() || + targetTypeOf == _typeOf<_i2.User?>())) { + if (canReturnNull && model == null) { + return null; + } + return (_map___i2$UserDto__To___i2$User((model as _i2.UserDto?)) + as TARGET); + } + if ((sourceTypeOf == _typeOf<_i2.ValueHolderDto>() || + sourceTypeOf == _typeOf<_i2.ValueHolderDto?>()) && + (targetTypeOf == _typeOf<_i2.ValueHolder>() || + targetTypeOf == _typeOf<_i2.ValueHolder?>())) { + if (canReturnNull && model == null) { + return null; + } + return (_map___i2$ValueHolderDto__To___i2$ValueHolder( + (model as _i2.ValueHolderDto?)) as TARGET); + } + throw Exception('No ${model.runtimeType} -> $targetTypeOf mapping.'); + } + + _i2.User _map___i2$UserDto__To___i2$User(_i2.UserDto? input) { + final model = input; + if (model == null) { + throw Exception( + r'Mapping UserDto → User failed because UserDto was null, and no default value was provided. ' + r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); + } + return _i2.User( + firstName: model.firstName, + lastName: model.lastName, + ); + } + + _i2.ValueHolder _map___i2$ValueHolderDto__To___i2$ValueHolder( + _i2.ValueHolderDto? input) { + final model = input; + if (model == null) { + throw Exception( + r'Mapping ValueHolderDto → ValueHolder failed because ValueHolderDto was null, and no default value was provided. ' + r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); + } + return _i2.ValueHolder(model.json); + } +} diff --git a/examples/json_serializable/test/fixture/json_serializable.dart b/examples/json_serializable/test/fixture/json_serializable.dart index 317e4ceb..01ecb731 100644 --- a/examples/json_serializable/test/fixture/json_serializable.dart +++ b/examples/json_serializable/test/fixture/json_serializable.dart @@ -1,6 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'json_serializable.auto_mappr.dart'; part 'json_serializable.g.dart'; @AutoMappr([ diff --git a/examples/json_serializable/test/fixture/json_serializable.g.dart b/examples/json_serializable/test/fixture/json_serializable.g.dart index 174c21ee..7445c5c6 100644 --- a/examples/json_serializable/test/fixture/json_serializable.g.dart +++ b/examples/json_serializable/test/fixture/json_serializable.g.dart @@ -2,246 +2,6 @@ part of 'json_serializable.dart'; -// ************************************************************************** -// AutoMapprGenerator -// ************************************************************************** - -// ignore_for_file: non_constant_identifier_names, prefer_const_constructors -// ignore_for_file: prefer_const_literals_to_create_immutables -// ignore_for_file: require_trailing_commas, unnecessary_const -// ignore_for_file: unnecessary_lambdas, unnecessary_parenthesis -// ignore_for_file: unnecessary_raw_strings - -/// {@template asset:examples_json_serializable/test/fixture/json_serializable.dart} -/// Available mappings: -/// - `UserDto` → `User`. -/// - `ValueHolderDto` → `ValueHolder`. -/// {@endtemplate} -class $Mappr implements AutoMapprInterface { - const $Mappr(); - - Type _typeOf() => T; - List get _modules => const []; - - /// {@macro AutoMapprInterface:canConvert} - /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} - @override - bool canConvert({bool recursive = true}) { - final sourceTypeOf = _typeOf(); - final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || targetTypeOf == _typeOf())) { - return true; - } - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { - return true; - } - if (recursive) { - for (final mappr in _modules) { - if (mappr.canConvert()) { - return true; - } - } - } - return false; - } - - /// {@macro AutoMapprInterface:convert} - /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} - @override - TARGET convert(SOURCE? model) { - if (canConvert(recursive: false)) { - return _convert(model)!; - } - for (final mappr in _modules) { - if (mappr.canConvert()) { - return mappr.convert(model)!; - } - } - - throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); - } - - /// {@macro AutoMapprInterface:tryConvert} - /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} - @override - TARGET? tryConvert(SOURCE? model) { - if (canConvert(recursive: false)) { - return _convert( - model, - canReturnNull: true, - ); - } - for (final mappr in _modules) { - if (mappr.canConvert()) { - return mappr.tryConvert(model); - } - } - - return null; - } - - /// {@macro AutoMapprInterface:convertIterable} - /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} - @override - Iterable convertIterable(Iterable model) { - if (canConvert(recursive: false)) { - return model.map((item) => _convert(item)!); - } - for (final mappr in _modules) { - if (mappr.canConvert()) { - return mappr.convertIterable(model); - } - } - - throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); - } - - /// For iterable items, converts from SOURCE to TARGET if such mapping is configured, into Iterable. - /// - /// When an item in the source iterable is null, uses `whenSourceIsNull` if defined or null - /// - /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} - @override - Iterable tryConvertIterable( - Iterable model) { - if (canConvert(recursive: false)) { - return model.map((item) => _convert(item, canReturnNull: true)); - } - for (final mappr in _modules) { - if (mappr.canConvert()) { - return mappr.tryConvertIterable(model); - } - } - - throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); - } - - /// {@macro AutoMapprInterface:convertList} - /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} - @override - List convertList(Iterable model) { - if (canConvert(recursive: false)) { - return convertIterable(model).toList(); - } - for (final mappr in _modules) { - if (mappr.canConvert()) { - return mappr.convertList(model); - } - } - - throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); - } - - /// For iterable items, converts from SOURCE to TARGET if such mapping is configured, into List. - /// - /// When an item in the source iterable is null, uses `whenSourceIsNull` if defined or null - /// - /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} - @override - List tryConvertList(Iterable model) { - if (canConvert(recursive: false)) { - return tryConvertIterable(model).toList(); - } - for (final mappr in _modules) { - if (mappr.canConvert()) { - return mappr.tryConvertList(model); - } - } - - throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); - } - - /// {@macro AutoMapprInterface:convertSet} - /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} - @override - Set convertSet(Iterable model) { - if (canConvert(recursive: false)) { - return convertIterable(model).toSet(); - } - for (final mappr in _modules) { - if (mappr.canConvert()) { - return mappr.convertSet(model); - } - } - - throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); - } - - /// For iterable items, converts from SOURCE to TARGET if such mapping is configured, into Set. - /// - /// When an item in the source iterable is null, uses `whenSourceIsNull` if defined or null - /// - /// {@macro asset:examples_json_serializable/test/fixture/json_serializable.dart} - @override - Set tryConvertSet(Iterable model) { - if (canConvert(recursive: false)) { - return tryConvertIterable(model).toSet(); - } - for (final mappr in _modules) { - if (mappr.canConvert()) { - return mappr.tryConvertSet(model); - } - } - - throw Exception('No ${_typeOf()} -> ${_typeOf()} mapping.'); - } - - TARGET? _convert( - SOURCE? model, { - bool canReturnNull = false, - }) { - final sourceTypeOf = _typeOf(); - final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || targetTypeOf == _typeOf())) { - if (canReturnNull && model == null) { - return null; - } - return (_map__UserDto__To__User((model as UserDto?)) as TARGET); - } - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || - targetTypeOf == _typeOf())) { - if (canReturnNull && model == null) { - return null; - } - return (_map__ValueHolderDto__To__ValueHolder((model as ValueHolderDto?)) - as TARGET); - } - throw Exception('No ${model.runtimeType} -> $targetTypeOf mapping.'); - } - - User _map__UserDto__To__User(UserDto? input) { - final model = input; - if (model == null) { - throw Exception( - r'Mapping UserDto → User failed because UserDto was null, and no default value was provided. ' - r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); - } - return User( - firstName: model.firstName, - lastName: model.lastName, - ); - } - - ValueHolder _map__ValueHolderDto__To__ValueHolder(ValueHolderDto? input) { - final model = input; - if (model == null) { - throw Exception( - r'Mapping ValueHolderDto → ValueHolder failed because ValueHolderDto was null, and no default value was provided. ' - r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); - } - return ValueHolder(model.json); - } -} - // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** diff --git a/packages/auto_mappr/.gitignore b/packages/auto_mappr/.gitignore index c6e36089..5f71119f 100644 --- a/packages/auto_mappr/.gitignore +++ b/packages/auto_mappr/.gitignore @@ -1,4 +1,5 @@ *.g.dart +*.auto_mappr.dart # Files and directories created by pub. .dart_tool/ diff --git a/packages/auto_mappr/CHANGELOG.md b/packages/auto_mappr/CHANGELOG.md index 41d3d72b..468fccd9 100644 --- a/packages/auto_mappr/CHANGELOG.md +++ b/packages/auto_mappr/CHANGELOG.md @@ -1,6 +1,8 @@ [//]: # (## Unreleased) -## Unreleased +## 2.0.0-beta1 +- **Breaking**: Allow "absorbing" modules using `includes` on `@AutoMappr`. Previous `modules` is now `delegates`. +- **Breaking**: Remove shared AutoMappr builder that used PartBuilder, now `.auto_mappr.dart` is generated using LibraryBuilder. - Add a `reverse` option on `MapType`, which includes the reverse mapping. [#115](https://github.com/netglade/auto_mappr/pull/115) - Add a support for Dart 3 and Records feature. [#116](https://github.com/netglade/auto_mappr/pull/116) diff --git a/packages/auto_mappr/README.md b/packages/auto_mappr/README.md index 30f819a8..7536685b 100644 --- a/packages/auto_mappr/README.md +++ b/packages/auto_mappr/README.md @@ -112,7 +112,7 @@ Then use `MapType()` for each mapping. ```dart import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; -part 'my_file.g.dart'; +import 'my_file.auto_mappr.dart'; @AutoMappr([ MapType(), @@ -127,7 +127,7 @@ See [features](#-features) for a complete list. ```dart import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; -part 'my_file.g.dart'; +import 'my_file.auto_mappr.dart'; @AutoMappr([ MapType( @@ -535,56 +535,95 @@ import 'my_domain.dart' as entity; class Mappr extends $Mappr {} ``` -Note that importing a list of `MapType` from another library -and putting it inside `@AutoMappr` annotation is not possible, -since we cannot generate the type correctly (it can overlap with something else) -while using shared part builder. - ### Modules -Each AutoMappr class can be used as a **module**. -That means a mappr used inside of another mappr. -Each AutoMappr class can include a list of modules -that can be used to nest modules -and use all of its underlying mappings. +Each AutoMappr can be considered as a **module**. +The only rule is that the mappr must be constant, +and that most of the time means you have to add an `const` constructor to be able to use it. +Other modules (AutoMappr classes) can then use it in two ways. -Note that modules work as disjunctive units -and their mappings cannot be internally used by by mappr that imported it. -They only work for grouping at the moment. +#### Including -Applications are often split into independent parts (we will call them **features**). -Each feature should probably have its own independent mappr, -that is used as a module. +Including a module means that you want to "absorb" it's mappings +and use them later anywhere **inside** any mapped object. +Basically imagine copy-pasting definitions from included module to yours. -Imagine that in a feature you have a local mappr `UserMappr`. +That can be handy when you have a common/shared mappr with mappings between objects shared across the app. +Since you want to use these common/shared mappings, +you **include** them in your mappr. ```dart -// file: user_mappr.dart -@AutoMappr([ - MapType(), -]) -class UserMappr extends $UserMappr { - const UserMappr(); // must implement const constructor +// file: shared_mappr.dart +@AutoMappr( + [ + MapType(), + ], +) +class SharedMappr extends $SharedMappr { + const SharedMappr(); // must be const! } + +// file: user_mappr.dart +@AutoMappr( + [ + MapType(), // UserDto uses AddressDto inside + ], + includes: [SharedMappr()], // include shared mappr +) +class UserMappr extends $UserMappr {} + +// file: settings_mappr.dart +@AutoMappr( + [ + MapType(), // ProfileDto uses AddressDto inside + ], + includes: [SharedMappr()], // include shared mappr +) +class SettingsMappr extends $SettingsMappr {} ``` -And in some global place, -you can have a main mappr that unifies all smaller mapprs -(`UserMappr` in this case). -As usual, it can also set it's own mappings -(`MapType()`). +#### Delegating + +Delegating to a module is a bit different from including them. +A mappr **delegates** to a **standalone** module. +When your mappr does not know how to convert the **top level object** (the object you put inside `mappr.convert()` method), +it asks delegates to do it. +So you can think of them as disjunctive units that are **grouped** together. + +This is usefull when you have an app with a mappr for each feature +and you want to create one main mappr using other feature mapprs. +The main mappr may not have any mapping at all +and it delegates everything to feature mapprs. ```dart // file: main_mappr.dart +@AutoMappr( + [], + delegates: [ + UserFeatureMappr(), + SettingsFeatureMappr(), + // other features + ], +) +class MainMappr extends $MainMappr {} + +// file: user_feature_mappr.dart @AutoMappr( [ - MapType(), + MapType(), + MapType(), ], - modules: [ - UserMappr(), // use module +) +class UserFeatureMappr extends $UserFeatureMappr {} + +// file: settings_feature_mappr.dart +@AutoMappr( + [ + MapType(), + MapType(), ], ) -class MainMappr extends $MainMappr {} +class SettingsFeatureMappr extends $SettingsFeatureMappr {} ``` Then you can use this main mappr to map between objects specified from every included mappr. @@ -592,14 +631,12 @@ Then you can use this main mappr to map between objects specified from every inc ```dart final mappr = MainMappr(); -final Group user = mappr.convert(GroupDto(...)); // from this mappr -final User user = mappr.convert(UserDto(...)); // from included mappr +final Settings settings = mappr.convert(SettingsDto(...)); // delegates to settings feature mappr +final User user = mappr.convert(UserDto(...)); // delegates to user feature mappr ``` That can be handy for example with dependency injection, -so you can only provide one grouping/main mappr that can handle everything. -Each feature in your app can return an instance of const `AutoMapprInterface`, -that each mappr internally implements. +so you can only provide one main mappr that can handle everything by delegating to other mapprs. ### Reverse mapping @@ -637,8 +674,8 @@ Equatable and other packages with similar conditions implicitly works. ### Works with `json_serializable` -AutoMappr uses a `SharedPartBuilder`. -That means it can share the `.g.dart` file with packages like JSON Serializable +AutoMappr uses a `LibraryBuilder` with `.auto_mappr.dart` file output. +That means it does not interfere with shared `.g.dart` file with packages like JSON Serializable to generate other code to the generated super class. ### Works with generated source and target classes @@ -656,10 +693,8 @@ Check the [customizing the build](#-customizing-the-build) chapter to learn more ## ⚙ Customizing the build -By default, AutoMappr uses the `auto_mappr:auto_mappr` builder -that works with `SharedPartBuilder`, which generates combined `.g.dart` files. -If you need to use `PartBuilder` to generate not-shared `.auto_mappr.dart` part files, -you can use the `auto_mappr:not_shared` builder. +By default, AutoMappr uses the `auto_mappr:auto_mappr` builder that works with `LibraryBuilder`, +which generates `.auto_mappr.dart` file. Modify your `build.yaml` file: @@ -671,19 +706,16 @@ targets: builders: # Or disable specific ones. auto_mappr: - enabled: false - # And enable the not_shared builder. - auto_mappr:not_shared: enabled: true ``` ### Builder options -- ignoreNullableSourceField - Force bang operator on non-nullable target's field if source's field is nullable + +- `ignoreNullableSourceField` - Force bang operator on non-nullable target's field if source's field is nullable ### Default dependencies -By default both `auto_mappr` builders has defined required inputs for freezed -and drift classes. +By default the `auto_mappr` builder has defined required inputs for freezed and drift classes. ```yaml required_inputs: [".freezed.dart", ".drift.dart"] @@ -700,25 +732,6 @@ which you can add a input dependency to. Specify the `required_inputs` dependency on your local AutoMappr builder and disable the builders provided by AutoMappr. -Shared builder: - -```yaml -targets: - $default: - auto_apply_builders: true - builders: - # Enable their generators according to their documentation. - drift_dev:not_shared: - enabled: true - drift_dev:preparing_builder: - enabled: true - # Disable Drift's shared builder - drift_dev:drift_dev: - enabled: false -``` - -Not shared builder: - ```yaml targets: $default: @@ -734,9 +747,6 @@ targets: enabled: false auto_mappr: - enabled: false - # Enable the not_shared builder. - auto_mappr:not_shared: enabled: true ``` diff --git a/packages/auto_mappr/build.yaml b/packages/auto_mappr/build.yaml index 905672fe..2fe76f57 100644 --- a/packages/auto_mappr/build.yaml +++ b/packages/auto_mappr/build.yaml @@ -13,16 +13,7 @@ builders: auto_mappr: import: "package:auto_mappr/auto_mappr.dart" builder_factories: ["autoMapprBuilder"] - build_extensions: { ".dart": [".auto_mappr.g.part"] } - auto_apply: dependents - build_to: cache - applies_builders: ["source_gen:combining_builder"] - required_inputs: [".freezed.dart", ".drift.dart"] - - not_shared: - import: "package:auto_mappr/auto_mappr.dart" - builder_factories: ["autoMapprBuilderNotShared"] build_extensions: { ".dart": [".auto_mappr.dart"] } - auto_apply: none + auto_apply: dependents build_to: source required_inputs: [".freezed.dart", ".drift.dart"] diff --git a/packages/auto_mappr/example/.gitignore b/packages/auto_mappr/example/.gitignore index 641b8adc..38c84cf9 100644 --- a/packages/auto_mappr/example/.gitignore +++ b/packages/auto_mappr/example/.gitignore @@ -1,2 +1,3 @@ # Example !*.g.dart +!*.auto_mappr.dart diff --git a/packages/auto_mappr/example/lib/mappr.g.dart b/packages/auto_mappr/example/lib/mappr.auto_mappr.dart similarity index 75% rename from packages/auto_mappr/example/lib/mappr.g.dart rename to packages/auto_mappr/example/lib/mappr.auto_mappr.dart index 364cd655..884c0f17 100644 --- a/packages/auto_mappr/example/lib/mappr.g.dart +++ b/packages/auto_mappr/example/lib/mappr.auto_mappr.dart @@ -1,40 +1,40 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'mappr.dart'; - // ************************************************************************** // AutoMapprGenerator // ************************************************************************** -// ignore_for_file: non_constant_identifier_names, prefer_const_constructors -// ignore_for_file: prefer_const_literals_to_create_immutables -// ignore_for_file: require_trailing_commas, unnecessary_const -// ignore_for_file: unnecessary_lambdas, unnecessary_parenthesis -// ignore_for_file: unnecessary_raw_strings +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:auto_mappr_annotation/auto_mappr_annotation.dart' as _i1; + +import 'mappr.dart' as _i2; -/// {@template package:auto_mappr_example/mappr.dart} +/// {@template asset:auto_mappr/example/lib/mappr.dart} /// Available mappings: /// - `UserDto` → `User`. /// {@endtemplate} -class $Mappr implements AutoMapprInterface { +class $Mappr implements _i1.AutoMapprInterface { const $Mappr(); Type _typeOf() => T; - List get _modules => const []; + List<_i1.AutoMapprInterface> get _delegates => const []; /// {@macro AutoMapprInterface:canConvert} - /// {@macro package:auto_mappr_example/mappr.dart} + /// {@macro asset:auto_mappr/example/lib/mappr.dart} @override bool canConvert({bool recursive = true}) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.UserDto>() || + sourceTypeOf == _typeOf<_i2.UserDto?>()) && + (targetTypeOf == _typeOf<_i2.User>() || + targetTypeOf == _typeOf<_i2.User?>())) { return true; } if (recursive) { - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return true; } @@ -44,13 +44,13 @@ class $Mappr implements AutoMapprInterface { } /// {@macro AutoMapprInterface:convert} - /// {@macro package:auto_mappr_example/mappr.dart} + /// {@macro asset:auto_mappr/example/lib/mappr.dart} @override TARGET convert(SOURCE? model) { if (canConvert(recursive: false)) { return _convert(model)!; } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convert(model)!; } @@ -60,7 +60,7 @@ class $Mappr implements AutoMapprInterface { } /// {@macro AutoMapprInterface:tryConvert} - /// {@macro package:auto_mappr_example/mappr.dart} + /// {@macro asset:auto_mappr/example/lib/mappr.dart} @override TARGET? tryConvert(SOURCE? model) { if (canConvert(recursive: false)) { @@ -69,7 +69,7 @@ class $Mappr implements AutoMapprInterface { canReturnNull: true, ); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvert(model); } @@ -79,13 +79,13 @@ class $Mappr implements AutoMapprInterface { } /// {@macro AutoMapprInterface:convertIterable} - /// {@macro package:auto_mappr_example/mappr.dart} + /// {@macro asset:auto_mappr/example/lib/mappr.dart} @override Iterable convertIterable(Iterable model) { if (canConvert(recursive: false)) { return model.map((item) => _convert(item)!); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertIterable(model); } @@ -98,14 +98,14 @@ class $Mappr implements AutoMapprInterface { /// /// When an item in the source iterable is null, uses `whenSourceIsNull` if defined or null /// - /// {@macro package:auto_mappr_example/mappr.dart} + /// {@macro asset:auto_mappr/example/lib/mappr.dart} @override Iterable tryConvertIterable( Iterable model) { if (canConvert(recursive: false)) { return model.map((item) => _convert(item, canReturnNull: true)); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertIterable(model); } @@ -115,13 +115,13 @@ class $Mappr implements AutoMapprInterface { } /// {@macro AutoMapprInterface:convertList} - /// {@macro package:auto_mappr_example/mappr.dart} + /// {@macro asset:auto_mappr/example/lib/mappr.dart} @override List convertList(Iterable model) { if (canConvert(recursive: false)) { return convertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertList(model); } @@ -134,13 +134,13 @@ class $Mappr implements AutoMapprInterface { /// /// When an item in the source iterable is null, uses `whenSourceIsNull` if defined or null /// - /// {@macro package:auto_mappr_example/mappr.dart} + /// {@macro asset:auto_mappr/example/lib/mappr.dart} @override List tryConvertList(Iterable model) { if (canConvert(recursive: false)) { return tryConvertIterable(model).toList(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertList(model); } @@ -150,13 +150,13 @@ class $Mappr implements AutoMapprInterface { } /// {@macro AutoMapprInterface:convertSet} - /// {@macro package:auto_mappr_example/mappr.dart} + /// {@macro asset:auto_mappr/example/lib/mappr.dart} @override Set convertSet(Iterable model) { if (canConvert(recursive: false)) { return convertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.convertSet(model); } @@ -169,13 +169,13 @@ class $Mappr implements AutoMapprInterface { /// /// When an item in the source iterable is null, uses `whenSourceIsNull` if defined or null /// - /// {@macro package:auto_mappr_example/mappr.dart} + /// {@macro asset:auto_mappr/example/lib/mappr.dart} @override Set tryConvertSet(Iterable model) { if (canConvert(recursive: false)) { return tryConvertIterable(model).toSet(); } - for (final mappr in _modules) { + for (final mappr in _delegates) { if (mappr.canConvert()) { return mappr.tryConvertSet(model); } @@ -190,25 +190,27 @@ class $Mappr implements AutoMapprInterface { }) { final sourceTypeOf = _typeOf(); final targetTypeOf = _typeOf(); - if ((sourceTypeOf == _typeOf() || - sourceTypeOf == _typeOf()) && - (targetTypeOf == _typeOf() || targetTypeOf == _typeOf())) { + if ((sourceTypeOf == _typeOf<_i2.UserDto>() || + sourceTypeOf == _typeOf<_i2.UserDto?>()) && + (targetTypeOf == _typeOf<_i2.User>() || + targetTypeOf == _typeOf<_i2.User?>())) { if (canReturnNull && model == null) { return null; } - return (_map__UserDto__To__User((model as UserDto?)) as TARGET); + return (_map___i2$UserDto__To___i2$User((model as _i2.UserDto?)) + as TARGET); } throw Exception('No ${model.runtimeType} -> $targetTypeOf mapping.'); } - User _map__UserDto__To__User(UserDto? input) { + _i2.User _map___i2$UserDto__To___i2$User(_i2.UserDto? input) { final model = input; if (model == null) { throw Exception( r'Mapping UserDto → User failed because UserDto was null, and no default value was provided. ' r'Consider setting the whenSourceIsNull parameter on the MapType to handle null values during mapping.'); } - return User( + return _i2.User( id: model.id, name: model.xname, ); diff --git a/packages/auto_mappr/example/lib/mappr.dart b/packages/auto_mappr/example/lib/mappr.dart index 77eaeeb2..e6c5fd84 100644 --- a/packages/auto_mappr/example/lib/mappr.dart +++ b/packages/auto_mappr/example/lib/mappr.dart @@ -1,6 +1,6 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; -part 'mappr.g.dart'; +import 'package:auto_mappr_example/mappr.auto_mappr.dart'; @AutoMappr([ MapType( diff --git a/packages/auto_mappr/example/pubspec.yaml b/packages/auto_mappr/example/pubspec.yaml index 0d169acf..3c5d8dd3 100644 --- a/packages/auto_mappr/example/pubspec.yaml +++ b/packages/auto_mappr/example/pubspec.yaml @@ -13,5 +13,5 @@ dependencies: dev_dependencies: auto_mappr: ^1.3.0 build_runner: ^2.0.0 - netglade_analysis: ^4.0.0 + netglade_analysis: ^4.2.0 test: ^1.16.0 diff --git a/packages/auto_mappr/lib/auto_mappr.dart b/packages/auto_mappr/lib/auto_mappr.dart index 48fc4da3..f6458534 100644 --- a/packages/auto_mappr/lib/auto_mappr.dart +++ b/packages/auto_mappr/lib/auto_mappr.dart @@ -5,12 +5,9 @@ import 'package:build/build.dart'; import 'package:source_gen/source_gen.dart'; /// Main Builder for the `AutoMappr` Annotation. -Builder autoMapprBuilder(BuilderOptions options) => SharedPartBuilder( - [AutoMapprGenerator(builderOptions: options)], - 'auto_mappr', - ); - -Builder autoMapprBuilderNotShared(BuilderOptions options) => PartBuilder( - [AutoMapprGenerator(builderOptions: options)], - '.auto_mappr.dart', +Builder autoMapprBuilder(BuilderOptions options) => LibraryBuilder( + AutoMapprGenerator(builderOptions: options), + generatedExtension: '.auto_mappr.dart', + allowSyntaxErrors: true, + options: options, ); diff --git a/packages/auto_mappr/lib/src/builder/assignments/iterable_assignment_builder.dart b/packages/auto_mappr/lib/src/builder/assignments/iterable_assignment_builder.dart index ca7ccf8f..20692d70 100644 --- a/packages/auto_mappr/lib/src/builder/assignments/iterable_assignment_builder.dart +++ b/packages/auto_mappr/lib/src/builder/assignments/iterable_assignment_builder.dart @@ -1,8 +1,8 @@ -import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:auto_mappr/src/builder/assignments/assignment_builder_base.dart'; import 'package:auto_mappr/src/builder/assignments/nested_object_mixin.dart'; import 'package:auto_mappr/src/extensions/dart_type_extension.dart'; import 'package:auto_mappr/src/extensions/expression_extension.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:auto_mappr/src/models/models.dart'; import 'package:code_builder/code_builder.dart'; @@ -24,14 +24,13 @@ class IterableAssignmentBuilder extends AssignmentBuilderBase with NestedObjectM final sourceType = assignment.sourceType!; final targetType = assignment.targetType; - final sourceNullable = sourceType.nullabilitySuffix == NullabilitySuffix.question; - final targetNullable = targetType.nullabilitySuffix == NullabilitySuffix.question; + final sourceNullable = sourceType.isNullable; + final targetNullable = targetType.isNullable; final sourceIterableType = sourceType.genericParameterTypeOrSelf; final targetIterableType = targetType.genericParameterTypeOrSelf; - final shouldFilterNullInSource = sourceIterableType.nullabilitySuffix == NullabilitySuffix.question && - targetIterableType.nullabilitySuffix != NullabilitySuffix.question; + final shouldFilterNullInSource = sourceIterableType.isNullable && targetIterableType.isNotNullable; final assignNestedObject = (!targetIterableType.isPrimitiveType && !targetIterableType.isSpecializedListType) && (!targetIterableType.isSame(sourceIterableType)); @@ -42,7 +41,7 @@ class IterableAssignmentBuilder extends AssignmentBuilderBase with NestedObjectM isOnNullable: sourceNullable, ); - final defaultIterableValueExpression = targetType.defaultIterableExpression(config: mapperConfig); + final defaultIterableValueExpression = targetType.defaultIterableExpression(); if (assignNestedObject) { return sourceIterableExpression @@ -51,14 +50,7 @@ class IterableAssignmentBuilder extends AssignmentBuilderBase with NestedObjectM .call( [_map(assignment)], {}, - [ - refer( - targetIterableType.getDisplayStringWithLibraryAlias( - withNullability: true, - config: mapperConfig, - ), - ), - ], + [EmitterHelper.current.typeRefer(type: targetIterableType)], ) // Call toList, toSet or nothing. // isOnNullable is false, because if map() was called, the value is non-null diff --git a/packages/auto_mappr/lib/src/builder/assignments/map_assignment_builder.dart b/packages/auto_mappr/lib/src/builder/assignments/map_assignment_builder.dart index a387e675..79052c8b 100644 --- a/packages/auto_mappr/lib/src/builder/assignments/map_assignment_builder.dart +++ b/packages/auto_mappr/lib/src/builder/assignments/map_assignment_builder.dart @@ -1,9 +1,9 @@ -import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:auto_mappr/src/builder/assignments/assignment_builder_base.dart'; import 'package:auto_mappr/src/builder/assignments/nested_object_mixin.dart'; import 'package:auto_mappr/src/extensions/dart_type_extension.dart'; import 'package:auto_mappr/src/extensions/expression_extension.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:auto_mappr/src/models/models.dart'; import 'package:code_builder/code_builder.dart'; import 'package:collection/collection.dart'; @@ -27,7 +27,7 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin final sourceType = assignment.sourceType!; final targetType = assignment.targetType; - final sourceNullable = sourceType.nullabilitySuffix == NullabilitySuffix.question; + final sourceNullable = sourceType.isNullable; final sourceKeyType = (sourceType as ParameterizedType).typeArguments.firstOrNull; final sourceValueType = sourceType.typeArguments.lastOrNull; @@ -35,20 +35,24 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin final targetKeyType = (targetType as ParameterizedType).typeArguments.firstOrNull; final targetValueType = targetType.typeArguments.lastOrNull; - final sourceNullableKey = sourceKeyType?.nullabilitySuffix == NullabilitySuffix.question; - final sourceNullableValue = sourceValueType?.nullabilitySuffix == NullabilitySuffix.question; - final targetNullableKey = targetKeyType?.nullabilitySuffix == NullabilitySuffix.question; - final targetNullableValue = targetValueType?.nullabilitySuffix == NullabilitySuffix.question; + final sourceNullableKey = sourceKeyType?.isNullable ?? false; + final sourceNullableValue = sourceValueType?.isNullable ?? false; + final targetNullableKey = targetKeyType?.isNullable ?? false; + final targetNullableValue = targetValueType?.isNullable ?? false; if (targetKeyType == null || targetValueType == null) { + final emittedTarget = EmitterHelper.current.typeReferEmitted(type: targetType); + throw InvalidGenerationSourceError( - 'Target key or value type is null for ${targetType.getDisplayStringWithLibraryAlias(config: assignment.config)}', + 'Target key or value type is null for $emittedTarget', ); } if (sourceKeyType == null || sourceValueType == null) { + final emittedSource = EmitterHelper.current.typeReferEmitted(type: sourceType); + throw InvalidGenerationSourceError( - 'Source key or value type is null for ${sourceType.getDisplayStringWithLibraryAlias(config: assignment.config)}', + 'Source key or value type is null for $emittedSource', ); } @@ -67,8 +71,8 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin final defaultMapValueExpression = literalMap( {}, - refer(targetKeyType.getDisplayStringWithLibraryAlias(withNullability: true, config: mapperConfig)), - refer(targetValueType.getDisplayStringWithLibraryAlias(withNullability: true, config: mapperConfig)), + EmitterHelper.current.typeRefer(type: targetKeyType), + EmitterHelper.current.typeRefer(type: targetValueType), ); final assignNestedObjectKey = !targetKeyType.isPrimitiveType && (targetKeyType != sourceKeyType); @@ -84,7 +88,6 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin valueIsNullable: shouldRemoveNullsValue, keyType: sourceKeyType, valueType: sourceValueType, - config: mapperConfig, ) .maybeCall( 'map', @@ -93,8 +96,8 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin condition: shouldDoMapCall, positionalArguments: [_map(assignment)], typeArguments: [ - refer(targetKeyType.getDisplayStringWithLibraryAlias(withNullability: true, config: mapperConfig)), - refer(targetValueType.getDisplayStringWithLibraryAlias(withNullability: true, config: mapperConfig)), + EmitterHelper.current.typeRefer(type: targetKeyType), + EmitterHelper.current.typeRefer(type: targetValueType), ], ) // When [sourceNullable], use default value. @@ -108,14 +111,16 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin final targetValueType = (assignment.targetType as ParameterizedType).typeArguments.lastOrNull; if (targetKeyType == null || targetValueType == null) { + final emittedTarget = EmitterHelper.current.typeReferEmitted(type: assignment.targetType); throw InvalidGenerationSourceError( - 'Target key or value type is null for ${assignment.targetType.getDisplayStringWithLibraryAlias(config: assignment.config)}', + 'Target key or value type is null for $emittedTarget', ); } if (sourceKeyType == null || sourceValueType == null) { + final emittedSource = EmitterHelper.current.typeReferEmitted(type: assignment.sourceType); throw InvalidGenerationSourceError( - 'Source key or value type is null for ${assignment.sourceType?.getDisplayStringWithLibraryAlias(config: assignment.config)}', + 'Source key or value type is null for $emittedSource', ); } @@ -152,7 +157,7 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin : targetMapExpression; return refer( - '(key, value) => MapEntry(${keyExpression.accept(DartEmitter())}, ${valueExpression.accept(DartEmitter())})', + '(key, value) => MapEntry(${keyExpression.accept(EmitterHelper.current.emitter)}, ${valueExpression.accept(EmitterHelper.current.emitter)})', ); } } diff --git a/packages/auto_mappr/lib/src/builder/assignments/nested_object_mixin.dart b/packages/auto_mappr/lib/src/builder/assignments/nested_object_mixin.dart index 6a83a62d..ddd49796 100644 --- a/packages/auto_mappr/lib/src/builder/assignments/nested_object_mixin.dart +++ b/packages/auto_mappr/lib/src/builder/assignments/nested_object_mixin.dart @@ -1,8 +1,8 @@ -import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:auto_mappr/src/builder/assignments/assignment_builder_base.dart'; import 'package:auto_mappr/src/builder/methods/method_builder_base.dart'; import 'package:auto_mappr/src/extensions/dart_type_extension.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:auto_mappr/src/models/models.dart'; import 'package:build/build.dart'; import 'package:code_builder/code_builder.dart'; @@ -32,21 +32,18 @@ mixin NestedObjectMixin on AssignmentBuilderBase { ); if (nestedMapping == null) { - final targetTypeName = target.getDisplayStringWithLibraryAlias( - withNullability: true, - config: mapperConfig, - ); final sourceName = assignment.sourceField?.getDisplayString(withNullability: true); - if (target.nullabilitySuffix == NullabilitySuffix.question) { + if (target.isNullable) { log.warning("Can't find nested mapping '$assignment' but target is nullable. Setting null"); return literalNull; } + final emittedTarget = EmitterHelper.current.typeReferEmitted(type: target); throw InvalidGenerationSourceError( 'Trying to map nested object from "$assignment" but no mapping is configured.', - todo: 'Configure mapping from $sourceName to $targetTypeName', + todo: 'Configure mapping from $sourceName to $emittedTarget', ); } @@ -60,7 +57,7 @@ mixin NestedObjectMixin on AssignmentBuilderBase { // If source == null and target not nullable -> use whenNullDefault if possible final fieldMapping = mapping.tryGetFieldMapping(assignment.targetName); - if (source.nullabilitySuffix == NullabilitySuffix.question && (fieldMapping?.whenNullExpression != null)) { + if (source.isNullable && (fieldMapping?.whenNullExpression != null)) { // Generates code like: // // model.name == null @@ -93,7 +90,7 @@ mixin NestedObjectMixin on AssignmentBuilderBase { Expression? convertMethodArgument, bool includeGenericTypes = false, }) { - final targetNullable = target.nullabilitySuffix == NullabilitySuffix.question; + final targetNullable = target.isNullable; final useNullableMethod = targetNullable && !mapping.hasWhenNullDefault(); @@ -126,8 +123,8 @@ mixin NestedObjectMixin on AssignmentBuilderBase { {}, includeGenericTypes ? [ - refer(source.getDisplayStringWithLibraryAlias(withNullability: true, config: mapperConfig)), - refer(target.getDisplayStringWithLibraryAlias(withNullability: true, config: mapperConfig)), + EmitterHelper.current.typeRefer(type: source), + EmitterHelper.current.typeRefer(type: target), ] : [], ); diff --git a/packages/auto_mappr/lib/src/builder/assignments/record_assignment_builder.dart b/packages/auto_mappr/lib/src/builder/assignments/record_assignment_builder.dart index 39ab0bb7..064111f1 100644 --- a/packages/auto_mappr/lib/src/builder/assignments/record_assignment_builder.dart +++ b/packages/auto_mappr/lib/src/builder/assignments/record_assignment_builder.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/element/type.dart' as type; import 'package:auto_mappr/src/builder/assignments/assignment_builder_base.dart'; import 'package:auto_mappr/src/builder/assignments/nested_object_mixin.dart'; import 'package:auto_mappr/src/extensions/dart_type_extension.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:auto_mappr/src/models/source_assignment.dart'; import 'package:code_builder/code_builder.dart'; import 'package:collection/collection.dart'; @@ -63,7 +64,7 @@ class RecordAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMix source: sourcePositional.elementAtOrNull(index), target: targetField, index: index + 1, - ).accept(DartEmitter()).toString(), + ).accept(EmitterHelper.current.emitter).toString(), ]; final namedFields = <({String key, String value})>[ @@ -74,7 +75,7 @@ class RecordAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMix assignment: assignment, source: sourceNamed.firstWhereOrNull((sourceField) => sourceField.name == targetField.name), target: targetField, - ).accept(DartEmitter()).toString(), + ).accept(EmitterHelper.current.emitter).toString(), ), ]; @@ -104,7 +105,7 @@ class RecordAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMix final targetRecordExpression = refer(assignment.sourceField!.name); if (!shouldAssignNestedObject) { - return refer('model.${targetRecordExpression.accept(DartEmitter())}.${source.name}'); + return refer('model.${targetRecordExpression.accept(EmitterHelper.current.emitter)}.${source.name}'); } final valueExpression = assignNestedObject( @@ -114,7 +115,7 @@ class RecordAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMix convertMethodArgument: valuesAreSameType ? null : targetRecordExpression, ); - return refer('${valueExpression.accept(DartEmitter())})'); + return refer('${valueExpression.accept(EmitterHelper.current.emitter)})'); } // Handles mapping of only one positional field. @@ -137,7 +138,7 @@ class RecordAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMix final targetRecordExpression = refer(assignment.sourceField!.name); if (!shouldAssignNestedObject) { - return refer('model.${targetRecordExpression.accept(DartEmitter())}.\$$index'); + return refer('model.${targetRecordExpression.accept(EmitterHelper.current.emitter)}.\$$index'); } final valueExpression = assignNestedObject( @@ -147,6 +148,6 @@ class RecordAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMix convertMethodArgument: valuesAreSameType ? null : targetRecordExpression, ); - return refer('${valueExpression.accept(DartEmitter())})'); + return refer('${valueExpression.accept(EmitterHelper.current.emitter)})'); } } diff --git a/packages/auto_mappr/lib/src/builder/auto_mappr_builder.dart b/packages/auto_mappr/lib/src/builder/auto_mappr_builder.dart index 56708c05..449d5f45 100644 --- a/packages/auto_mappr/lib/src/builder/auto_mappr_builder.dart +++ b/packages/auto_mappr/lib/src/builder/auto_mappr_builder.dart @@ -1,9 +1,8 @@ // ignore_for_file: public_member_api_docs import 'package:analyzer/dart/element/element.dart'; -import 'package:auto_mappr/src/builder/map_model_body_method_builder.dart'; import 'package:auto_mappr/src/builder/methods/methods.dart'; -import 'package:auto_mappr/src/extensions/dart_type_extension.dart'; +import 'package:auto_mappr/src/helpers/urls.dart'; import 'package:auto_mappr/src/models/auto_mappr_config.dart'; import 'package:auto_mappr/src/models/type_mapping.dart'; import 'package:built_collection/built_collection.dart'; @@ -15,16 +14,9 @@ class AutoMapprBuilder { final ClassElement mapperClassElement; static const List fileIgnores = [ - 'unnecessary_parenthesis', - 'non_constant_identifier_names', - 'unnecessary_const', - 'require_trailing_commas', - 'unnecessary_raw_strings', - 'unnecessary_lambdas', - - // Can we fix this somehow? (const defaults, const customs). - 'prefer_const_constructors', - 'prefer_const_literals_to_create_immutables', + // ignore everything + // ignore: unnecessary-trailing-comma + 'type=lint', ]; const AutoMapprBuilder({ @@ -36,18 +28,16 @@ class AutoMapprBuilder { return Library( (b) => b ..ignoreForFile = ListBuilder(fileIgnores) - ..body.addAll( - [ - Class( - (b) => b - ..name = '\$${mapperClassElement.displayName}' - ..implements = ListBuilder([refer('AutoMapprInterface')]) - ..methods.addAll(_buildMethods()) - ..constructors.addAll(_buildConstructors()) - ..docs = ListBuilder(config.getAvailableMappingsDocComment()), - ), - ], - ), + ..body.addAll([ + Class( + (cb) => cb + ..name = '\$${mapperClassElement.displayName}' + ..implements = ListBuilder([refer('AutoMapprInterface', Urls.annotationPackageUrl)]) + ..methods.addAll(_buildMethods()) + ..constructors.addAll(_buildConstructors()) + ..docs = ListBuilder(config.getAvailableMappingsDocComment()), + ), + ]), ); } @@ -116,51 +106,17 @@ class AutoMapprBuilder { PrivateConvertMethodBuilder(config).buildMethod(), // Generate non-nullable mapping method. - // TODO(later): switch to MappingMethodBuilder. for (final mapping in config.mappers) - Method( - (b) => b - ..name = mapping.mappingMethodName(config: config) - ..requiredParameters.addAll([ - Parameter( - (p) => p - ..name = 'input' - ..type = refer('${mapping.source.getDisplayStringWithLibraryAlias(config: config)}?'), - ), - ]) - ..returns = refer( - mapping.target.getDisplayStringWithLibraryAlias(config: config), - ) - ..body = MapModelBodyMethodBuilder( - mapping: mapping, - mapperConfig: config, - usedNullableMethodCallback: usedNullableMappingMethod, - ).build(), - ), + MappingMethodBuilder( + config, + mapping: mapping, + usedNullableMethodCallback: usedNullableMappingMethod, + ).buildMethod(), // Generates nullable mapping method only when nullable method is used. - // TODO(later): switch to MappingMethodBuilder. + // ignore: avoid-shadowing for (final mapping in config.mappers.where(nullableMappings.contains)) - Method( - (b) => b - ..name = mapping.nullableMappingMethodName(config: config) - ..requiredParameters.addAll([ - Parameter( - (p) => p - ..name = 'input' - ..type = refer('${mapping.source.getDisplayStringWithLibraryAlias(config: config)}?'), - ), - ]) - ..returns = refer('${mapping.target.getDisplayStringWithLibraryAlias( - withNullability: true, - config: config, - )}?') - ..body = MapModelBodyMethodBuilder( - mapping: mapping, - mapperConfig: config, - nullable: true, - ).build(), - ), + MappingMethodBuilder(config, mapping: mapping, nullable: true).buildMethod(), ]; } } diff --git a/packages/auto_mappr/lib/src/builder/map_bodies/class_body_builder.dart b/packages/auto_mappr/lib/src/builder/map_bodies/class_body_builder.dart index 91c8685f..dd372c83 100644 --- a/packages/auto_mappr/lib/src/builder/map_bodies/class_body_builder.dart +++ b/packages/auto_mappr/lib/src/builder/map_bodies/class_body_builder.dart @@ -1,13 +1,13 @@ import 'package:analyzer/dart/element/element.dart'; -import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:auto_mappr/src/builder/map_bodies/map_body_builder_base.dart'; import 'package:auto_mappr/src/builder/value_assignment_builder.dart'; -import 'package:auto_mappr/src/extensions/element_extension.dart'; +import 'package:auto_mappr/src/extensions/dart_type_extension.dart'; import 'package:auto_mappr/src/extensions/interface_type_extension.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:auto_mappr/src/models/source_assignment.dart'; import 'package:build/build.dart'; -import 'package:code_builder/code_builder.dart' show Code, Expression, refer; +import 'package:code_builder/code_builder.dart' show Code, Expression; import 'package:collection/collection.dart'; import 'package:source_gen/source_gen.dart'; @@ -15,7 +15,6 @@ class ClassBodyBuilder extends MapBodyBuilderBase { const ClassBodyBuilder({ required super.mapperConfig, required super.mapping, - required super.nullable, required super.usedNullableMethodCallback, }); @@ -103,8 +102,7 @@ class ClassBodyBuilder extends MapBodyBuilderBase { // Custom mapping has precedence. if (fieldMapping?.hasCustomMapping() ?? false) { - final targetField = - targetClassGetters.firstWhereOrNull((targetField) => targetField.displayName == fieldMapping?.field); + final targetField = targetClassGetters.firstWhereOrNull((f) => f.displayName == fieldMapping?.field); if (targetField == null) continue; @@ -117,8 +115,6 @@ class ClassBodyBuilder extends MapBodyBuilderBase { targetField: targetField, targetConstructorParam: constructorAssignment, fieldMapping: mapping.tryGetFieldMapping(targetField.displayName), - typeMapping: mapping, - config: mapperConfig, ); mappedTargetConstructorParams.add(sourceAssignment); @@ -145,8 +141,6 @@ class ClassBodyBuilder extends MapBodyBuilderBase { targetField: targetField, targetConstructorParam: constructorAssignment, fieldMapping: mapping.tryGetFieldMapping(targetField.displayName), - typeMapping: mapping, - config: mapperConfig, ); mappedTargetConstructorParams.add(sourceAssignment); @@ -158,8 +152,6 @@ class ClassBodyBuilder extends MapBodyBuilderBase { final targetField = (mapping.target).getAllGetters().firstWhereOrNull((field) => field.displayName == param.displayName); - final fieldMapping = mapping.tryGetFieldMapping(param.displayName); - if (targetField == null && fieldMapping == null) { throw InvalidGenerationSourceError( "Can't find mapping for target's constructor parameter: ${param.displayName}. Parameter is required and no mapping or target's class field not found", @@ -172,8 +164,6 @@ class ClassBodyBuilder extends MapBodyBuilderBase { targetField: targetField, fieldMapping: fieldMapping, targetConstructorParam: constructorAssignment, - typeMapping: mapping, - config: mapperConfig, ), ); } @@ -205,13 +195,13 @@ class ClassBodyBuilder extends MapBodyBuilderBase { void _assertParamFieldCanBeIgnored(ParameterElement param, PropertyAccessorElement sourceField) { final sourceFieldName = sourceField.getDisplayString(withNullability: true); - if (param.isPositional && param.type.nullabilitySuffix != NullabilitySuffix.question) { + if (param.isPositional && param.type.isNotNullable) { throw InvalidGenerationSourceError( "Can't ignore field '$sourceFieldName' as it is positional not-nullable parameter", ); } - if (param.isRequiredNamed && param.type.nullabilitySuffix != NullabilitySuffix.question) { + if (param.isRequiredNamed && param.type.isNotNullable) { throw InvalidGenerationSourceError( "Can't ignore field '$sourceFieldName' as it is required named not-nullable parameter", ); @@ -255,8 +245,6 @@ class ClassBodyBuilder extends MapBodyBuilderBase { assignment: SourceAssignment( sourceField: sourceField, targetField: targetField, - typeMapping: mapping, - config: mapperConfig, ), usedNullableMethodCallback: usedNullableMethodCallback, ).build(), @@ -299,10 +287,9 @@ class ClassBodyBuilder extends MapBodyBuilderBase { required List positional, required List named, }) { - final alias = targetConstructor.enclosingElement.getLibraryAlias(config: mapperConfig); final constructorName = targetConstructor.displayName; - return refer('$alias$constructorName').newInstance( + return EmitterHelper.current.refer(constructorName, targetConstructor.library.identifier).newInstance( positional.map( (assignment) => ValueAssignmentBuilder( mapperConfig: mapperConfig, @@ -325,13 +312,13 @@ class ClassBodyBuilder extends MapBodyBuilderBase { void _assertNotMappedConstructorParameters(Iterable notMapped) { for (final param in notMapped) { - if (param.isPositional && param.type.nullabilitySuffix != NullabilitySuffix.question) { + if (param.isPositional && param.type.isNotNullable) { throw InvalidGenerationSourceError( "Can't generate mapping $mapping as there is non mapped not-nullable positional parameter ${param.displayName}", ); } - if (param.isRequiredNamed && param.type.nullabilitySuffix != NullabilitySuffix.question) { + if (param.isRequiredNamed && param.type.isNotNullable) { if (param.type.isDartCoreList) return; throw InvalidGenerationSourceError( "Can't generate mapping $mapping as there is non mapped not-nullable required named parameter ${param.displayName}", diff --git a/packages/auto_mappr/lib/src/builder/map_bodies/enum_body_builder.dart b/packages/auto_mappr/lib/src/builder/map_bodies/enum_body_builder.dart index 1caef1e1..cc2bb8b4 100644 --- a/packages/auto_mappr/lib/src/builder/map_bodies/enum_body_builder.dart +++ b/packages/auto_mappr/lib/src/builder/map_bodies/enum_body_builder.dart @@ -1,6 +1,6 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:auto_mappr/src/builder/map_bodies/map_body_builder_base.dart'; -import 'package:auto_mappr/src/extensions/dart_type_extension.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:code_builder/code_builder.dart'; import 'package:source_gen/source_gen.dart'; @@ -8,7 +8,6 @@ class EnumBodyBuilder extends MapBodyBuilderBase { const EnumBodyBuilder({ required super.mapperConfig, required super.mapping, - required super.nullable, required super.usedNullableMethodCallback, }); @@ -16,14 +15,14 @@ class EnumBodyBuilder extends MapBodyBuilderBase { Code build() { final isSourceEnum = mapping.source.element is EnumElement; final isTargetEnum = mapping.target.element is EnumElement; + // Check that both source and target enums are enums. if (!isSourceEnum || !isTargetEnum) { + final sourceDisplay = mapping.source.getDisplayString(withNullability: true); + final targetDisplay = mapping.target.getDisplayString(withNullability: true); + throw InvalidGenerationSourceError( - 'Failed to map $mapping because ${isSourceEnum ? 'target ${mapping.target.getDisplayStringWithLibraryAlias( - config: mapperConfig, - )}' : 'source ${mapping.source.getDisplayStringWithLibraryAlias( - config: mapperConfig, - )}'} is not an enum.', + 'Failed to map $mapping because ${isSourceEnum ? 'target $targetDisplay' : 'source $sourceDisplay'} is not an enum.', ); } @@ -36,18 +35,14 @@ class EnumBodyBuilder extends MapBodyBuilderBase { final sourceIsSubset = targetValues.containsAll(sourceValues); if (!sourceIsSubset && !mapping.hasWhenNullDefault()) { + final sourceDisplay = mapping.source.getDisplayString(withNullability: true); + final targetDisplay = mapping.target.getDisplayString(withNullability: true); throw InvalidGenerationSourceError( - "Can't map enum ${mapping.source.getDisplayStringWithLibraryAlias( - config: mapperConfig, - )} into ${mapping.target.getDisplayStringWithLibraryAlias( - config: mapperConfig, - )}. Target enum is not superset of source enum.", + "Can't map enum $sourceDisplay into $targetDisplay. Target enum is not superset of source enum.", ); } - final targetReference = refer( - mapping.target.getDisplayStringWithLibraryAlias(config: mapperConfig), - ); + final targetReference = EmitterHelper.current.typeRefer(type: mapping.target); return targetReference .property('values') @@ -57,7 +52,7 @@ class EnumBodyBuilder extends MapBodyBuilderBase { { if (mapping.hasWhenNullDefault()) 'orElse': refer( - '() => ${mapping.whenSourceIsNullExpression!.accept(DartEmitter())}', + '() => ${mapping.whenSourceIsNullExpression!.accept(EmitterHelper.current.emitter)}', ), }, ) diff --git a/packages/auto_mappr/lib/src/builder/map_bodies/map_body_builder_base.dart b/packages/auto_mappr/lib/src/builder/map_bodies/map_body_builder_base.dart index d90dff23..259a0c4a 100644 --- a/packages/auto_mappr/lib/src/builder/map_bodies/map_body_builder_base.dart +++ b/packages/auto_mappr/lib/src/builder/map_bodies/map_body_builder_base.dart @@ -6,13 +6,11 @@ abstract class MapBodyBuilderBase { final AutoMapprConfig mapperConfig; final TypeMapping mapping; - final bool nullable; final void Function(TypeMapping? mapping)? usedNullableMethodCallback; const MapBodyBuilderBase({ required this.mapperConfig, required this.mapping, - required this.nullable, required this.usedNullableMethodCallback, }); diff --git a/packages/auto_mappr/lib/src/builder/map_model_body_method_builder.dart b/packages/auto_mappr/lib/src/builder/map_model_body_method_builder.dart index 687d0fd4..d842306b 100644 --- a/packages/auto_mappr/lib/src/builder/map_model_body_method_builder.dart +++ b/packages/auto_mappr/lib/src/builder/map_model_body_method_builder.dart @@ -29,7 +29,6 @@ class MapModelBodyMethodBuilder { final enumMapBodyBuilder = EnumBodyBuilder( mapperConfig: mapperConfig, mapping: mapping, - nullable: nullable, usedNullableMethodCallback: usedNullableMethodCallback, ); if (enumMapBodyBuilder.canProcess()) { @@ -41,7 +40,6 @@ class MapModelBodyMethodBuilder { final classMapBodyBuilder = ClassBodyBuilder( mapperConfig: mapperConfig, mapping: mapping, - nullable: nullable, usedNullableMethodCallback: usedNullableMethodCallback, ); diff --git a/packages/auto_mappr/lib/src/builder/methods/can_convert_method_builder.dart b/packages/auto_mappr/lib/src/builder/methods/can_convert_method_builder.dart index 82c404df..7cd79b23 100644 --- a/packages/auto_mappr/lib/src/builder/methods/can_convert_method_builder.dart +++ b/packages/auto_mappr/lib/src/builder/methods/can_convert_method_builder.dart @@ -6,7 +6,7 @@ import 'package:built_collection/built_collection.dart'; import 'package:code_builder/code_builder.dart'; class CanConvertMethodBuilder extends MethodBuilderBase implements CallableMethod, CallableProperty { - CanConvertMethodBuilder(super.config); + const CanConvertMethodBuilder(super.config); @override Method buildMethod() { @@ -63,7 +63,7 @@ class CanConvertMethodBuilder extends MethodBuilderBase implements CallableMetho condition: refer('recursive'), ifBody: ExpressionExtension.forStatement( item: refer('mappr'), - iterable: refer('_modules'), + iterable: refer(MethodBuilderBase.delegatesField), body: ExpressionExtension.ifStatement( condition: CanConvertMethodBuilder(config).propertyCall(on: refer('mappr')), ifBody: literalTrue.returned.statement, diff --git a/packages/auto_mappr/lib/src/builder/methods/convert_iterable_method_builder.dart b/packages/auto_mappr/lib/src/builder/methods/convert_iterable_method_builder.dart index 19c38ca2..8cf7b7c6 100644 --- a/packages/auto_mappr/lib/src/builder/methods/convert_iterable_method_builder.dart +++ b/packages/auto_mappr/lib/src/builder/methods/convert_iterable_method_builder.dart @@ -1,6 +1,7 @@ import 'package:auto_mappr/src/builder/methods/can_convert_method_builder.dart'; import 'package:auto_mappr/src/builder/methods/method_builder_base.dart'; import 'package:auto_mappr/src/extensions/expression_extension.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:built_collection/built_collection.dart'; import 'package:code_builder/code_builder.dart'; @@ -10,7 +11,7 @@ class ConvertIterableMethodBuilder extends MethodBuilderBase { final String wrapper; final String? iterableTransformer; - ConvertIterableMethodBuilder( + const ConvertIterableMethodBuilder( super.config, { required this.wrapper, this.iterableTransformer, @@ -31,10 +32,11 @@ class ConvertIterableMethodBuilder extends MethodBuilderBase { Parameter( (p) => p ..name = 'model' - ..type = Reference('Iterable<${MethodBuilderBase.nullableSourceTypeReference.accept(DartEmitter())}>'), + ..type = + Reference('Iterable<${MethodBuilderBase.nullableSourceTypeReference.accept(EmitterHelper.current.emitter)}>'), ), ) - ..returns = Reference('$wrapper<${MethodBuilderBase.targetTypeReference.accept(DartEmitter())}>') + ..returns = Reference('$wrapper<${MethodBuilderBase.targetTypeReference.accept(EmitterHelper.current.emitter)}>') ..body = buildBody(), ); } @@ -81,7 +83,7 @@ class ConvertIterableMethodBuilder extends MethodBuilderBase { block.statements.add( ExpressionExtension.forStatement( item: refer('mappr'), - iterable: refer('_modules'), + iterable: refer(MethodBuilderBase.delegatesField), body: ExpressionExtension.ifStatement( condition: CanConvertMethodBuilder(config).propertyCall(on: refer('mappr')), ifBody: refer('mappr').property('convert$wrapper').call([refer('model')], {}, []).returned.statement, diff --git a/packages/auto_mappr/lib/src/builder/methods/convert_method_builder.dart b/packages/auto_mappr/lib/src/builder/methods/convert_method_builder.dart index 8b59ff69..9c78a0c1 100644 --- a/packages/auto_mappr/lib/src/builder/methods/convert_method_builder.dart +++ b/packages/auto_mappr/lib/src/builder/methods/convert_method_builder.dart @@ -5,7 +5,7 @@ import 'package:built_collection/built_collection.dart'; import 'package:code_builder/code_builder.dart'; class ConvertMethodBuilder extends MethodBuilderBase { - ConvertMethodBuilder(super.config); + const ConvertMethodBuilder(super.config); @override Method buildMethod() { @@ -56,7 +56,7 @@ class ConvertMethodBuilder extends MethodBuilderBase { block.statements.add( ExpressionExtension.forStatement( item: refer('mappr'), - iterable: refer('_modules'), + iterable: refer(MethodBuilderBase.delegatesField), body: ExpressionExtension.ifStatement( condition: CanConvertMethodBuilder(config).propertyCall(on: refer('mappr')), ifBody: refer('mappr').property('convert').call([refer('model')], {}, []).nullChecked.returned.statement, diff --git a/packages/auto_mappr/lib/src/builder/methods/mapping_method_builder.dart b/packages/auto_mappr/lib/src/builder/methods/mapping_method_builder.dart index 9ca9631b..de2cbaff 100644 --- a/packages/auto_mappr/lib/src/builder/methods/mapping_method_builder.dart +++ b/packages/auto_mappr/lib/src/builder/methods/mapping_method_builder.dart @@ -1,5 +1,7 @@ import 'package:auto_mappr/src/builder/map_model_body_method_builder.dart'; import 'package:auto_mappr/src/builder/methods/method_builder_base.dart'; +import 'package:auto_mappr/src/extensions/expression_extension.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:auto_mappr/src/models/type_mapping.dart'; import 'package:code_builder/code_builder.dart'; @@ -8,7 +10,7 @@ class MappingMethodBuilder extends MethodBuilderBase { final bool nullable; final void Function(TypeMapping? mapping)? usedNullableMethodCallback; - MappingMethodBuilder( + const MappingMethodBuilder( super.config, { required this.mapping, this.nullable = false, @@ -17,49 +19,35 @@ class MappingMethodBuilder extends MethodBuilderBase { @override Method buildMethod() { - // TODO(later): rework mapping to this builder + var returnType = EmitterHelper.current.typeRefer(type: mapping.target); + + if (nullable) { + returnType = returnType.nullabled(); + } return Method( (b) => b - ..name = mapping.mappingMethodName(config: config) + ..name = + nullable ? mapping.nullableMappingMethodName(config: config) : mapping.mappingMethodName(config: config) ..requiredParameters.addAll([ Parameter( (p) => p ..name = 'input' - ..type = refer('${mapping.source.getDisplayString(withNullability: false)}?'), + ..type = EmitterHelper.current.typeRefer(type: mapping.source).nullabled(), ), ]) - ..returns = refer(mapping.target.getDisplayString(withNullability: false)) - ..body = MapModelBodyMethodBuilder( - mapping: mapping, - mapperConfig: config, - usedNullableMethodCallback: usedNullableMethodCallback, - ).build(), + ..returns = returnType + ..body = buildBody(), ); - - // nullable - // return Method( - // (b) => b - // ..name = mapping.nullableMappingMethodName - // ..requiredParameters.addAll([ - // Parameter( - // (p) => p - // ..name = 'input' - // ..type = refer('${mapping.source.getDisplayString(withNullability: false)}?'), - // ) - // ]) - // ..returns = refer('${mapping.target.getDisplayString(withNullability: true)}?') - // ..body = MapModelBodyMethodBuilder( - // mapping: mapping, - // mapperConfig: config, - // nullable: true, - // ).build(), - // ); } @override Code buildBody() { - // TODO(later): rework - return const Code('T'); + return MapModelBodyMethodBuilder( + mapping: mapping, + mapperConfig: config, + usedNullableMethodCallback: usedNullableMethodCallback, + nullable: nullable, + ).build(); } } diff --git a/packages/auto_mappr/lib/src/builder/methods/method_builder_base.dart b/packages/auto_mappr/lib/src/builder/methods/method_builder_base.dart index f61d9240..e0dc25d4 100644 --- a/packages/auto_mappr/lib/src/builder/methods/method_builder_base.dart +++ b/packages/auto_mappr/lib/src/builder/methods/method_builder_base.dart @@ -1,6 +1,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:auto_mappr/src/extensions/dart_type_extension.dart'; import 'package:auto_mappr/src/extensions/expression_extension.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:auto_mappr/src/models/auto_mappr_config.dart'; import 'package:auto_mappr/src/models/type_mapping.dart'; import 'package:built_collection/built_collection.dart'; @@ -9,6 +10,8 @@ import 'package:meta/meta.dart'; /// Base class for method builders. abstract class MethodBuilderBase { + static const delegatesField = '_delegates'; + static const sourceKey = 'SOURCE'; static const sourceTypeReference = Reference(sourceKey); static const nullableSourceTypeReference = Reference('$sourceKey?'); @@ -22,19 +25,15 @@ abstract class MethodBuilderBase { static final ListBuilder overrideAnnotation = ListBuilder([const Reference('override')]); final AutoMapprConfig config; - final Set nullableMappings; - MethodBuilderBase(this.config) : nullableMappings = {}; + const MethodBuilderBase(this.config); static String constructConvertMethodName({ required DartType source, required DartType target, required AutoMapprConfig config, }) => - '_map__${source.toConvertMethodName(withNullability: false, config: config)}__To__${target.toConvertMethodName( - withNullability: false, - config: config, - )}'; + '_map__${source.toConvertMethodName()}__To__${target.toConvertMethodName()}'; static String constructNullableConvertMethodName({ required DartType source, @@ -47,16 +46,6 @@ abstract class MethodBuilderBase { config: config, )}_Nullable'; - bool shouldGenerateNullableMappingMethod(TypeMapping mapping) { - return nullableMappings.contains(mapping); - } - - void usedNullableMappingMethod(TypeMapping? mapping) { - if (mapping == null) return; - - final _ = nullableMappings.add(mapping); - } - Method buildMethod(); @protected @@ -78,8 +67,8 @@ abstract class MethodBuilderBase { required Reference targetTypeOfReference, required Spec inIfExpression, }) { - final sourceName = mapping.source.getDisplayStringWithLibraryAlias(config: config); - final targetName = mapping.target.getDisplayStringWithLibraryAlias(config: config); + final sourceName = EmitterHelper.current.typeReferEmitted(type: mapping.source); + final targetName = EmitterHelper.current.typeReferEmitted(type: mapping.target); final modelIsTypeExpression = sourceTypeOfReference .equalTo(refer('_typeOf<$sourceName>()')) diff --git a/packages/auto_mappr/lib/src/builder/methods/private_convert_method_builder.dart b/packages/auto_mappr/lib/src/builder/methods/private_convert_method_builder.dart index 56fe1ae0..28613960 100644 --- a/packages/auto_mappr/lib/src/builder/methods/private_convert_method_builder.dart +++ b/packages/auto_mappr/lib/src/builder/methods/private_convert_method_builder.dart @@ -1,10 +1,10 @@ import 'package:auto_mappr/src/builder/methods/method_builder_base.dart'; -import 'package:auto_mappr/src/extensions/dart_type_extension.dart'; import 'package:auto_mappr/src/extensions/expression_extension.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:code_builder/code_builder.dart'; class PrivateConvertMethodBuilder extends MethodBuilderBase { - PrivateConvertMethodBuilder(super.config); + const PrivateConvertMethodBuilder(super.config); @override Method buildMethod() { @@ -74,8 +74,7 @@ class PrivateConvertMethodBuilder extends MethodBuilderBase { refer(mapping.mappingMethodName(config: config)) .call( [ - refer('model') - .asA(refer('${mapping.source.getDisplayStringWithLibraryAlias(config: config)}?')), + refer('model').asA(EmitterHelper.current.typeRefer(type: mapping.source).nullabled()), ], ) .asA(MethodBuilderBase.targetTypeReference) @@ -89,7 +88,11 @@ class PrivateConvertMethodBuilder extends MethodBuilderBase { block.addExpression( refer('Exception').newInstance( - [refer("'No \${model.runtimeType} -> \$${targetTypeOfReference.accept(DartEmitter())} mapping.'")], + [ + refer( + "'No \${model.runtimeType} -> \$${targetTypeOfReference.accept(EmitterHelper.current.emitter)} mapping.'", + ), + ], ).thrown, ); diff --git a/packages/auto_mappr/lib/src/builder/methods/private_modules_method_builder.dart b/packages/auto_mappr/lib/src/builder/methods/private_modules_method_builder.dart index a01ad827..15963b97 100644 --- a/packages/auto_mappr/lib/src/builder/methods/private_modules_method_builder.dart +++ b/packages/auto_mappr/lib/src/builder/methods/private_modules_method_builder.dart @@ -1,15 +1,19 @@ import 'package:auto_mappr/src/builder/methods/method_builder_base.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; +import 'package:auto_mappr/src/helpers/urls.dart'; import 'package:code_builder/code_builder.dart'; class PrivateModulesMethodBuilder extends MethodBuilderBase { - PrivateModulesMethodBuilder(super.config); + const PrivateModulesMethodBuilder(super.config); @override Method buildMethod() { + final interfaceRefer = EmitterHelper.current.referEmitted('AutoMapprInterface', Urls.annotationPackageUrl); + return Method( (builder) => builder - ..name = '_modules' - ..returns = refer('List') + ..name = MethodBuilderBase.delegatesField + ..returns = refer('List<$interfaceRefer>') ..lambda = true ..type = MethodType.getter ..body = buildBody(), @@ -18,6 +22,6 @@ class PrivateModulesMethodBuilder extends MethodBuilderBase { @override Code buildBody() { - return refer('const ${(config.modulesCode ?? literalList([])).accept(DartEmitter())}').code; + return refer('const ${(config.modulesCode ?? literalList([])).accept(EmitterHelper.current.emitter)}').code; } } diff --git a/packages/auto_mappr/lib/src/builder/methods/try_convert_iterable_method_builder.dart b/packages/auto_mappr/lib/src/builder/methods/try_convert_iterable_method_builder.dart index 90d72efe..7e49756c 100644 --- a/packages/auto_mappr/lib/src/builder/methods/try_convert_iterable_method_builder.dart +++ b/packages/auto_mappr/lib/src/builder/methods/try_convert_iterable_method_builder.dart @@ -1,6 +1,7 @@ import 'package:auto_mappr/src/builder/methods/can_convert_method_builder.dart'; import 'package:auto_mappr/src/builder/methods/method_builder_base.dart'; import 'package:auto_mappr/src/extensions/expression_extension.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:built_collection/built_collection.dart'; import 'package:code_builder/code_builder.dart'; @@ -10,7 +11,7 @@ class TryConvertIterableMethodBuilder extends MethodBuilderBase { final String wrapper; final String? iterableTransformer; - TryConvertIterableMethodBuilder( + const TryConvertIterableMethodBuilder( super.config, { required this.wrapper, this.iterableTransformer, @@ -34,10 +35,12 @@ class TryConvertIterableMethodBuilder extends MethodBuilderBase { Parameter( (p) => p ..name = 'model' - ..type = Reference('Iterable<${MethodBuilderBase.nullableSourceTypeReference.accept(DartEmitter())}>'), + ..type = + Reference('Iterable<${MethodBuilderBase.nullableSourceTypeReference.accept(EmitterHelper.current.emitter)}>'), ), ) - ..returns = Reference('$wrapper<${MethodBuilderBase.nullableTargetTypeReference.accept(DartEmitter())}>') + ..returns = + Reference('$wrapper<${MethodBuilderBase.nullableTargetTypeReference.accept(EmitterHelper.current.emitter)}>') ..body = buildBody(), ); } @@ -90,7 +93,7 @@ class TryConvertIterableMethodBuilder extends MethodBuilderBase { block.statements.add( ExpressionExtension.forStatement( item: refer('mappr'), - iterable: refer('_modules'), + iterable: refer(MethodBuilderBase.delegatesField), body: ExpressionExtension.ifStatement( condition: CanConvertMethodBuilder(config).propertyCall(on: refer('mappr')), ifBody: refer('mappr').property('tryConvert$wrapper').call([refer('model')], {}, []).returned.statement, diff --git a/packages/auto_mappr/lib/src/builder/methods/try_convert_method_builder.dart b/packages/auto_mappr/lib/src/builder/methods/try_convert_method_builder.dart index 71809d4a..3f7b6d43 100644 --- a/packages/auto_mappr/lib/src/builder/methods/try_convert_method_builder.dart +++ b/packages/auto_mappr/lib/src/builder/methods/try_convert_method_builder.dart @@ -7,7 +7,7 @@ import 'package:code_builder/code_builder.dart'; // modules OK // modules tests OK class TryConvertMethodBuilder extends MethodBuilderBase { - TryConvertMethodBuilder(super.config); + const TryConvertMethodBuilder(super.config); @override Method buildMethod() { @@ -58,7 +58,7 @@ class TryConvertMethodBuilder extends MethodBuilderBase { block.statements.add( ExpressionExtension.forStatement( item: refer('mappr'), - iterable: refer('_modules'), + iterable: refer(MethodBuilderBase.delegatesField), body: ExpressionExtension.ifStatement( condition: CanConvertMethodBuilder(config).propertyCall(on: refer('mappr')), ifBody: refer('mappr').property('tryConvert').call([refer('model')], {}, []).returned.statement, diff --git a/packages/auto_mappr/lib/src/builder/methods/type_of_method_builder.dart b/packages/auto_mappr/lib/src/builder/methods/type_of_method_builder.dart index 8cd1a31a..b5acc7fb 100644 --- a/packages/auto_mappr/lib/src/builder/methods/type_of_method_builder.dart +++ b/packages/auto_mappr/lib/src/builder/methods/type_of_method_builder.dart @@ -2,7 +2,7 @@ import 'package:auto_mappr/src/builder/methods/method_builder_base.dart'; import 'package:code_builder/code_builder.dart'; class TypeOfMethodBuilder extends MethodBuilderBase { - TypeOfMethodBuilder(super.config); + const TypeOfMethodBuilder(super.config); @override Method buildMethod() { diff --git a/packages/auto_mappr/lib/src/builder/value_assignment_builder.dart b/packages/auto_mappr/lib/src/builder/value_assignment_builder.dart index 8a3c411e..b606802d 100644 --- a/packages/auto_mappr/lib/src/builder/value_assignment_builder.dart +++ b/packages/auto_mappr/lib/src/builder/value_assignment_builder.dart @@ -1,5 +1,6 @@ -import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:auto_mappr/src/builder/assignments/assignments.dart'; +import 'package:auto_mappr/src/extensions/dart_type_extension.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:auto_mappr/src/models/models.dart'; import 'package:code_builder/code_builder.dart'; @@ -34,8 +35,13 @@ class ValueAssignmentBuilder { return fieldMapping.apply(assignment); } - final rightSide = - refer(sourceField.isStatic ? '${sourceField.enclosingElement.name}' : 'model').property(sourceField.name); + final rightSide = (sourceField.isStatic + // Static field. + ? EmitterHelper.current + .refer(sourceField.enclosingElement.name!, sourceField.enclosingElement.library?.identifier) + // Non static field. + : refer(sourceField.isStatic ? '${sourceField.enclosingElement.name}' : 'model')) + .property(sourceField.name); final assignmentBuilders = [ // Iterable. @@ -82,8 +88,8 @@ class ValueAssignmentBuilder { return rightSide.ifNullThen(fieldMapping!.whenNullExpression!); } - final sourceNullable = assignment.sourceType!.nullabilitySuffix == NullabilitySuffix.question; - final targetNullable = assignment.targetType.nullabilitySuffix == NullabilitySuffix.question; + final sourceNullable = assignment.sourceType!.isNullable; + final targetNullable = assignment.targetType.isNullable; // BANG operator when Source is nullable and Target not final shouldIgnoreNull = fieldMapping?.ignoreNull ?? diff --git a/packages/auto_mappr/lib/src/extensions/dart_object_extension.dart b/packages/auto_mappr/lib/src/extensions/dart_object_extension.dart index c1e7b0b4..4ea1550c 100644 --- a/packages/auto_mappr/lib/src/extensions/dart_object_extension.dart +++ b/packages/auto_mappr/lib/src/extensions/dart_object_extension.dart @@ -1,9 +1,8 @@ //ignore_for_file: no-object-declaration import 'package:analyzer/dart/constant/value.dart'; -import 'package:auto_mappr/src/extensions/element_extension.dart'; import 'package:auto_mappr/src/extensions/executable_element_extension.dart'; -import 'package:auto_mappr/src/models/auto_mappr_config.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:code_builder/code_builder.dart'; import 'package:collection/collection.dart'; import 'package:source_gen/source_gen.dart'; @@ -12,10 +11,7 @@ extension DartObjectExtension on DartObject { /// If the top most object is a function, then return its code expression. /// /// Otherwise return code expression of literals or objects. - Expression? toCodeExpression({ - required AutoMapprConfig config, - bool passModelArgument = false, - }) { + Expression? toCodeExpression({bool passModelArgument = false}) { if (isNull) { return null; } @@ -23,22 +19,19 @@ extension DartObjectExtension on DartObject { // If the top most object is function, call it. final asFunction = toFunctionValue(); if (asFunction != null) { - return refer(asFunction.referCallString).call([ + return EmitterHelper.current.refer(asFunction.referCallString, asFunction.library.identifier).call([ if (passModelArgument) refer('model'), ]); } - final emitter = DartEmitter(); - final output = _ToCodeExpressionConverter(config: config).convert(this).accept(emitter); + final output = const _ToCodeExpressionConverter().convert(this).accept(EmitterHelper.current.emitter); return CodeExpression(Code('$output')); } } class _ToCodeExpressionConverter { - final AutoMapprConfig config; - - const _ToCodeExpressionConverter({required this.config}); + const _ToCodeExpressionConverter(); Spec convert(DartObject dartObject) { return _toSpec(dartObject); @@ -91,13 +84,13 @@ class _ToCodeExpressionConverter { final revived = ConstantReader(dartObject).revive(); final location = revived.source.toString().split('#'); - final libraryAlias = dartObject.type!.element!.getLibraryAlias(config: config); + final libraryUrl = dartObject.type?.element?.library?.identifier; // Getters, Setters, Methods can't be declared as constants so this // literal must either be a top-level constant or a static constant and // can be directly accessed by `revived.accessor`. if (location.length <= 1) { - return refer('$libraryAlias${revived.accessor}'); + return EmitterHelper.current.refer(revived.accessor, libraryUrl); } // If this is a class instantiation then `location[1]` will be populated @@ -108,7 +101,7 @@ class _ToCodeExpressionConverter { final instantiation = location.elementAtOrNull(1); final useNamedConstructor = revived.accessor.isNotEmpty; - final revivedInstance = refer('$libraryAlias$instantiation'); + final revivedInstance = EmitterHelper.current.refer('$instantiation', libraryUrl); final positionalArguments = revived.positionalArguments.map((argument) => _toSpec(argument) as Expression); diff --git a/packages/auto_mappr/lib/src/extensions/dart_type_extension.dart b/packages/auto_mappr/lib/src/extensions/dart_type_extension.dart index f0a1ac63..a9e5baa6 100644 --- a/packages/auto_mappr/lib/src/extensions/dart_type_extension.dart +++ b/packages/auto_mappr/lib/src/extensions/dart_type_extension.dart @@ -1,7 +1,6 @@ import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; -import 'package:auto_mappr/src/extensions/element_extension.dart'; -import 'package:auto_mappr/src/models/auto_mappr_config.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:code_builder/code_builder.dart'; import 'package:collection/collection.dart'; @@ -15,6 +14,14 @@ extension DartTypeExtension on DartType { isDartCoreEnum || isDartCoreSymbol; + bool get isNullable { + return nullabilitySuffix == NullabilitySuffix.question; + } + + bool get isNotNullable { + return !isNullable; + } + /// Is special variant of integer. /// /// See `[Uint8List], [Uint16List], [Uint32List], [Uint64List]`. @@ -60,96 +67,31 @@ extension DartTypeExtension on DartType { } // Nullability matches. - final thisNullability = nullabilitySuffix == NullabilitySuffix.question; - final otherNullability = other.nullabilitySuffix == NullabilitySuffix.question; + final thisNullability = isNullable; + final otherNullability = other.isNullable; final isSameNullability = thisNullability == otherNullability; return isSameExceptNullability && isSameNullability; } - Expression defaultIterableExpression({required AutoMapprConfig config}) { + Expression defaultIterableExpression() { final itemType = genericParameterTypeOrSelf; return isDartCoreSet - ? literalSet( - {}, - refer( - itemType.getDisplayStringWithLibraryAlias( - config: config, - withNullability: true, - ), - ), - ) - : literalList( - [], - refer( - itemType.getDisplayStringWithLibraryAlias( - config: config, - withNullability: true, - ), - ), - ); + ? literalSet({}, EmitterHelper.current.typeRefer(type: itemType)) + : literalList([], EmitterHelper.current.typeRefer(type: itemType)); } - String getDisplayStringWithLibraryAlias({ - required AutoMapprConfig config, - bool withNullability = false, - }) { - final alias = element?.getLibraryAlias(config: config); - final typeName = element?.name; - - if (alias == null || typeName == null) { - return '??'; - } - - final buffer = StringBuffer('$alias$typeName'); - - if (this is ParameterizedType && (this as ParameterizedType).typeArguments.isNotEmpty) { - final arguments = (this as ParameterizedType) - .typeArguments - .map( - (argument) => argument.getDisplayStringWithLibraryAlias( - withNullability: withNullability, - config: config, - ), - ) - .join(','); - buffer.write('<$arguments>'); - } - - // Nullability - if (withNullability && nullabilitySuffix == NullabilitySuffix.question) { - buffer.write('?'); - } - - return buffer.toString(); - } - - String toConvertMethodName({ - required bool withNullability, - required AutoMapprConfig config, - }) { - final alias = element!.getLibraryAlias(config: config, postfix: '_'); - final typeName = element!.name; - final buffer = StringBuffer()..write('$alias$typeName'); - - if (this is ParameterizedType && (this as ParameterizedType).typeArguments.isNotEmpty) { - final arguments = (this as ParameterizedType) - .typeArguments - .map( - (argument) => argument.toConvertMethodName( - withNullability: withNullability, - config: config, - ), - ) - .join(r'$'); - buffer.write('\$$arguments'); - } - - // Nullability - if (withNullability && nullabilitySuffix == NullabilitySuffix.question) { - buffer.write('?'); - } + String toConvertMethodName() { + final emittedThis = EmitterHelper.current + .typeReferEmitted(type: this) + .replaceAll(' ', '') + .replaceAll('?', '') + .replaceAll('.', r'$') + .replaceAll(',', r'_$') + .replaceAll('<', r'$') + .replaceAll('>', r'$'); + final buffer = StringBuffer()..write(emittedThis); return buffer.toString(); } diff --git a/packages/auto_mappr/lib/src/extensions/element_extension.dart b/packages/auto_mappr/lib/src/extensions/element_extension.dart deleted file mode 100644 index 4d75f685..00000000 --- a/packages/auto_mappr/lib/src/extensions/element_extension.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:analyzer/dart/element/element.dart'; -import 'package:auto_mappr/src/models/auto_mappr_config.dart'; - -extension ElementExtension on Element { - /// Returns an library alias with [postfix] (usually '.'), - /// or empty string if no alias detected. - String getLibraryAlias({ - required AutoMapprConfig config, - String postfix = '.', - }) { - final libraryUri = source?.uri.toString(); - final contains = config.libraryUriToAlias.containsKey(libraryUri); - - return contains ? '${config.libraryUriToAlias[libraryUri]!}$postfix' : ''; - } -} diff --git a/packages/auto_mappr/lib/src/extensions/expression_extension.dart b/packages/auto_mappr/lib/src/extensions/expression_extension.dart index 54a45bc2..bd45eeb1 100644 --- a/packages/auto_mappr/lib/src/extensions/expression_extension.dart +++ b/packages/auto_mappr/lib/src/extensions/expression_extension.dart @@ -1,6 +1,6 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:auto_mappr/src/extensions/dart_type_extension.dart'; -import 'package:auto_mappr/src/models/auto_mappr_config.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:code_builder/code_builder.dart'; extension ExpressionExtension on Expression { @@ -19,7 +19,10 @@ extension ExpressionExtension on Expression { } if ((source.isDartCoreList || forceCast) && target.isSpecializedListType) { - return refer(target.getDisplayString(withNullability: false)).property('fromList').call([this]); + return EmitterHelper.current + .typeRefer(type: target, withNullabilitySuffix: false) + .property('fromList') + .call([this]); } // Keep iterable as is. @@ -82,7 +85,6 @@ extension ExpressionExtension on Expression { required bool valueIsNullable, required DartType keyType, required DartType valueType, - required AutoMapprConfig config, }) { if (!keyIsNullable && !valueIsNullable) return this; @@ -94,60 +96,52 @@ extension ExpressionExtension on Expression { [refer('(key, value) => $keyCondition $and $valueCondition')], {}, [ - refer(keyType.getDisplayStringWithLibraryAlias(config: config)), - refer(valueType.getDisplayStringWithLibraryAlias(config: config)), + EmitterHelper.current.typeRefer(type: keyType, withNullabilitySuffix: false), + EmitterHelper.current.typeRefer(type: valueType, withNullabilitySuffix: false), ], ); } - Expression maybeAsA(Expression expression, {required bool condition}) { - if (!condition) return this; - - return asA(expression); - } - - static Expression ifStatement({ + static Reference ifStatement({ required Spec condition, required Spec ifBody, Spec? elseBody, }) { - final dartEmitter = DartEmitter(); + final emitter = EmitterHelper.current.emitter; - final ifBlock = '{ ${ifBody.accept(dartEmitter)} }'; - final elseBlock = (elseBody != null) ? 'else { ${elseBody.accept(dartEmitter)} }' : ''; + final ifBlock = '{ ${ifBody.accept(emitter)} }'; + final elseBlock = (elseBody != null) ? 'else { ${elseBody.accept(emitter)} }' : ''; - return refer('''if ( ${condition.accept(dartEmitter)} ) $ifBlock $elseBlock'''); + return refer('''if ( ${condition.accept(emitter)} ) $ifBlock $elseBlock'''); } - Expression ifStatement2({required Spec ifBody, Spec? elseBody}) { - final dartEmitter = DartEmitter(); - - final ifBlock = '{ ${ifBody.accept(dartEmitter)} }'; - final elseBlock = (elseBody != null) ? 'else { ${elseBody.accept(dartEmitter)} }' : ''; + Reference ifStatement2({required Spec ifBody, Spec? elseBody}) { + final ifBlock = '{ ${ifBody.accept(EmitterHelper.current.emitter)} }'; + final elseBlock = (elseBody != null) ? 'else { ${elseBody.accept(EmitterHelper.current.emitter)} }' : ''; - return refer('''if ( ${accept(dartEmitter)} ) $ifBlock $elseBlock'''); + return refer('''if ( ${accept(EmitterHelper.current.emitter)} ) $ifBlock $elseBlock'''); } - static Expression forStatement({ + static Reference forStatement({ required Reference item, required Reference iterable, required Spec body, }) { - final dartEmitter = DartEmitter(); + final emitter = EmitterHelper.current.emitter; return refer(''' -for (final ${item.accept(dartEmitter)} in ${iterable.accept(dartEmitter)}) { - ${body.accept(dartEmitter)} +for (final ${item.accept(emitter)} in ${iterable.accept(emitter)}) { + ${body.accept(emitter)} } '''); } - Expression bracketed() { - return refer('(${accept(DartEmitter())})'); + Reference bracketed() { + return refer('(${accept(EmitterHelper.current.emitter)})'); } - Expression nullabled() { - return refer('${accept(DartEmitter())}?'); + Reference nullabled() { + return refer('${accept(EmitterHelper.current.emitter)}?'); } Expression equalToNull() => equalTo(literalNull); diff --git a/packages/auto_mappr/lib/src/extensions/reference_extension.dart b/packages/auto_mappr/lib/src/extensions/reference_extension.dart deleted file mode 100644 index cab8b802..00000000 --- a/packages/auto_mappr/lib/src/extensions/reference_extension.dart +++ /dev/null @@ -1,5 +0,0 @@ -import 'package:code_builder/code_builder.dart'; - -extension ReferenceExtension on Reference { - Reference get nullabled => refer('${accept(DartEmitter())}?'); -} diff --git a/packages/auto_mappr/lib/src/generator/auto_mappr_generator.dart b/packages/auto_mappr/lib/src/generator/auto_mappr_generator.dart index 231c208b..369d537e 100644 --- a/packages/auto_mappr/lib/src/generator/auto_mappr_generator.dart +++ b/packages/auto_mappr/lib/src/generator/auto_mappr_generator.dart @@ -5,13 +5,13 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:auto_mappr/src/builder/auto_mappr_builder.dart'; import 'package:auto_mappr/src/extensions/dart_object_extension.dart'; -import 'package:auto_mappr/src/extensions/dart_type_extension.dart'; import 'package:auto_mappr/src/extensions/list_extension.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; +import 'package:auto_mappr/src/helpers/run_zoned_auto_mappr.dart'; import 'package:auto_mappr/src/models/auto_mappr_options.dart'; import 'package:auto_mappr/src/models/models.dart'; import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:build/build.dart'; -import 'package:code_builder/code_builder.dart'; import 'package:collection/collection.dart'; import 'package:source_gen/source_gen.dart'; @@ -19,71 +19,82 @@ import 'package:source_gen/source_gen.dart'; class AutoMapprGenerator extends GeneratorForAnnotation { final BuilderOptions builderOptions; + // Constants for AutoMappr. + static const String annotationAutoMappr = 'AutoMappr'; + static const String annotationFieldDelegates = 'delegates'; + static const String annotationFieldMappers = 'mappers'; + static const String annotationFieldIncludes = 'includes'; + + // Constants for MapType. + static const String mapTypeFieldFields = 'fields'; + static const String mapTypeFieldWhenSourceIsNull = 'whenSourceIsNull'; + static const String mapTypeFieldConstructor = 'constructor'; + static const String mapTypeFieldIgnoreFieldNull = 'ignoreFieldNull'; + static const String mapTypeFieldReverse = 'reverse'; + + // Constants for Field. + static const String fieldFieldField = 'field'; + static const String fieldFieldIgnore = 'ignore'; + static const String fieldFieldFrom = 'from'; + static const String fieldFieldCustom = 'custom'; + static const String fieldFieldWhenNull = 'whenNull'; + static const String fieldFieldIgnoreNull = 'ignoreNull'; + const AutoMapprGenerator({required this.builderOptions}); @override dynamic generateForAnnotatedElement(Element element, ConstantReader annotation, BuildStep buildStep) { - if (element is! ClassElement) { - throw InvalidGenerationSourceError( - '${element.displayName} is not a class and cannot be annotated with @AutoMappr.', - element: element, - todo: 'Use @AutoMappr annotation on a class', - ); - } - - final libraryUriToAlias = _getLibraryAliases(element: element); - - final mapprOptions = AutoMapprOptions.fromJson(builderOptions.config); - - final tmpConfig = AutoMapprConfig( - mappers: [], - availableMappingsMacroId: 'tmp', - libraryUriToAlias: libraryUriToAlias, - mapprOptions: mapprOptions, - ); - - final constant = annotation.objectValue; - final mappersField = constant.getField('mappers')!; - final mappersList = mappersField.toListValue()!; - final modulesExpression = constant.getField('modules')!.toCodeExpression(config: tmpConfig); - final modulesList = constant.getField('modules')!.toListValue(); - - final mappers = _processMappers( - mappers: mappersList, - element: element, - config: tmpConfig, - ); - - final duplicates = mappers.duplicates; - if (duplicates.isNotEmpty) { - throw InvalidGenerationSourceError( - '@AutoMappr has configured duplicated mappings:\n\t${duplicates.map( - (e) => e.toStringWithLibraryAlias(config: tmpConfig), - ).join('\n\t')}', + final filePath = element.library?.identifier; + final fileUri = filePath != null ? Uri.parse(filePath) : null; + + return runZonedAutoMappr(libraryUri: fileUri, () { + if (element is! ClassElement) { + throw InvalidGenerationSourceError( + '${element.displayName} is not a class and cannot be annotated with @AutoMappr.', + element: element, + todo: 'Use @AutoMappr annotation on a class', + ); + } + + final mapprOptions = AutoMapprOptions.fromJson(builderOptions.config); + + final constant = annotation.objectValue; + final mappersList = constant.getField(annotationFieldMappers)!.toListValue()!; + final delegatesExpression = constant.getField(annotationFieldDelegates)!.toCodeExpression(); + final delegatesList = constant.getField(annotationFieldDelegates)!.toListValue(); + final includesList = constant.getField(annotationFieldIncludes)!.toListValue(); + + final allMappers = [...mappersList, ..._mappersFromRecursiveIncludes(includesList: includesList ?? [])]; + final mappers = _processMappers(mappers: allMappers, element: element); + + final duplicates = mappers.duplicates; + if (duplicates.isNotEmpty) { + throw InvalidGenerationSourceError( + '@AutoMappr has configured duplicated mappings:\n\t${duplicates.map( + (e) => e.toString(), + ).join('\n\t')}', + ); + } + + final config = AutoMapprConfig( + mappers: mappers, + availableMappingsMacroId: element.library.identifier, + modulesCode: delegatesExpression, + delegatesList: delegatesList ?? [], + mapprOptions: mapprOptions, ); - } - - final config = AutoMapprConfig( - mappers: mappers, - availableMappingsMacroId: element.library.identifier, - libraryUriToAlias: libraryUriToAlias, - modulesCode: modulesExpression, - modulesList: modulesList ?? [], - mapprOptions: mapprOptions, - ); - final builder = AutoMapprBuilder(mapperClassElement: element, config: config); + final builder = AutoMapprBuilder(mapperClassElement: element, config: config); - final output = builder.build(); - final emitter = DartEmitter(orderDirectives: true, useNullSafetySyntax: true); + final output = builder.build(); - return '${output.accept(emitter)}'; + return '${output.accept(EmitterHelper.current.emitter)}'; + }); } List _processMappers({ required List mappers, required ClassElement element, - required AutoMapprConfig config, }) { return mappers .map((mapper) { @@ -93,36 +104,39 @@ class AutoMapprGenerator extends GeneratorForAnnotation { final targetType = mapperType.typeArguments.lastOrNull; if (sourceType is! InterfaceType) { + final emittedSource = EmitterHelper.current.typeReferEmitted(type: sourceType); + throw InvalidGenerationSourceError( - '${sourceType?.getDisplayStringWithLibraryAlias(config: config, withNullability: true)} is not a class and cannot be mapped from', + '$emittedSource is not a class and cannot be mapped from', element: element, todo: 'Use a class', ); } if (targetType is! InterfaceType) { + final emittedTarget = EmitterHelper.current.typeReferEmitted(type: targetType); + throw InvalidGenerationSourceError( - '${targetType?.getDisplayStringWithLibraryAlias(config: config, withNullability: true)} is not a class and cannot be mapped to', + '$emittedTarget is not a class and cannot be mapped to', element: element, todo: 'Use a class', ); } - final fields = mapper.getField('fields')?.toListValue(); - final whenSourceIsNull = mapper.getField('whenSourceIsNull')?.toCodeExpression(config: config); - final constructor = mapper.getField('constructor')?.toStringValue(); - final ignoreFieldNull = mapper.getField('ignoreFieldNull')?.toBoolValue(); - final reverse = mapper.getField('reverse')?.toBoolValue(); + final fields = mapper.getField(mapTypeFieldFields)?.toListValue(); + final whenSourceIsNull = mapper.getField(mapTypeFieldWhenSourceIsNull)?.toCodeExpression(); + final constructor = mapper.getField(mapTypeFieldConstructor)?.toStringValue(); + final ignoreFieldNull = mapper.getField(mapTypeFieldIgnoreFieldNull)?.toBoolValue(); + final reverse = mapper.getField(mapTypeFieldReverse)?.toBoolValue(); final fieldMappings = fields ?.map( (fieldMapping) => FieldMapping( - field: fieldMapping.getField('field')!.toStringValue()!, - ignore: fieldMapping.getField('ignore')!.toBoolValue()!, - from: fieldMapping.getField('from')!.toStringValue(), - customExpression: - fieldMapping.getField('custom')!.toCodeExpression(passModelArgument: true, config: config), - whenNullExpression: fieldMapping.getField('whenNull')!.toCodeExpression(config: config), - ignoreNull: fieldMapping.getField('ignoreNull')?.toBoolValue(), + field: fieldMapping.getField(fieldFieldField)!.toStringValue()!, + ignore: fieldMapping.getField(fieldFieldIgnore)!.toBoolValue()!, + from: fieldMapping.getField(fieldFieldFrom)!.toStringValue(), + customExpression: fieldMapping.getField(fieldFieldCustom)!.toCodeExpression(passModelArgument: true), + whenNullExpression: fieldMapping.getField(fieldFieldWhenNull)!.toCodeExpression(), + ignoreNull: fieldMapping.getField(fieldFieldIgnoreNull)?.toBoolValue(), ), ) .toList(); @@ -151,41 +165,31 @@ class AutoMapprGenerator extends GeneratorForAnnotation { .toList(); } - Map _getLibraryAliases({required ClassElement element}) { - final libraryUriToAlias = {}; - - final imports = element.library.libraryImports; - final aliases = imports.map((e) => e.prefix?.element.name).toList(); - final uris = imports.map((e) => e.importedLibrary!.identifier).toList(); - - for (var i = 0; i < imports.length; i++) { - final currentAlias = aliases.elementAtOrNull(i); - if (currentAlias == null) continue; - - final importedLibrary = imports.elementAtOrNull(i)?.importedLibrary; - final exports = importedLibrary == null ? [] : _getRecursiveLibraryExports(importedLibrary); - - final uri = uris.elementAtOrNull(i); - - libraryUriToAlias.addAll({ - // Current library. - if (uri != null) uri: currentAlias, - // It's exports. - for (final exported in exports) exported.identifier: currentAlias, - }); + /// Recursively returns all mappings from includes. + Iterable _mappersFromRecursiveIncludes({required List includesList}) { + final mappings = []; + + for (final include in includesList) { + // For each include locate AutoMappr annotation. + if (include.type?.element?.metadata + .firstWhereOrNull((data) => data.element?.displayName == annotationAutoMappr) + ?.computeConstantValue() + case final includeConstant?) { + // This -- mappers. + final mappers = includeConstant.getField(annotationFieldMappers)?.toListValue(); + if (mappers != null) { + mappings.addAll(mappers); + } + + // Bellow -- recursive includes. + final includes = includeConstant.getField(annotationFieldIncludes)?.toListValue(); + if (includes != null) { + // ignore: avoid-recursive-calls, it's handled + mappings.addAll(_mappersFromRecursiveIncludes(includesList: includes)); + } + } } - return libraryUriToAlias; - } - - /// Recursively returns all exports (even nested) for [library]. - Iterable _getRecursiveLibraryExports(LibraryElement library) { - final exports = library.libraryExports; - if (exports.isEmpty) return []; - - return [ - ...exports.map((e) => e.exportedLibrary!), - ...exports.map((e) => _getRecursiveLibraryExports(e.exportedLibrary!)).flattened, - ]; + return mappings; } } diff --git a/packages/auto_mappr/lib/src/helpers/di.dart b/packages/auto_mappr/lib/src/helpers/di.dart new file mode 100644 index 00000000..e69de29b diff --git a/packages/auto_mappr/lib/src/helpers/emitter_helper.dart b/packages/auto_mappr/lib/src/helpers/emitter_helper.dart new file mode 100644 index 00000000..6ec87878 --- /dev/null +++ b/packages/auto_mappr/lib/src/helpers/emitter_helper.dart @@ -0,0 +1,118 @@ +import 'dart:async'; + +import 'package:analyzer/dart/element/type.dart'; +import 'package:auto_mappr/src/extensions/dart_type_extension.dart'; +import 'package:code_builder/code_builder.dart' as cb; +import 'package:path/path.dart' as p; + +/// Helper class for emitting and package import uri resolution. +class EmitterHelper { + /// Global emitter so we can emit on the fly and all imports are preserved. + final cb.DartEmitter emitter = cb.DartEmitter( + allocator: cb.Allocator.simplePrefixing(), + orderDirectives: true, + useNullSafetySyntax: true, + ); + + final Uri? fileWithAnnotation; + + static Symbol get zoneSymbol => #autoMapprEmitter; + static EmitterHelper get current => Zone.current[zoneSymbol] as EmitterHelper; + + EmitterHelper({required this.fileWithAnnotation}); + + /// `refer` that is processed by helper. + cb.Reference refer(String symbol, String? url) { + final importUrl = + // TODO(module): can we check whether the url is from THIS package and therefore we can use relative, also in current project test must be relative + // type.isPrimitiveType || type.isDartCoreObject + // ? _resolveAssetImport(libraryPath) + // : + _relative(url, fileWithAnnotation); + + return cb.refer(symbol, importUrl); + } + + /// `refer` that is emitted to String using [emitter]. + String referEmitted(String symbol, [String? url]) { + return refer(symbol, url).accept(emitter).toString(); + } + + /// [typeRefer] that is also emitted to String using [emitter]. + String typeReferEmitted({ + required DartType? type, + // Uri? targetFile, + bool withNullabilitySuffix = true, + }) { + if (type == null) { + return '???'; + } + + return '${typeRefer(type: type, withNullabilitySuffix: withNullabilitySuffix).accept(emitter)}'; + } + + /// Produces a reference to [type] with an import alias prefix. + /// When [fileWithAnnotation] is also set, import is relative. + /// + /// Inspired by injectable. + cb.Reference typeRefer({ + required DartType type, + bool withNullabilitySuffix = true, + }) { + final libraryPath = type.element?.library?.identifier; + final importUrl = type.isPrimitiveType || type.isDartCoreObject + ? _resolveAssetImport(libraryPath) + : _relative(libraryPath, fileWithAnnotation); + + return cb.TypeReference((reference) { + reference + ..symbol = type.element?.name + ..url = importUrl + ..isNullable = withNullabilitySuffix && type.isNullable; + + if (type is ParameterizedType && type.typeArguments.isNotEmpty) { + reference.types.addAll( + // ignore: avoid-recursive-calls, it's handled + type.typeArguments.map((e) => typeRefer(type: e)), + ); + } + }); + } + + String? _relative(String? path, Uri? to) { + if (path == null || to == null) { + return null; + } + + final fileUri = Uri.parse(path); + final libName = to.pathSegments.firstOrNull; + + if (fileUri.scheme == 'dart') { + return 'dart:${fileUri.path}'; + } + + if ((to.scheme == 'package' && fileUri.scheme == 'package' && fileUri.pathSegments.firstOrNull == libName) || + (to.scheme == 'asset' && fileUri.scheme != 'package')) { + if (fileUri.path == to.path) { + return fileUri.pathSegments.lastOrNull; + } + + return p.posix.relative(fileUri.path, from: to.path).replaceFirst('../', ''); + } + + return path; + } + + String? _resolveAssetImport(String? path) { + if (path == null) { + return null; + } + + final fileUri = Uri.parse(path); + if (fileUri.scheme == 'asset') { + return '/${fileUri.path}'; + } + + return path; + } +} diff --git a/packages/auto_mappr/lib/src/helpers/run_zoned_auto_mappr.dart b/packages/auto_mappr/lib/src/helpers/run_zoned_auto_mappr.dart new file mode 100644 index 00000000..8d4dfa49 --- /dev/null +++ b/packages/auto_mappr/lib/src/helpers/run_zoned_auto_mappr.dart @@ -0,0 +1,14 @@ +import 'dart:async'; + +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; + +/// We need to use zones so we can easily have "scoped globals" for EmitterHelper. +// ignore: prefer-static-class, must be top level +R runZonedAutoMappr(R Function() body, {Uri? libraryUri}) { + return runZoned( + () { + return body(); + }, + zoneValues: {EmitterHelper.zoneSymbol: EmitterHelper(fileWithAnnotation: libraryUri)}, + ); +} diff --git a/packages/auto_mappr/lib/src/helpers/urls.dart b/packages/auto_mappr/lib/src/helpers/urls.dart new file mode 100644 index 00000000..42769fd1 --- /dev/null +++ b/packages/auto_mappr/lib/src/helpers/urls.dart @@ -0,0 +1,3 @@ +class Urls { + static const annotationPackageUrl = 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; +} diff --git a/packages/auto_mappr/lib/src/models/auto_mappr_config.dart b/packages/auto_mappr/lib/src/models/auto_mappr_config.dart index 0a65e03c..20659be9 100644 --- a/packages/auto_mappr/lib/src/models/auto_mappr_config.dart +++ b/packages/auto_mappr/lib/src/models/auto_mappr_config.dart @@ -1,7 +1,7 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:auto_mappr/src/extensions/dart_type_extension.dart'; -import 'package:auto_mappr/src/extensions/element_extension.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:auto_mappr/src/models/auto_mappr_options.dart'; import 'package:auto_mappr/src/models/type_mapping.dart'; import 'package:code_builder/code_builder.dart'; @@ -11,24 +11,24 @@ class AutoMapprConfig { final List mappers; final String availableMappingsMacroId; final Expression? modulesCode; - final List modulesList; - final Map libraryUriToAlias; + final List includesList; + final List delegatesList; final AutoMapprOptions mapprOptions; String get availableMappingsDocComment { return [ '/// {@macro $availableMappingsMacroId}', - ..._modulesDocComment(), + ..._delegatesDocComment(), ].join('\n'); } const AutoMapprConfig({ required this.mappers, required this.availableMappingsMacroId, - required this.libraryUriToAlias, required this.mapprOptions, this.modulesCode, - this.modulesList = const [], + this.includesList = const [], + this.delegatesList = const [], }); TypeMapping? findMapping({ @@ -46,18 +46,32 @@ class AutoMapprConfig { '/// Available mappings:', for (final mapper in mappers) _getTypeMappingDocs(mapper), '/// {@endtemplate}', - ..._modulesDocComment(), + ..._includesDocComment(), + ..._delegatesDocComment(), ]; } - List _modulesDocComment() { + List _includesDocComment() { return [ - if (modulesList.isNotEmpty) ...[ + if (includesList.isNotEmpty) ...[ '///', - "/// Available modules: ${modulesList.map((e) { - final alias = e.type!.element!.getLibraryAlias(config: this); + "/// Used includes: ${includesList.map((e) { + final emittedInclude = EmitterHelper.current.typeReferEmitted(type: e.type); - return '[$alias\$${e.type!.getDisplayString(withNullability: false)}]'; + return '[$emittedInclude]'; + }).join(', ')}", + ], + ]; + } + + List _delegatesDocComment() { + return [ + if (delegatesList.isNotEmpty) ...[ + '///', + "/// Used delegates: ${delegatesList.map((e) { + final emittedDelegate = EmitterHelper.current.typeReferEmitted(type: e.type); + + return '[$emittedDelegate]'; }).join(', ')}", ], ]; @@ -65,12 +79,11 @@ class AutoMapprConfig { String _getTypeMappingDocs(TypeMapping typeMapping) { final trailingPart = typeMapping.hasWhenNullDefault() ? ' -- With default value.' : '.'; + // Display without import aliases. + final emittedSource = typeMapping.source.getDisplayString(withNullability: true); + final emittedTarget = typeMapping.target.getDisplayString(withNullability: true); // ignore: avoid-non-ascii-symbols, it is ok - return '/// - `${typeMapping.source.getDisplayStringWithLibraryAlias( - config: this, - )}` → `${typeMapping.target.getDisplayStringWithLibraryAlias( - config: this, - )}`$trailingPart'; + return '/// - `$emittedSource` → `$emittedTarget`$trailingPart'; } } diff --git a/packages/auto_mappr/lib/src/models/field_mapping.dart b/packages/auto_mappr/lib/src/models/field_mapping.dart index d98cc4ef..95ac3de9 100644 --- a/packages/auto_mappr/lib/src/models/field_mapping.dart +++ b/packages/auto_mappr/lib/src/models/field_mapping.dart @@ -30,10 +30,6 @@ class FieldMapping extends Equatable { this.whenNullExpression, }); - bool isRenamed() { - return from != null; - } - bool hasCustomMapping() { return customExpression != null; } diff --git a/packages/auto_mappr/lib/src/models/source_assignment.dart b/packages/auto_mappr/lib/src/models/source_assignment.dart index 455520f8..3e6fc7a1 100644 --- a/packages/auto_mappr/lib/src/models/source_assignment.dart +++ b/packages/auto_mappr/lib/src/models/source_assignment.dart @@ -3,6 +3,7 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:auto_mappr/src/extensions/dart_type_extension.dart'; +import 'package:auto_mappr/src/helpers/emitter_helper.dart'; import 'package:auto_mappr/src/models/models.dart'; import 'package:code_builder/code_builder.dart' show Expression, literalList, literalMap, literalNull, literalSet; @@ -26,15 +27,6 @@ class SourceAssignment { /// Like filed 'name' from 'userName' etc. final FieldMapping? fieldMapping; - /// Mapping of type. - /// - /// Like UserDto to User. - final TypeMapping typeMapping; - - final AutoMapprConfig config; - - bool get shouldBeIgnored => fieldMapping?.ignore ?? false; - DartType? get sourceType => sourceField?.returnType; String? get sourceName => sourceField?.displayName; @@ -46,8 +38,6 @@ class SourceAssignment { const SourceAssignment({ required this.sourceField, required this.targetField, - required this.typeMapping, - required this.config, this.targetConstructorParam, this.fieldMapping, }); @@ -69,14 +59,12 @@ class SourceAssignment { return isSourceRecord && isTargetRecord; } - bool canAssignComplexObject() => !targetType.isPrimitiveType; - @override String toString() { - final sourceTypeName = sourceType?.getDisplayStringWithLibraryAlias(withNullability: true, config: config); - final targetTypeName = targetType.getDisplayStringWithLibraryAlias(withNullability: true, config: config); + final emittedSource = EmitterHelper.current.typeReferEmitted(type: sourceType); + final emittedTarget = EmitterHelper.current.typeReferEmitted(type: targetType); - return '$sourceTypeName $sourceName -> $targetTypeName $targetName'; + return '$emittedSource $sourceName -> $emittedTarget $targetName'; } Expression getDefaultValue() { diff --git a/packages/auto_mappr/lib/src/models/type_mapping.dart b/packages/auto_mappr/lib/src/models/type_mapping.dart index 59ee7d15..2715595a 100644 --- a/packages/auto_mappr/lib/src/models/type_mapping.dart +++ b/packages/auto_mappr/lib/src/models/type_mapping.dart @@ -1,7 +1,6 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:auto_mappr/src/builder/methods/method_builder_base.dart'; -import 'package:auto_mappr/src/extensions/dart_type_extension.dart'; import 'package:auto_mappr/src/models/auto_mappr_config.dart'; import 'package:auto_mappr/src/models/field_mapping.dart'; import 'package:code_builder/code_builder.dart'; @@ -66,12 +65,11 @@ class TypeMapping extends Equatable { @override String toString() { - // ignore: avoid-non-ascii-symbols, it is ok - return '$source → $target'; - } + // Without import aliases, used to display errors to user. + final sourceAsString = source.getDisplayString(withNullability: true); + final targetAsString = target.getDisplayString(withNullability: true); - String toStringWithLibraryAlias({required AutoMapprConfig config}) { // ignore: avoid-non-ascii-symbols, it is ok - return '${source.getDisplayStringWithLibraryAlias(config: config)} → ${target.getDisplayStringWithLibraryAlias(config: config)}'; + return '$sourceAsString → $targetAsString'; } } diff --git a/packages/auto_mappr/pubspec.yaml b/packages/auto_mappr/pubspec.yaml index 16041bce..7c38a8ec 100644 --- a/packages/auto_mappr/pubspec.yaml +++ b/packages/auto_mappr/pubspec.yaml @@ -1,6 +1,6 @@ name: auto_mappr description: Code generation for mapping between different objects with ease. -version: 1.7.0 +version: 2.0.0-beta1 repository: https://github.com/netglade/auto_mappr issue_tracker: https://github.com/netglade/auto_mappr/issues screenshots: @@ -13,12 +13,13 @@ environment: dependencies: # TODO: Support analyzer same way as json_serializable https://github.com/google/json_serializable.dart/pull/1333 analyzer: ">=5.4.0 <7.0.0" - auto_mappr_annotation: ^1.2.0 + auto_mappr_annotation: ^2.0.0-beta1 build: ^2.3.1 built_collection: ^5.1.1 code_builder: ^4.4.0 collection: ^1.17.0 equatable: ^2.0.5 + get_it: ^7.6.4 meta: ^1.8.0 path: ^1.8.2 source_gen: ^1.2.6 @@ -27,6 +28,6 @@ dev_dependencies: build_runner: ^2.0.0 generator_test: ^0.2.0 mocktail: ^1.0.0 - netglade_analysis: ^4.0.0 + netglade_analysis: ^4.2.0 source_gen_test: ^1.0.4 test: ^1.16.0 diff --git a/packages/auto_mappr/test/builder/convert_method_builder_test.dart b/packages/auto_mappr/test/builder/convert_method_builder_test.dart index 11386c54..3a8036be 100644 --- a/packages/auto_mappr/test/builder/convert_method_builder_test.dart +++ b/packages/auto_mappr/test/builder/convert_method_builder_test.dart @@ -2,7 +2,8 @@ import 'package:auto_mappr/src/builder/methods/convert_method_builder.dart'; import 'package:auto_mappr/src/builder/methods/private_convert_method_builder.dart'; import 'package:auto_mappr/src/builder/methods/try_convert_method_builder.dart'; import 'package:auto_mappr/src/builder/methods/type_of_method_builder.dart'; -import 'package:auto_mappr/src/extensions/reference_extension.dart'; +import 'package:auto_mappr/src/extensions/expression_extension.dart'; +import 'package:auto_mappr/src/helpers/run_zoned_auto_mappr.dart'; import 'package:auto_mappr/src/models/auto_mappr_config.dart'; import 'package:auto_mappr/src/models/auto_mappr_options.dart'; import 'package:code_builder/code_builder.dart'; @@ -11,101 +12,105 @@ import 'package:test/test.dart'; void main() { test('buildConvertMethod has the correct interface', () { - final result = ConvertMethodBuilder( - const AutoMapprConfig( - mappers: [], - availableMappingsMacroId: 'test', - libraryUriToAlias: {}, - mapprOptions: AutoMapprOptions(ignoreNullableSourceField: false), - ), - ).buildMethod(); - - expect(result, isA()); - expect(result.name, equals('convert')); - expect(result.types.length, equals(2)); - expect(result.returns, equals(result.types.elementAtOrNull(1))); - expect(result.optionalParameters, isEmpty); - expect( - result.requiredParameters, - equals([ - Parameter( - (p) => p - ..name = 'model' - ..type = result.types.firstOrNull?.nullabled, + runZonedAutoMappr(() { + final result = const ConvertMethodBuilder( + AutoMapprConfig( + mappers: [], + availableMappingsMacroId: 'test', + mapprOptions: AutoMapprOptions(ignoreNullableSourceField: false), ), - ]), - ); + ).buildMethod(); + + expect(result, isA()); + expect(result.name, equals('convert')); + expect(result.types.length, equals(2)); + expect(result.returns, equals(result.types.elementAtOrNull(1))); + expect(result.optionalParameters, isEmpty); + expect( + result.requiredParameters, + equals([ + Parameter( + (p) => p + ..name = 'model' + ..type = result.types.firstOrNull?.nullabled(), + ), + ]), + ); + }); }); test('buildTryConvertMethod has the correct interface', () { - final result = TryConvertMethodBuilder( - const AutoMapprConfig( - mappers: [], - availableMappingsMacroId: 'test', - libraryUriToAlias: {}, - mapprOptions: AutoMapprOptions(ignoreNullableSourceField: false), - ), - ).buildMethod(); - - expect(result, isA()); - expect(result.name, equals('tryConvert')); - expect(result.types.length, equals(2)); - expect(result.returns, equals(result.types.elementAtOrNull(1)?.nullabled)); - expect(result.optionalParameters, isEmpty); - expect( - result.requiredParameters, - equals([ - Parameter( - (p) => p - ..name = 'model' - ..type = result.types.firstOrNull?.nullabled, + runZonedAutoMappr(() { + final result = const TryConvertMethodBuilder( + AutoMapprConfig( + mappers: [], + availableMappingsMacroId: 'test', + mapprOptions: AutoMapprOptions(ignoreNullableSourceField: false), ), - ]), - ); + ).buildMethod(); + + expect(result, isA()); + expect(result.name, equals('tryConvert')); + expect(result.types.length, equals(2)); + expect(result.returns, equals(result.types.elementAtOrNull(1)?.nullabled())); + expect(result.optionalParameters, isEmpty); + expect( + result.requiredParameters, + equals([ + Parameter( + (p) => p + ..name = 'model' + ..type = result.types.firstOrNull?.nullabled(), + ), + ]), + ); + }); }); test('buildInternalConvertMethod has the correct interface', () { - final result = PrivateConvertMethodBuilder( - const AutoMapprConfig( - mappers: [], - availableMappingsMacroId: 'test', - libraryUriToAlias: {}, - mapprOptions: AutoMapprOptions(ignoreNullableSourceField: false), - ), - ).buildMethod(); - - expect(result, isA()); - expect(result.name, equals('_convert')); - expect(result.types.length, equals(2)); - expect(result.returns, equals(result.types.elementAtOrNull(1)?.nullabled)); - expect(result.optionalParameters.isEmpty, isFalse); - expect( - result.requiredParameters, - equals([ - Parameter( - (p) => p - ..name = 'model' - ..type = result.types.firstOrNull?.nullabled, + runZonedAutoMappr(() { + final result = const PrivateConvertMethodBuilder( + AutoMapprConfig( + mappers: [], + availableMappingsMacroId: 'test', + mapprOptions: AutoMapprOptions(ignoreNullableSourceField: false), ), - ]), - ); + ).buildMethod(); + + expect(result, isA()); + expect(result.name, equals('_convert')); + expect(result.types.length, equals(2)); + expect(result.returns, equals(result.types.elementAtOrNull(1)?.nullabled())); + expect(result.optionalParameters.isEmpty, isFalse); + expect( + result.requiredParameters, + equals([ + Parameter( + (p) => p + ..name = 'model' + ..type = result.types.firstOrNull?.nullabled(), + ), + ]), + ); + }); }); test('buildTypeOfHelperMethod has the correct interface', () { - final result = TypeOfMethodBuilder( - const AutoMapprConfig( - mappers: [], - availableMappingsMacroId: 'test', - libraryUriToAlias: {}, - mapprOptions: AutoMapprOptions(ignoreNullableSourceField: false), - ), - ).buildMethod(); + runZonedAutoMappr(() { + final result = const TypeOfMethodBuilder( + AutoMapprConfig( + mappers: [], + availableMappingsMacroId: 'test', + mapprOptions: AutoMapprOptions(ignoreNullableSourceField: false), + ), + ).buildMethod(); - expect(result, isA()); - expect(result.name, equals('_typeOf')); - expect(result.types.length, equals(1)); - expect(result.returns, equals(refer('Type'))); - expect(result.optionalParameters, isEmpty); - expect(result.requiredParameters, isEmpty); + expect(result, isA()); + expect(result.name, equals('_typeOf')); + expect(result.types.length, equals(1)); + expect(result.returns, equals(refer('Type'))); + expect(result.optionalParameters, isEmpty); + expect(result.requiredParameters, isEmpty); + }); }); } diff --git a/packages/auto_mappr/test/integration/modules_test.dart b/packages/auto_mappr/test/integration/delegates_test.dart similarity index 98% rename from packages/auto_mappr/test/integration/modules_test.dart rename to packages/auto_mappr/test/integration/delegates_test.dart index 639bb87f..93116737 100644 --- a/packages/auto_mappr/test/integration/modules_test.dart +++ b/packages/auto_mappr/test/integration/delegates_test.dart @@ -1,9 +1,9 @@ import 'package:test/test.dart'; -import 'fixture/modules.dart' as fixture_group; -import 'fixture/modules/module_alpha.dart' as fixture_alpha; -import 'fixture/modules/module_beta.dart' as fixture_beta; -import 'fixture/modules/module_gama.dart' as fixture_gama; +import 'fixture/delegates.dart' as fixture_group; +import 'fixture/delegates/module_alpha.dart' as fixture_alpha; +import 'fixture/delegates/module_beta.dart' as fixture_beta; +import 'fixture/delegates/module_gama.dart' as fixture_gama; // modules hierarchy: // diff --git a/packages/auto_mappr/test/integration/enum_mapping_test.dart b/packages/auto_mappr/test/integration/enum_mapping_test.dart index 1d50cd7a..67ba32fd 100644 --- a/packages/auto_mappr/test/integration/enum_mapping_test.dart +++ b/packages/auto_mappr/test/integration/enum_mapping_test.dart @@ -1,4 +1,5 @@ import 'package:auto_mappr/auto_mappr.dart'; +import 'package:auto_mappr/src/helpers/run_zoned_auto_mappr.dart'; import 'package:generator_test/generator_test.dart'; import 'package:source_gen/source_gen.dart'; import 'package:test/test.dart'; @@ -45,43 +46,47 @@ void main() { group('Error handling', () { test("Can't map source enum to target when target is not enum", () { - final generator = SuccessGenerator.fromBuilder( - 'enum_mapping_not_enum', - autoMapprBuilder, - inputDir: 'test/integration/error_fixture', - compareWithFixture: false, - ); - - expect( - generator.test, - throwsA( - isA().having( - (x) => x.message, - 'Match message', - 'Failed to map Source → Target because target Target is not an enum.', + runZonedAutoMappr(() { + final generator = SuccessGenerator.fromBuilder( + 'enum_mapping_not_enum', + autoMapprBuilder, + inputDir: 'test/integration/error_fixture', + compareWithFixture: false, + ); + + expect( + generator.test, + throwsA( + isA().having( + (x) => x.message, + 'Match message', + 'Failed to map Source → Target because target Target is not an enum.', + ), ), - ), - ); + ); + }); }); test("Can't map source enum to target when target is not superset of source", () { - final generator = SuccessGenerator.fromBuilder( - 'enum_mapping_subset', - autoMapprBuilder, - inputDir: 'test/integration/error_fixture', - compareWithFixture: false, - ); - - expect( - generator.test, - throwsA( - isA().having( - (x) => x.message, - 'Match message', - "Can't map enum Source into Target. Target enum is not superset of source enum.", + runZonedAutoMappr(() { + final generator = SuccessGenerator.fromBuilder( + 'enum_mapping_subset', + autoMapprBuilder, + inputDir: 'test/integration/error_fixture', + compareWithFixture: false, + ); + + expect( + generator.test, + throwsA( + isA().having( + (x) => x.message, + 'Match message', + "Can't map enum Source into Target. Target enum is not superset of source enum.", + ), ), - ), - ); + ); + }); }); }); } diff --git a/packages/auto_mappr/test/integration/error_fixture/enum_mapping_not_enum.dart b/packages/auto_mappr/test/integration/error_fixture/enum_mapping_not_enum.dart index d797631e..7bbc575d 100644 --- a/packages/auto_mappr/test/integration/error_fixture/enum_mapping_not_enum.dart +++ b/packages/auto_mappr/test/integration/error_fixture/enum_mapping_not_enum.dart @@ -1,6 +1,6 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; -part 'enum_mapping_not_enum.g.dart'; +import 'enum_mapping_not_enum.auto_mappr.dart'; enum Source { a, b } diff --git a/packages/auto_mappr/test/integration/error_fixture/enum_mapping_subset.dart b/packages/auto_mappr/test/integration/error_fixture/enum_mapping_subset.dart index 0491f219..ff222e7e 100644 --- a/packages/auto_mappr/test/integration/error_fixture/enum_mapping_subset.dart +++ b/packages/auto_mappr/test/integration/error_fixture/enum_mapping_subset.dart @@ -1,6 +1,6 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; -part 'enum_mapping_subset.g.dart'; +import 'enum_mapping_subset.auto_mappr.dart'; enum Source { a, b } diff --git a/packages/auto_mappr/test/integration/fixture/complex_types.dart b/packages/auto_mappr/test/integration/fixture/complex_types.dart index 5a885dc9..45802458 100644 --- a/packages/auto_mappr/test/integration/fixture/complex_types.dart +++ b/packages/auto_mappr/test/integration/fixture/complex_types.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'complex_types.g.dart'; +import 'complex_types.auto_mappr.dart'; @AutoMappr( [ diff --git a/packages/auto_mappr/test/integration/fixture/constructor_parameters.dart b/packages/auto_mappr/test/integration/fixture/constructor_parameters.dart index 7098f990..d21eec25 100644 --- a/packages/auto_mappr/test/integration/fixture/constructor_parameters.dart +++ b/packages/auto_mappr/test/integration/fixture/constructor_parameters.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'constructor_parameters.g.dart'; +import 'constructor_parameters.auto_mappr.dart'; @AutoMappr([ MapType(), diff --git a/packages/auto_mappr/test/integration/fixture/convert_iterable.dart b/packages/auto_mappr/test/integration/fixture/convert_iterable.dart index ea5acefa..e415e811 100644 --- a/packages/auto_mappr/test/integration/fixture/convert_iterable.dart +++ b/packages/auto_mappr/test/integration/fixture/convert_iterable.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'convert_iterable.g.dart'; +import 'convert_iterable.auto_mappr.dart'; @AutoMappr([ MapType(), diff --git a/packages/auto_mappr/test/integration/fixture/custom_mapping.dart b/packages/auto_mappr/test/integration/fixture/custom_mapping.dart index 21164069..5c5470e4 100644 --- a/packages/auto_mappr/test/integration/fixture/custom_mapping.dart +++ b/packages/auto_mappr/test/integration/fixture/custom_mapping.dart @@ -3,7 +3,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'custom_mapping.g.dart'; +import 'custom_mapping.auto_mappr.dart'; @AutoMappr([ // custom type diff --git a/packages/auto_mappr/test/integration/fixture/default_field.dart b/packages/auto_mappr/test/integration/fixture/default_field.dart index 9175bfb9..36871b23 100644 --- a/packages/auto_mappr/test/integration/fixture/default_field.dart +++ b/packages/auto_mappr/test/integration/fixture/default_field.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'default_field.g.dart'; +import 'default_field.auto_mappr.dart'; @AutoMappr([ MapType(), diff --git a/packages/auto_mappr/test/integration/fixture/default_target.dart b/packages/auto_mappr/test/integration/fixture/default_target.dart index 3ebdad5e..255570e2 100644 --- a/packages/auto_mappr/test/integration/fixture/default_target.dart +++ b/packages/auto_mappr/test/integration/fixture/default_target.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'default_target.g.dart'; +import 'default_target.auto_mappr.dart'; @AutoMappr([ MapType(), diff --git a/packages/auto_mappr/test/integration/fixture/modules.dart b/packages/auto_mappr/test/integration/fixture/delegates.dart similarity index 72% rename from packages/auto_mappr/test/integration/fixture/modules.dart rename to packages/auto_mappr/test/integration/fixture/delegates.dart index da0df0ba..d8baa72c 100644 --- a/packages/auto_mappr/test/integration/fixture/modules.dart +++ b/packages/auto_mappr/test/integration/fixture/delegates.dart @@ -1,11 +1,10 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -import 'modules/module_alpha.dart'; +import 'delegates.auto_mappr.dart'; +import 'delegates/module_alpha.dart'; -part 'modules.g.dart'; - -@AutoMappr([MapType()], modules: [MapprAlpha()]) +@AutoMappr([MapType()], delegates: [MapprAlpha()]) class MapprGroup extends $MapprGroup { const MapprGroup(); } diff --git a/packages/auto_mappr/test/integration/fixture/delegates/module_alpha.dart b/packages/auto_mappr/test/integration/fixture/delegates/module_alpha.dart new file mode 100644 index 00000000..1dd873a5 --- /dev/null +++ b/packages/auto_mappr/test/integration/fixture/delegates/module_alpha.dart @@ -0,0 +1,25 @@ +import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; +import 'package:equatable/equatable.dart'; + +import 'module_alpha.auto_mappr.dart'; +import 'module_beta.dart'; + +@AutoMappr([MapType()], delegates: [MapprBeta()]) +class MapprAlpha extends $MapprAlpha { + const MapprAlpha(); +} + +class AlphaDto { + final int value; + + const AlphaDto(this.value); +} + +class Alpha with EquatableMixin { + final int value; + + @override + List get props => [value]; + + const Alpha(this.value); +} diff --git a/packages/auto_mappr/test/integration/fixture/modules/module_beta.dart b/packages/auto_mappr/test/integration/fixture/delegates/module_beta.dart similarity index 79% rename from packages/auto_mappr/test/integration/fixture/modules/module_beta.dart rename to packages/auto_mappr/test/integration/fixture/delegates/module_beta.dart index 95f5d516..1cd48ac3 100644 --- a/packages/auto_mappr/test/integration/fixture/modules/module_beta.dart +++ b/packages/auto_mappr/test/integration/fixture/delegates/module_beta.dart @@ -1,11 +1,10 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; +import 'module_beta.auto_mappr.dart'; import 'module_gama.dart'; -part 'module_beta.g.dart'; - -@AutoMappr([MapType()], modules: [MapprGama()]) +@AutoMappr([MapType()], delegates: [MapprGama()]) class MapprBeta extends $MapprBeta { const MapprBeta(); } diff --git a/packages/auto_mappr/test/integration/fixture/modules/module_gama.dart b/packages/auto_mappr/test/integration/fixture/delegates/module_gama.dart similarity index 91% rename from packages/auto_mappr/test/integration/fixture/modules/module_gama.dart rename to packages/auto_mappr/test/integration/fixture/delegates/module_gama.dart index fee4a6d6..e00e7f7a 100644 --- a/packages/auto_mappr/test/integration/fixture/modules/module_gama.dart +++ b/packages/auto_mappr/test/integration/fixture/delegates/module_gama.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'module_gama.g.dart'; +import 'module_gama.auto_mappr.dart'; @AutoMappr([MapType()]) class MapprGama extends $MapprGama { diff --git a/packages/auto_mappr/test/integration/fixture/enum_mapping.dart b/packages/auto_mappr/test/integration/fixture/enum_mapping.dart index 74509e4d..2e9fafad 100644 --- a/packages/auto_mappr/test/integration/fixture/enum_mapping.dart +++ b/packages/auto_mappr/test/integration/fixture/enum_mapping.dart @@ -1,6 +1,6 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; -part 'enum_mapping.g.dart'; +import 'enum_mapping.auto_mappr.dart'; enum Person { employee, parent, student } @@ -53,12 +53,13 @@ enum EnhancedTarget { String get row => '$id+$name'; } -LocalPerson _localRemoteUnknownDefault() => LocalPerson.unknown; +// ignore: prefer-static-class, for testing +LocalPerson localRemoteUnknownDefault() => LocalPerson.unknown; @AutoMappr([ MapType(), MapType( - whenSourceIsNull: _localRemoteUnknownDefault, + whenSourceIsNull: localRemoteUnknownDefault, ), MapType(), MapType( diff --git a/packages/auto_mappr/test/integration/fixture/equatable.dart b/packages/auto_mappr/test/integration/fixture/equatable.dart index 662754b5..723f1c5f 100644 --- a/packages/auto_mappr/test/integration/fixture/equatable.dart +++ b/packages/auto_mappr/test/integration/fixture/equatable.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'equatable.g.dart'; +import 'equatable.auto_mappr.dart'; @AutoMappr([MapType()]) class Mappr extends $Mappr { diff --git a/packages/auto_mappr/test/integration/fixture/forced_null_source_field.dart b/packages/auto_mappr/test/integration/fixture/forced_null_source_field.dart index 937d51bf..068b8f91 100644 --- a/packages/auto_mappr/test/integration/fixture/forced_null_source_field.dart +++ b/packages/auto_mappr/test/integration/fixture/forced_null_source_field.dart @@ -1,6 +1,6 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; -part 'forced_null_source_field.g.dart'; +import 'forced_null_source_field.auto_mappr.dart'; @AutoMappr([ MapType( diff --git a/packages/auto_mappr/test/integration/fixture/generics.dart b/packages/auto_mappr/test/integration/fixture/generics.dart index 542e67b4..96bfa463 100644 --- a/packages/auto_mappr/test/integration/fixture/generics.dart +++ b/packages/auto_mappr/test/integration/fixture/generics.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'generics.g.dart'; +import 'generics.auto_mappr.dart'; @AutoMappr([ // simple diff --git a/packages/auto_mappr/test/integration/fixture/import_alias.dart b/packages/auto_mappr/test/integration/fixture/import_alias.dart index 84308046..87f84fee 100644 --- a/packages/auto_mappr/test/integration/fixture/import_alias.dart +++ b/packages/auto_mappr/test/integration/fixture/import_alias.dart @@ -1,12 +1,11 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; +import 'import_alias.auto_mappr.dart'; import 'import_alias/import_alias_1.dart' as a1; import 'import_alias/import_alias_2.dart' as a2; import 'import_alias/import_alias_module.dart' as module; -part 'import_alias.g.dart'; - @AutoMappr( [ MapType(), @@ -27,7 +26,7 @@ part 'import_alias.g.dart'; MapType, ListHolder>(), MapType, MapHolder>(), ], - modules: [module.ImportAliasModule()], + delegates: [module.ImportAliasModule()], ) class Mappr extends $Mappr { const Mappr(); diff --git a/packages/auto_mappr/test/integration/fixture/import_alias/import_alias_module.dart b/packages/auto_mappr/test/integration/fixture/import_alias/import_alias_module.dart index db1a6de6..8aaa412f 100644 --- a/packages/auto_mappr/test/integration/fixture/import_alias/import_alias_module.dart +++ b/packages/auto_mappr/test/integration/fixture/import_alias/import_alias_module.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'import_alias_module.g.dart'; +import 'import_alias_module.auto_mappr.dart'; @AutoMappr([MapType()]) class ImportAliasModule extends $ImportAliasModule { diff --git a/packages/auto_mappr/test/integration/fixture/includes.dart b/packages/auto_mappr/test/integration/fixture/includes.dart new file mode 100644 index 00000000..e3e64025 --- /dev/null +++ b/packages/auto_mappr/test/integration/fixture/includes.dart @@ -0,0 +1,31 @@ +import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; +import 'package:equatable/equatable.dart'; + +import 'includes.auto_mappr.dart'; +import 'includes/module_alpha.dart' as alpha_feature; +import 'includes/module_beta.dart'; +import 'includes/module_gama.dart'; + +@AutoMappr([MapType()], includes: [alpha_feature.MapprAlpha()]) +class MapprGroup extends $MapprGroup { + const MapprGroup(); +} + +class GroupDto { + final alpha_feature.AlphaDto alpha; + final BetaDto beta; + final GamaDto gama; + + const GroupDto(this.alpha, this.beta, this.gama); +} + +class Group with EquatableMixin { + final alpha_feature.Alpha alpha; + final Beta beta; + final Gama gama; + + @override + List get props => [alpha, beta, gama]; + + const Group(this.alpha, this.beta, this.gama); +} diff --git a/packages/auto_mappr/test/integration/fixture/modules/module_alpha.dart b/packages/auto_mappr/test/integration/fixture/includes/module_alpha.dart similarity index 79% rename from packages/auto_mappr/test/integration/fixture/modules/module_alpha.dart rename to packages/auto_mappr/test/integration/fixture/includes/module_alpha.dart index d4ab7cb9..d4390764 100644 --- a/packages/auto_mappr/test/integration/fixture/modules/module_alpha.dart +++ b/packages/auto_mappr/test/integration/fixture/includes/module_alpha.dart @@ -1,11 +1,10 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; +import 'module_alpha.auto_mappr.dart'; import 'module_beta.dart'; -part 'module_alpha.g.dart'; - -@AutoMappr([MapType()], modules: [MapprBeta()]) +@AutoMappr([MapType()], includes: [MapprBeta()]) class MapprAlpha extends $MapprAlpha { const MapprAlpha(); } diff --git a/packages/auto_mappr/test/integration/fixture/includes/module_beta.dart b/packages/auto_mappr/test/integration/fixture/includes/module_beta.dart new file mode 100644 index 00000000..1f00211f --- /dev/null +++ b/packages/auto_mappr/test/integration/fixture/includes/module_beta.dart @@ -0,0 +1,25 @@ +import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; +import 'package:equatable/equatable.dart'; + +import 'module_beta.auto_mappr.dart'; +import 'module_gama.dart'; + +@AutoMappr([MapType()], includes: [MapprGama()]) +class MapprBeta extends $MapprBeta { + const MapprBeta(); +} + +class BetaDto { + final int value; + + const BetaDto(this.value); +} + +class Beta with EquatableMixin { + final int value; + + @override + List get props => [value]; + + const Beta(this.value); +} diff --git a/packages/auto_mappr/test/integration/fixture/includes/module_gama.dart b/packages/auto_mappr/test/integration/fixture/includes/module_gama.dart new file mode 100644 index 00000000..e00e7f7a --- /dev/null +++ b/packages/auto_mappr/test/integration/fixture/includes/module_gama.dart @@ -0,0 +1,24 @@ +import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; +import 'package:equatable/equatable.dart'; + +import 'module_gama.auto_mappr.dart'; + +@AutoMappr([MapType()]) +class MapprGama extends $MapprGama { + const MapprGama(); +} + +class GamaDto { + final int value; + + const GamaDto(this.value); +} + +class Gama with EquatableMixin { + final int value; + + @override + List get props => [value]; + + const Gama(this.value); +} diff --git a/packages/auto_mappr/test/integration/fixture/iterable.dart b/packages/auto_mappr/test/integration/fixture/iterable.dart index aa3844c0..b2f9c82b 100644 --- a/packages/auto_mappr/test/integration/fixture/iterable.dart +++ b/packages/auto_mappr/test/integration/fixture/iterable.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'iterable.g.dart'; +import 'iterable.auto_mappr.dart'; @AutoMappr([ MapType(), diff --git a/packages/auto_mappr/test/integration/fixture/list.dart b/packages/auto_mappr/test/integration/fixture/list.dart index 4a99430d..1c592926 100644 --- a/packages/auto_mappr/test/integration/fixture/list.dart +++ b/packages/auto_mappr/test/integration/fixture/list.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'list.g.dart'; +import 'list.auto_mappr.dart'; @AutoMappr([ MapType(), diff --git a/packages/auto_mappr/test/integration/fixture/map.dart b/packages/auto_mappr/test/integration/fixture/map.dart index 541ba39b..736855c2 100644 --- a/packages/auto_mappr/test/integration/fixture/map.dart +++ b/packages/auto_mappr/test/integration/fixture/map.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'map.g.dart'; +import 'map.auto_mappr.dart'; @AutoMappr([ MapType(), diff --git a/packages/auto_mappr/test/integration/fixture/mapping_from_source.dart b/packages/auto_mappr/test/integration/fixture/mapping_from_source.dart index 921cfe83..9c6edfbf 100644 --- a/packages/auto_mappr/test/integration/fixture/mapping_from_source.dart +++ b/packages/auto_mappr/test/integration/fixture/mapping_from_source.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'mapping_from_source.g.dart'; +import 'mapping_from_source.auto_mappr.dart'; @AutoMappr([ MapType(), diff --git a/packages/auto_mappr/test/integration/fixture/mapping_to_target.dart b/packages/auto_mappr/test/integration/fixture/mapping_to_target.dart index 91d56590..79e92a29 100644 --- a/packages/auto_mappr/test/integration/fixture/mapping_to_target.dart +++ b/packages/auto_mappr/test/integration/fixture/mapping_to_target.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'mapping_to_target.g.dart'; +import 'mapping_to_target.auto_mappr.dart'; @AutoMappr([MapType()]) class Mappr extends $Mappr { diff --git a/packages/auto_mappr/test/integration/fixture/multiple_annotations.dart b/packages/auto_mappr/test/integration/fixture/multiple_annotations.dart index 0c397738..fa11e821 100644 --- a/packages/auto_mappr/test/integration/fixture/multiple_annotations.dart +++ b/packages/auto_mappr/test/integration/fixture/multiple_annotations.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'multiple_annotations.g.dart'; +import 'multiple_annotations.auto_mappr.dart'; class AnnotationA { const AnnotationA(); diff --git a/packages/auto_mappr/test/integration/fixture/primitive_types.dart b/packages/auto_mappr/test/integration/fixture/primitive_types.dart index 73b320f1..1a92c855 100644 --- a/packages/auto_mappr/test/integration/fixture/primitive_types.dart +++ b/packages/auto_mappr/test/integration/fixture/primitive_types.dart @@ -2,7 +2,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; -part 'primitive_types.g.dart'; +import 'primitive_types.auto_mappr.dart'; @AutoMappr([ MapType(), diff --git a/packages/auto_mappr/test/integration/fixture/record.dart b/packages/auto_mappr/test/integration/fixture/record.dart index 74454579..faca3e81 100644 --- a/packages/auto_mappr/test/integration/fixture/record.dart +++ b/packages/auto_mappr/test/integration/fixture/record.dart @@ -3,7 +3,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'record.g.dart'; +import 'record.auto_mappr.dart'; @AutoMappr([ // simple @@ -41,7 +41,6 @@ class PositionalDto extends Equatable { } class PositionalNullable extends Equatable { - // ignore: prefer-trailing-comma, false positive final (int?, bool?, String?, int?, bool?) value; @override @@ -69,7 +68,6 @@ class Named extends Equatable { } class NamedNullable extends Equatable { - // ignore: prefer-trailing-comma, dcm has to fix this final ({int alpha, bool beta, String gama, int? delta, bool? epsilon}) value; @override diff --git a/packages/auto_mappr/test/integration/fixture/regression/uint8_issue_77.dart b/packages/auto_mappr/test/integration/fixture/regression/uint8_issue_77.dart index 3de6ca91..cebc91ad 100644 --- a/packages/auto_mappr/test/integration/fixture/regression/uint8_issue_77.dart +++ b/packages/auto_mappr/test/integration/fixture/regression/uint8_issue_77.dart @@ -3,7 +3,7 @@ import 'dart:typed_data'; import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'uint8_issue_77.g.dart'; +import 'uint8_issue_77.auto_mappr.dart'; class Source { final Uint8List int8List; diff --git a/packages/auto_mappr/test/integration/fixture/rename.dart b/packages/auto_mappr/test/integration/fixture/rename.dart index 90cfedcc..32bfa30d 100644 --- a/packages/auto_mappr/test/integration/fixture/rename.dart +++ b/packages/auto_mappr/test/integration/fixture/rename.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'rename.g.dart'; +import 'rename.auto_mappr.dart'; @AutoMappr([ // nested diff --git a/packages/auto_mappr/test/integration/fixture/reverse.dart b/packages/auto_mappr/test/integration/fixture/reverse.dart index c79569b0..58acf2d5 100644 --- a/packages/auto_mappr/test/integration/fixture/reverse.dart +++ b/packages/auto_mappr/test/integration/fixture/reverse.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'reverse.g.dart'; +import 'reverse.auto_mappr.dart'; @AutoMappr([ MapType(reverse: true), diff --git a/packages/auto_mappr/test/integration/fixture/selecting_constructor.dart b/packages/auto_mappr/test/integration/fixture/selecting_constructor.dart index 2c2bb7fa..f3fbcff5 100644 --- a/packages/auto_mappr/test/integration/fixture/selecting_constructor.dart +++ b/packages/auto_mappr/test/integration/fixture/selecting_constructor.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'selecting_constructor.g.dart'; +import 'selecting_constructor.auto_mappr.dart'; @AutoMappr([ // empty diff --git a/packages/auto_mappr/test/integration/fixture/set.dart b/packages/auto_mappr/test/integration/fixture/set.dart index 1fb5e99b..2f40bee8 100644 --- a/packages/auto_mappr/test/integration/fixture/set.dart +++ b/packages/auto_mappr/test/integration/fixture/set.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'set.g.dart'; +import 'set.auto_mappr.dart'; @AutoMappr([ MapType(), diff --git a/packages/auto_mappr/test/integration/fixture/special_characters.dart b/packages/auto_mappr/test/integration/fixture/special_characters.dart index 24bb41d1..8a7b6663 100644 --- a/packages/auto_mappr/test/integration/fixture/special_characters.dart +++ b/packages/auto_mappr/test/integration/fixture/special_characters.dart @@ -3,7 +3,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'special_characters.g.dart'; +import 'special_characters.auto_mappr.dart'; @AutoMappr([ // in class diff --git a/packages/auto_mappr/test/integration/fixture/super_class.dart b/packages/auto_mappr/test/integration/fixture/super_class.dart index 6f0a1071..403c369c 100644 --- a/packages/auto_mappr/test/integration/fixture/super_class.dart +++ b/packages/auto_mappr/test/integration/fixture/super_class.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'super_class.g.dart'; +import 'super_class.auto_mappr.dart'; @AutoMappr([ MapType(), diff --git a/packages/auto_mappr/test/integration/fixture/try_convert.dart b/packages/auto_mappr/test/integration/fixture/try_convert.dart index 8339278b..54cf9e81 100644 --- a/packages/auto_mappr/test/integration/fixture/try_convert.dart +++ b/packages/auto_mappr/test/integration/fixture/try_convert.dart @@ -1,7 +1,7 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'try_convert.g.dart'; +import 'try_convert.auto_mappr.dart'; @AutoMappr([ MapType(), diff --git a/packages/auto_mappr/test/integration/fixture/when_source_is_null.dart b/packages/auto_mappr/test/integration/fixture/when_source_is_null.dart index e13d284b..2555e2db 100644 --- a/packages/auto_mappr/test/integration/fixture/when_source_is_null.dart +++ b/packages/auto_mappr/test/integration/fixture/when_source_is_null.dart @@ -1,6 +1,6 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; -part 'when_source_is_null.g.dart'; +import 'when_source_is_null.auto_mappr.dart'; class SourceValue { final String? name; @@ -25,18 +25,19 @@ class Target { @AutoMappr([ MapType(fields: [Field('name', whenNull: 'static')]), MapType( - fields: [Field('name', whenNull: Mappr._whenSourceIsNull)], + fields: [Field('name', whenNull: Mappr.whenSourceIsNull)], ), MapType( - fields: [Field('name', whenNull: _whenSourceIsNullTopLevel)], + fields: [Field('name', whenNull: whenSourceIsNullTopLevel)], ), ]) class Mappr extends $Mappr { - static String _whenSourceIsNull() { + static String whenSourceIsNull() { return 'whenSourceIsNull'; } } -String _whenSourceIsNullTopLevel() { +// ignore: prefer-static-class, for testing +String whenSourceIsNullTopLevel() { return 'whenSourceIsNullTopLevel'; } diff --git a/packages/auto_mappr/test/integration/includes_test.dart b/packages/auto_mappr/test/integration/includes_test.dart new file mode 100644 index 00000000..c4d563f0 --- /dev/null +++ b/packages/auto_mappr/test/integration/includes_test.dart @@ -0,0 +1,660 @@ +import 'package:test/test.dart'; + +import 'fixture/includes.dart' as fixture_group; +import 'fixture/includes/module_alpha.dart' as fixture_alpha; +import 'fixture/includes/module_beta.dart' as fixture_beta; +import 'fixture/includes/module_gama.dart' as fixture_gama; + +// includes hierarchy: +// +// - Group (this one) +// - Alpha +// - Beta +// - Gama +void main() { + late final fixture_group.MapprGroup mappr; + + setUpAll(() { + mappr = const fixture_group.MapprGroup(); + }); + + group('convert', () { + test('group', () { + const dto = fixture_group.GroupDto(fixture_alpha.AlphaDto(1), fixture_beta.BetaDto(2), fixture_gama.GamaDto(3)); + final converted = mappr.convert(dto); + + expect( + converted, + equals(const fixture_group.Group(fixture_alpha.Alpha(1), fixture_beta.Beta(2), fixture_gama.Gama(3))), + ); + }); + + test('alpha', () { + const dto = fixture_alpha.AlphaDto(4); + final converted = mappr.convert(dto); + + expect(converted, equals(const fixture_alpha.Alpha(4))); + }); + + test('beta', () { + const dto = fixture_beta.BetaDto(5); + final converted = mappr.convert(dto); + + expect(converted, equals(const fixture_beta.Beta(5))); + }); + + test('gama', () { + const dto = fixture_gama.GamaDto(6); + final converted = mappr.convert(dto); + + expect(converted, equals(const fixture_gama.Gama(6))); + }); + }); + + group('tryConvert', () { + test('group', () { + const dto = fixture_group.GroupDto(fixture_alpha.AlphaDto(1), fixture_beta.BetaDto(2), fixture_gama.GamaDto(3)); + final converted = mappr.tryConvert(dto); + + expect( + converted, + equals(const fixture_group.Group(fixture_alpha.Alpha(1), fixture_beta.Beta(2), fixture_gama.Gama(3))), + ); + }); + + test('group w/ null', () { + const fixture_group.GroupDto? dto = null; + final converted = mappr.tryConvert(dto); + + expect(converted, isNull); + }); + + test('alpha', () { + const dto = fixture_alpha.AlphaDto(2); + final converted = mappr.tryConvert(dto); + + expect(converted, equals(const fixture_alpha.Alpha(2))); + }); + + test('alpha w/ null', () { + const fixture_alpha.AlphaDto? dto = null; + final converted = mappr.tryConvert(dto); + + expect(converted, isNull); + }); + + test('beta', () { + const dto = fixture_beta.BetaDto(3); + final converted = mappr.tryConvert(dto); + + expect(converted, equals(const fixture_beta.Beta(3))); + }); + + test('beta w/ null', () { + const fixture_beta.BetaDto? dto = null; + final converted = mappr.tryConvert(dto); + + expect(converted, isNull); + }); + + test('gama', () { + const dto = fixture_gama.GamaDto(4); + final converted = mappr.tryConvert(dto); + + expect(converted, equals(const fixture_gama.Gama(4))); + }); + + test('gama w/ null', () { + const fixture_gama.GamaDto? dto = null; + final converted = mappr.tryConvert(dto); + + expect(converted, isNull); + }); + }); + + group('convertIterable', () { + test('group', () { + final dto = [ + const fixture_group.GroupDto(fixture_alpha.AlphaDto(1), fixture_beta.BetaDto(2), fixture_gama.GamaDto(3)), + const fixture_group.GroupDto(fixture_alpha.AlphaDto(4), fixture_beta.BetaDto(5), fixture_gama.GamaDto(6)), + const fixture_group.GroupDto(fixture_alpha.AlphaDto(7), fixture_beta.BetaDto(8), fixture_gama.GamaDto(9)), + ].map((e) => e); + final converted = mappr.convertIterable(dto); + + expect( + converted, + equals(const [ + fixture_group.Group(fixture_alpha.Alpha(1), fixture_beta.Beta(2), fixture_gama.Gama(3)), + fixture_group.Group(fixture_alpha.Alpha(4), fixture_beta.Beta(5), fixture_gama.Gama(6)), + fixture_group.Group(fixture_alpha.Alpha(7), fixture_beta.Beta(8), fixture_gama.Gama(9)), + ]), + ); + }); + + test('alpha', () { + final dto = [ + const fixture_alpha.AlphaDto(4), + const fixture_alpha.AlphaDto(5), + ].map((e) => e); + final converted = mappr.convertIterable(dto); + + expect( + converted, + equals(const [fixture_alpha.Alpha(4), fixture_alpha.Alpha(5)]), + ); + }); + + test('beta', () { + final dto = [ + const fixture_beta.BetaDto(6), + const fixture_beta.BetaDto(7), + const fixture_beta.BetaDto(8), + ].map((e) => e); + final converted = mappr.convertIterable(dto); + + expect( + converted, + equals(const [ + fixture_beta.Beta(6), + fixture_beta.Beta(7), + fixture_beta.Beta(8), + ]), + ); + }); + + test('gama', () { + final dto = [ + const fixture_gama.GamaDto(9), + const fixture_gama.GamaDto(10), + ].map((e) => e); + final converted = mappr.convertIterable(dto); + + expect(converted, equals(const [fixture_gama.Gama(9), fixture_gama.Gama(10)])); + }); + }); + + group('tryConvertIterable', () { + test('group', () { + final dto = const [ + fixture_group.GroupDto(fixture_alpha.AlphaDto(11), fixture_beta.BetaDto(12), fixture_gama.GamaDto(13)), + fixture_group.GroupDto(fixture_alpha.AlphaDto(14), fixture_beta.BetaDto(15), fixture_gama.GamaDto(16)), + fixture_group.GroupDto(fixture_alpha.AlphaDto(17), fixture_beta.BetaDto(18), fixture_gama.GamaDto(19)), + ].map((e) => e); + final converted = mappr.tryConvertIterable(dto); + + expect( + converted, + equals(const [ + fixture_group.Group(fixture_alpha.Alpha(11), fixture_beta.Beta(12), fixture_gama.Gama(13)), + fixture_group.Group(fixture_alpha.Alpha(14), fixture_beta.Beta(15), fixture_gama.Gama(16)), + fixture_group.Group(fixture_alpha.Alpha(17), fixture_beta.Beta(18), fixture_gama.Gama(19)), + ]), + ); + }); + + test('group w/ null', () { + final dto = [ + const fixture_group.GroupDto(fixture_alpha.AlphaDto(101), fixture_beta.BetaDto(102), fixture_gama.GamaDto(103)), + null, + const fixture_group.GroupDto(fixture_alpha.AlphaDto(201), fixture_beta.BetaDto(202), fixture_gama.GamaDto(203)), + ].map((e) => e); + final converted = mappr.tryConvertIterable(dto); + + expect( + converted, + equals(const [ + fixture_group.Group(fixture_alpha.Alpha(101), fixture_beta.Beta(102), fixture_gama.Gama(103)), + null, + fixture_group.Group(fixture_alpha.Alpha(201), fixture_beta.Beta(202), fixture_gama.Gama(203)), + ]), + ); + }); + + test('alpha', () { + final dto = [ + const fixture_alpha.AlphaDto(4), + const fixture_alpha.AlphaDto(5), + ].map((e) => e); + final converted = mappr.tryConvertIterable(dto); + + expect( + converted, + equals(const [fixture_alpha.Alpha(4), fixture_alpha.Alpha(5)]), + ); + }); + + test('alpha w/ null', () { + final dto = [ + const fixture_alpha.AlphaDto(4), + const fixture_alpha.AlphaDto(5), + null, + ].map((e) => e); + final converted = mappr.tryConvertIterable(dto); + + expect( + converted, + equals(const [fixture_alpha.Alpha(4), fixture_alpha.Alpha(5), null]), + ); + }); + + test('beta', () { + final dto = [ + const fixture_beta.BetaDto(6), + const fixture_beta.BetaDto(7), + const fixture_beta.BetaDto(8), + ].map((e) => e); + final converted = mappr.tryConvertIterable(dto); + + expect( + converted, + equals(const [ + fixture_beta.Beta(6), + fixture_beta.Beta(7), + fixture_beta.Beta(8), + ]), + ); + }); + + test('beta w/ null', () { + final dto = [ + null, + const fixture_beta.BetaDto(7), + const fixture_beta.BetaDto(8), + ].map((e) => e); + final converted = mappr.tryConvertIterable(dto); + + expect( + converted, + equals(const [null, fixture_beta.Beta(7), fixture_beta.Beta(8)]), + ); + }); + + test('gama', () { + final dto = [ + const fixture_gama.GamaDto(9), + const fixture_gama.GamaDto(10), + ].map((e) => e); + final converted = mappr.tryConvertIterable(dto); + + expect(converted, equals(const [fixture_gama.Gama(9), fixture_gama.Gama(10)])); + }); + + test('gama w/ null', () { + final dto = [ + null, + const fixture_gama.GamaDto(9), + const fixture_gama.GamaDto(10), + ].map((e) => e); + final converted = mappr.tryConvertIterable(dto); + + expect( + converted, + equals(const [null, fixture_gama.Gama(9), fixture_gama.Gama(10)]), + ); + }); + }); + + group('convertList', () { + test('group', () { + const dto = [ + fixture_group.GroupDto(fixture_alpha.AlphaDto(21), fixture_beta.BetaDto(22), fixture_gama.GamaDto(23)), + fixture_group.GroupDto(fixture_alpha.AlphaDto(24), fixture_beta.BetaDto(25), fixture_gama.GamaDto(26)), + fixture_group.GroupDto(fixture_alpha.AlphaDto(27), fixture_beta.BetaDto(28), fixture_gama.GamaDto(29)), + ]; + final converted = mappr.convertList(dto); + + expect( + converted, + equals(const [ + fixture_group.Group(fixture_alpha.Alpha(21), fixture_beta.Beta(22), fixture_gama.Gama(23)), + fixture_group.Group(fixture_alpha.Alpha(24), fixture_beta.Beta(25), fixture_gama.Gama(26)), + fixture_group.Group(fixture_alpha.Alpha(27), fixture_beta.Beta(28), fixture_gama.Gama(29)), + ]), + ); + }); + + test('alpha', () { + const dto = [ + fixture_alpha.AlphaDto(4), + fixture_alpha.AlphaDto(5), + ]; + final converted = mappr.convertList(dto); + + expect( + converted, + equals(const [fixture_alpha.Alpha(4), fixture_alpha.Alpha(5)]), + ); + }); + + test('beta', () { + const dto = [ + fixture_beta.BetaDto(6), + fixture_beta.BetaDto(7), + fixture_beta.BetaDto(8), + ]; + final converted = mappr.convertList(dto); + + expect( + converted, + equals(const [ + fixture_beta.Beta(6), + fixture_beta.Beta(7), + fixture_beta.Beta(8), + ]), + ); + }); + + test('gama', () { + const dto = [ + fixture_gama.GamaDto(9), + fixture_gama.GamaDto(10), + ]; + final converted = mappr.convertList(dto); + + expect(converted, equals(const [fixture_gama.Gama(9), fixture_gama.Gama(10)])); + }); + }); + + group('tryConvertList', () { + test('group', () { + const dto = [ + fixture_group.GroupDto(fixture_alpha.AlphaDto(31), fixture_beta.BetaDto(32), fixture_gama.GamaDto(33)), + fixture_group.GroupDto(fixture_alpha.AlphaDto(34), fixture_beta.BetaDto(35), fixture_gama.GamaDto(36)), + fixture_group.GroupDto(fixture_alpha.AlphaDto(37), fixture_beta.BetaDto(38), fixture_gama.GamaDto(39)), + ]; + final converted = mappr.tryConvertList(dto); + + expect( + converted, + equals(const [ + fixture_group.Group(fixture_alpha.Alpha(31), fixture_beta.Beta(32), fixture_gama.Gama(33)), + fixture_group.Group(fixture_alpha.Alpha(34), fixture_beta.Beta(35), fixture_gama.Gama(36)), + fixture_group.Group(fixture_alpha.Alpha(37), fixture_beta.Beta(38), fixture_gama.Gama(39)), + ]), + ); + }); + + test('group w/ null', () { + const dto = [ + fixture_group.GroupDto(fixture_alpha.AlphaDto(221), fixture_beta.BetaDto(222), fixture_gama.GamaDto(223)), + null, + fixture_group.GroupDto(fixture_alpha.AlphaDto(231), fixture_beta.BetaDto(232), fixture_gama.GamaDto(233)), + ]; + final converted = mappr.tryConvertList(dto); + + expect( + converted, + equals(const [ + fixture_group.Group(fixture_alpha.Alpha(221), fixture_beta.Beta(222), fixture_gama.Gama(223)), + null, + fixture_group.Group(fixture_alpha.Alpha(231), fixture_beta.Beta(232), fixture_gama.Gama(233)), + ]), + ); + }); + + test('alpha', () { + const dto = [ + fixture_alpha.AlphaDto(4), + fixture_alpha.AlphaDto(5), + ]; + final converted = mappr.tryConvertList(dto); + + expect( + converted, + equals(const [fixture_alpha.Alpha(4), fixture_alpha.Alpha(5)]), + ); + }); + + test('alpha w/ null', () { + const dto = [ + fixture_alpha.AlphaDto(4), + fixture_alpha.AlphaDto(5), + null, + ]; + final converted = mappr.tryConvertList(dto); + + expect( + converted, + equals(const [fixture_alpha.Alpha(4), fixture_alpha.Alpha(5), null]), + ); + }); + + test('beta', () { + const dto = [ + fixture_beta.BetaDto(6), + fixture_beta.BetaDto(7), + fixture_beta.BetaDto(8), + ]; + final converted = mappr.tryConvertList(dto); + + expect( + converted, + equals(const [ + fixture_beta.Beta(6), + fixture_beta.Beta(7), + fixture_beta.Beta(8), + ]), + ); + }); + + test('beta w/ null', () { + const dto = [ + null, + fixture_beta.BetaDto(7), + fixture_beta.BetaDto(8), + ]; + final converted = mappr.tryConvertList(dto); + + expect( + converted, + equals(const [null, fixture_beta.Beta(7), fixture_beta.Beta(8)]), + ); + }); + + test('gama', () { + const dto = [ + fixture_gama.GamaDto(9), + fixture_gama.GamaDto(10), + ]; + final converted = mappr.tryConvertList(dto); + + expect(converted, equals(const [fixture_gama.Gama(9), fixture_gama.Gama(10)])); + }); + + test('gama w/ null', () { + const dto = [ + null, + fixture_gama.GamaDto(9), + fixture_gama.GamaDto(10), + ]; + final converted = mappr.tryConvertList(dto); + + expect( + converted, + equals(const [null, fixture_gama.Gama(9), fixture_gama.Gama(10)]), + ); + }); + }); + + group('convertSet', () { + test('group', () { + const dto = { + fixture_group.GroupDto(fixture_alpha.AlphaDto(41), fixture_beta.BetaDto(42), fixture_gama.GamaDto(43)), + fixture_group.GroupDto(fixture_alpha.AlphaDto(44), fixture_beta.BetaDto(45), fixture_gama.GamaDto(46)), + fixture_group.GroupDto(fixture_alpha.AlphaDto(47), fixture_beta.BetaDto(48), fixture_gama.GamaDto(49)), + }; + final converted = mappr.convertSet(dto); + + expect( + converted, + equals(const [ + fixture_group.Group(fixture_alpha.Alpha(41), fixture_beta.Beta(42), fixture_gama.Gama(43)), + fixture_group.Group(fixture_alpha.Alpha(44), fixture_beta.Beta(45), fixture_gama.Gama(46)), + fixture_group.Group(fixture_alpha.Alpha(47), fixture_beta.Beta(48), fixture_gama.Gama(49)), + ]), + ); + }); + + test('alpha', () { + const dto = { + fixture_alpha.AlphaDto(4), + fixture_alpha.AlphaDto(5), + }; + final converted = mappr.convertSet(dto); + + expect( + converted, + equals(const [fixture_alpha.Alpha(4), fixture_alpha.Alpha(5)]), + ); + }); + + test('beta', () { + const dto = { + fixture_beta.BetaDto(6), + fixture_beta.BetaDto(7), + fixture_beta.BetaDto(8), + }; + final converted = mappr.convertSet(dto); + + expect( + converted, + equals(const [ + fixture_beta.Beta(6), + fixture_beta.Beta(7), + fixture_beta.Beta(8), + ]), + ); + }); + + test('gama', () { + const dto = { + fixture_gama.GamaDto(9), + fixture_gama.GamaDto(10), + }; + final converted = mappr.convertSet(dto); + + expect(converted, equals(const [fixture_gama.Gama(9), fixture_gama.Gama(10)])); + }); + }); + + group('tryConvertSet', () { + test('group', () { + const dto = { + fixture_group.GroupDto(fixture_alpha.AlphaDto(51), fixture_beta.BetaDto(52), fixture_gama.GamaDto(53)), + fixture_group.GroupDto(fixture_alpha.AlphaDto(54), fixture_beta.BetaDto(55), fixture_gama.GamaDto(56)), + fixture_group.GroupDto(fixture_alpha.AlphaDto(57), fixture_beta.BetaDto(58), fixture_gama.GamaDto(59)), + }; + final converted = mappr.tryConvertSet(dto); + + expect( + converted, + equals(const [ + fixture_group.Group(fixture_alpha.Alpha(51), fixture_beta.Beta(52), fixture_gama.Gama(53)), + fixture_group.Group(fixture_alpha.Alpha(54), fixture_beta.Beta(55), fixture_gama.Gama(56)), + fixture_group.Group(fixture_alpha.Alpha(57), fixture_beta.Beta(58), fixture_gama.Gama(59)), + ]), + ); + }); + + test('group w/ null', () { + const dto = { + fixture_group.GroupDto(fixture_alpha.AlphaDto(421), fixture_beta.BetaDto(422), fixture_gama.GamaDto(423)), + null, + fixture_group.GroupDto(fixture_alpha.AlphaDto(431), fixture_beta.BetaDto(432), fixture_gama.GamaDto(433)), + }; + final converted = mappr.tryConvertSet(dto); + + expect( + converted, + equals(const [ + fixture_group.Group(fixture_alpha.Alpha(421), fixture_beta.Beta(422), fixture_gama.Gama(423)), + null, + fixture_group.Group(fixture_alpha.Alpha(431), fixture_beta.Beta(432), fixture_gama.Gama(433)), + ]), + ); + }); + + test('alpha', () { + const dto = { + fixture_alpha.AlphaDto(4), + fixture_alpha.AlphaDto(5), + }; + final converted = mappr.tryConvertSet(dto); + + expect( + converted, + equals(const [fixture_alpha.Alpha(4), fixture_alpha.Alpha(5)]), + ); + }); + + test('alpha w/ null', () { + const dto = { + fixture_alpha.AlphaDto(4), + fixture_alpha.AlphaDto(5), + null, + }; + final converted = mappr.tryConvertSet(dto); + + expect( + converted, + equals(const [fixture_alpha.Alpha(4), fixture_alpha.Alpha(5), null]), + ); + }); + + test('beta', () { + const dto = { + fixture_beta.BetaDto(6), + fixture_beta.BetaDto(7), + fixture_beta.BetaDto(8), + }; + final converted = mappr.tryConvertSet(dto); + + expect( + converted, + equals(const [ + fixture_beta.Beta(6), + fixture_beta.Beta(7), + fixture_beta.Beta(8), + ]), + ); + }); + + test('beta w/ null', () { + const dto = { + null, + fixture_beta.BetaDto(7), + fixture_beta.BetaDto(8), + }; + final converted = mappr.tryConvertSet(dto); + + expect( + converted, + equals(const [null, fixture_beta.Beta(7), fixture_beta.Beta(8)]), + ); + }); + + test('gama', () { + const dto = { + fixture_gama.GamaDto(9), + fixture_gama.GamaDto(10), + }; + final converted = mappr.tryConvertSet(dto); + + expect(converted, equals(const [fixture_gama.Gama(9), fixture_gama.Gama(10)])); + }); + + test('gama w/ null', () { + const dto = { + null, + fixture_gama.GamaDto(9), + fixture_gama.GamaDto(10), + }; + final converted = mappr.tryConvertSet(dto); + + expect( + converted, + equals(const [null, fixture_gama.Gama(9), fixture_gama.Gama(10)]), + ); + }); + }); +} diff --git a/packages/auto_mappr_annotation/CHANGELOG.md b/packages/auto_mappr_annotation/CHANGELOG.md index 4fe11239..d5074e29 100644 --- a/packages/auto_mappr_annotation/CHANGELOG.md +++ b/packages/auto_mappr_annotation/CHANGELOG.md @@ -1,6 +1,6 @@ [//]: # (## Unreleased) -## Unreleased +## 2.0.0-beta1 - Adhere to netglade_analysis 4.0.0 - Add `reverse` option to `MapType`. diff --git a/packages/auto_mappr_annotation/README.md b/packages/auto_mappr_annotation/README.md index 889d2292..0d023843 100644 --- a/packages/auto_mappr_annotation/README.md +++ b/packages/auto_mappr_annotation/README.md @@ -21,7 +21,7 @@ Developed with 💚 by [netglade][netglade_link] ```dart import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; -part 'main.g.dart'; +import 'main.auto_mappr.dart'; @AutoMappr([ MapType(), diff --git a/packages/auto_mappr_annotation/example/lib/main.dart b/packages/auto_mappr_annotation/example/lib/main.dart index d8d842d6..d6b539ce 100644 --- a/packages/auto_mappr_annotation/example/lib/main.dart +++ b/packages/auto_mappr_annotation/example/lib/main.dart @@ -1,6 +1,6 @@ import 'package:auto_mappr_annotation/auto_mappr_annotation.dart'; -// part 'main.g.dart'; +// part 'main.auto_mappr.dart'; @AutoMappr([ MapType(), diff --git a/packages/auto_mappr_annotation/example/pubspec.yaml b/packages/auto_mappr_annotation/example/pubspec.yaml index 3a603837..250c3f1c 100644 --- a/packages/auto_mappr_annotation/example/pubspec.yaml +++ b/packages/auto_mappr_annotation/example/pubspec.yaml @@ -12,5 +12,5 @@ dependencies: dev_dependencies: build_runner: ^2.0.0 - netglade_analysis: ^4.0.0 + netglade_analysis: ^4.2.0 test: ^1.16.0 diff --git a/packages/auto_mappr_annotation/lib/src/auto_mappr.dart b/packages/auto_mappr_annotation/lib/src/auto_mappr.dart index e45ea2cb..cac577f1 100644 --- a/packages/auto_mappr_annotation/lib/src/auto_mappr.dart +++ b/packages/auto_mappr_annotation/lib/src/auto_mappr.dart @@ -6,12 +6,17 @@ final class AutoMappr { /// List of mapprs. final List> mappers; - /// List of other AutoMappr classes to use as modules. + /// List of mapprs that should be included to this mappr. + /// + /// Imagine copy-pasting mappings from included mappr to this one. + final List? includes; + + /// List of mapprs used as delegates. /// /// When current mappr cannot convert source to target, /// it lets modules in order try to convert it instead. - final List? modules; + final List? delegates; /// Constructs AutoMappr. - const AutoMappr(this.mappers, {this.modules}); + const AutoMappr(this.mappers, {this.includes, this.delegates}); } diff --git a/packages/auto_mappr_annotation/pubspec.yaml b/packages/auto_mappr_annotation/pubspec.yaml index 13b63e20..f30d5f06 100644 --- a/packages/auto_mappr_annotation/pubspec.yaml +++ b/packages/auto_mappr_annotation/pubspec.yaml @@ -1,6 +1,6 @@ name: auto_mappr_annotation description: Annotations for the auto_mappr code-generator of mapping between objects with ease. -version: 1.2.0 +version: 2.0.0-beta1 repository: https://github.com/netglade/auto_mappr issue_tracker: https://github.com/netglade/auto_mappr/issues @@ -8,5 +8,5 @@ environment: sdk: ^3.0.0 dev_dependencies: - netglade_analysis: ^4.0.0 + netglade_analysis: ^4.2.0 test: ^1.16.0