33// BSD-style license that can be found in the LICENSE file.
44
55import 'package:analyzer/dart/constant/value.dart' ;
6- import 'package:analyzer/dart/element/element.dart' ;
76import 'package:analyzer/dart/element/element2.dart' ;
87import 'package:analyzer/dart/element/type.dart' ;
98import 'package:json_annotation/json_annotation.dart' ;
@@ -17,22 +16,17 @@ const _jsonKeyChecker = TypeChecker.fromRuntime(JsonKey);
1716
1817DartObject ? _jsonKeyAnnotation (FieldElement2 element) =>
1918 _jsonKeyChecker.firstAnnotationOf (element) ??
20- (element.getter2 == null
21- ? null
22- : _jsonKeyChecker.firstAnnotationOf (element.getter2! ));
19+ (element.getter2 == null ? null : _jsonKeyChecker.firstAnnotationOf (element.getter2! ));
2320
24- ConstantReader jsonKeyAnnotation (FieldElement2 element) =>
25- ConstantReader (_jsonKeyAnnotation (element));
21+ ConstantReader jsonKeyAnnotation (FieldElement2 element) => ConstantReader (_jsonKeyAnnotation (element));
2622
2723/// Returns `true` if [element] is annotated with [JsonKey] .
28- bool hasJsonKeyAnnotation (FieldElement2 element) =>
29- _jsonKeyAnnotation (element) != null ;
24+ bool hasJsonKeyAnnotation (FieldElement2 element) => _jsonKeyAnnotation (element) != null ;
3025
31- Never throwUnsupported (FieldElement2 element, String message) =>
32- throw InvalidGenerationSourceError (
33- 'Error with `@JsonKey` on the `${element .name3 }` field. $message ' ,
34- element: element,
35- );
26+ Never throwUnsupported (FieldElement2 element, String message) => throw InvalidGenerationSourceError (
27+ 'Error with `@JsonKey` on the `${element .name3 }` field. $message ' ,
28+ element: element,
29+ );
3630
3731T ? readEnum <T extends Enum >(ConstantReader reader, List <T > values) =>
3832 reader.isNull ? null : enumValueForDartObject <T >(reader.objectValue, values, (f) => f.name);
@@ -69,11 +63,7 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable(
6963/// Note: if [JsonSerializable.genericArgumentFactories] is `false` for [reader]
7064/// and `true` for [config] , the corresponding field in the return value will
7165/// only be `true` if [classElement] has type parameters.
72- ClassConfig mergeConfig (
73- ClassConfig config,
74- ConstantReader reader, {
75- required ClassElement2 classElement,
76- }) {
66+ ClassConfig mergeConfig (ClassConfig config, ConstantReader reader, {required ClassElement2 classElement}) {
7767 final annotation = _valueForAnnotation (reader);
7868 assert (config.ctorParamDefaults.isEmpty);
7969
@@ -104,19 +94,15 @@ ClassConfig mergeConfig(
10494 fieldRename: annotation.fieldRename ?? config.fieldRename,
10595 genericArgumentFactories:
10696 annotation.genericArgumentFactories ??
107- (classElement.typeParameters2.isNotEmpty &&
108- config.genericArgumentFactories),
97+ (classElement.typeParameters2.isNotEmpty && config.genericArgumentFactories),
10998 ignoreUnannotated: annotation.ignoreUnannotated ?? config.ignoreUnannotated,
11099 includeIfNull: annotation.includeIfNull ?? config.includeIfNull,
111100 ctorParamDefaults: paramDefaultValueMap,
112101 converters: converters.isNull ? const [] : converters.listValue,
113102 );
114103}
115104
116- ConstructorElement2 ? _constructorByNameOrNull (
117- ClassElement2 classElement,
118- String name,
119- ) {
105+ ConstructorElement2 ? _constructorByNameOrNull (ClassElement2 classElement, String name) {
120106 try {
121107 return constructorByName (classElement, name);
122108 } on InvalidGenerationSourceError {
@@ -147,20 +133,19 @@ ConstructorElement2 constructorByName(ClassElement2 classElement, String name) {
147133 return ctor;
148134}
149135
150- /// If [targetType] is an enum, returns the [FieldElement ] instances associated
136+ /// If [targetType] is an enum, returns the [FieldElement2 ] instances associated
151137/// with its values.
152138///
153139/// Otherwise, `null` .
154140Iterable <FieldElement2 >? iterateEnumFields (DartType targetType) {
155- if ( /*targetType is InterfaceType && */ targetType.element3
156- is EnumElement2 ) {
141+ if ( /*targetType is InterfaceType && */ targetType.element3 is EnumElement2 ) {
157142 return (targetType.element3 as EnumElement2 ).constants2;
158143 }
159144 return null ;
160145}
161146
162147extension DartTypeExtension on DartType {
163- DartType promoteNonNullable () => element ? .library ? .typeSystem.promoteToNonNull (this ) ?? this ;
148+ DartType promoteNonNullable () => element3 ? .library2 ? .typeSystem.promoteToNonNull (this ) ?? this ;
164149
165150 String toStringNonNullable () {
166151 final val = getDisplayString (withNullability: false );
@@ -190,7 +175,7 @@ String typeToCode(DartType type, {bool forceNullable = false}) {
190175 return 'dynamic' ;
191176 } else if (type is InterfaceType ) {
192177 return [
193- type.element.name ,
178+ type.element3.name3 ,
194179 if (type.typeArguments.isNotEmpty) '<${type .typeArguments .map (typeToCode ).join (', ' )}>' ,
195180 (type.isNullableType || forceNullable) ? '?' : '' ,
196181 ].join ();
@@ -227,7 +212,7 @@ String? defaultDecodeLogic(DartType targetType, String expression, {bool default
227212
228213extension ExecutableElementExtension on ExecutableElement2 {
229214 /// Returns the name of `this` qualified with the class name if it's a
230- /// [MethodElement ] .
215+ /// [MethodElement2 ] .
231216 String get qualifiedName {
232217 if (this is TopLevelFunctionElement ) {
233218 return name3! ;
0 commit comments