2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- import 'package:analyzer/dart/element/element .dart' ;
5
+ import 'package:analyzer/dart/element/element2 .dart' ;
6
6
import 'package:analyzer/dart/element/nullability_suffix.dart' ;
7
7
import 'package:build/build.dart' ;
8
8
import 'package:source_gen/source_gen.dart' ;
@@ -23,7 +23,7 @@ class CreateFactoryResult {
23
23
24
24
mixin DecodeHelper implements HelperCore {
25
25
CreateFactoryResult createFactory (
26
- Map <String , FieldElement > accessibleFields,
26
+ Map <String , FieldElement2 > accessibleFields,
27
27
Map <String , String > unavailableReasons,
28
28
) {
29
29
assert (config.createFactory);
@@ -37,14 +37,14 @@ mixin DecodeHelper implements HelperCore {
37
37
);
38
38
39
39
if (config.genericArgumentFactories) {
40
- for (var arg in element.typeParameters ) {
40
+ for (var arg in element.typeParameters2 ) {
41
41
final helperName = fromJsonForType (
42
42
arg.instantiate (nullabilitySuffix: NullabilitySuffix .none),
43
43
);
44
44
45
- buffer.write (', ${arg .name } Function(Object? json) $helperName ' );
45
+ buffer.write (', ${arg .name3 } Function(Object? json) $helperName ' );
46
46
}
47
- if (element.typeParameters .isNotEmpty) {
47
+ if (element.typeParameters2 .isNotEmpty) {
48
48
buffer.write (',' );
49
49
}
50
50
}
@@ -55,7 +55,7 @@ mixin DecodeHelper implements HelperCore {
55
55
56
56
String deserializeFun (
57
57
String paramOrFieldName, {
58
- ParameterElement ? ctorParam,
58
+ FormalParameterElement ? ctorParam,
59
59
}) => _deserializeForField (
60
60
accessibleFields[paramOrFieldName]! ,
61
61
ctorParam: ctorParam,
@@ -66,21 +66,28 @@ mixin DecodeHelper implements HelperCore {
66
66
config.constructor,
67
67
accessibleFields.keys,
68
68
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! )
71
78
.toList (),
72
79
unavailableReasons,
73
80
deserializeFun,
74
81
);
75
82
76
83
final checks = _checkKeys (
77
84
accessibleFields.values.where (
78
- (fe) => data.usedCtorParamsAndFields.contains (fe.name ),
85
+ (fe) => data.usedCtorParamsAndFields.contains (fe.name3 ),
79
86
),
80
87
).toList ();
81
88
82
89
if (config.checked) {
83
- final classLiteral = escapeDartString (element.name );
90
+ final classLiteral = escapeDartString (element.name3 ! );
84
91
85
92
final sectionBuffer = StringBuffer ()
86
93
..write ('''
@@ -163,11 +170,11 @@ mixin DecodeHelper implements HelperCore {
163
170
return CreateFactoryResult (buffer.toString (), data.usedCtorParamsAndFields);
164
171
}
165
172
166
- Iterable <String > _checkKeys (Iterable <FieldElement > accessibleFields) sync * {
173
+ Iterable <String > _checkKeys (Iterable <FieldElement2 > accessibleFields) sync * {
167
174
final args = < String > [];
168
175
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 ())}' ;
171
178
172
179
if (config.disallowUnrecognizedKeys) {
173
180
final allowKeysLiteral = constantList (accessibleFields);
@@ -201,8 +208,8 @@ mixin DecodeHelper implements HelperCore {
201
208
/// If [checkedProperty] is `true` , we're using this function to write to a
202
209
/// setter.
203
210
String _deserializeForField (
204
- FieldElement field, {
205
- ParameterElement ? ctorParam,
211
+ FieldElement2 field, {
212
+ FormalParameterElement ? ctorParam,
206
213
bool checkedProperty = false ,
207
214
}) {
208
215
final jsonKeyName = safeNameAccess (field);
@@ -246,7 +253,7 @@ mixin DecodeHelper implements HelperCore {
246
253
if (defaultValue != null ) {
247
254
if (jsonKey.disallowNullValue && jsonKey.required ) {
248
255
log.warning (
249
- 'The `defaultValue` on field `${field .name }` will have no '
256
+ 'The `defaultValue` on field `${field .name3 }` will have no '
250
257
'effect because both `disallowNullValue` and `required` are set to '
251
258
'`true`.' ,
252
259
);
@@ -267,30 +274,30 @@ mixin DecodeHelper implements HelperCore {
267
274
/// [writableFields] are also populated, but only if they have not already
268
275
/// been defined by a constructor parameter with the same name.
269
276
_ConstructorData _writeConstructorInvocation (
270
- ClassElement classElement,
277
+ ClassElement2 classElement,
271
278
String constructorName,
272
279
Iterable <String > availableConstructorParameters,
273
280
Iterable <String > writableFields,
274
281
Map <String , String > unavailableReasons,
275
- String Function (String paramOrFieldName, {ParameterElement ctorParam})
282
+ String Function (String paramOrFieldName, {FormalParameterElement ctorParam})
276
283
deserializeForField,
277
284
) {
278
- final className = classElement.name ;
285
+ final className = classElement.name3 ;
279
286
280
287
final ctor = constructorByName (classElement, constructorName);
281
288
282
289
final usedCtorParamsAndFields = < String > {};
283
- final constructorArguments = < ParameterElement > [];
284
- final namedConstructorArguments = < ParameterElement > [];
290
+ final constructorArguments = < FormalParameterElement > [];
291
+ final namedConstructorArguments = < FormalParameterElement > [];
285
292
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 )) {
288
295
if (arg.isRequired) {
289
296
var msg =
290
297
'Cannot populate the required constructor '
291
- 'argument: ${arg .name }.' ;
298
+ 'argument: ${arg .name3 }.' ;
292
299
293
- final additionalInfo = unavailableReasons[arg.name ];
300
+ final additionalInfo = unavailableReasons[arg.name3 ];
294
301
295
302
if (additionalInfo != null ) {
296
303
msg = '$msg $additionalInfo ' ;
@@ -308,7 +315,7 @@ _ConstructorData _writeConstructorInvocation(
308
315
} else {
309
316
constructorArguments.add (arg);
310
317
}
311
- usedCtorParamsAndFields.add (arg.name );
318
+ usedCtorParamsAndFields.add (arg.name3 ! );
312
319
}
313
320
314
321
// fields that aren't already set by the constructor and that aren't final
@@ -327,7 +334,7 @@ _ConstructorData _writeConstructorInvocation(
327
334
..writeAll (
328
335
constructorArguments.map ((paramElement) {
329
336
final content = deserializeForField (
330
- paramElement.name ,
337
+ paramElement.name3 ! ,
331
338
ctorParam: paramElement,
332
339
);
333
340
return ' $content ,\n ' ;
@@ -336,10 +343,10 @@ _ConstructorData _writeConstructorInvocation(
336
343
..writeAll (
337
344
namedConstructorArguments.map ((paramElement) {
338
345
final value = deserializeForField (
339
- paramElement.name ,
346
+ paramElement.name3 ! ,
340
347
ctorParam: paramElement,
341
348
);
342
- return ' ${paramElement .name }: $value ,\n ' ;
349
+ return ' ${paramElement .name3 ! }: $value ,\n ' ;
343
350
}),
344
351
)
345
352
..write (')' );
0 commit comments