@@ -6,7 +6,7 @@ import 'package:analyzer/dart/analysis/results.dart';
66import 'package:analyzer/dart/analysis/session.dart' ;
77import 'package:analyzer/dart/ast/ast.dart' ;
88import 'package:analyzer/dart/constant/value.dart' ;
9- import 'package:analyzer/dart/element/element2 .dart' ;
9+ import 'package:analyzer/dart/element/element .dart' ;
1010import 'package:analyzer/dart/element/type.dart' ;
1111import 'package:collection/collection.dart' ;
1212import 'package:source_gen/source_gen.dart' ;
@@ -56,7 +56,7 @@ const List<_TypeHelper> _helpers = <_TypeHelper>[
5656
5757/// Checks if has a function that converts string to string, such as encode and decode.
5858bool _isStringToStringFunction (
59- ExecutableElement2 ? executableElement,
59+ ExecutableElement ? executableElement,
6060 String name,
6161) {
6262 if (executableElement == null ) {
@@ -71,9 +71,10 @@ bool _isStringToStringFunction(
7171
7272/// Returns the custom codec for the annotation.
7373String ? _getCustomCodec (ElementAnnotation annotation, String name) {
74- final ExecutableElement2 ? executableElement =
75- // ignore: experimental_member_use
76- annotation.computeConstantValue ()? .getField (name)? .toFunctionValue2 ();
74+ final ExecutableElement ? executableElement = annotation
75+ .computeConstantValue ()
76+ ? .getField (name)
77+ ? .toFunctionValue ();
7778 if (_isStringToStringFunction (executableElement, name)) {
7879 return executableElement! .displayName;
7980 }
@@ -111,7 +112,7 @@ String decodeParameter(
111112 } else {
112113 throw InvalidGenerationSourceError (
113114 'The parameter type '
114- '`${paramType .getDisplayString (withNullability : false )}` not have a well defined CustomParameterCodec decorator.' ,
115+ '`${withoutNullability ( paramType .getDisplayString () )}` not have a well defined CustomParameterCodec decorator.' ,
115116 element: element,
116117 );
117118 }
@@ -141,7 +142,7 @@ String decodeParameter(
141142///
142143/// Otherwise, throws an [InvalidGenerationSourceError] .
143144String encodeField (
144- PropertyAccessorElement2 element,
145+ PropertyAccessorElement element,
145146 List <ElementAnnotation >? metadata,
146147) {
147148 for (final _TypeHelper helper in _helpers) {
@@ -161,7 +162,7 @@ String encodeField(
161162 } else {
162163 throw InvalidGenerationSourceError (
163164 'The parameter type '
164- '`${element .type .getDisplayString (withNullability : false )}` not have a well defined CustomParameterCodec decorator.' ,
165+ '`${withoutNullability ( element .type .getDisplayString () )}` not have a well defined CustomParameterCodec decorator.' ,
165166 element: element,
166167 );
167168 }
@@ -182,18 +183,15 @@ String encodeField(
182183}
183184
184185/// Returns an AstNode type from a InterfaceElement2.
185- T ? getNodeDeclaration <T extends AstNode >(InterfaceElement2 element) {
186+ T ? getNodeDeclaration <T extends AstNode >(InterfaceElement element) {
186187 final AnalysisSession ? session = element.session;
187188 if (session == null ) {
188189 return null ;
189190 }
190191
191192 final parsedLibrary =
192- // ignore: experimental_member_use
193- session.getParsedLibraryByElement2 (element.library2)
194- as ParsedLibraryResult ;
193+ session.getParsedLibraryByElement (element.library) as ParsedLibraryResult ;
195194 final FragmentDeclarationResult ? declaration = parsedLibrary
196- // ignore: experimental_member_use
197195 .getFragmentDeclaration (element.firstFragment);
198196 final AstNode ? node = declaration? .node;
199197
@@ -698,10 +696,9 @@ class _TypeHelperJson extends _TypeHelperWithHelper {
698696 return false ;
699697 }
700698
701- final MethodElement2 ? toJsonMethod = type.lookUpMethod3 (
699+ final MethodElement ? toJsonMethod = type.lookUpMethod (
702700 'toJson' ,
703- // ignore: experimental_member_use
704- type.element3.library2,
701+ type.element.library,
705702 );
706703 if (toJsonMethod == null ||
707704 ! toJsonMethod.isPublic ||
@@ -715,22 +712,21 @@ class _TypeHelperJson extends _TypeHelperWithHelper {
715712 return _matchesType (type.typeArguments.first);
716713 }
717714
718- // ignore: experimental_member_use
719- final ConstructorElement2 ? fromJsonMethod = type.element3
720- . getNamedConstructor2 ( 'fromJson' );
715+ final ConstructorElement ? fromJsonMethod = type.element. getNamedConstructor (
716+ 'fromJson' ,
717+ );
721718
722719 if (fromJsonMethod == null ||
723720 ! fromJsonMethod.isPublic ||
724721 fromJsonMethod.formalParameters.length != 1 ||
725- fromJsonMethod.formalParameters.first.type. getDisplayString (
726- withNullability : false ,
722+ withoutNullability (
723+ fromJsonMethod.formalParameters.first.type. getDisplayString () ,
727724 ) !=
728725 'Map<String, dynamic>' ) {
729726 throw InvalidGenerationSourceError (
730727 'The parameter type '
731- '`${type .getDisplayString (withNullability : false )}` not have a supported fromJson definition.' ,
732- // ignore: experimental_member_use
733- element: type.element3,
728+ '`${withoutNullability (type .getDisplayString ())}` not have a supported fromJson definition.' ,
729+ element: type.element,
734730 );
735731 }
736732
@@ -759,9 +755,9 @@ class _TypeHelperJson extends _TypeHelperWithHelper {
759755
760756 bool _isNestedTemplate (InterfaceType type) {
761757 // check if has fromJson constructor
762- // ignore: experimental_member_use
763- final ConstructorElement2 ? fromJsonMethod = type.element3
764- . getNamedConstructor2 ( 'fromJson' );
758+ final ConstructorElement ? fromJsonMethod = type.element. getNamedConstructor (
759+ 'fromJson' ,
760+ );
765761 if (fromJsonMethod == null || ! fromJsonMethod.isPublic) {
766762 return false ;
767763 }
@@ -778,13 +774,12 @@ class _TypeHelperJson extends _TypeHelperWithHelper {
778774 }
779775
780776 final FormalParameterElement firstParam = parameters[0 ];
781- if (firstParam.type.getDisplayString (withNullability : false ) !=
777+ if (withoutNullability ( firstParam.type.getDisplayString () ) !=
782778 'Map<String, dynamic>' ) {
783779 throw InvalidGenerationSourceError (
784780 'The parameter type '
785- '`${type .getDisplayString (withNullability : false )}` not have a supported fromJson definition.' ,
786- // ignore: experimental_member_use
787- element: type.element3,
781+ '`${withoutNullability (type .getDisplayString ())}` not have a supported fromJson definition.' ,
782+ element: type.element,
788783 );
789784 }
790785
@@ -795,17 +790,14 @@ class _TypeHelperJson extends _TypeHelperWithHelper {
795790 }
796791
797792 final functionType = secondParam.type as FunctionType ;
798- // ignore: experimental_member_use
799793 if (functionType.formalParameters.length != 1 ||
800794 functionType.returnType.getDisplayString () !=
801795 type.element.typeParameters.first.displayName ||
802- // ignore: experimental_member_use
803796 functionType.formalParameters[0 ].type.getDisplayString () != 'Object?' ) {
804797 throw InvalidGenerationSourceError (
805798 'The parameter type '
806- '`${type .getDisplayString (withNullability : false )}` not have a supported fromJson definition.' ,
807- // ignore: experimental_member_use
808- element: type.element3,
799+ '`${withoutNullability (type .getDisplayString ())}` not have a supported fromJson definition.' ,
800+ element: type.element,
809801 );
810802 }
811803
@@ -866,7 +858,7 @@ extension FormalParameterElementExtension on FormalParameterElement {
866858/// An error thrown when a default value is used with a nullable type.
867859class NullableDefaultValueError extends InvalidGenerationSourceError {
868860 /// An error thrown when a default value is used with a nullable type.
869- NullableDefaultValueError (Element2 element)
861+ NullableDefaultValueError (Element element)
870862 : super (
871863 'Default value used with a nullable type. Only non-nullable type can have a default value.' ,
872864 todo: 'Remove the default value or make the type non-nullable.' ,
0 commit comments