Skip to content

Commit 57e04de

Browse files
authored
Update to latest analyzer release and fix deprecations (#1510)
1 parent bc8fcb9 commit 57e04de

File tree

9 files changed

+28
-28
lines changed

9 files changed

+28
-28
lines changed

analysis_options.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ include: package:dart_flutter_team_lints/analysis_options.yaml
44
analyzer:
55
language:
66
strict-casts: true
7-
errors:
8-
# Analyzer v7.4.0 crazy
9-
deprecated_member_use: ignore
107

118
linter:
129
rules:

json_serializable/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 6.10.0-wip
2+
3+
- Required `analyzer: ^7.4.0`.
4+
15
## 6.10.0-dev
26

37
- Switch to analyzer element2 model and `build: ^3.0.0-dev`.

json_serializable/lib/src/enum_utils.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'json_literal_generator.dart';
1313
import 'utils.dart';
1414

1515
String constMapName(DartType targetType) =>
16-
'_\$${targetType.element!.name}EnumMap';
16+
'_\$${targetType.element3!.name3}EnumMap';
1717

1818
/// If [targetType] is not an enum, return `null`.
1919
///
@@ -45,7 +45,7 @@ String? enumValueMapFromType(
4545
final items = enumMap.entries
4646
.map(
4747
(e) =>
48-
' ${targetType.element!.name}.${e.key.name3}: '
48+
' ${targetType.element3!.name3}.${e.key.name3}: '
4949
'${jsonLiteralAsDart(e.value)},',
5050
)
5151
.join();
@@ -57,7 +57,7 @@ Map<FieldElement2, Object?>? _enumMap(
5757
DartType targetType, {
5858
bool nullWithNoAnnotation = false,
5959
}) {
60-
final targetTypeElement = targetType.element;
60+
final targetTypeElement = targetType.element3;
6161
if (targetTypeElement == null) return null;
6262
final annotation = _jsonEnumChecker.firstAnnotationOf(targetTypeElement);
6363
final jsonEnum = _fromAnnotation(annotation);

json_serializable/lib/src/helper_core.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ $converterOrKeyInstructions
7979
} else if (field.type != error.type) {
8080
message = '$message because of type `${typeToCode(error.type)}`';
8181
} else {
82-
final element = error.type.element?.name;
82+
final element = error.type.element3?.name3;
8383
todo =
8484
'''
8585
To support the type `${element ?? error.type}` you can:

json_serializable/lib/src/json_key_utils.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ KeyConfig _from(FieldElement2 element, ClassConfig classAnnotation) {
6666
// literal, which is NOT supported!
6767
badType = 'Function';
6868
} else if (!reader.isLiteral) {
69-
badType = dartObject.type!.element?.name;
69+
badType = dartObject.type!.element3?.name3;
7070
}
7171

7272
if (badType != null) {
@@ -194,7 +194,7 @@ KeyConfig _from(FieldElement2 element, ClassConfig classAnnotation) {
194194
(n) => n,
195195
);
196196

197-
return '${annotationType.element!.name}.$enumValueName';
197+
return '${annotationType.element3!.name3}.$enumValueName';
198198
} else {
199199
final defaultValueLiteral = literalForObject(fieldName, objectValue, []);
200200
if (defaultValueLiteral == null) {
@@ -331,7 +331,7 @@ bool _includeIfNull(
331331
bool _interfaceTypesEqual(DartType a, DartType b) {
332332
if (a is InterfaceType && b is InterfaceType) {
333333
// Handle nullability case. Pretty sure this is fine for enums.
334-
return a.element == b.element;
334+
return a.element3 == b.element3;
335335
}
336336
return a == b;
337337
}

json_serializable/lib/src/type_helpers/json_converter_helper.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ _JsonConvertData? _typeConverterFrom(
244244

245245
if (match.genericTypeArg != null) {
246246
return _JsonConvertData.genericClass(
247-
match.annotation.type!.element!.name!,
247+
match.annotation.type!.element3!.name3!,
248248
match.genericTypeArg!,
249249
reviver.accessor,
250250
match.jsonType,
@@ -253,7 +253,7 @@ _JsonConvertData? _typeConverterFrom(
253253
}
254254

255255
return _JsonConvertData.className(
256-
match.annotation.type!.element!.name!,
256+
match.annotation.type!.element3!.name3!,
257257
reviver.accessor,
258258
match.jsonType,
259259
match.fieldType,
@@ -291,7 +291,7 @@ _ConverterMatch? _compatibleMatch(
291291
return null;
292292
}
293293

294-
assert(jsonConverterSuper.element.typeParameters.length == 2);
294+
assert(jsonConverterSuper.element3.typeParameters2.length == 2);
295295
assert(jsonConverterSuper.typeArguments.length == 2);
296296

297297
final fieldType = jsonConverterSuper.typeArguments[0];
@@ -308,7 +308,7 @@ _ConverterMatch? _compatibleMatch(
308308
}
309309

310310
if (fieldType is TypeParameterType && targetType is TypeParameterType) {
311-
assert(annotation?.element is! PropertyAccessorElement2);
311+
assert(annotation?.element2 is! PropertyAccessorElement2);
312312
assert(converterClassElement.typeParameters2.isNotEmpty);
313313
if (converterClassElement.typeParameters2.length > 1) {
314314
throw InvalidGenerationSourceError(
@@ -323,7 +323,7 @@ _ConverterMatch? _compatibleMatch(
323323
annotation,
324324
constantValue,
325325
jsonConverterSuper.typeArguments[1],
326-
'${targetType.element.name}${targetType.isNullableType ? '?' : ''}',
326+
'${targetType.element3.name3}${targetType.isNullableType ? '?' : ''}',
327327
fieldType,
328328
);
329329
}

json_serializable/lib/src/type_helpers/json_helper.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ List<String> _helperParams(
157157
final args = <String>[];
158158

159159
for (var helperArg in rest) {
160-
final typeParamIndex = type.element.typeParameters.indexOf(
161-
helperArg.element,
160+
final typeParamIndex = type.element3.typeParameters2.indexOf(
161+
helperArg.element3,
162162
);
163163

164164
// TODO: throw here if `typeParamIndex` is -1 ?
@@ -181,7 +181,7 @@ TypeParameterType _decodeHelper(
181181
type.normalParameterTypes.length == 1) {
182182
final funcReturnType = type.returnType;
183183

184-
if (param.name3 == fromJsonForName(funcReturnType.element!.name!)) {
184+
if (param.name3 == fromJsonForName(funcReturnType.element3!.name3!)) {
185185
final funcParamType = type.normalParameterTypes.single;
186186

187187
if ((funcParamType.isDartCoreObject && funcParamType.isNullableType) ||
@@ -212,7 +212,7 @@ TypeParameterType _encodeHelper(
212212
type.normalParameterTypes.length == 1) {
213213
final funcParamType = type.normalParameterTypes.single;
214214

215-
if (param.name3 == toJsonForName(funcParamType.element!.name!)) {
215+
if (param.name3 == toJsonForName(funcParamType.element3!.name3!)) {
216216
if (funcParamType is TypeParameterType) {
217217
return funcParamType;
218218
}
@@ -252,7 +252,7 @@ InterfaceType? _instantiate(
252252
InterfaceType classType,
253253
) {
254254
final argTypes = ctorParamType.typeArguments.map((arg) {
255-
final typeParamIndex = classType.element.typeParameters.indexWhere(
255+
final typeParamIndex = classType.element3.typeParameters2.indexWhere(
256256
// TODO: not 100% sure `nullabilitySuffix` is right
257257
(e) => e.instantiate(nullabilitySuffix: arg.nullabilitySuffix) == arg,
258258
);
@@ -269,7 +269,7 @@ InterfaceType? _instantiate(
269269
return null;
270270
}
271271

272-
return ctorParamType.element.instantiate(
272+
return ctorParamType.element3.instantiate(
273273
typeArguments: argTypes.cast<DartType>(),
274274
nullabilitySuffix: ctorParamType.nullabilitySuffix,
275275
);

json_serializable/lib/src/utils.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer/dart/constant/value.dart';
6-
import 'package:analyzer/dart/element/element.dart';
76
import 'package:analyzer/dart/element/element2.dart';
87
import 'package:analyzer/dart/element/type.dart';
98
import 'package:json_annotation/json_annotation.dart';
@@ -163,7 +162,7 @@ ConstructorElement2 constructorByName(ClassElement2 classElement, String name) {
163162
return ctor;
164163
}
165164

166-
/// If [targetType] is an enum, returns the [FieldElement] instances associated
165+
/// If [targetType] is an enum, returns the [FieldElement2] instances associated
167166
/// with its values.
168167
///
169168
/// Otherwise, `null`.
@@ -177,7 +176,7 @@ Iterable<FieldElement2>? iterateEnumFields(DartType targetType) {
177176

178177
extension DartTypeExtension on DartType {
179178
DartType promoteNonNullable() =>
180-
element?.library?.typeSystem.promoteToNonNull(this) ?? this;
179+
element3?.library2?.typeSystem.promoteToNonNull(this) ?? this;
181180

182181
String toStringNonNullable() {
183182
final val = getDisplayString();
@@ -209,7 +208,7 @@ String typeToCode(DartType type, {bool forceNullable = false}) {
209208
return 'dynamic';
210209
} else if (type is InterfaceType) {
211210
return [
212-
type.element.name,
211+
type.element3.name3,
213212
if (type.typeArguments.isNotEmpty)
214213
'<${type.typeArguments.map(typeToCode).join(', ')}>',
215214
(type.isNullableType || forceNullable) ? '?' : '',
@@ -251,7 +250,7 @@ String? defaultDecodeLogic(
251250

252251
extension ExecutableElementExtension on ExecutableElement2 {
253252
/// Returns the name of `this` qualified with the class name if it's a
254-
/// [MethodElement].
253+
/// [MethodElement2].
255254
String get qualifiedName {
256255
if (this is TopLevelFunctionElement) {
257256
return name3!;

json_serializable/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json_serializable
2-
version: 6.10.0-dev
2+
version: 6.10.0-wip
33
description: >-
44
Automatically generate code for converting to and from JSON by annotating
55
Dart classes.
@@ -15,7 +15,7 @@ topics:
1515
resolution: workspace
1616

1717
dependencies:
18-
analyzer: '>=6.9.0 <8.0.0'
18+
analyzer: ^7.4.0
1919
async: ^2.10.0
2020
build: ^3.0.0-dev
2121
build_config: ^1.1.0

0 commit comments

Comments
 (0)