Skip to content

Commit

Permalink
Merge pull request #167 from netglade/feat/adhere-to-analysis-6
Browse files Browse the repository at this point in the history
Adhere to netglade_analysis 6
  • Loading branch information
tenhobi authored Dec 13, 2023
2 parents 5c9fbf7 + d76d7b7 commit 6dd33a0
Show file tree
Hide file tree
Showing 36 changed files with 130 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1
- uses: bluefireteam/melos-action@v2
- uses: bluefireteam/melos-action@v3

- name: Generate AutoMappr files
run: melos run gen:build-all
Expand Down
2 changes: 1 addition & 1 deletion examples/drift/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ dev_dependencies:
auto_mappr: ^2.0.0
build_runner: ^2.0.0
drift_dev: ^2.7.0
netglade_analysis: ^5.0.0
netglade_analysis: ^6.0.0
test: ^1.16.0
2 changes: 1 addition & 1 deletion examples/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ dependencies:
dev_dependencies:
auto_mappr: ^2.0.0
build_runner: ^2.0.0
netglade_analysis: ^5.0.0
netglade_analysis: ^6.0.0
test: ^1.16.0
2 changes: 1 addition & 1 deletion examples/freezed/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ dev_dependencies:
auto_mappr: ^2.0.0
build_runner: ^2.0.0
freezed: ^2.3.2
netglade_analysis: ^5.0.0
netglade_analysis: ^6.0.0
test: ^1.16.0
2 changes: 1 addition & 1 deletion examples/injectable/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ dev_dependencies:
auto_mappr: ^2.0.0
build_runner: ^2.0.0
injectable_generator: ^2.1.5
netglade_analysis: ^5.0.0
netglade_analysis: ^6.0.0
test: ^1.16.0
2 changes: 1 addition & 1 deletion examples/json_serializable/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ dev_dependencies:
auto_mappr: ^2.0.0
build_runner: ^2.0.0
json_serializable: ^6.6.1
netglade_analysis: ^5.0.0
netglade_analysis: ^6.0.0
test: ^1.16.0
2 changes: 1 addition & 1 deletion packages/auto_mappr/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ dependencies:
dev_dependencies:
auto_mappr: ^2.0.0
build_runner: ^2.0.0
netglade_analysis: ^5.0.0
netglade_analysis: ^6.0.0
test: ^1.16.0
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ abstract class AssignmentBuilderBase {
final SourceAssignment assignment;
final AutoMapprConfig mapperConfig;
final TypeMapping mapping;
final void Function(TypeMapping? mapping)? usedNullableMethodCallback;
// ignore: prefer-typedefs-for-callbacks, private API
final void Function(TypeMapping? mapping)? onUsedNullableMethodCallback;

static const Reference modelReference = Reference('model');

const AssignmentBuilderBase({
required this.assignment,
required this.mapperConfig,
required this.mapping,
required this.usedNullableMethodCallback,
required this.onUsedNullableMethodCallback,
});

Expression buildAssignment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class IterableAssignmentBuilder extends AssignmentBuilderBase with NestedObjectM
required super.assignment,
required super.mapperConfig,
required super.mapping,
required super.usedNullableMethodCallback,
required super.onUsedNullableMethodCallback,
});

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin
required super.assignment,
required super.mapperConfig,
required super.mapping,
required super.usedNullableMethodCallback,
required super.onUsedNullableMethodCallback,
});

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class NestedObjectAssignmentBuilder extends AssignmentBuilderBase with NestedObj
required super.assignment,
required super.mapperConfig,
required super.mapping,
required super.usedNullableMethodCallback,
required super.onUsedNullableMethodCallback,
required this.source,
required this.target,
this.convertMethodArgument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mixin NestedObjectMixin on AssignmentBuilderBase {
assignment: assignment,
mapperConfig: mapperConfig,
mapping: mapping,
usedNullableMethodCallback: null,
onUsedNullableMethodCallback: null,
convertMethodArgument: convertMethodArgument,
source: source,
target: target,
Expand Down Expand Up @@ -102,7 +102,7 @@ mixin NestedObjectMixin on AssignmentBuilderBase {
/// When [convertMethodArgument] is null, then a tear off `_mapAlphaDto_to_Alpha` is generated.
///
/// This function also marks nullable mapping to be generated
/// using the [usedNullableMethodCallback] callback.
/// using the [onUsedNullableMethodCallback] callback.
Expression mappingCall({
required DartType source,
required DartType target,
Expand Down Expand Up @@ -133,7 +133,7 @@ mixin NestedObjectMixin on AssignmentBuilderBase {
);

if (useNullableMethod) {
usedNullableMethodCallback?.call(nestedMapping);
onUsedNullableMethodCallback?.call(nestedMapping);
}

return convertMethodArgument == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RecordAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMix
required super.assignment,
required super.mapperConfig,
required super.mapping,
required super.usedNullableMethodCallback,
required super.onUsedNullableMethodCallback,
});

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TypeConverterBuilder extends AssignmentBuilderBase {
required super.assignment,
required super.mapperConfig,
required super.mapping,
required super.usedNullableMethodCallback,
required super.onUsedNullableMethodCallback,
required this.convertMethodArgument,
required this.source,
required this.target,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class AutoMapprBuilder {
MappingMethodBuilder(
config,
mapping: mapping,
usedNullableMethodCallback: usedNullableMappingMethod,
onUsedNullableMethodCallback: usedNullableMappingMethod,
).buildMethod(),

// Generates nullable mapping method only when nullable method is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ClassBodyBuilder extends MapBodyBuilderBase {
const ClassBodyBuilder({
required super.mapperConfig,
required super.mapping,
required super.usedNullableMethodCallback,
required super.onUsedNullableMethodCallback,
});

@override
Expand Down Expand Up @@ -249,7 +249,7 @@ class ClassBodyBuilder extends MapBodyBuilderBase {
targetField: targetField,
typeConverters: mapping.typeConverters,
),
usedNullableMethodCallback: usedNullableMethodCallback,
onUsedNullableMethodCallback: onUsedNullableMethodCallback,
).build(),
);
}
Expand Down Expand Up @@ -299,7 +299,7 @@ class ClassBodyBuilder extends MapBodyBuilderBase {
mapperConfig: mapperConfig,
mapping: mapping,
assignment: assignment,
usedNullableMethodCallback: usedNullableMethodCallback,
onUsedNullableMethodCallback: onUsedNullableMethodCallback,
).build(),
),
{
Expand All @@ -308,7 +308,7 @@ class ClassBodyBuilder extends MapBodyBuilderBase {
mapperConfig: mapperConfig,
mapping: mapping,
assignment: assignment,
usedNullableMethodCallback: usedNullableMethodCallback,
onUsedNullableMethodCallback: onUsedNullableMethodCallback,
).build(),
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class EnumBodyBuilder extends MapBodyBuilderBase {
const EnumBodyBuilder({
required super.mapperConfig,
required super.mapping,
required super.usedNullableMethodCallback,
required super.onUsedNullableMethodCallback,
});

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ abstract class MapBodyBuilderBase {
final AutoMapprConfig mapperConfig;
final TypeMapping mapping;

final void Function(TypeMapping? mapping)? usedNullableMethodCallback;
// ignore: prefer-typedefs-for-callbacks, private API
final void Function(TypeMapping? mapping)? onUsedNullableMethodCallback;

const MapBodyBuilderBase({
required this.mapperConfig,
required this.mapping,
required this.usedNullableMethodCallback,
required this.onUsedNullableMethodCallback,
});

Code build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ class MapModelBodyMethodBuilder {
final AutoMapprConfig mapperConfig;
final TypeMapping mapping;
final bool nullable;
final void Function(TypeMapping? mapping)? usedNullableMethodCallback;
// ignore: prefer-typedefs-for-callbacks, private API
final void Function(TypeMapping? mapping)? onUsedNullableMethodCallback;

const MapModelBodyMethodBuilder({
required this.mapperConfig,
required this.mapping,
this.usedNullableMethodCallback,
this.onUsedNullableMethodCallback,
this.nullable = false,
});

Expand All @@ -29,7 +30,7 @@ class MapModelBodyMethodBuilder {
final enumMapBodyBuilder = EnumBodyBuilder(
mapperConfig: mapperConfig,
mapping: mapping,
usedNullableMethodCallback: usedNullableMethodCallback,
onUsedNullableMethodCallback: onUsedNullableMethodCallback,
);
if (enumMapBodyBuilder.canProcess()) {
block.statements.add(enumMapBodyBuilder.build());
Expand All @@ -40,7 +41,7 @@ class MapModelBodyMethodBuilder {
final classMapBodyBuilder = ClassBodyBuilder(
mapperConfig: mapperConfig,
mapping: mapping,
usedNullableMethodCallback: usedNullableMethodCallback,
onUsedNullableMethodCallback: onUsedNullableMethodCallback,
);

// Return a constructor call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import 'package:code_builder/code_builder.dart';
class MappingMethodBuilder extends MethodBuilderBase {
final TypeMapping mapping;
final bool nullable;
final void Function(TypeMapping? mapping)? usedNullableMethodCallback;
// ignore: prefer-typedefs-for-callbacks, private API
final void Function(TypeMapping? mapping)? onUsedNullableMethodCallback;

const MappingMethodBuilder(
super.config, {
required this.mapping,
this.nullable = false,
this.usedNullableMethodCallback,
this.onUsedNullableMethodCallback,
});

@override
Expand Down Expand Up @@ -46,7 +47,7 @@ class MappingMethodBuilder extends MethodBuilderBase {
return MapModelBodyMethodBuilder(
mapping: mapping,
mapperConfig: config,
usedNullableMethodCallback: usedNullableMethodCallback,
onUsedNullableMethodCallback: onUsedNullableMethodCallback,
nullable: nullable,
).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ class ValueAssignmentBuilder {
final AutoMapprConfig mapperConfig;
final TypeMapping mapping;
final SourceAssignment assignment;
final void Function(TypeMapping? mapping)? usedNullableMethodCallback;
// ignore: prefer-typedefs-for-callbacks, private API
final void Function(TypeMapping? mapping)? onUsedNullableMethodCallback;

const ValueAssignmentBuilder({
required this.mapperConfig,
required this.mapping,
required this.assignment,
required this.usedNullableMethodCallback,
required this.onUsedNullableMethodCallback,
});

Expression build() {
Expand Down Expand Up @@ -49,7 +50,7 @@ class ValueAssignmentBuilder {
assignment: assignment,
mapperConfig: mapperConfig,
mapping: mapping,
usedNullableMethodCallback: usedNullableMethodCallback,
onUsedNullableMethodCallback: onUsedNullableMethodCallback,
source: assignment.sourceType!,
target: assignment.targetType,
convertMethodArgument: rightSide,
Expand All @@ -59,28 +60,28 @@ class ValueAssignmentBuilder {
assignment: assignment,
mapperConfig: mapperConfig,
mapping: mapping,
usedNullableMethodCallback: usedNullableMethodCallback,
onUsedNullableMethodCallback: onUsedNullableMethodCallback,
),
// Map.
MapAssignmentBuilder(
assignment: assignment,
mapperConfig: mapperConfig,
mapping: mapping,
usedNullableMethodCallback: usedNullableMethodCallback,
onUsedNullableMethodCallback: onUsedNullableMethodCallback,
),
// Record.
RecordAssignmentBuilder(
assignment: assignment,
mapperConfig: mapperConfig,
mapping: mapping,
usedNullableMethodCallback: usedNullableMethodCallback,
onUsedNullableMethodCallback: onUsedNullableMethodCallback,
),
// Nested object.
NestedObjectAssignmentBuilder(
assignment: assignment,
mapperConfig: mapperConfig,
mapping: mapping,
usedNullableMethodCallback: usedNullableMethodCallback,
onUsedNullableMethodCallback: onUsedNullableMethodCallback,
source: assignment.sourceType!,
target: assignment.targetType,
convertMethodArgument: rightSide,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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
// ignore: prefer-static-class, must be top level, prefer-typedefs-for-callbacks, simpler this way
R runZonedAutoMappr<R>(R Function() body, {Uri? libraryUri}) {
return runZoned(
() {
Expand Down
2 changes: 1 addition & 1 deletion packages/auto_mappr/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ dev_dependencies:
build_runner: ^2.0.0
generator_test: ^0.2.0
mocktail: ^1.0.0
netglade_analysis: ^5.0.0
netglade_analysis: ^6.0.0
source_gen_test: ^1.0.4
test: ^1.16.0
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void main() {
expect(result.returns, equals(result.types.elementAtOrNull(1)));
expect(result.optionalParameters, isEmpty);
expect(
result.requiredParameters,
result.requiredParameters.toList(),
equals([
Parameter(
(p) => p
Expand Down Expand Up @@ -55,7 +55,7 @@ void main() {
expect(result.returns, equals(result.types.elementAtOrNull(1)?.nullabled()));
expect(result.optionalParameters, isEmpty);
expect(
result.requiredParameters,
result.requiredParameters.toList(),
equals([
Parameter(
(p) => p
Expand Down Expand Up @@ -83,7 +83,7 @@ void main() {
expect(result.returns, equals(result.types.elementAtOrNull(1)?.nullabled()));
expect(result.optionalParameters.isEmpty, isFalse);
expect(
result.requiredParameters,
result.requiredParameters.toList(),
equals([
Parameter(
(p) => p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ void main() {
{_getUserDto(1), _getUserDto(2), _getUserDto(3)},
);

// ignore: avoid-misused-test-matchers, checking list vs set
expect(converted, equals({_getUser(1), _getUser(2), _getUser(3)}));
});

Expand All @@ -237,6 +238,7 @@ void main() {
{_getUserDto(1), _getUserDto(2), _getUserDto(3), null},
);

// ignore: avoid-misused-test-matchers, checking list vs set
expect(converted, equals({_getUser(1), _getUser(2), _getUser(3), null}));
});

Expand Down
Loading

0 comments on commit 6dd33a0

Please sign in to comment.