diff --git a/analysis_options.yaml b/analysis_options.yaml index 24ad09c2..e6a95071 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -4,9 +4,6 @@ include: package:dart_flutter_team_lints/analysis_options.yaml analyzer: language: strict-casts: true - errors: - # Analyzer v7.4.0 crazy - deprecated_member_use: ignore linter: rules: diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 34b778c9..1f49c4ea 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.10.0-wip + +- Required `analyzer: ^7.4.0`. + ## 6.10.0-dev - Switch to analyzer element2 model and `build: ^3.0.0-dev`. diff --git a/json_serializable/lib/src/enum_utils.dart b/json_serializable/lib/src/enum_utils.dart index c5d5d1b5..77518c13 100644 --- a/json_serializable/lib/src/enum_utils.dart +++ b/json_serializable/lib/src/enum_utils.dart @@ -13,7 +13,7 @@ import 'json_literal_generator.dart'; import 'utils.dart'; String constMapName(DartType targetType) => - '_\$${targetType.element!.name}EnumMap'; + '_\$${targetType.element3!.name3}EnumMap'; /// If [targetType] is not an enum, return `null`. /// @@ -45,7 +45,7 @@ String? enumValueMapFromType( final items = enumMap.entries .map( (e) => - ' ${targetType.element!.name}.${e.key.name3}: ' + ' ${targetType.element3!.name3}.${e.key.name3}: ' '${jsonLiteralAsDart(e.value)},', ) .join(); @@ -57,7 +57,7 @@ Map? _enumMap( DartType targetType, { bool nullWithNoAnnotation = false, }) { - final targetTypeElement = targetType.element; + final targetTypeElement = targetType.element3; if (targetTypeElement == null) return null; final annotation = _jsonEnumChecker.firstAnnotationOf(targetTypeElement); final jsonEnum = _fromAnnotation(annotation); diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index b30bc36e..43a78303 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -79,7 +79,7 @@ $converterOrKeyInstructions } else if (field.type != error.type) { message = '$message because of type `${typeToCode(error.type)}`'; } else { - final element = error.type.element?.name; + final element = error.type.element3?.name3; todo = ''' To support the type `${element ?? error.type}` you can: diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 4ab7742b..4d4f0a4c 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -66,7 +66,7 @@ KeyConfig _from(FieldElement2 element, ClassConfig classAnnotation) { // literal, which is NOT supported! badType = 'Function'; } else if (!reader.isLiteral) { - badType = dartObject.type!.element?.name; + badType = dartObject.type!.element3?.name3; } if (badType != null) { @@ -194,7 +194,7 @@ KeyConfig _from(FieldElement2 element, ClassConfig classAnnotation) { (n) => n, ); - return '${annotationType.element!.name}.$enumValueName'; + return '${annotationType.element3!.name3}.$enumValueName'; } else { final defaultValueLiteral = literalForObject(fieldName, objectValue, []); if (defaultValueLiteral == null) { @@ -331,7 +331,7 @@ bool _includeIfNull( bool _interfaceTypesEqual(DartType a, DartType b) { if (a is InterfaceType && b is InterfaceType) { // Handle nullability case. Pretty sure this is fine for enums. - return a.element == b.element; + return a.element3 == b.element3; } return a == b; } diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index dc8a5c2a..00ba9042 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -244,7 +244,7 @@ _JsonConvertData? _typeConverterFrom( if (match.genericTypeArg != null) { return _JsonConvertData.genericClass( - match.annotation.type!.element!.name!, + match.annotation.type!.element3!.name3!, match.genericTypeArg!, reviver.accessor, match.jsonType, @@ -253,7 +253,7 @@ _JsonConvertData? _typeConverterFrom( } return _JsonConvertData.className( - match.annotation.type!.element!.name!, + match.annotation.type!.element3!.name3!, reviver.accessor, match.jsonType, match.fieldType, @@ -291,7 +291,7 @@ _ConverterMatch? _compatibleMatch( return null; } - assert(jsonConverterSuper.element.typeParameters.length == 2); + assert(jsonConverterSuper.element3.typeParameters2.length == 2); assert(jsonConverterSuper.typeArguments.length == 2); final fieldType = jsonConverterSuper.typeArguments[0]; @@ -308,7 +308,7 @@ _ConverterMatch? _compatibleMatch( } if (fieldType is TypeParameterType && targetType is TypeParameterType) { - assert(annotation?.element is! PropertyAccessorElement2); + assert(annotation?.element2 is! PropertyAccessorElement2); assert(converterClassElement.typeParameters2.isNotEmpty); if (converterClassElement.typeParameters2.length > 1) { throw InvalidGenerationSourceError( @@ -323,7 +323,7 @@ _ConverterMatch? _compatibleMatch( annotation, constantValue, jsonConverterSuper.typeArguments[1], - '${targetType.element.name}${targetType.isNullableType ? '?' : ''}', + '${targetType.element3.name3}${targetType.isNullableType ? '?' : ''}', fieldType, ); } diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index 4b9b2621..c2cd52a4 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -157,8 +157,8 @@ List _helperParams( final args = []; for (var helperArg in rest) { - final typeParamIndex = type.element.typeParameters.indexOf( - helperArg.element, + final typeParamIndex = type.element3.typeParameters2.indexOf( + helperArg.element3, ); // TODO: throw here if `typeParamIndex` is -1 ? @@ -181,7 +181,7 @@ TypeParameterType _decodeHelper( type.normalParameterTypes.length == 1) { final funcReturnType = type.returnType; - if (param.name3 == fromJsonForName(funcReturnType.element!.name!)) { + if (param.name3 == fromJsonForName(funcReturnType.element3!.name3!)) { final funcParamType = type.normalParameterTypes.single; if ((funcParamType.isDartCoreObject && funcParamType.isNullableType) || @@ -212,7 +212,7 @@ TypeParameterType _encodeHelper( type.normalParameterTypes.length == 1) { final funcParamType = type.normalParameterTypes.single; - if (param.name3 == toJsonForName(funcParamType.element!.name!)) { + if (param.name3 == toJsonForName(funcParamType.element3!.name3!)) { if (funcParamType is TypeParameterType) { return funcParamType; } @@ -252,7 +252,7 @@ InterfaceType? _instantiate( InterfaceType classType, ) { final argTypes = ctorParamType.typeArguments.map((arg) { - final typeParamIndex = classType.element.typeParameters.indexWhere( + final typeParamIndex = classType.element3.typeParameters2.indexWhere( // TODO: not 100% sure `nullabilitySuffix` is right (e) => e.instantiate(nullabilitySuffix: arg.nullabilitySuffix) == arg, ); @@ -269,7 +269,7 @@ InterfaceType? _instantiate( return null; } - return ctorParamType.element.instantiate( + return ctorParamType.element3.instantiate( typeArguments: argTypes.cast(), nullabilitySuffix: ctorParamType.nullabilitySuffix, ); diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 42dffb9b..f7a014ab 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/constant/value.dart'; -import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; @@ -163,7 +162,7 @@ ConstructorElement2 constructorByName(ClassElement2 classElement, String name) { return ctor; } -/// If [targetType] is an enum, returns the [FieldElement] instances associated +/// If [targetType] is an enum, returns the [FieldElement2] instances associated /// with its values. /// /// Otherwise, `null`. @@ -177,7 +176,7 @@ Iterable? iterateEnumFields(DartType targetType) { extension DartTypeExtension on DartType { DartType promoteNonNullable() => - element?.library?.typeSystem.promoteToNonNull(this) ?? this; + element3?.library2?.typeSystem.promoteToNonNull(this) ?? this; String toStringNonNullable() { final val = getDisplayString(); @@ -209,7 +208,7 @@ String typeToCode(DartType type, {bool forceNullable = false}) { return 'dynamic'; } else if (type is InterfaceType) { return [ - type.element.name, + type.element3.name3, if (type.typeArguments.isNotEmpty) '<${type.typeArguments.map(typeToCode).join(', ')}>', (type.isNullableType || forceNullable) ? '?' : '', @@ -251,7 +250,7 @@ String? defaultDecodeLogic( extension ExecutableElementExtension on ExecutableElement2 { /// Returns the name of `this` qualified with the class name if it's a - /// [MethodElement]. + /// [MethodElement2]. String get qualifiedName { if (this is TopLevelFunctionElement) { return name3!; diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index c32d46ee..06c449b1 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 6.10.0-dev +version: 6.10.0-wip description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -15,7 +15,7 @@ topics: resolution: workspace dependencies: - analyzer: '>=6.9.0 <8.0.0' + analyzer: ^7.4.0 async: ^2.10.0 build: ^3.0.0-dev build_config: ^1.1.0