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,11 +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) =>
170- 'const ${jsonLiteralAsDart (things .map (nameAccess ).toList ())}' ;
176+ String constantList (Iterable <FieldElement2 > things) =>
177+ 'const ${jsonLiteralAsDart (things .map < String > (nameAccess ).toList ())}' ;
171178
172179 if (config.disallowUnrecognizedKeys) {
173180 final allowKeysLiteral = constantList (accessibleFields);
@@ -201,8 +208,8 @@ mixin DecodeHelper implements HelperCore {
201208 /// If [checkedProperty] is `true` , we're using this function to write to a
202209 /// setter.
203210 String _deserializeForField (
204- FieldElement field, {
205- ParameterElement ? ctorParam,
211+ FieldElement2 field, {
212+ FormalParameterElement ? ctorParam,
206213 bool checkedProperty = false ,
207214 }) {
208215 final jsonKeyName = safeNameAccess (field);
@@ -246,7 +253,7 @@ mixin DecodeHelper implements HelperCore {
246253 if (defaultValue != null ) {
247254 if (jsonKey.disallowNullValue && jsonKey.required ) {
248255 log.warning (
249- 'The `defaultValue` on field `${field .name }` will have no '
256+ 'The `defaultValue` on field `${field .name3 }` will have no '
250257 'effect because both `disallowNullValue` and `required` are set to '
251258 '`true`.' ,
252259 );
@@ -267,30 +274,30 @@ mixin DecodeHelper implements HelperCore {
267274/// [writableFields] are also populated, but only if they have not already
268275/// been defined by a constructor parameter with the same name.
269276_ConstructorData _writeConstructorInvocation (
270- ClassElement classElement,
277+ ClassElement2 classElement,
271278 String constructorName,
272279 Iterable <String > availableConstructorParameters,
273280 Iterable <String > writableFields,
274281 Map <String , String > unavailableReasons,
275- String Function (String paramOrFieldName, {ParameterElement ctorParam})
282+ String Function (String paramOrFieldName, {FormalParameterElement ctorParam})
276283 deserializeForField,
277284) {
278- final className = classElement.name ;
285+ final className = classElement.name3 ;
279286
280287 final ctor = constructorByName (classElement, constructorName);
281288
282289 final usedCtorParamsAndFields = < String > {};
283- final constructorArguments = < ParameterElement > [];
284- final namedConstructorArguments = < ParameterElement > [];
290+ final constructorArguments = < FormalParameterElement > [];
291+ final namedConstructorArguments = < FormalParameterElement > [];
285292
286- for (final arg in ctor.parameters ) {
287- if (! availableConstructorParameters.contains (arg.name )) {
293+ for (final arg in ctor.formalParameters ) {
294+ if (! availableConstructorParameters.contains (arg.name3 )) {
288295 if (arg.isRequired) {
289296 var msg =
290297 'Cannot populate the required constructor '
291- 'argument: ${arg .name }.' ;
298+ 'argument: ${arg .name3 }.' ;
292299
293- final additionalInfo = unavailableReasons[arg.name ];
300+ final additionalInfo = unavailableReasons[arg.name3 ];
294301
295302 if (additionalInfo != null ) {
296303 msg = '$msg $additionalInfo ' ;
@@ -308,7 +315,7 @@ _ConstructorData _writeConstructorInvocation(
308315 } else {
309316 constructorArguments.add (arg);
310317 }
311- usedCtorParamsAndFields.add (arg.name );
318+ usedCtorParamsAndFields.add (arg.name3 ! );
312319 }
313320
314321 // fields that aren't already set by the constructor and that aren't final
@@ -327,7 +334,7 @@ _ConstructorData _writeConstructorInvocation(
327334 ..writeAll (
328335 constructorArguments.map ((paramElement) {
329336 final content = deserializeForField (
330- paramElement.name ,
337+ paramElement.name3 ! ,
331338 ctorParam: paramElement,
332339 );
333340 return ' $content ,\n ' ;
@@ -336,10 +343,10 @@ _ConstructorData _writeConstructorInvocation(
336343 ..writeAll (
337344 namedConstructorArguments.map ((paramElement) {
338345 final value = deserializeForField (
339- paramElement.name ,
346+ paramElement.name3 ! ,
340347 ctorParam: paramElement,
341348 );
342- return ' ${paramElement .name }: $value ,\n ' ;
349+ return ' ${paramElement .name3 ! }: $value ,\n ' ;
343350 }),
344351 )
345352 ..write (')' );
0 commit comments