Repository: mobxjs/mobx.dart

Issue:
incompatible with build_runner: ^2.6.0
<img width="1115" height="253" alt="Image" src="https://github.com/user-attachments/assets/9a37e86b-84f5-41ba-ad4d-adf26dc5840c" />

latest `build_runner` uses build 3.0.0 which is incompatible with current `mobx_codegen` version
[severe] incompatible to analyzer ^7.0.0
build runner even doesn't start
<img width="1047" alt="Image" src="https://github.com/user-attachments/assets/275173ca-16bd-46e5-bd55-9b7778f67a62" />

maybe related https://github.com/mobxjs/mobx.dart/issues/1036


Discussion: 
Still a problem:

<img width="1044" alt="Image" src="https://github.com/user-attachments/assets/0d743f21-b367-44d1-9bc4-254aad7515e5" />

bump to analyzer ^7.3.0
Bump. With the latest `analyzer: 7.4.5` and `mobx_codegen: 2.7.0` , receiving similar output and messages:

<img width="1407" alt="Image" src="https://github.com/user-attachments/assets/7a7bcec7-038a-458d-a4ba-3f499829ba9e" />

Fix patch:
diff --git a/mobx_codegen/CHANGELOG.md b/mobx_codegen/CHANGELOG.md
index 3f5617c7..746a1336 100644
--- a/mobx_codegen/CHANGELOG.md
+++ b/mobx_codegen/CHANGELOG.md
@@ -1,3 +1,9 @@
+## 2.7.2
+- Update analyzer version to `>=7.4.0 < 8.0.0`
+- Update source_gen version to 3.0.0
+- Update build version to 3.0.0
+- Update build_resolvers version to 3.0.0
+
 ## 2.7.1
 - Update source_gen package to 2.0.0
 - Update analyzer version to `>=6.9.0 < 8.0.0`
diff --git a/mobx_codegen/lib/src/mobx_codegen_base.dart b/mobx_codegen/lib/src/mobx_codegen_base.dart
index 45081939..c8a8898a 100644
--- a/mobx_codegen/lib/src/mobx_codegen_base.dart
+++ b/mobx_codegen/lib/src/mobx_codegen_base.dart
@@ -3,7 +3,7 @@
 
 import 'dart:async';
 
-import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/element2.dart';
 import 'package:analyzer/dart/element/nullability_suffix.dart';
 import 'package:analyzer/dart/element/type_system.dart';
 import 'package:build/build.dart';
@@ -43,7 +43,7 @@ class StoreGenerator extends Generator {
 
   Iterable<String> _generateCodeForMixinStore(
     LibraryReader library,
-    ClassElement baseClass,
+    ClassElement2 baseClass,
     TypeSystem typeSystem,
   ) sync* {
     final typeNameFinder = LibraryScopedNameFinder(library.element);
@@ -52,7 +52,7 @@ class StoreGenerator extends Generator {
       final mixedClass = otherClasses.firstWhere((c) {
         // If our base class has different type parameterization requirements than
         // the class we're evaluating provides, we know it's not a subclass.
-        if (baseClass.typeParameters.length !=
+        if (baseClass.typeParameters2.length !=
             c.supertype!.typeArguments.length) {
           return false;
         }
@@ -68,7 +68,7 @@ class StoreGenerator extends Generator {
       });
 
       yield _generateCodeFromTemplate(
-          mixedClass.name, baseClass, MixinStoreTemplate(), typeNameFinder);
+          mixedClass.name3!, baseClass, MixinStoreTemplate(), typeNameFinder);
       // ignore: avoid_catching_errors
     } on StateError {
       // ignore the case when no element is found
@@ -77,15 +77,15 @@ class StoreGenerator extends Generator {
 
   String _generateCodeFromTemplate(
     String publicTypeName,
-    ClassElement userStoreClass,
+    ClassElement2 userStoreClass,
     StoreTemplate template,
     LibraryScopedNameFinder typeNameFinder,
   ) {
     final visitor = StoreClassVisitor(
         publicTypeName, userStoreClass, template, typeNameFinder, options);
     userStoreClass
-      ..accept(visitor)
-      ..visitChildren(visitor);
+      ..accept2(visitor)
+      ..visitChildren2(visitor);
     return visitor.source;
   }
 }
diff --git a/mobx_codegen/lib/src/store_class_visitor.dart b/mobx_codegen/lib/src/store_class_visitor.dart
index 37b858c7..30f50d86 100644
--- a/mobx_codegen/lib/src/store_class_visitor.dart
+++ b/mobx_codegen/lib/src/store_class_visitor.dart
@@ -1,8 +1,8 @@
 // https://github.com/dart-lang/sdk/blob/main/pkg/analyzer/doc/element_model_migration_guide.md
 // ignore_for_file: deprecated_member_use
 
-import 'package:analyzer/dart/element/element.dart';
-import 'package:analyzer/dart/element/visitor.dart';
+import 'package:analyzer/dart/element/element2.dart';
+import 'package:analyzer/dart/element/visitor2.dart';
 import 'package:build/build.dart';
 import 'package:meta/meta.dart';
 import 'package:mobx/mobx.dart';
@@ -23,19 +23,20 @@ import 'package:mobx_codegen/src/type_names.dart';
 import 'package:mobx_codegen/src/utils/non_private_name_extension.dart';
 import 'package:source_gen/source_gen.dart';
 
-class StoreClassVisitor extends SimpleElementVisitor {
+class StoreClassVisitor extends SimpleElementVisitor2 {
   StoreClassVisitor(
     String publicTypeName,
-    ClassElement userClass,
+    ClassElement2 userClass,
     StoreTemplate template,
     this.typeNameFinder,
     this.options,
   ) : errors = StoreClassCodegenErrors(publicTypeName) {
     _storeTemplate = template
-      ..typeParams.templates.addAll(userClass.typeParameters
+      ..typeParams.templates.addAll(userClass.typeParameters2
           .map((type) => typeParamTemplate(type, typeNameFinder)))
-      ..typeArgs.templates.addAll(userClass.typeParameters.map((t) => t.name))
-      ..parentTypeName = userClass.name
+      ..typeArgs.templates.addAll(
+          userClass.typeParameters2.map((t) => t.name3).whereType<String>())
+      ..parentTypeName = userClass.name3!
       ..publicTypeName = publicTypeName;
   }
 
@@ -56,7 +57,7 @@ class StoreClassVisitor extends SimpleElementVisitor {
   final StoreClassCodegenErrors errors;
 
   @visibleForTesting
-  final publicSettersCache = <PropertyAccessorElement>[];
+  final publicSettersCache = <PropertyAccessorElement2>[];
 
   String get source {
     validate();
@@ -68,24 +69,24 @@ class StoreClassVisitor extends SimpleElementVisitor {
   }
 
   @override
-  void visitClassElement(ClassElement element) {
+  void visitClassElement(ClassElement2 element) {
     if (isMixinStoreClass(element)) {
       errors.nonAbstractStoreMixinDeclarations
-          .addIf(!element.isAbstract, element.name);
+          .addIf(!element.isAbstract, element.name3!);
     }
     // if the class is annotated to generate toString() method we add the information to the _storeTemplate
     _storeTemplate.generateToString = hasGeneratedToString(options, element);
   }
 
   @override
-  void visitFieldElement(FieldElement element) {
+  void visitFieldElement(FieldElement2 element) {
     if (_computedChecker.hasAnnotationOfExact(element)) {
-      errors.invalidComputedAnnotations.addIf(true, element.name);
+      errors.invalidComputedAnnotations.addIf(true, element.name3!);
       return;
     }
 
     if (_actionChecker.hasAnnotationOfExact(element)) {
-      errors.invalidActionAnnotations.addIf(true, element.name);
+      errors.invalidActionAnnotations.addIf(true, element.name3!);
       return;
     }
 
@@ -99,9 +100,9 @@ class StoreClassVisitor extends SimpleElementVisitor {
 
     final template = ObservableTemplate(
       storeTemplate: _storeTemplate,
-      atomName: '_\$${element.name}Atom',
+      atomName: '_\$${element.name3}Atom',
       type: typeNameFinder.findVariableTypeName(element),
-      name: element.name,
+      name: element.name3!,
       isPrivate: element.isPrivate,
       isReadOnly: _isObservableReadOnly(element),
       isLate: element.isLate,
@@ -112,56 +113,64 @@ class StoreClassVisitor extends SimpleElementVisitor {
     return;
   }
 
-  bool _isObservableReadOnly(FieldElement element) =>
+  bool _isObservableReadOnly(FieldElement2 element) =>
       _observableChecker
           .firstAnnotationOfExact(element)
           ?.getField('readOnly')
           ?.toBoolValue() ??
       false;
 
-  ExecutableElement? _getEquals(FieldElement element) => _observableChecker
+  ExecutableElement2? _getEquals(FieldElement2 element) => _observableChecker
       .firstAnnotationOfExact(element)
       ?.getField('equals')
-      ?.toFunctionValue();
+      ?.toFunctionValue2();
 
-  bool _fieldIsNotValid(FieldElement element) => _any([
-        errors.staticObservables.addIf(element.isStatic, element.name),
-        errors.finalObservables.addIf(element.isFinal, element.name),
+  bool _fieldIsNotValid(FieldElement2 element) => _any([
+        errors.staticObservables.addIf(element.isStatic, element.name3!),
+        errors.finalObservables.addIf(element.isFinal, element.name3!),
         errors.invalidReadOnlyAnnotations.addIf(
-          _isObservableReadOnly(element) && element.setter!.isPublic,
-          element.name,
+          _isObservableReadOnly(element) && element.setter2!.isPublic,
+          element.name3!,
         ),
       ]);
 
-  bool? _isComputedKeepAlive(Element element) => _computedChecker
+  bool? _isComputedKeepAlive(Element2 element) => _computedChecker
       .firstAnnotationOfExact(element)
       ?.getField('keepAlive')
       ?.toBoolValue();
 
   @override
-  void visitPropertyAccessorElement(PropertyAccessorElement element) {
-    if (element.isSetter && element.isPublic) {
+  void visitGetterElement(GetterElement element) =>
+      visitPropertyAccessorElement(element);
+
+  @override
+  void visitSetterElement(SetterElement element) =>
+      visitPropertyAccessorElement(element);
+
+  void visitPropertyAccessorElement(PropertyAccessorElement2 element) {
+    if (element is SetterElement && element.isPublic) {
       publicSettersCache.add(element);
     }
 
     if (_observableChecker.hasAnnotationOfExact(element)) {
-      errors.invalidObservableAnnotations.addIf(true, element.name);
+      errors.invalidObservableAnnotations.addIf(true, element.name3!);
       return;
     }
 
     if (_actionChecker.hasAnnotationOfExact(element)) {
-      errors.invalidActionAnnotations.addIf(true, element.name);
+      errors.invalidActionAnnotations.addIf(true, element.name3!);
       return;
     }
 
-    if (!element.isGetter || !_computedChecker.hasAnnotationOfExact(element)) {
+    if (element is! GetterElement ||
+        !_computedChecker.hasAnnotationOfExact(element)) {
       return;
     }
 
     final template = ComputedTemplate(
-        computedName: '_\$${element.name}Computed',
+        computedName: '_\$${element.name3}Computed',
         storeTemplate: _storeTemplate,
-        name: element.name,
+        name: element.name3!,
         type: typeNameFinder.findGetterTypeName(element),
         isPrivate: element.isPrivate,
         isKeepAlive: _isComputedKeepAlive(element));
@@ -171,9 +180,9 @@ class StoreClassVisitor extends SimpleElementVisitor {
   }
 
   @override
-  void visitMethodElement(MethodElement element) {
+  void visitMethodElement(MethodElement2 element) {
     if (_computedChecker.hasAnnotationOfExact(element)) {
-      errors.invalidComputedAnnotations.addIf(true, element.name);
+      errors.invalidComputedAnnotations.addIf(true, element.name3!);
       return;
     }
 
@@ -182,14 +191,14 @@ class StoreClassVisitor extends SimpleElementVisitor {
         return;
       }
 
-      if (element.isAsynchronous) {
+      if (element.fragments.any((fragment) => fragment.isAsynchronous)) {
         final template = AsyncActionTemplate(
           storeTemplate: _storeTemplate,
           isObservable: _observableChecker.hasAnnotationOfExact(element),
           method: MethodOverrideTemplate.fromElement(element, typeNameFinder),
-          hasProtected: element.hasProtected,
-          hasVisibleForOverriding: element.hasVisibleForOverriding,
-          hasVisibleForTesting: element.hasVisibleForTesting,
+          hasProtected: element.metadata2.hasProtected,
+          hasVisibleForOverriding: element.metadata2.hasVisibleForOverriding,
+          hasVisibleForTesting: element.metadata2.hasVisibleForTesting,
         );
 
         _storeTemplate.asyncActions.add(template);
@@ -197,9 +206,9 @@ class StoreClassVisitor extends SimpleElementVisitor {
         final template = ActionTemplate(
           storeTemplate: _storeTemplate,
           method: MethodOverrideTemplate.fromElement(element, typeNameFinder),
-          hasProtected: element.hasProtected,
-          hasVisibleForOverriding: element.hasVisibleForOverriding,
-          hasVisibleForTesting: element.hasVisibleForTesting,
+          hasProtected: element.metadata2.hasProtected,
+          hasVisibleForOverriding: element.metadata2.hasVisibleForOverriding,
+          hasVisibleForTesting: element.metadata2.hasVisibleForTesting,
         );
 
         _storeTemplate.actions.add(template);
@@ -212,18 +221,18 @@ class StoreClassVisitor extends SimpleElementVisitor {
       if (_asyncChecker.returnsFuture(element)) {
         final template = ObservableFutureTemplate(
           method: MethodOverrideTemplate.fromElement(element, typeNameFinder),
-          hasProtected: element.hasProtected,
-          hasVisibleForOverriding: element.hasVisibleForOverriding,
-          hasVisibleForTesting: element.hasVisibleForTesting,
+          hasProtected: element.metadata2.hasProtected,
+          hasVisibleForOverriding: element.metadata2.hasVisibleForOverriding,
+          hasVisibleForTesting: element.metadata2.hasVisibleForTesting,
         );
 
         _storeTemplate.observableFutures.add(template);
       } else if (_asyncChecker.returnsStream(element)) {
         final template = ObservableStreamTemplate(
           method: MethodOverrideTemplate.fromElement(element, typeNameFinder),
-          hasProtected: element.hasProtected,
-          hasVisibleForOverriding: element.hasVisibleForOverriding,
-          hasVisibleForTesting: element.hasVisibleForTesting,
+          hasProtected: element.metadata2.hasProtected,
+          hasVisibleForOverriding: element.metadata2.hasVisibleForOverriding,
+          hasVisibleForTesting: element.metadata2.hasVisibleForTesting,
         );
 
         _storeTemplate.observableStreams.add(template);
@@ -233,18 +242,21 @@ class StoreClassVisitor extends SimpleElementVisitor {
     return;
   }
 
-  bool _asyncObservableIsNotValid(MethodElement method) => _any([
-        errors.staticMethods.addIf(method.isStatic, method.name),
+  bool _asyncObservableIsNotValid(MethodElement2 method) => _any([
+        errors.staticMethods.addIf(method.isStatic, method.name3!),
         errors.nonAsyncMethods.addIf(
             !_asyncChecker.returnsFuture(method) &&
                 !_asyncChecker.returnsStream(method),
-            method.name),
+            method.name3!),
       ]);
 
-  bool _actionIsNotValid(MethodElement element) => _any([
-        errors.staticMethods.addIf(element.isStatic, element.name),
-        errors.asyncGeneratorActions
-            .addIf(element.isAsynchronous && element.isGenerator, element.name),
+  bool _actionIsNotValid(MethodElement2 element) => _any([
+        errors.staticMethods.addIf(element.isStatic, element.name3!),
+        errors.asyncGeneratorActions.addIf(
+          element.fragments.any((fragment) => fragment.isAsynchronous) &&
+              element.fragments.any((fragment) => fragment.isGenerator),
+          element.name3!,
+        ),
       ]);
 
   /// Runs validations after all elements have been visited.
@@ -258,7 +270,7 @@ class StoreClassVisitor extends SimpleElementVisitor {
   }
 
   bool _isInvalidPublicSetterOnReadOnlyObservable(
-          PropertyAccessorElement publicSetter) =>
+          PropertyAccessorElement2 publicSetter) =>
       _storeTemplate.observables.templates.any(
         (template) =>
             template.name.nonPrivateName == publicSetter.displayName &&
@@ -269,14 +281,14 @@ class StoreClassVisitor extends SimpleElementVisitor {
 const _storeMixinChecker = TypeChecker.fromRuntime(Store);
 const _toStringAnnotationChecker = TypeChecker.fromRuntime(StoreConfig);
 
-bool isMixinStoreClass(ClassElement classElement) =>
+bool isMixinStoreClass(ClassElement2 classElement) =>
     classElement.mixins.any(_storeMixinChecker.isExactlyType);
 
 // Checks if the class as a toString annotation
-bool isStoreConfigAnnotatedStoreClass(ClassElement classElement) =>
+bool isStoreConfigAnnotatedStoreClass(ClassElement2 classElement) =>
     _toStringAnnotationChecker.hasAnnotationOfExact(classElement);
 
-bool hasGeneratedToString(BuilderOptions options, ClassElement? classElement) {
+bool hasGeneratedToString(BuilderOptions options, ClassElement2? classElement) {
   const fieldKey = 'hasToString';
 
   if (classElement != null && isStoreConfigAnnotatedStoreClass(classElement)) {
diff --git a/mobx_codegen/lib/src/template/method_override.dart b/mobx_codegen/lib/src/template/method_override.dart
index 8e4d147a..66dccddc 100644
--- a/mobx_codegen/lib/src/template/method_override.dart
+++ b/mobx_codegen/lib/src/template/method_override.dart
@@ -1,4 +1,4 @@
-import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/element2.dart';
 import 'package:mobx_codegen/src/template/comma_list.dart';
 import 'package:mobx_codegen/src/template/params.dart';
 import 'package:mobx_codegen/src/template/util.dart';
@@ -10,31 +10,32 @@ class MethodOverrideTemplate {
 
   MethodOverrideTemplate.fromElement(
     // ignore: deprecated_member_use
-    ExecutableElement method,
+    ExecutableElement2 method,
     LibraryScopedNameFinder typeNameFinder,
   ) {
     // ignore: prefer_function_declarations_over_variables, deprecated_member_use
-    final param = (ParameterElement element) => ParamTemplate(
-        name: element.name,
+    final param = (FormalParameterElement element) => ParamTemplate(
+        name: element.name3!,
         type: typeNameFinder.findParameterTypeName(element),
         defaultValue: element.defaultValueCode,
         hasRequiredKeyword: element.isRequiredNamed);
 
-    final positionalParams = method.parameters
+    final positionalParams = method.formalParameters
         .where((param) => param.isPositional && !param.isOptionalPositional)
         .toList();
 
-    final optionalParams =
-        method.parameters.where((param) => param.isOptionalPositional).toList();
+    final optionalParams = method.formalParameters
+        .where((param) => param.isOptionalPositional)
+        .toList();
 
     final namedParams =
-        method.parameters.where((param) => param.isNamed).toList();
+        method.formalParameters.where((param) => param.isNamed).toList();
 
     this
-      ..name = method.name
+      ..name = method.name3!
       ..returnType = typeNameFinder.findReturnTypeName(method)
       // ignore: deprecated_member_use
-      ..setTypeParams(method.typeParameters
+      ..setTypeParams(method.typeParameters2
           .map((type) => typeParamTemplate(type, typeNameFinder)))
       ..positionalParams = positionalParams.map(param)
       ..optionalParams = optionalParams.map(param)
diff --git a/mobx_codegen/lib/src/template/observable.dart b/mobx_codegen/lib/src/template/observable.dart
index 58dee93a..b75c032c 100644
--- a/mobx_codegen/lib/src/template/observable.dart
+++ b/mobx_codegen/lib/src/template/observable.dart
@@ -1,4 +1,4 @@
-import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/element2.dart';
 import 'package:meta/meta.dart';
 import 'package:mobx_codegen/src/template/store.dart';
 import 'package:mobx_codegen/src/utils/non_private_name_extension.dart';
@@ -24,7 +24,7 @@ class ObservableTemplate {
   final bool isReadOnly;
   final bool isLate;
   // ignore: deprecated_member_use
-  final ExecutableElement? equals;
+  final ExecutableElement2? equals;
   final bool? useDeepEquality;
 
   /// Formats the `name` from `_foo_bar` to `foo_bar`
@@ -66,7 +66,7 @@ class ObservableTemplate {
     $atomName.reportWrite(value, _${name}IsInitialized ? super.$name : null, () {
       super.$name = value;
       _${name}IsInitialized = true;
-    }${equals != null ? ', equals: ${equals!.name}' : ''});
+    }${equals != null ? ', equals: ${equals!.name3}' : ''});
   }''';
     }
 
@@ -75,7 +75,7 @@ class ObservableTemplate {
   set $name($type value) {
     $atomName.reportWrite(value, super.$name, () {
       super.$name = value;
-    }${equals != null ? ', equals: ${equals!.name}' : ''}${useDeepEquality != null ? ', useDeepEquality: $useDeepEquality' : ''});
+    }${equals != null ? ', equals: ${equals!.name3}' : ''}${useDeepEquality != null ? ', useDeepEquality: $useDeepEquality' : ''});
   }''';
   }
 
diff --git a/mobx_codegen/lib/src/template/util.dart b/mobx_codegen/lib/src/template/util.dart
index 2ababff3..5f12c0f6 100644
--- a/mobx_codegen/lib/src/template/util.dart
+++ b/mobx_codegen/lib/src/template/util.dart
@@ -1,5 +1,4 @@
-
-import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/element2.dart';
 import 'package:analyzer/dart/element/type.dart';
 import 'package:mobx_codegen/src/template/params.dart';
 import 'package:mobx_codegen/src/type_names.dart';
@@ -11,7 +10,7 @@ String surroundNonEmpty(String prefix, String suffix, dynamic content) {
   return contentStr.isEmpty ? '' : '$prefix$contentStr$suffix';
 }
 
-const _streamChecker = TypeChecker.fromRuntime(Stream);
+const _streamChecker = TypeChecker.typeNamed(Stream, inSdk: true);
 
 class AsyncMethodChecker {
   AsyncMethodChecker([TypeChecker? checkStream]) {
@@ -21,27 +20,27 @@ class AsyncMethodChecker {
   late TypeChecker _checkStream;
 
   // ignore: deprecated_member_use
-  bool returnsFuture(MethodElement method) =>
+  bool returnsFuture(MethodElement2 method) =>
       method.returnType.isDartAsyncFuture ||
-      (method.isAsynchronous &&
-          !method.isGenerator &&
+      (method.fragments.any((fragment) => fragment.isAsynchronous) &&
+          !method.fragments.any((fragment) => fragment.isGenerator) &&
           method.returnType is DynamicType);
 
   // ignore: deprecated_member_use
-  bool returnsStream(MethodElement method) =>
+  bool returnsStream(MethodElement2 method) =>
       _checkStream.isAssignableFromType(method.returnType) ||
-      (method.isAsynchronous &&
-          method.isGenerator &&
+      (method.fragments.any((fragment) => fragment.isAsynchronous) &&
+          method.fragments.any((fragment) => fragment.isGenerator) &&
           method.returnType is DynamicType);
 }
 
 TypeParamTemplate typeParamTemplate(
   // ignore: deprecated_member_use
-  TypeParameterElement param,
+  TypeParameterElement2 param,
   LibraryScopedNameFinder typeNameFinder,
 ) =>
     TypeParamTemplate(
-        name: param.name,
+        name: param.name3!,
         bound: param.bound != null
             ? typeNameFinder.findTypeParameterBoundsTypeName(param)
             : null);
diff --git a/mobx_codegen/lib/src/type_names.dart b/mobx_codegen/lib/src/type_names.dart
index aa90011f..92d0f0e0 100644
--- a/mobx_codegen/lib/src/type_names.dart
+++ b/mobx_codegen/lib/src/type_names.dart
@@ -1,7 +1,7 @@
 // https://github.com/dart-lang/sdk/blob/main/pkg/analyzer/doc/element_model_migration_guide.md
 // ignore_for_file: deprecated_member_use
 
-import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/element2.dart';
 import 'package:analyzer/dart/element/nullability_suffix.dart';
 import 'package:analyzer/dart/element/type.dart';
 import 'package:mobx_codegen/src/template/comma_list.dart';
@@ -23,53 +23,63 @@ import 'package:mobx_codegen/src/template/comma_list.dart';
 class LibraryScopedNameFinder {
   LibraryScopedNameFinder(this.library);
 
-  final LibraryElement library;
+  final LibraryElement2 library;
 
-  final Map<Element, String?> _namesByElement = {};
+  final Map<Element2, String?> _namesByElement = {};
 
-  Map<Element, String?> get namesByElement {
+  Map<Element2, String?> get namesByElement {
     // Add all of this library's type-defining elements to the name map
-    final libraryElements =
-        library.topLevelElements.whereType<TypeDefiningElement>();
+    final libraryElements = library.children2.whereType<TypeDefiningElement2>();
     for (final element in libraryElements) {
-      _namesByElement[element] = element.name;
+      _namesByElement[element] = element.name3;
     }
 
     // Reverse each import's export namespace so we can map elements to their
-    // library-local names. Note that the definedNames include a prefix if there
-    // is one.
-
-    for (final import in library.definingCompilationUnit.libraryImports) {
-      for (final entry in import.namespace.definedNames.entries) {
-        _namesByElement[entry.value] = entry.key;
+    // library-local names.
+    //
+    // Prior to analyzer 7.4.0, definedNames included the import prefix, but it
+    // no longer does with the new element API. This means we need to construct
+    // it manually.
+
+    final libraryImports = library.fragments
+        .map((fragment) => fragment.libraryImports2)
+        .expand((t) => t);
+
+    for (final import in libraryImports) {
+      final prefix = import.prefix2;
+      for (final entry in import.namespace.definedNames2.entries) {
+        _namesByElement[entry.value] = prefix?.name2 != null
+            // If the prefix exists, we prepend it to the name
+            ? '${prefix!.name2!}.${entry.key}'
+            // Otherwise, we just use the name
+            : entry.key;
       }
     }
 
     return _namesByElement;
   }
 
-  String findVariableTypeName(VariableElement variable) =>
+  String findVariableTypeName(VariableElement2 variable) =>
       _getDartTypeName(variable.type);
 
-  String findGetterTypeName(PropertyAccessorElement getter) {
-    assert(getter.isGetter);
+  String findGetterTypeName(GetterElement getter) {
     return findReturnTypeName(getter);
   }
 
-  String findParameterTypeName(ParameterElement parameter) =>
+  String findParameterTypeName(FormalParameterElement parameter) =>
       _getDartTypeName(parameter.type);
 
-  String findReturnTypeName(FunctionTypedElement executable) =>
+  String findReturnTypeName(FunctionTypedElement2 executable) =>
       _getDartTypeName(executable.returnType);
 
-  List<String?> findReturnTypeArgumentTypeNames(ExecutableElement executable) {
+  List<String?> findReturnTypeArgumentTypeNames(ExecutableElement2 executable) {
     final returnType = executable.returnType;
     return returnType is ParameterizedType
         ? returnType.typeArguments.map(_getDartTypeName).toList()
         : [];
   }
 
-  String? findTypeParameterBoundsTypeName(TypeParameterElement typeParameter) {
+  String? findTypeParameterBoundsTypeName(TypeParameterElement2 typeParameter) {
     assert(typeParameter.bound != null);
     return _getDartTypeName(typeParameter.bound!);
   }
@@ -78,12 +88,12 @@ class LibraryScopedNameFinder {
   ///
   /// The returned string will include import prefixes on all applicable types.
   String _getDartTypeName(DartType type) {
-    var typeElement = type.element;
+    var typeElement = type.element3;
     if (type is FunctionType) {
       // If we're dealing with a typedef, we let it undergo the standard name
       // lookup. Otherwise, we special case the function naming.
-      if (type.alias?.element is TypeAliasElement) {
-        typeElement = type.alias!.element.aliasedElement?.enclosingElement3;
+      if (type.alias?.element2 is TypeAliasElement2) {
+        typeElement = type.alias!.element2;
       } else {
         return _getFunctionTypeName(type);
       }
@@ -95,7 +105,7 @@ class LibraryScopedNameFinder {
       return type.getDisplayString(withNullability: true);
     }
 
-    return _getNamedElementTypeName(typeElement!, type);
+    return _getNamedElementTypeName(typeElement, type);
   }
 
   String _getFunctionTypeName(FunctionType type) {
@@ -120,7 +130,7 @@ class LibraryScopedNameFinder {
     return '$returnTypeName Function($parameterTypeNames)';
   }
 
-  String _getNamedElementTypeName(Element typeElement, DartType type) {
+  String _getNamedElementTypeName(Element2 typeElement, DartType type) {
     // Determine the name of the type, without type arguments.
     assert(namesByElement.containsKey(typeElement));
 
diff --git a/mobx_codegen/lib/version.dart b/mobx_codegen/lib/version.dart
index 1339fd41..ecf58046 100644
--- a/mobx_codegen/lib/version.dart
+++ b/mobx_codegen/lib/version.dart
@@ -1,4 +1,4 @@
 // Generated via set_version.dart. !!!DO NOT MODIFY BY HAND!!!
 
 /// The current version as per `pubspec.yaml`.
-const version = '2.7.1';
+const version = '2.7.2';
diff --git a/mobx_codegen/pubspec.yaml b/mobx_codegen/pubspec.yaml
index 783642b7..1d8aef1b 100644
--- a/mobx_codegen/pubspec.yaml
+++ b/mobx_codegen/pubspec.yaml
@@ -1,6 +1,6 @@
 name: mobx_codegen
 description: Code generator for MobX that adds support for annotating your code with @observable, @computed, @action and also creating Store classes.
-version: 2.7.1
+version: 2.7.2
 
 repository: https://github.com/mobxjs/mobx.dart
 issue_tracker: https://github.com/mobxjs/mobx.dart/issues
@@ -14,17 +14,17 @@ environment:
   sdk: '>=3.0.0 <4.0.0'
 
 dependencies:
-  analyzer: '>=6.9.0 <8.0.0'
-  build: ^2.2.1
-  build_resolvers: ^2.0.6
+  analyzer: '>=7.4.0 <8.0.0'
+  build: ^3.0.0
+  build_resolvers: ^3.0.0
   meta: ^1.3.0
   mobx: ^2.5.0
   path: ^1.8.0
-  source_gen: '>=1.2.1 <3.0.0'
+  source_gen: ^3.0.0
 
 dev_dependencies:
-  build_runner: ^2.4.9
-  build_test: ^2.1.5
+  build_runner: ^2.6.0
+  build_test: ^3.3.0
   coverage: ^1.8.0
   lints: ^5.0.0
   logging: ^1.0.2


Test patch:
diff --git a/mobx_codegen/test/data/invalid_action_multiple_output.txt b/mobx_codegen/test/data/invalid_action_multiple_output.txt
index 640c64ac..75a7132f 100644
--- a/mobx_codegen/test/data/invalid_action_multiple_output.txt
+++ b/mobx_codegen/test/data/invalid_action_multiple_output.txt
@@ -1,2 +1,2 @@
 Could not make class "Test" observable. Changes needed:
-  1. Remove @action annotation for members "lastName" and "firstName". They only apply to methods.
+  1. Remove @action annotation for members "firstName" and "lastName". They only apply to methods.
diff --git a/mobx_codegen/test/store_class_visitor_test.dart b/mobx_codegen/test/store_class_visitor_test.dart
index 4eec4d0f..eba9a900 100644
--- a/mobx_codegen/test/store_class_visitor_test.dart
+++ b/mobx_codegen/test/store_class_visitor_test.dart
@@ -1,4 +1,4 @@
-import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/element2.dart';
 import 'package:build/build.dart';
 import 'package:mobx_codegen/src/store_class_visitor.dart';
 import 'package:mobx_codegen/src/template/observable.dart';
@@ -9,7 +9,8 @@ import 'package:test/test.dart';
 
 class PropertyAccessorElementMock extends Fake
     // ignore: deprecated_member_use
-    implements PropertyAccessorElement {
+    implements
+        PropertyAccessorElement2 {
   PropertyAccessorElementMock(this._displayName);
 
   final String _displayName;
@@ -19,17 +20,17 @@ class PropertyAccessorElementMock extends Fake
 }
 
 // ignore: deprecated_member_use
-class ClassElementMock extends Fake implements ClassElement {
+class ClassElementMock extends Fake implements ClassElement2 {
   ClassElementMock(this._name);
 
   final String _name;
 
   @override
-  String get name => _name;
+  String get name3 => _name;
 
   @override
   // ignore: deprecated_member_use
-  List<TypeParameterElement> get typeParameters => [];
+  List<TypeParameterElement2> get typeParameters2 => [];
 }
 
 class StoreTemplateFake extends StoreTemplate {}
diff --git a/mobx_codegen/test/test_utils.dart b/mobx_codegen/test/test_utils.dart
index b9e12105..b6fd16d9 100644
--- a/mobx_codegen/test/test_utils.dart
+++ b/mobx_codegen/test/test_utils.dart
@@ -20,11 +20,11 @@ class TestInfo {
 const String pkgName = 'generator_sample';
 
 Future<String> generate(String source) async {
-// Recreate generator for each test because we repeatedly create
-// classes with the same name in the same library, which will clash.
+  // Recreate generator for each test because we repeatedly create
+  // classes with the same name in the same library, which will clash.
   final Builder builder = PartBuilder([StoreGenerator()], '.g.dart');
 
-  final srcs = {
+  final sources = {
     '$pkgName|lib/generator_sample.dart': source,
   };
 
@@ -41,28 +41,34 @@ Future<String> generate(String source) async {
     }
   }
 
-  final writer = InMemoryAssetWriter();
-  await testBuilder(builder, srcs,
-      rootPackage: pkgName,
-      reader: await PackageAssetReader.currentIsolate(),
-      writer: writer,
-      onLog: captureError);
-
-  return errors.isNotEmpty
-      ? errors.join('\n')
-      : String.fromCharCodes(
-          writer.assets[AssetId(pkgName, 'lib/generator_sample.g.dart')] ?? []);
+  final readerWriter = TestReaderWriter(rootPackage: pkgName);
+  await readerWriter.testing.loadIsolateSources();
+
+  await testBuilder(builder, sources,
+      rootPackage: pkgName, readerWriter: readerWriter, onLog: captureError);
+
+  if (errors.isNotEmpty) {
+    return errors.join('\n');
+  }
+
+  final assetId = AssetId(pkgName,
+      '.dart_tool/build/generated/generator_sample/lib/generator_sample.g.dart');
+  final assetExists = await readerWriter.canRead(assetId);
+
+  if (!assetExists) {
+    return '';
+  }
+
+  return readerWriter.testing.readString(assetId);
 }
 
 String getFilePath(String filename) {
   final context = path.Context(
       style: Platform.isWindows ? path.Style.windows : path.Style.posix);
   final baseDir = context.dirname(Directory.current.path);
-  var filePath = context.join(baseDir, 'mobx_codegen/test/', filename);
-  filePath = context.fromUri(context.normalize(filePath));
-  filePath = context.fromUri(filePath).split('file:').last;
+  final filePath = context.join(baseDir, 'mobx_codegen', 'test', filename);
 
-  return filePath;
+  return context.normalize(filePath);
 }
 
 Future<String> readFile(String filename) {
diff --git a/mobx_codegen/test/util_test.dart b/mobx_codegen/test/util_test.dart
index 38f4ad07..b24bbc0e 100644
--- a/mobx_codegen/test/util_test.dart
+++ b/mobx_codegen/test/util_test.dart
@@ -1,4 +1,4 @@
-import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/element2.dart';
 import 'package:analyzer/dart/element/type.dart';
 import 'package:mobx_codegen/src/template/util.dart';
 import 'package:mobx_codegen/src/utils/non_private_name_extension.dart';
@@ -9,7 +9,9 @@ import 'package:test/test.dart';
 class MockTypeChecker extends Mock implements TypeChecker {}
 
 // ignore: deprecated_member_use
-class MockMethod extends Mock implements MethodElement {}
+class MockMethod extends Mock implements MethodElement2 {}
+
+class MockMethodFragment extends Mock implements MethodFragment {}
 
 class MockType extends Mock implements DartType {}
 
@@ -31,10 +33,14 @@ MockMethod mockFutureMethod({
   when(() => returnType.isDartAsyncFuture).thenReturn(returnsFuture);
   when(() => returnType.isDartAsyncFutureOr).thenReturn(returnsFutureOr);
 
+  final methodFragment = MockMethodFragment();
+  when(() => methodFragment.isGenerator).thenReturn(isGenerator);
+  when(() => methodFragment.isAsynchronous).thenReturn(isAsync);
+
   final method = MockMethod();
   when(() => method.returnType).thenReturn(returnType);
-  when(() => method.isAsynchronous).thenReturn(isAsync);
-  when(() => method.isGenerator).thenReturn(isGenerator);
+  when(() => method.fragments).thenReturn([methodFragment]);
+
   return method;
 }
 
@@ -50,10 +56,14 @@ MockMethod mockStreamMethod({
     returnType = MockType();
   }
 
+  final mockMethodFragment = MockMethodFragment();
+  when(() => mockMethodFragment.isGenerator).thenReturn(isGenerator);
+  when(() => mockMethodFragment.isAsynchronous).thenReturn(isAsync);
+
   final method = MockMethod();
   when(() => method.returnType).thenReturn(returnType);
-  when(() => method.isAsynchronous).thenReturn(isAsync);
-  when(() => method.isGenerator).thenReturn(isGenerator);
+  when(() => method.fragments).thenReturn([mockMethodFragment]);
+
   return method;
 }