@@ -3,17 +3,17 @@ import 'dart:collection';
33import 'package:analyzer/dart/element/element.dart' ;
44import 'package:code_builder/code_builder.dart' ;
55import 'package:smartstruct_generator/code_builders/parameter_copy.dart' ;
6+ import 'package:smartstruct_generator/mapper_config.dart' ;
67import 'package:smartstruct_generator/models/RefChain.dart' ;
78import 'package:smartstruct_generator/models/source_assignment.dart' ;
8- import 'package:smartstruct_generator/mapper_config.dart' ;
99import 'package:source_gen/source_gen.dart' ;
1010
1111import 'assignment_builder.dart' ;
1212
1313/// Generates the implemented mapper method by the given abstract [MethodElement] .
1414Method buildMapperImplementation (Map <String , dynamic > config,
1515 MethodElement method, ClassElement abstractMapper) {
16- if (method.returnType.element2 == null ) {
16+ if (method.returnType.element == null ) {
1717 throw InvalidGenerationSourceError (
1818 '${method .returnType } is not a valid return type' ,
1919 element: method,
@@ -28,21 +28,20 @@ Method buildMapperImplementation(Map<String, dynamic> config,
2828 refer (method.returnType.getDisplayString (withNullability: true )));
2929}
3030
31-
3231/// Generates the implemented mapper method by the given abstract [MethodElement] .
3332Method buildStaticMapperImplementation (Map <String , dynamic > config,
3433 MethodElement method, ClassElement abstractMapper) {
3534 return Method (
36- (b) => b
35+ (b) => b
3736 ..name = '_\$ ${method .name }'
38- ..requiredParameters.addAll (method.parameters.map ((e) => copyParameter (e)))
37+ ..requiredParameters
38+ .addAll (method.parameters.map ((e) => copyParameter (e)))
3939 ..body = _generateBody (config, method, abstractMapper)
4040 ..returns =
41- refer (method.returnType.getDisplayString (withNullability: true )),
41+ refer (method.returnType.getDisplayString (withNullability: true )),
4242 );
4343}
4444
45-
4645/// Generates the body for the mapping method.
4746///
4847/// Uses the default constructor of the target mapping class to populate optional and required named and positional parameters.
@@ -51,7 +50,7 @@ Code _generateBody(Map<String, dynamic> config, MethodElement method,
5150 ClassElement abstractMapper) {
5251 final blockBuilder = BlockBuilder ();
5352
54- final targetClass = method.returnType.element2 as ClassElement ;
53+ final targetClass = method.returnType.element as ClassElement ;
5554
5655 final sourceParams = method.parameters;
5756
@@ -161,7 +160,7 @@ List<HashMap<String, SourceAssignment>> _targetToSource(
161160 ClassElement target,
162161 MethodElement method,
163162 Map <String , dynamic > config) {
164- final sourceMap = {for (var e in sources) e.type.element2 as ClassElement : e};
163+ final sourceMap = {for (var e in sources) e.type.element as ClassElement : e};
165164
166165 final caseSensitiveFields = config['caseSensitiveFields' ];
167166 final fieldMapper = caseSensitiveFields ? (a) => a : (a) => a.toUpperCase ();
@@ -202,10 +201,11 @@ List<HashMap<String, SourceAssignment>> _targetToSource(
202201 for (var matchedTarget in matchedSourceClazzInSourceMapping.keys) {
203202 final sourceValueList =
204203 matchedSourceClazzInSourceMapping[matchedTarget]! ;
205- final fieldClazz = f.type.element2 as ClassElement ;
206-
207- final refChain = RefChain .byPropNames (sourceEntry.value, sourceValueList.sublist (1 ));
208- targetToSource[matchedTarget] = SourceAssignment .fromRefChain (refChain);
204+
205+ final refChain = RefChain .byPropNames (
206+ sourceEntry.value, sourceValueList.sublist (1 ));
207+ targetToSource[matchedTarget] =
208+ SourceAssignment .fromRefChain (refChain);
209209 }
210210 } else {
211211 targetToSource[f.name] =
@@ -302,13 +302,14 @@ FieldElement? _findMatchingField(
302302 final foundField = potentielFinds.first;
303303 // foundField is not string
304304 if (_shouldSearchMoreFields (foundField)) {
305- final searchClazz = foundField.type.element2 as ClassElement ;
305+ final searchClazz = foundField.type.element as ClassElement ;
306306 return _findMatchingField (
307307 sources.skip (1 ).toList (), _findFields (searchClazz));
308308 } else {
309309 return foundField;
310310 }
311311 }
312+ return null ;
312313}
313314
314315/// A search for a potential underlying should only be continued, if the field is not a primitive type (string, int, double etc)
0 commit comments