1- // ignore_for_file: deprecated_member_use
2-
3- import 'package:analyzer/dart/element/element2.dart' ;
1+ import 'package:analyzer/dart/element/element.dart' ;
42import 'package:build/build.dart' ;
53import 'package:luthor/luthor.dart' ;
64import 'package:luthor_generator/checkers.dart' ;
@@ -10,33 +8,33 @@ import 'package:source_gen/source_gen.dart';
108class LuthorGenerator extends GeneratorForAnnotation <Luthor > {
119 @override
1210 String generateForAnnotatedElement (
13- Element2 element,
11+ Element element,
1412 ConstantReader annotation,
1513 BuildStep buildStep,
1614 ) {
1715 // Reset the generation context for each annotated element
1816 GenerationContext .reset ();
19- if (element is ! ClassElement2 ) {
17+ if (element is ! ClassElement ) {
2018 throw InvalidGenerationSourceError (
2119 'Luthor can only be applied to classes.' ,
2220 element: element,
2321 );
2422 }
2523
26- if (element.constructors2 .isEmpty) {
24+ if (element.constructors .isEmpty) {
2725 throw InvalidGenerationSourceError (
2826 'Luthor can only be applied to classes with at least one constructor.' ,
2927 element: element,
3028 );
3129 }
3230
33- final name = element.name3 ;
34- final constructor = element.constructors2 .first;
31+ final name = element.name ;
32+ final constructor = element.constructors .first;
3533
3634 final isDartMappableClass =
3735 getAnnotation (dartMappableChecker, element) != null ;
38- final hasFromJsonCtor = element.constructors2 .any (
39- (element) => element.isFactory && element.name3 == 'fromJson' ,
36+ final hasFromJsonCtor = element.constructors .any (
37+ (element) => element.isFactory && element.name == 'fromJson' ,
4038 );
4139 if (! hasFromJsonCtor && ! isDartMappableClass) {
4240 throw InvalidGenerationSourceError (
@@ -57,7 +55,7 @@ class LuthorGenerator extends GeneratorForAnnotation<Luthor> {
5755 );
5856
5957 for (final param in params) {
60- final fieldName = param.name3 ! ;
58+ final fieldName = param.name ;
6159 buffer.write (" ${name }SchemaKeys.$fieldName : " );
6260 buffer.write (getValidations (param, enclosingClass: element));
6361 buffer.write (',\n ' );
@@ -119,7 +117,7 @@ class LuthorGenerator extends GeneratorForAnnotation<Luthor> {
119117 void _writeSchemaKeysRecord (
120118 StringBuffer buffer,
121119 String name,
122- ConstructorElement2 constructor,
120+ ConstructorElement constructor,
123121 ) {
124122 buffer.write ('\n\n ' );
125123
@@ -128,7 +126,7 @@ class LuthorGenerator extends GeneratorForAnnotation<Luthor> {
128126 buffer.write ('const ${name }SchemaKeys = (\n ' );
129127
130128 for (final param in constructor.formalParameters) {
131- final fieldName = _getRecordFieldName (param.name3 ! );
129+ final fieldName = _getRecordFieldName (param.name ! );
132130 final jsonKeyName = _getJsonKeyName (param);
133131 buffer.write (' $fieldName : "$jsonKeyName ",\n ' );
134132 }
@@ -139,7 +137,7 @@ class LuthorGenerator extends GeneratorForAnnotation<Luthor> {
139137 void _writeErrorKeysRecord (
140138 StringBuffer buffer,
141139 String name,
142- ConstructorElement2 constructor,
140+ ConstructorElement constructor,
143141 ) {
144142 buffer.write ('\n\n ' );
145143
@@ -165,15 +163,15 @@ class LuthorGenerator extends GeneratorForAnnotation<Luthor> {
165163 Set <String > visitedTypes,
166164 ) {
167165 for (final param in parameters) {
168- final fieldName = _getRecordFieldName (param.name3 ! );
166+ final fieldName = _getRecordFieldName (param.name ! );
169167 final jsonKeyName = _getJsonKeyName (param);
170168 final fullKey = prefix.isEmpty ? jsonKeyName : '$prefix .$jsonKeyName ' ;
171169 final isNestedSchema = _isNestedSchema (param);
172170
173171 if (isNestedSchema) {
174172 final nestedClass = _getNestedClassElement (param);
175173 if (nestedClass != null ) {
176- final className = nestedClass.name3 ! ;
174+ final className = nestedClass.name ! ;
177175
178176 // Check for circular reference
179177 if (visitedTypes.contains (className)) {
@@ -185,7 +183,7 @@ class LuthorGenerator extends GeneratorForAnnotation<Luthor> {
185183 buffer.write ('$indent $fieldName : (\n ' );
186184 _writeErrorKeysValues (
187185 buffer,
188- nestedClass.constructors2 .first.formalParameters,
186+ nestedClass.constructors .first.formalParameters,
189187 '$indent ' ,
190188 fullKey,
191189 visitedTypes,
@@ -210,26 +208,26 @@ class LuthorGenerator extends GeneratorForAnnotation<Luthor> {
210208 .firstAnnotationOf (param)
211209 ? .getField ('name' )
212210 ? .toStringValue ();
213- return jsonKeyName ?? param.name3 ! ;
211+ return jsonKeyName ?? param.name ! ;
214212 }
215213
216214 bool _isNestedSchema (FormalParameterElement param) {
217- final element = param.type.element3 ;
215+ final element = param.type.element ;
218216 if (element == null ) return false ;
219217
220218 final hasLuthorAnnotation = getAnnotation (luthorChecker, element) != null ;
221219 if (hasLuthorAnnotation) return true ;
222220
223- if (element is ClassElement2 && isCompatibleForAutoGeneration (element)) {
221+ if (element is ClassElement && isCompatibleForAutoGeneration (element)) {
224222 return true ;
225223 }
226224
227225 return false ;
228226 }
229227
230- ClassElement2 ? _getNestedClassElement (FormalParameterElement param) {
231- final element = param.type.element3 ;
232- if (element is ClassElement2 ) {
228+ ClassElement ? _getNestedClassElement (FormalParameterElement param) {
229+ final element = param.type.element ;
230+ if (element is ClassElement ) {
233231 final hasLuthorAnnotation = getAnnotation (luthorChecker, element) != null ;
234232 if (hasLuthorAnnotation || isCompatibleForAutoGeneration (element)) {
235233 return element;
@@ -239,8 +237,8 @@ class LuthorGenerator extends GeneratorForAnnotation<Luthor> {
239237 }
240238
241239 /// Generates schema for a compatible class
242- String _generateAutoSchema (ClassElement2 element, String className) {
243- final constructor = element.constructors2 .first;
240+ String _generateAutoSchema (ClassElement element, String className) {
241+ final constructor = element.constructors .first;
244242 final isDartMappableClass =
245243 getAnnotation (dartMappableChecker, element) != null ;
246244
@@ -255,7 +253,7 @@ class LuthorGenerator extends GeneratorForAnnotation<Luthor> {
255253 );
256254
257255 for (final param in constructor.formalParameters) {
258- final fieldName = param.name3 ! ;
256+ final fieldName = param.name ! ;
259257 buffer.write (" ${className }SchemaKeys.$fieldName : " );
260258 buffer.write (getValidations (param, enclosingClass: element));
261259 buffer.write (',\n ' );
@@ -285,7 +283,7 @@ class LuthorGenerator extends GeneratorForAnnotation<Luthor> {
285283 final currentClass = GenerationContext .discoveredClasses.first;
286284 GenerationContext .discoveredClasses.remove (currentClass);
287285
288- final className = currentClass.name3 ! ;
286+ final className = currentClass.name ! ;
289287
290288 // Skip if already processed
291289 if (processedClasses.contains (className)) {
0 commit comments