Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions json_serializable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
6 changes: 3 additions & 3 deletions json_serializable/lib/src/enum_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
///
Expand Down Expand Up @@ -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();
Expand All @@ -57,7 +57,7 @@ Map<FieldElement2, Object?>? _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);
Expand Down
2 changes: 1 addition & 1 deletion json_serializable/lib/src/helper_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions json_serializable/lib/src/json_key_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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];
Expand All @@ -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(
Expand All @@ -323,7 +323,7 @@ _ConverterMatch? _compatibleMatch(
annotation,
constantValue,
jsonConverterSuper.typeArguments[1],
'${targetType.element.name}${targetType.isNullableType ? '?' : ''}',
'${targetType.element3.name3}${targetType.isNullableType ? '?' : ''}',
fieldType,
);
}
Expand Down
12 changes: 6 additions & 6 deletions json_serializable/lib/src/type_helpers/json_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ List<String> _helperParams(
final args = <String>[];

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 ?
Expand All @@ -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) ||
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
);
Expand All @@ -269,7 +269,7 @@ InterfaceType? _instantiate(
return null;
}

return ctorParamType.element.instantiate(
return ctorParamType.element3.instantiate(
typeArguments: argTypes.cast<DartType>(),
nullabilitySuffix: ctorParamType.nullabilitySuffix,
);
Expand Down
9 changes: 4 additions & 5 deletions json_serializable/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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`.
Expand All @@ -177,7 +176,7 @@ Iterable<FieldElement2>? 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();
Expand Down Expand Up @@ -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) ? '?' : '',
Expand Down Expand Up @@ -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!;
Expand Down
4 changes: 2 additions & 2 deletions json_serializable/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down