22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- import 'package:analyzer/dart/element/element .dart' ;
5+ import 'package:analyzer/dart/element/element2 .dart' ;
66import 'package:analyzer/dart/element/nullability_suffix.dart' ;
77import 'package:build/build.dart' ;
88import 'package:source_gen/source_gen.dart' ;
@@ -23,7 +23,7 @@ class CreateFactoryResult {
2323
2424mixin DecodeHelper implements HelperCore {
2525 CreateFactoryResult createFactory (
26- Map <String , FieldElement > accessibleFields,
26+ Map <String , FieldElement2 > accessibleFields,
2727 Map <String , String > unavailableReasons,
2828 ) {
2929 assert (config.createFactory);
@@ -37,14 +37,14 @@ mixin DecodeHelper implements HelperCore {
3737 );
3838
3939 if (config.genericArgumentFactories) {
40- for (var arg in element.typeParameters ) {
40+ for (var arg in element.typeParameters2 ) {
4141 final helperName = fromJsonForType (
4242 arg.instantiate (nullabilitySuffix: NullabilitySuffix .none),
4343 );
4444
45- buffer.write (', ${arg .name } Function(Object? json) $helperName ' );
45+ buffer.write (', ${arg .name3 } Function(Object? json) $helperName ' );
4646 }
47- if (element.typeParameters .isNotEmpty) {
47+ if (element.typeParameters2 .isNotEmpty) {
4848 buffer.write (',' );
4949 }
5050 }
@@ -55,7 +55,7 @@ mixin DecodeHelper implements HelperCore {
5555
5656 String deserializeFun (
5757 String paramOrFieldName, {
58- ParameterElement ? ctorParam,
58+ FormalParameterElement ? ctorParam,
5959 }) => _deserializeForField (
6060 accessibleFields[paramOrFieldName]! ,
6161 ctorParam: ctorParam,
@@ -66,21 +66,28 @@ mixin DecodeHelper implements HelperCore {
6666 config.constructor,
6767 accessibleFields.keys,
6868 accessibleFields.values
69- .where ((fe) => element.lookUpSetter (fe.name, element.library) != null )
70- .map ((fe) => fe.name)
69+ .where (
70+ (fe) =>
71+ element.lookUpSetter2 (
72+ name: fe.name3! ,
73+ library: element.library2,
74+ ) !=
75+ null ,
76+ )
77+ .map ((fe) => fe.name3! )
7178 .toList (),
7279 unavailableReasons,
7380 deserializeFun,
7481 );
7582
7683 final checks = _checkKeys (
7784 accessibleFields.values.where (
78- (fe) => data.usedCtorParamsAndFields.contains (fe.name ),
85+ (fe) => data.usedCtorParamsAndFields.contains (fe.name3 ),
7986 ),
8087 ).toList ();
8188
8289 if (config.checked) {
83- final classLiteral = escapeDartString (element.name );
90+ final classLiteral = escapeDartString (element.name3 ! );
8491
8592 final sectionBuffer = StringBuffer ()
8693 ..write ('''
@@ -163,10 +170,11 @@ mixin DecodeHelper implements HelperCore {
163170 return CreateFactoryResult (buffer.toString (), data.usedCtorParamsAndFields);
164171 }
165172
166- Iterable <String > _checkKeys (Iterable <FieldElement > accessibleFields) sync * {
173+ Iterable <String > _checkKeys (Iterable <FieldElement2 > accessibleFields) sync * {
167174 final args = < String > [];
168175
169- String constantList (Iterable <FieldElement > things) => 'const ${jsonLiteralAsDart (things .map (nameAccess ).toList ())}' ;
176+ String constantList (Iterable <FieldElement2 > things) =>
177+ 'const ${jsonLiteralAsDart (things .map <String >(nameAccess ).toList ())}' ;
170178
171179 if (config.disallowUnrecognizedKeys) {
172180 final allowKeysLiteral = constantList (accessibleFields);
@@ -198,8 +206,8 @@ mixin DecodeHelper implements HelperCore {
198206 /// If [checkedProperty] is `true` , we're using this function to write to a
199207 /// setter.
200208 String _deserializeForField (
201- FieldElement field, {
202- ParameterElement ? ctorParam,
209+ FieldElement2 field, {
210+ FormalParameterElement ? ctorParam,
203211 bool checkedProperty = false ,
204212 }) {
205213 final jsonKeyName = safeNameAccess (field);
@@ -241,7 +249,7 @@ mixin DecodeHelper implements HelperCore {
241249 if (defaultValue != null ) {
242250 if (jsonKey.disallowNullValue && jsonKey.required ) {
243251 log.warning (
244- 'The `defaultValue` on field `${field .name }` will have no '
252+ 'The `defaultValue` on field `${field .name3 }` will have no '
245253 'effect because both `disallowNullValue` and `required` are set to '
246254 '`true`.' ,
247255 );
@@ -262,30 +270,30 @@ mixin DecodeHelper implements HelperCore {
262270/// [writableFields] are also populated, but only if they have not already
263271/// been defined by a constructor parameter with the same name.
264272_ConstructorData _writeConstructorInvocation (
265- ClassElement classElement,
273+ ClassElement2 classElement,
266274 String constructorName,
267275 Iterable <String > availableConstructorParameters,
268276 Iterable <String > writableFields,
269277 Map <String , String > unavailableReasons,
270- String Function (String paramOrFieldName, {ParameterElement ctorParam})
278+ String Function (String paramOrFieldName, {FormalParameterElement ctorParam})
271279 deserializeForField,
272280) {
273- final className = classElement.name ;
281+ final className = classElement.name3 ;
274282
275283 final ctor = constructorByName (classElement, constructorName);
276284
277285 final usedCtorParamsAndFields = < String > {};
278- final constructorArguments = < ParameterElement > [];
279- final namedConstructorArguments = < ParameterElement > [];
286+ final constructorArguments = < FormalParameterElement > [];
287+ final namedConstructorArguments = < FormalParameterElement > [];
280288
281- for (final arg in ctor.parameters ) {
282- if (! availableConstructorParameters.contains (arg.name )) {
289+ for (final arg in ctor.formalParameters ) {
290+ if (! availableConstructorParameters.contains (arg.name3 )) {
283291 if (arg.isRequired) {
284292 var msg =
285293 'Cannot populate the required constructor '
286- 'argument: ${arg .name }.' ;
294+ 'argument: ${arg .name3 }.' ;
287295
288- final additionalInfo = unavailableReasons[arg.name ];
296+ final additionalInfo = unavailableReasons[arg.name3 ];
289297
290298 if (additionalInfo != null ) {
291299 msg = '$msg $additionalInfo ' ;
@@ -303,7 +311,7 @@ _ConstructorData _writeConstructorInvocation(
303311 } else {
304312 constructorArguments.add (arg);
305313 }
306- usedCtorParamsAndFields.add (arg.name );
314+ usedCtorParamsAndFields.add (arg.name3 ! );
307315 }
308316
309317 // fields that aren't already set by the constructor and that aren't final
@@ -322,7 +330,7 @@ _ConstructorData _writeConstructorInvocation(
322330 ..writeAll (
323331 constructorArguments.map ((paramElement) {
324332 final content = deserializeForField (
325- paramElement.name ,
333+ paramElement.name3 ! ,
326334 ctorParam: paramElement,
327335 );
328336 return ' $content ,\n ' ;
@@ -331,10 +339,10 @@ _ConstructorData _writeConstructorInvocation(
331339 ..writeAll (
332340 namedConstructorArguments.map ((paramElement) {
333341 final value = deserializeForField (
334- paramElement.name ,
342+ paramElement.name3 ! ,
335343 ctorParam: paramElement,
336344 );
337- return ' ${paramElement .name }: $value ,\n ' ;
345+ return ' ${paramElement .name3 ! }: $value ,\n ' ;
338346 }),
339347 )
340348 ..write (')' );
0 commit comments