Version 3.6.0-206.0.dev

Merge 8de1422a0e4f5566da39de9631689390e4edb144 into dev
diff --git a/pkg/analysis_server/lib/src/cider/local_library_contributor.dart b/pkg/analysis_server/lib/src/cider/local_library_contributor.dart
index 1ad1223..a4fca61 100644
--- a/pkg/analysis_server/lib/src/cider/local_library_contributor.dart
+++ b/pkg/analysis_server/lib/src/cider/local_library_contributor.dart
@@ -95,7 +95,7 @@
     if (element.isOperator) {
       return;
     }
-    if (element.enclosingElement is! CompilationUnitElement) {
+    if (element.enclosingElement3 is! CompilationUnitElement) {
       return;
     }
     var returnType = element.returnType;
@@ -134,7 +134,7 @@
         (opType.includeAnnotationSuggestions &&
             variable != null &&
             variable.isConst)) {
-      var parent = element.enclosingElement;
+      var parent = element.enclosingElement3;
       if (parent is InterfaceElement || parent is ExtensionElement) {
         if (element.isSynthetic) {
           if (element.isGetter) {
diff --git a/pkg/analysis_server/lib/src/cider/rename.dart b/pkg/analysis_server/lib/src/cider/rename.dart
index 781501e..4da587a 100644
--- a/pkg/analysis_server/lib/src/cider/rename.dart
+++ b/pkg/analysis_server/lib/src/cider/rename.dart
@@ -66,7 +66,7 @@
 
   void _analyzePossibleConflicts(
       ConstructorElement element, RefactoringStatus result, String newName) {
-    var parentClass = element.enclosingElement;
+    var parentClass = element.enclosingElement3;
     // Check if the "newName" is the name of the enclosing class.
     if (parentClass.name == newName) {
       result.addError('The constructor should not have the same name '
@@ -254,8 +254,8 @@
     var stateName = flutterState.newName;
     var match = await canRename._fileResolver.findReferences2(stateClass);
     var sourcePath = stateClass.source.fullName;
-    var location =
-        stateClass.enclosingElement.lineInfo.getLocation(stateClass.nameOffset);
+    var location = stateClass.enclosingElement3.lineInfo
+        .getLocation(stateClass.nameOffset);
     CiderSearchMatch ciderMatch;
     var searchInfo =
         CiderSearchInfo(location, stateClass.nameLength, MatchKind.DECLARATION);
@@ -297,7 +297,7 @@
 
   Future<CiderReplaceMatch?> _replaceSyntheticConstructor() async {
     var element = canRename.refactoringElement.element;
-    var interfaceElement = element.enclosingElement;
+    var interfaceElement = element.enclosingElement3;
 
     var fileResolver = canRename._fileResolver;
     var libraryPath = interfaceElement!.library!.source.fullName;
@@ -382,7 +382,7 @@
   }
 
   bool _canRenameElement(Element element) {
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     if (element is ConstructorElement) {
       return true;
     }
diff --git a/pkg/analysis_server/lib/src/computer/computer_call_hierarchy.dart b/pkg/analysis_server/lib/src/computer/computer_call_hierarchy.dart
index 3c4c683..7d9bb02 100644
--- a/pkg/analysis_server/lib/src/computer/computer_call_hierarchy.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_call_hierarchy.dart
@@ -106,7 +106,7 @@
         codeRange = _codeRangeForElement(element),
         file = element.source!.fullName,
         kind = CallHierarchyKind.forElement(element) {
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     var container =
         enclosingElement != null ? _getContainer(enclosingElement) : null;
     containerName = container != null ? _getDisplayName(container) : null;
diff --git a/pkg/analysis_server/lib/src/computer/computer_color.dart b/pkg/analysis_server/lib/src/computer/computer_color.dart
index 1a72c03..5d78069 100644
--- a/pkg/analysis_server/lib/src/computer/computer_color.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_color.dart
@@ -74,7 +74,7 @@
 
     var constructor = expression.constructorName;
     var staticElement = constructor.staticElement;
-    var classElement = staticElement?.enclosingElement;
+    var classElement = staticElement?.enclosingElement3;
     var className = classElement?.name;
     var constructorName = constructor.name?.name;
     var constructorArgs = expression.argumentList.arguments
diff --git a/pkg/analysis_server/lib/src/computer/computer_highlights.dart b/pkg/analysis_server/lib/src/computer/computer_highlights.dart
index b444474..7ba7268 100644
--- a/pkg/analysis_server/lib/src/computer/computer_highlights.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_highlights.dart
@@ -332,7 +332,7 @@
     var isInvocation =
         parent is MethodInvocation && parent.methodName.token == nameToken;
     HighlightRegionType type;
-    var isTopLevel = element.enclosingElement is CompilationUnitElement;
+    var isTopLevel = element.enclosingElement3 is CompilationUnitElement;
     type = isTopLevel
         ? isInvocation
             ? HighlightRegionType.TOP_LEVEL_FUNCTION_REFERENCE
@@ -357,7 +357,7 @@
       return false;
     }
     // getter or setter
-    var isTopLevel = element.enclosingElement is CompilationUnitElement;
+    var isTopLevel = element.enclosingElement3 is CompilationUnitElement;
     HighlightRegionType type;
     if (element.isGetter) {
       if (isTopLevel) {
diff --git a/pkg/analysis_server/lib/src/computer/computer_hover.dart b/pkg/analysis_server/lib/src/computer/computer_hover.dart
index d890070..f52d99c 100644
--- a/pkg/analysis_server/lib/src/computer/computer_hover.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_hover.dart
@@ -74,7 +74,7 @@
         hover.elementKind = element.kind.displayName;
         hover.isDeprecated = element.hasDeprecated;
         // not local element
-        if (element.enclosingElement is! ExecutableElement) {
+        if (element.enclosingElement3 is! ExecutableElement) {
           // containing class
           hover.containingClassDescription = _containingClass(element);
           // containing library
@@ -267,7 +267,7 @@
   /// incorrect types to be shown and so we stick with the synthetic getter.
   bool _useNonSyntheticElement(Element element) {
     return element is PropertyAccessorElement &&
-        !(element.enclosingElement is EnumElement &&
+        !(element.enclosingElement3 is EnumElement &&
             element.name == 'values' &&
             element.isSynthetic);
   }
@@ -282,7 +282,7 @@
       element = element.field;
     }
     if (element is ParameterElement) {
-      element = element.enclosingElement;
+      element = element.enclosingElement3;
     }
     if (element == null) {
       // This can happen when the code is invalid, such as having a field formal
@@ -330,9 +330,9 @@
     var result =
         dartdocInfo.processDartdoc(rawDoc, includeSummary: includeSummary);
 
-    var documentedElementClass = documentedElement.enclosingElement;
+    var documentedElementClass = documentedElement.enclosingElement3;
     if (documentedElementClass != null &&
-        documentedElementClass != element.enclosingElement) {
+        documentedElementClass != element.enclosingElement3) {
       var documentedClass = documentedElementClass.displayName;
       result.full = '${result.full}\n\nCopied from `$documentedClass`.';
     }
diff --git a/pkg/analysis_server/lib/src/computer/computer_outline.dart b/pkg/analysis_server/lib/src/computer/computer_outline.dart
index ba996ed..00e39d7 100644
--- a/pkg/analysis_server/lib/src/computer/computer_outline.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_outline.dart
@@ -550,7 +550,7 @@
   /// Return `true` if the given [element] is a top-level member of the test
   /// package.
   bool _isInsideTestPackage(engine.FunctionElement element) {
-    var parent = element.enclosingElement;
+    var parent = element.enclosingElement3;
     return parent is engine.CompilationUnitElement &&
         parent.source.fullName.endsWith('test.dart');
   }
diff --git a/pkg/analysis_server/lib/src/computer/computer_overrides.dart b/pkg/analysis_server/lib/src/computer/computer_overrides.dart
index 94094a2..31fefef 100644
--- a/pkg/analysis_server/lib/src/computer/computer_overrides.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_overrides.dart
@@ -10,7 +10,7 @@
 
 /// Return the elements that the given [element] overrides.
 OverriddenElements findOverriddenElements(Element element) {
-  if (element.enclosingElement is InterfaceElement) {
+  if (element.enclosingElement3 is InterfaceElement) {
     return _OverriddenElementsFinder(element).find();
   }
   return OverriddenElements(element, <Element>[], <Element>[]);
@@ -110,7 +110,7 @@
   final Set<InterfaceElement> _visited = {};
 
   factory _OverriddenElementsFinder(Element seed) {
-    var class_ = seed.enclosingElement as InterfaceElement;
+    var class_ = seed.enclosingElement3 as InterfaceElement;
     var library = class_.library;
     var name = seed.displayName;
     List<ElementKind> kinds;
diff --git a/pkg/analysis_server/lib/src/computer/imported_elements_computer.dart b/pkg/analysis_server/lib/src/computer/imported_elements_computer.dart
index 08c7610..73b87ad 100644
--- a/pkg/analysis_server/lib/src/computer/imported_elements_computer.dart
+++ b/pkg/analysis_server/lib/src/computer/imported_elements_computer.dart
@@ -112,7 +112,10 @@
     if (element == null) {
       return;
     }
-    if (element.enclosingElement is! CompilationUnitElement) {
+    if (element is PrefixElement) {
+      return;
+    }
+    if (element.enclosingElement3 is! CompilationUnitElement) {
       return;
     }
 
diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_definition.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_definition.dart
index 90742d8..ef58e23 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/handler_definition.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_definition.dart
@@ -188,7 +188,7 @@
     // the parameters / representation type but we want the whole declaration
     // for the code range because otherwise previews will just show `(int a)`
     // which is not what the user expects.
-    if (codeElement.enclosingElement case ExtensionTypeElement enclosingElement
+    if (codeElement.enclosingElement3 case ExtensionTypeElement enclosingElement
         when enclosingElement.primaryConstructor == codeElement) {
       codeElement = enclosingElement;
     }
diff --git a/pkg/analysis_server/lib/src/protocol_server.dart b/pkg/analysis_server/lib/src/protocol_server.dart
index 56addc5..e575e3fe 100644
--- a/pkg/analysis_server/lib/src/protocol_server.dart
+++ b/pkg/analysis_server/lib/src/protocol_server.dart
@@ -245,7 +245,7 @@
 /// Construct based on an element from the analyzer engine.
 OverriddenMember newOverriddenMember_fromEngine(engine.Element member) {
   var element = convertElement(member);
-  var className = member.enclosingElement!.displayName;
+  var className = member.enclosingElement3!.displayName;
   return OverriddenMember(element, className);
 }
 
@@ -305,9 +305,8 @@
     return element;
   }
 
-  var enclosingElement = element.enclosingElement;
-  if (enclosingElement is engine.LibraryElement) {
-    element = enclosingElement;
+  if (element.enclosingElement3 case engine.LibraryElement enclosing) {
+    return enclosing.definingCompilationUnit;
   }
 
   if (element is engine.LibraryElement) {
diff --git a/pkg/analysis_server/lib/src/search/element_references.dart b/pkg/analysis_server/lib/src/search/element_references.dart
index 150484d..683120e 100644
--- a/pkg/analysis_server/lib/src/search/element_references.dart
+++ b/pkg/analysis_server/lib/src/search/element_references.dart
@@ -97,6 +97,6 @@
     if (element is ConstructorElement) {
       return false;
     }
-    return element.enclosingElement is InterfaceElement;
+    return element.enclosingElement3 is InterfaceElement;
   }
 }
diff --git a/pkg/analysis_server/lib/src/search/type_hierarchy.dart b/pkg/analysis_server/lib/src/search/type_hierarchy.dart
index cb5d5c2..1e67981 100644
--- a/pkg/analysis_server/lib/src/search/type_hierarchy.dart
+++ b/pkg/analysis_server/lib/src/search/type_hierarchy.dart
@@ -159,10 +159,10 @@
     bool pivotFieldFinal = false;
     if (pivotElement is FieldElement) {
       pivotFieldFinal = pivotElement.isFinal;
-      element = pivotElement.enclosingElement;
+      element = pivotElement.enclosingElement3;
     }
     if (pivotElement is ExecutableElement) {
-      element = pivotElement.enclosingElement;
+      element = pivotElement.enclosingElement3;
     }
     InterfaceElement? pivotClass;
     if (element is InterfaceElement) {
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/candidate_suggestion.dart b/pkg/analysis_server/lib/src/services/completion/dart/candidate_suggestion.dart
index fdd84d8..83cc29a 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/candidate_suggestion.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/candidate_suggestion.dart
@@ -188,7 +188,7 @@
 
   @override
   String get completion {
-    var enclosingClass = element.enclosingElement.augmented.declaration;
+    var enclosingClass = element.enclosingElement3.augmented.declaration;
 
     var className = enclosingClass.name;
 
@@ -234,7 +234,7 @@
   @override
   String get completion {
     if (includeEnumName) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       return '$completionPrefix${enclosingElement.name}.${element.name}';
     } else {
       return element.name;
@@ -596,7 +596,7 @@
     var inheritanceDistance = 0.0;
     var element = this.element;
     if (!(element is FieldElement && element.isEnumConstant)) {
-      var declaringClass = element.enclosingElement;
+      var declaringClass = element.enclosingElement3;
       var referencingInterface = this.referencingInterface;
       if (referencingInterface != null && declaringClass is InterfaceElement) {
         inheritanceDistance = featureComputer.inheritanceDistanceFeature(
@@ -754,7 +754,7 @@
   /// The enclosing element must be either a class, or extension; otherwise
   /// we either fail with assertion, or return `null`.
   String? get _enclosingClassOrExtensionName {
-    var enclosing = element.enclosingElement;
+    var enclosing = element.enclosingElement3;
     if (enclosing is InterfaceElement) {
       return enclosing.name;
     } else if (enclosing is ExtensionElement) {
@@ -900,7 +900,7 @@
 
   @override
   String get completion {
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     return '$completionPrefix${enclosingElement.name}.${element.name}';
   }
 }
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart b/pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart
index ed1399f..ec94750 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart
@@ -227,7 +227,7 @@
   /// be skipped because the cursor is inside that field's name.
   void addFieldsForInitializers(
       ConstructorDeclaration constructor, FieldElement? fieldToInclude) {
-    var containingElement = constructor.declaredElement?.enclosingElement;
+    var containingElement = constructor.declaredElement?.enclosingElement3;
     if (containingElement == null) {
       return;
     }
@@ -554,7 +554,7 @@
   void addPossibleRedirectionsInLibrary(
       ConstructorElement redirectingConstructor, LibraryElement library) {
     var classElement =
-        redirectingConstructor.enclosingElement.augmented.declaration;
+        redirectingConstructor.enclosingElement3.augmented.declaration;
     var classType = classElement.thisType;
     var typeSystem = library.typeSystem;
     for (var unit in library.units) {
@@ -1273,7 +1273,7 @@
               (containingElement is EnumElement && field.name == 'values')) &&
           field.isVisibleIn(request.libraryElement)) {
         if (field.isEnumConstant) {
-          var enumElement = field.enclosingElement;
+          var enumElement = field.enclosingElement3;
           var matcherScore =
               state.matcher.score('${enumElement.name}.${field.name}');
           if (matcherScore != -1) {
@@ -1379,7 +1379,7 @@
     }
 
     if (element.isProtected) {
-      var elementInterface = element.enclosingElement;
+      var elementInterface = element.enclosingElement3;
       if (elementInterface is! InterfaceElement) {
         return false;
       }
@@ -1486,7 +1486,7 @@
     }
     if (importData?.isNotImported ?? false) {
       if (!visibilityTracker.isVisible(
-          element: element.enclosingElement, importData: importData)) {
+          element: element.enclosingElement3, importData: importData)) {
         // If the constructor is on a class from a not-yet-imported library and
         // the class isn't visible, then we shouldn't suggest it.
         //
@@ -1500,7 +1500,7 @@
       // Add the class to the visibility tracker so that we will know later that
       // any non-imported elements with the same name are not visible.
       visibilityTracker.isVisible(
-          element: element.enclosingElement, importData: importData);
+          element: element.enclosingElement3, importData: importData);
     }
 
     // TODO(keertip): Compute the completion string.
@@ -1715,7 +1715,7 @@
       }
       var matcherScore = state.matcher.score(method.displayName);
       if (matcherScore != -1) {
-        var enclosingElement = method.enclosingElement;
+        var enclosingElement = method.enclosingElement3;
         if (method.name == 'setState' &&
             enclosingElement is ClassElement &&
             enclosingElement.isExactState) {
@@ -1857,7 +1857,7 @@
         request.libraryElement.typeSystem
             .isSubtypeOf(element.type, contextType)) {
       if (element.isEnumConstant) {
-        var enumElement = element.enclosingElement;
+        var enumElement = element.enclosingElement3;
         var matcherScore = state.matcher
             .score('${enumElement.displayName}.${element.displayName}');
         if (matcherScore != -1) {
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/relevance_computer.dart b/pkg/analysis_server/lib/src/services/completion/dart/relevance_computer.dart
index 0f74ba0..9fdddb8 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/relevance_computer.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/relevance_computer.dart
@@ -324,7 +324,7 @@
   /// Compute the relevance for [ConstructorElement].
   int _computeConstructorRelevance(ConstructorElement element,
       NeverType neverType, bool isNotImportedLibrary) {
-    var enclosingClass = element.enclosingElement.augmented.declaration;
+    var enclosingClass = element.enclosingElement3.augmented.declaration;
     var returnType = instantiateInstanceElement(enclosingClass, neverType);
     return computeTopLevelRelevance(element,
         elementType: returnType, isNotImportedLibrary: isNotImportedLibrary);
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart b/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart
index 89cd3b7..1b4d168 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart
@@ -254,7 +254,7 @@
     // If the class name is already in the text, then we don't support
     // prepending a prefix.
     assert(!hasClassName || prefix == null);
-    var enclosingClass = constructor.enclosingElement.augmented.declaration;
+    var enclosingClass = constructor.enclosingElement3.augmented.declaration;
 
     if (completion == null) {
       var className = enclosingClass.name;
@@ -307,10 +307,10 @@
     } else if (element is ExtensionElement) {
       suggestExtension(element, kind: kind);
     } else if (element is FunctionElement &&
-        element.enclosingElement is CompilationUnitElement) {
+        element.enclosingElement3 is CompilationUnitElement) {
       suggestTopLevelFunction(element, kind: kind);
     } else if (element is PropertyAccessorElement &&
-        element.enclosingElement is CompilationUnitElement) {
+        element.enclosingElement3 is CompilationUnitElement) {
       suggestTopLevelPropertyAccessor(element);
     } else if (element is TypeAliasElement) {
       suggestTypeAlias(element);
@@ -324,7 +324,7 @@
   void suggestEnumConstant(FieldElement constant,
       {String? prefix, int? relevance}) {
     var constantName = constant.name;
-    var enumElement = constant.enclosingElement;
+    var enumElement = constant.enclosingElement3;
     var enumName = enumElement.name;
     var completion = '$enumName.$constantName';
     relevance ??= relevanceComputer.computeTopLevelRelevance(constant,
@@ -655,10 +655,10 @@
 
     // Optionally add Flutter child widget details.
     // TODO(pq): revisit this special casing; likely it can be generalized away.
-    var element = parameter.enclosingElement;
+    var element = parameter.enclosingElement3;
     // If `appendColon` is false, default values should never be appended.
     if (element is ConstructorElement && appendColon) {
-      if (element.enclosingElement.augmented.declaration.isWidget) {
+      if (element.enclosingElement3.augmented.declaration.isWidget) {
         var analysisOptions = request.analysisSession.analysisContext
             .getAnalysisOptionsForFile(
                 request.resourceProvider.getFile(request.path));
@@ -974,9 +974,9 @@
   void suggestTopLevelPropertyAccessor(PropertyAccessorElement accessor,
       {String? prefix, int? relevance}) {
     assert(
-        accessor.enclosingElement is CompilationUnitElement,
+        accessor.enclosingElement3 is CompilationUnitElement,
         'Enclosing element of ${accessor.runtimeType} is '
-        '${accessor.enclosingElement.runtimeType}.');
+        '${accessor.enclosingElement3.runtimeType}.');
     if (accessor.isSynthetic) {
       // Avoid visiting a field twice. All fields induce a getter, but only
       // non-final fields induce a setter, so we don't add a suggestion for a
@@ -1033,7 +1033,7 @@
     var completion = _getCompletionString(variable);
     if (completion == null) return;
     if (_couldMatch(completion, prefix)) {
-      assert(variable.enclosingElement is CompilationUnitElement);
+      assert(variable.enclosingElement3 is CompilationUnitElement);
       relevance ??= relevanceComputer.computeTopLevelRelevance(variable,
           elementType: variable.type,
           isNotImportedLibrary: isNotImportedLibrary);
@@ -1115,7 +1115,7 @@
           // `InScopeCompletionPass`.
           var suggestedElement = suggestion.orgElement;
           if (suggestedElement is ConstructorElement) {
-            var parentName = suggestedElement.enclosingElement.name;
+            var parentName = suggestedElement.enclosingElement3.name;
             var existingSuggestion = _suggestionMap[parentName];
             if (existingSuggestion is _CompletionSuggestionBuilderImpl &&
                 existingSuggestion.orgElement is! ClassElement) {
@@ -1231,7 +1231,7 @@
 
     var suggestedElement = protocol.convertElement(element);
 
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
 
     String? declaringType;
     if (enclosingElement is InterfaceElement) {
@@ -1287,7 +1287,7 @@
   /// The enclosing element must be either a class, or extension; otherwise
   /// we either fail with assertion, or return `null`.
   String? _enclosingClassOrExtensionName(Element element) {
-    var enclosing = element.enclosingElement;
+    var enclosing = element.enclosingElement3;
     if (enclosing is InterfaceElement) {
       return enclosing.name;
     } else if (enclosing is ExtensionElement) {
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_late.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_late.dart
index ad89c33..6452ec0 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/add_late.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/add_late.dart
@@ -63,7 +63,7 @@
       if (getter is PropertyAccessorElement &&
           getter.isGetter &&
           getter.isSynthetic &&
-          getter.enclosingElement is InterfaceElement) {
+          getter.enclosingElement3 is InterfaceElement) {
         var variableElement = getter.variable2;
         if (variableElement != null &&
             !variableElement.isSynthetic &&
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/change_to_static_access.dart b/pkg/analysis_server/lib/src/services/correction/dart/change_to_static_access.dart
index 9b714c3..bdbe265 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/change_to_static_access.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/change_to_static_access.dart
@@ -50,7 +50,7 @@
     }
 
     var target_final = target;
-    var declaringElement = invokedElement.enclosingElement;
+    var declaringElement = invokedElement.enclosingElement3;
 
     if (declaringElement is InterfaceElement) {
       _className = declaringElement.name;
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_class_to_enum.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_class_to_enum.dart
index 8d033f6..4086241 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/convert_class_to_enum.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_class_to_enum.dart
@@ -77,7 +77,7 @@
     var constructorElement = node.constructorName.staticElement;
     return constructorElement != null &&
         !constructorElement.isFactory &&
-        constructorElement.enclosingElement == classElement;
+        constructorElement.enclosingElement3 == classElement;
   }
 }
 
@@ -581,7 +581,7 @@
                       initializer.constructorName.staticElement;
                   if (constructorElement != null &&
                       !constructorElement.isFactory &&
-                      constructorElement.enclosingElement == classElement) {
+                      constructorElement.enclosingElement3 == classElement) {
                     var fieldValue = fieldElement.computeConstantValue();
                     if (fieldValue != null) {
                       if (fieldList.variables.length != 1) {
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_class_to_mixin.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_class_to_mixin.dart
index ae65961..eb2cda2 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/convert_class_to_mixin.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_class_to_mixin.dart
@@ -109,7 +109,7 @@
 
   void _addElement(Element? element) {
     if (element is ExecutableElement) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       if (enclosingElement is ClassElement) {
         referencedClasses.add(enclosingElement);
       }
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_into_final_field.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_into_final_field.dart
index f58000b..129d8c0 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/convert_into_final_field.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_into_final_field.dart
@@ -54,7 +54,7 @@
       if (element == null) {
         return;
       }
-      var enclosing = element.enclosingElement;
+      var enclosing = element.enclosingElement3;
       if (enclosing is InterfaceElement) {
         if (enclosing.getSetter(element.name) != null) {
           return;
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_into_is_not_empty.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_into_is_not_empty.dart
index bb63877..21a150a 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/convert_into_is_not_empty.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_into_is_not_empty.dart
@@ -50,7 +50,7 @@
       return;
     }
     // should have "isNotEmpty"
-    var propertyTarget = propertyElement.enclosingElement;
+    var propertyTarget = propertyElement.enclosingElement3;
     if (propertyTarget == null ||
         getChildren(propertyTarget, 'isNotEmpty').isEmpty) {
       return;
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_map_from_iterable_to_for_literal.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_map_from_iterable_to_for_literal.dart
index 3d94bb6..352c3a7 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/convert_map_from_iterable_to_for_literal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_map_from_iterable_to_for_literal.dart
@@ -42,7 +42,7 @@
     var element = creation.constructorName.staticElement;
     if (element == null ||
         element.name != 'fromIterable' ||
-        element.enclosingElement != typeProvider.mapElement) {
+        element.enclosingElement3 != typeProvider.mapElement) {
       return;
     }
     //
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/create_constructor.dart b/pkg/analysis_server/lib/src/services/correction/dart/create_constructor.dart
index e492d29..8bc5143 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/create_constructor.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/create_constructor.dart
@@ -156,7 +156,7 @@
     }
 
     // prepare target ClassDeclaration
-    var targetElement = constructorElement.enclosingElement;
+    var targetElement = constructorElement.enclosingElement3;
     var targetResult = await sessionHelper.getElementDeclaration(targetElement);
     if (targetResult == null) {
       return;
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateful_widget.dart b/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateful_widget.dart
index ae3ee52..c8f7459 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateful_widget.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateful_widget.dart
@@ -316,7 +316,7 @@
     }
     var element = node.staticElement;
     if (element is ExecutableElement &&
-        element.enclosingElement == widgetClassElement &&
+        element.enclosingElement3 == widgetClassElement &&
         !elementsToMove.contains(element)) {
       var offset = node.offset - linesRange.offset;
       var qualifier =
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateless_widget.dart b/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateless_widget.dart
index 985143f..9148c75 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateless_widget.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateless_widget.dart
@@ -319,7 +319,7 @@
     }
     var element = node.staticElement;
     if (element is ExecutableElement &&
-        element.enclosingElement == widgetClassElement &&
+        element.enclosingElement3 == widgetClassElement &&
         !elementsToMove.contains(element)) {
       var parent = node.parent;
       if (parent is PrefixedIdentifier) {
@@ -370,7 +370,7 @@
   void visitMethodInvocation(MethodInvocation node) {
     var methodElement = node.methodName.staticElement?.declaration;
     if (methodElement is ClassMemberElement) {
-      var classElement = methodElement.enclosingElement;
+      var classElement = methodElement.enclosingElement3;
       if (classElement is ClassElement &&
           classElement.isExactState &&
           !FlutterConvertToStatelessWidget._isDefaultOverride(
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/import_add_show.dart b/pkg/analysis_server/lib/src/services/correction/dart/import_add_show.dart
index c69ae00..227b704 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/import_add_show.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/import_add_show.dart
@@ -67,32 +67,32 @@
 
   @override
   void visitAssignmentExpression(AssignmentExpression node) {
-    _addImplicitExtensionName(node.readElement?.enclosingElement);
-    _addImplicitExtensionName(node.writeElement?.enclosingElement);
+    _addImplicitExtensionName(node.readElement?.enclosingElement3);
+    _addImplicitExtensionName(node.writeElement?.enclosingElement3);
     super.visitAssignmentExpression(node);
   }
 
   @override
   void visitBinaryExpression(BinaryExpression node) {
-    _addImplicitExtensionName(node.staticElement?.enclosingElement);
+    _addImplicitExtensionName(node.staticElement?.enclosingElement3);
     super.visitBinaryExpression(node);
   }
 
   @override
   void visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
-    _addImplicitExtensionName(node.staticElement?.enclosingElement);
+    _addImplicitExtensionName(node.staticElement?.enclosingElement3);
     super.visitFunctionExpressionInvocation(node);
   }
 
   @override
   void visitIndexExpression(IndexExpression node) {
-    _addImplicitExtensionName(node.staticElement?.enclosingElement);
+    _addImplicitExtensionName(node.staticElement?.enclosingElement3);
     super.visitIndexExpression(node);
   }
 
   @override
   void visitMethodInvocation(MethodInvocation node) {
-    _addImplicitExtensionName(node.methodName.staticElement?.enclosingElement);
+    _addImplicitExtensionName(node.methodName.staticElement?.enclosingElement3);
     super.visitMethodInvocation(node);
   }
 
@@ -104,26 +104,26 @@
 
   @override
   void visitPatternField(PatternField node) {
-    _addImplicitExtensionName(node.element?.enclosingElement);
+    _addImplicitExtensionName(node.element?.enclosingElement3);
     super.visitPatternField(node);
   }
 
   @override
   void visitPrefixedIdentifier(PrefixedIdentifier node) {
-    _addImplicitExtensionName(node.staticElement?.enclosingElement);
+    _addImplicitExtensionName(node.staticElement?.enclosingElement3);
     super.visitPrefixedIdentifier(node);
   }
 
   @override
   void visitPrefixExpression(PrefixExpression node) {
-    _addImplicitExtensionName(node.staticElement?.enclosingElement);
+    _addImplicitExtensionName(node.staticElement?.enclosingElement3);
     super.visitPrefixExpression(node);
   }
 
   @override
   void visitPropertyAccess(PropertyAccess node) {
     _addImplicitExtensionName(
-        node.propertyName.staticElement?.enclosingElement);
+        node.propertyName.staticElement?.enclosingElement3);
     super.visitPropertyAccess(node);
   }
 
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/make_field_not_final.dart b/pkg/analysis_server/lib/src/services/correction/dart/make_field_not_final.dart
index fd774e0..5b7ca88 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/make_field_not_final.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/make_field_not_final.dart
@@ -55,7 +55,7 @@
     }
 
     // It must be a field declaration.
-    if (getter.enclosingElement is! ClassElement) {
+    if (getter.enclosingElement3 is! ClassElement) {
       return;
     }
 
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/qualify_reference.dart b/pkg/analysis_server/lib/src/services/correction/dart/qualify_reference.dart
index 11d3b9c8..f4804eb 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/qualify_reference.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/qualify_reference.dart
@@ -47,7 +47,7 @@
       return;
     }
 
-    var enclosingElement = memberElement.enclosingElement;
+    var enclosingElement = memberElement.enclosingElement3;
     if (enclosingElement == null ||
         enclosingElement.library != libraryElement) {
       // TODO(brianwilkerson): Support qualifying references to members defined
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/shadow_field.dart b/pkg/analysis_server/lib/src/services/correction/dart/shadow_field.dart
index 9f41f97..3c2a42e 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/shadow_field.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/shadow_field.dart
@@ -35,7 +35,7 @@
       return;
     }
 
-    if (!accessor.isGetter || accessor.enclosingElement is! InterfaceElement) {
+    if (!accessor.isGetter || accessor.enclosingElement3 is! InterfaceElement) {
       // TODO(brianwilkerson): Should we also require that the getter be synthetic?
       return;
     }
diff --git a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_matcher.dart b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_matcher.dart
index ed82eb29..094e6cc 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_matcher.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_matcher.dart
@@ -257,7 +257,7 @@
         );
       }
     } else if (parent is SuperConstructorInvocation) {
-      var superclassName = parent.staticElement?.enclosingElement.name;
+      var superclassName = parent.staticElement?.enclosingElement3.name;
       if (superclassName != null) {
         _addMatcher(
           components: [parent.constructorName?.name ?? '', superclassName],
@@ -537,7 +537,7 @@
         // Add enclosing element to the matcher for non top level property
         // accessors when possible.
         if (staticElement is PropertyAccessorElement) {
-          var enclosingElement = staticElement.enclosingElement;
+          var enclosingElement = staticElement.enclosingElement3;
           if (enclosingElement is! CompilationUnitElement) {
             _addMatcher(
                 components: [node.name, enclosingElement.displayName],
@@ -576,7 +576,7 @@
       }
     }
     if (element != null) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       if (enclosingElement is InterfaceElement) {
         return [identifier.name, enclosingElement.name];
       } else if (enclosingElement is ExtensionElement) {
diff --git a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/rename_parameter.dart b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/rename_parameter.dart
index 8cd6e6b..3b29c86 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/rename_parameter.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/rename_parameter.dart
@@ -132,7 +132,7 @@
   ExecutableElement? overriddenElement() {
     var element = declaredElement;
     if (element != null) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       if (enclosingElement is InterfaceElement) {
         var name = Name(enclosingElement.library.source.uri, element.name);
         return InheritanceManager3().getInherited2(enclosingElement, name);
diff --git a/pkg/analysis_server/lib/src/services/correction/namespace.dart b/pkg/analysis_server/lib/src/services/correction/namespace.dart
index e9461fd..1c6dd12 100644
--- a/pkg/analysis_server/lib/src/services/correction/namespace.dart
+++ b/pkg/analysis_server/lib/src/services/correction/namespace.dart
@@ -38,7 +38,7 @@
 /// [element] - the referenced element.
 LibraryImportElement? _getImportElement(
     LibraryElement libraryElement, String prefix, Element element) {
-  if (element.enclosingElement is! CompilationUnitElement) {
+  if (element.enclosingElement3 is! CompilationUnitElement) {
     return null;
   }
   var usedLibrary = element.library;
diff --git a/pkg/analysis_server/lib/src/services/correction/util.dart b/pkg/analysis_server/lib/src/services/correction/util.dart
index d5fd2ab..9d2dbc6 100644
--- a/pkg/analysis_server/lib/src/services/correction/util.dart
+++ b/pkg/analysis_server/lib/src/services/correction/util.dart
@@ -80,7 +80,7 @@
 String getElementQualifiedName(Element element) {
   var kind = element.kind;
   if (kind == ElementKind.FIELD || kind == ElementKind.METHOD) {
-    return '${element.enclosingElement!.displayName}.${element.displayName}';
+    return '${element.enclosingElement3!.displayName}.${element.displayName}';
   } else if (kind == ElementKind.LIBRARY) {
     // Libraries may not have names, so use a path relative to the context root.
     var session = element.session!;
diff --git a/pkg/analysis_server/lib/src/services/flutter/property.dart b/pkg/analysis_server/lib/src/services/flutter/property.dart
index ee28274..4943522 100644
--- a/pkg/analysis_server/lib/src/services/flutter/property.dart
+++ b/pkg/analysis_server/lib/src/services/flutter/property.dart
@@ -459,7 +459,7 @@
     if (propertyExpression is InstanceCreationExpression) {
       var constructor = propertyExpression.constructorName.staticElement;
       if (constructor != null &&
-          constructor.enclosingElement == classEdgeInsets) {
+          constructor.enclosingElement3 == classEdgeInsets) {
         var arguments = propertyExpression.argumentList;
         var constructorName = constructor.name;
         if (constructorName == 'all') {
diff --git a/pkg/analysis_server/lib/src/services/flutter/widget_descriptions.dart b/pkg/analysis_server/lib/src/services/flutter/widget_descriptions.dart
index 22eac1f..47ee07a 100644
--- a/pkg/analysis_server/lib/src/services/flutter/widget_descriptions.dart
+++ b/pkg/analysis_server/lib/src/services/flutter/widget_descriptions.dart
@@ -276,7 +276,7 @@
     constructorElement ??= classDescription?.constructor;
     if (constructorElement == null) return;
 
-    var enclosingElement = constructorElement.enclosingElement;
+    var enclosingElement = constructorElement.enclosingElement3;
     if (!elementsBeingProcessed.add(enclosingElement)) return;
 
     var existingNamed = <String>{};
@@ -506,7 +506,7 @@
   }
 
   protocol.FlutterWidgetPropertyValueEnumItem _toEnumItem(FieldElement field) {
-    var interfaceElement = field.enclosingElement as InterfaceElement;
+    var interfaceElement = field.enclosingElement3 as InterfaceElement;
     var libraryUriStr = '${interfaceElement.library.source.uri}';
     var documentation = getFieldDocumentation(field);
 
@@ -532,7 +532,7 @@
       if (element is PropertyAccessorElement && element.isGetter) {
         var field = element.variable2;
         if (field is FieldElement && field.isStatic) {
-          var enclosingClass = field.enclosingElement as InterfaceElement;
+          var enclosingClass = field.enclosingElement3 as InterfaceElement;
           if (field.isEnumConstant ||
               enclosingClass.isExactAlignment ||
               enclosingClass.isExactAlignmentDirectional) {
diff --git a/pkg/analysis_server/lib/src/services/kythe/kythe_visitors.dart b/pkg/analysis_server/lib/src/services/kythe/kythe_visitors.dart
index 542fbfd..0bb006f 100644
--- a/pkg/analysis_server/lib/src/services/kythe/kythe_visitors.dart
+++ b/pkg/analysis_server/lib/src/services/kythe/kythe_visitors.dart
@@ -14,7 +14,7 @@
 /// name of the constructor, unless the constructor is a named constructor in
 /// which '<class-name>.<constructor-name>' is returned.
 String _computeConstructorElementName(ConstructorElement element) {
-  var name = element.enclosingElement.name;
+  var name = element.enclosingElement3.name;
   var constructorName = element.name;
   if (constructorName.isNotEmpty) {
     name = '$name.$constructorName';
@@ -150,7 +150,7 @@
 
   @override
   StringBuffer visitElement(Element element) {
-    var enclosingElt = element.enclosingElement!;
+    var enclosingElt = element.enclosingElement3!;
     var buffer = enclosingElt.accept(this)!;
     if (buffer.isNotEmpty) {
       buffer.write('#');
@@ -182,7 +182,7 @@
     // It is legal to have a named constructor with the same name as a type
     // parameter.  So we distinguish them by using '.' between the class (or
     // typedef) name and the type parameter name.
-    return element.enclosingElement!.accept(this)!
+    return element.enclosingElement3!.accept(this)!
       ..write('.')
       ..write(element.name);
   }
diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_getter_to_method.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_getter_to_method.dart
index dd921c2..9958a6d 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_getter_to_method.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_getter_to_method.dart
@@ -49,15 +49,15 @@
   Future<SourceChange> createChange() async {
     change = SourceChange(refactoringName);
     // function
-    if (element.enclosingElement is CompilationUnitElement) {
+    if (element.enclosingElement3 is CompilationUnitElement) {
       await _updateElementDeclaration(element);
       await _updateElementReferences(element);
     }
     // method
     var field = element.variable2;
     if (field is FieldElement &&
-        (field.enclosingElement is InterfaceElement ||
-            field.enclosingElement is ExtensionElement)) {
+        (field.enclosingElement3 is InterfaceElement ||
+            field.enclosingElement3 is ExtensionElement)) {
       var elements = await getHierarchyMembers(searchEngine, field);
       await Future.forEach(elements, (Element member) async {
         if (member is FieldElement) {
diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_method_to_getter.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_method_to_getter.dart
index 395670b..76f8bb4 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_method_to_getter.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_method_to_getter.dart
@@ -81,7 +81,7 @@
 
     // check Element type
     if (element is FunctionElement) {
-      if (element.enclosingElement is! CompilationUnitElement) {
+      if (element.enclosingElement3 is! CompilationUnitElement) {
         return RefactoringStatus.fatal(
             'Only top-level functions can be converted to getters.');
       }
diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart
index be85987..daae91b 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart
@@ -191,7 +191,7 @@
   return element is LocalVariableElement ||
       element is ParameterElement ||
       element is FunctionElement &&
-          element.enclosingElement is! CompilationUnitElement;
+          element.enclosingElement3 is! CompilationUnitElement;
 }
 
 Element? _getLocalElement(SimpleIdentifier node) {
diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_widget.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_widget.dart
index e827f5c..98ebb9f 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_widget.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_widget.dart
@@ -657,7 +657,7 @@
         enclosingClass,
         ...enclosingClass.allSupertypes.map((t) => t.element)
       ];
-      return enclosingClasses.contains(element.enclosingElement);
+      return enclosingClasses.contains(element.enclosingElement3);
     }
     return false;
   }
diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/inline_method.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/inline_method.dart
index 12de740..400c4fb 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/legacy/inline_method.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/inline_method.dart
@@ -221,7 +221,7 @@
 
   @override
   String? get className {
-    var interfaceElement = _methodElement?.enclosingElement;
+    var interfaceElement = _methodElement?.enclosingElement3;
     if (interfaceElement is InterfaceElement) {
       return interfaceElement.displayName;
     }
@@ -867,13 +867,13 @@
     } else {
       return;
     }
-    if (element.enclosingElement is! InterfaceElement) {
+    if (element.enclosingElement3 is! InterfaceElement) {
       return;
     }
     // record the implicit static or instance reference
     var offset = node.offset;
     if (element.isStatic) {
-      var className = element.enclosingElement.displayName;
+      var className = element.enclosingElement3.displayName;
       result.addImplicitClassNameOffset(className, offset);
     } else {
       result.addImplicitThisOffset(offset);
diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart
index 2090c0d..025d61f 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart
@@ -421,7 +421,10 @@
         return null;
       }
     }
-    var enclosingElement = element.enclosingElement;
+    if (element is LibraryImportElement) {
+      return RenameImportRefactoringImpl(workspace, sessionHelper, element);
+    }
+    var enclosingElement = element.enclosingElement3;
     if (enclosingElement is CompilationUnitElement) {
       return RenameUnitMemberRefactoringImpl(
           workspace, sessionHelper, resolvedUnit, element);
@@ -430,9 +433,6 @@
       return RenameConstructorRefactoringImpl(
           workspace, sessionHelper, element);
     }
-    if (element is LibraryImportElement) {
-      return RenameImportRefactoringImpl(workspace, sessionHelper, element);
-    }
     if (element is LabelElement) {
       return RenameLabelRefactoringImpl(workspace, sessionHelper, element);
     }
diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_class_member.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_class_member.dart
index 0a85ddc..910a9bc 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_class_member.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_class_member.dart
@@ -98,7 +98,7 @@
       } else {
         processor.addDeclarationEdit(renameElement);
         if (!newName.startsWith('_')) {
-          var interfaceElement = renameElement.enclosingElement;
+          var interfaceElement = renameElement.enclosingElement3;
           if (interfaceElement is InterfaceElement) {
             for (var constructor in interfaceElement.constructors) {
               for (var parameter in constructor.parameters) {
@@ -232,7 +232,7 @@
     var declarations = await searchEngine.searchMemberDeclarations(name);
     for (var declaration in declarations) {
       var nameElement = getSyntheticAccessorVariable(declaration.element);
-      var nameClass = nameElement.enclosingElement;
+      var nameClass = nameElement.enclosingElement3;
       // the renamed Element shadows a member of a superclass
       if (superClasses.contains(nameClass)) {
         result.addError(
@@ -372,7 +372,7 @@
         interfaceElement, subClasses, OperationPerformanceImpl('<root>'));
     // check shadowing of class names
     for (var element in elements) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       if (enclosingElement is InterfaceElement &&
           enclosingElement.name == name) {
         result.addError(
diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_constructor.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_constructor.dart
index edabcd5..29fbfb4 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_constructor.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_constructor.dart
@@ -131,7 +131,7 @@
   }
 
   void _analyzePossibleConflicts(RefactoringStatus result) {
-    var parentClass = element.enclosingElement;
+    var parentClass = element.enclosingElement3;
     // Check if the "newName" is the name of the enclosing class.
     if (parentClass.name == newName) {
       result.addError('The constructor should not have the same name '
@@ -181,7 +181,7 @@
   }
 
   Future<void> _replaceSynthetic() async {
-    var classElement = element.enclosingElement;
+    var classElement = element.enclosingElement3;
 
     var result = await sessionHelper.getElementDeclaration(classElement);
     if (result == null) {
diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_type_parameter.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_type_parameter.dart
index 4be7f50..fb88b8e 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_type_parameter.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_type_parameter.dart
@@ -27,7 +27,7 @@
   Future<RefactoringStatus> checkFinalConditions() async {
     var result = RefactoringStatus();
 
-    var enclosing = element.enclosingElement;
+    var enclosing = element.enclosingElement3;
     if (enclosing is TypeParameterizedElement) {
       for (var sibling in enclosing.typeParameters) {
         if (sibling.name == newName) {
diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_unit_member.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_unit_member.dart
index 01e8a1e..2a1dca7 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_unit_member.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_unit_member.dart
@@ -226,7 +226,7 @@
     var declarations = await searchEngine.searchMemberDeclarations(name);
     for (var declaration in declarations) {
       var member = declaration.element;
-      var declaringClass = member.enclosingElement as InterfaceElement;
+      var declaringClass = member.enclosingElement3 as InterfaceElement;
       var memberReferences = await searchEngine.searchReferences(member);
       for (var memberReference in memberReferences) {
         var refElement = memberReference.element;
diff --git a/pkg/analysis_server/lib/src/services/refactoring/move_top_level_to_file.dart b/pkg/analysis_server/lib/src/services/refactoring/move_top_level_to_file.dart
index d81b4a9..b47eac7 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/move_top_level_to_file.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/move_top_level_to_file.dart
@@ -308,7 +308,7 @@
         .expand((unit) => unit.unit.declarations)
         .expand((declaration) => declaration.sealedSuperclassElements)
         // Check if any of them are in the source file.
-        .map((element) => element.enclosingElement)
+        .map((element) => element.enclosingElement3)
         .contains(unitResult.unit.declaredElement);
   }
 
diff --git a/pkg/analysis_server/lib/src/services/search/hierarchy.dart b/pkg/analysis_server/lib/src/services/search/hierarchy.dart
index f58efc5..3fb09f6 100644
--- a/pkg/analysis_server/lib/src/services/search/hierarchy.dart
+++ b/pkg/analysis_server/lib/src/services/search/hierarchy.dart
@@ -114,7 +114,7 @@
   Set<ClassMemberElement> members = HashSet<ClassMemberElement>();
   Set<ParameterElement> parameters = HashSet<ParameterElement>();
   // extension member
-  var enclosingElement = member.enclosingElement;
+  var enclosingElement = member.enclosingElement3;
   if (enclosingElement is ExtensionElement) {
     members.add(member);
     return (members, parameters);
@@ -185,7 +185,7 @@
 Future<List<ParameterElement>> getHierarchyNamedParameters(
     SearchEngine searchEngine, ParameterElement element) async {
   if (element.isNamed) {
-    var method = element.enclosingElement;
+    var method = element.enclosingElement3;
     if (method is MethodElement) {
       var hierarchyParameters = <ParameterElement>[];
       var hierarchyMembers = await getHierarchyMembers(searchEngine, method);
diff --git a/pkg/analysis_server/lib/src/utilities/extensions/element.dart b/pkg/analysis_server/lib/src/utilities/extensions/element.dart
index 43f190d..ed8cf0d 100644
--- a/pkg/analysis_server/lib/src/utilities/extensions/element.dart
+++ b/pkg/analysis_server/lib/src/utilities/extensions/element.dart
@@ -30,15 +30,14 @@
     if (hasDeprecated) {
       return true;
     }
-    var ancestor = enclosingElement;
+    var ancestor = enclosingElement3;
     if (ancestor is InterfaceElement) {
       if (ancestor.hasDeprecated) {
         return true;
       }
-      ancestor = ancestor.enclosingElement;
+      ancestor = ancestor.enclosingElement3;
     }
-    return ancestor is CompilationUnitElement &&
-        ancestor.enclosingElement.hasDeprecated;
+    return ancestor is CompilationUnitElement && ancestor.library.hasDeprecated;
   }
 
   /// Return this element and all its enclosing elements.
@@ -46,8 +45,11 @@
     var current = this;
     while (true) {
       yield current;
-      var enclosing = current.enclosingElement;
+      var enclosing = current.enclosingElement3;
       if (enclosing == null) {
+        if (current is CompilationUnitElement) {
+          yield current.library;
+        }
         break;
       }
       current = enclosing;
@@ -69,7 +71,7 @@
     if (name != 'cast') {
       return false;
     }
-    var definingClass = enclosingElement;
+    var definingClass = enclosingElement3;
     if (definingClass is! ClassElement) {
       return false;
     }
@@ -85,7 +87,7 @@
     if (name != 'toList') {
       return false;
     }
-    var definingClass = enclosingElement;
+    var definingClass = enclosingElement3;
     if (definingClass is! ClassElement) {
       return false;
     }
@@ -98,7 +100,7 @@
     if (name != 'toSet') {
       return false;
     }
-    var definingClass = enclosingElement;
+    var definingClass = enclosingElement3;
     if (definingClass is! ClassElement) {
       return false;
     }
diff --git a/pkg/analysis_server/lib/src/utilities/extensions/flutter.dart b/pkg/analysis_server/lib/src/utilities/extensions/flutter.dart
index bea0d5d..cdd689b 100644
--- a/pkg/analysis_server/lib/src/utilities/extensions/flutter.dart
+++ b/pkg/analysis_server/lib/src/utilities/extensions/flutter.dart
@@ -348,14 +348,14 @@
   /// class `Widget` as a superclass.
   bool get isWidgetCreation {
     var element =
-        constructorName.staticElement?.enclosingElement.augmented.declaration;
+        constructorName.staticElement?.enclosingElement3.augmented.declaration;
     return element.isWidget;
   }
 
   /// The presentation for this node.
   String? get widgetPresentationText {
     var element =
-        constructorName.staticElement?.enclosingElement.augmented.declaration;
+        constructorName.staticElement?.enclosingElement3.augmented.declaration;
     if (!element.isWidget) {
       return null;
     }
diff --git a/pkg/analysis_server/lib/src/utilities/import_analyzer.dart b/pkg/analysis_server/lib/src/utilities/import_analyzer.dart
index d8e3c51..af58b3a 100644
--- a/pkg/analysis_server/lib/src/utilities/import_analyzer.dart
+++ b/pkg/analysis_server/lib/src/utilities/import_analyzer.dart
@@ -354,9 +354,9 @@
       return;
     }
     if (element is ExecutableElement &&
-        element.enclosingElement is ExtensionElement &&
+        element.enclosingElement3 is ExtensionElement &&
         !element.isStatic) {
-      element = element.enclosingElement;
+      element = element.enclosingElement3;
     }
     if (!element.isInterestingReference) {
       return;
@@ -370,5 +370,8 @@
 extension on Element {
   /// Return `true` if this element reference is an interesting reference from
   /// the perspective of determining which imports need to be added.
-  bool get isInterestingReference => enclosingElement is CompilationUnitElement;
+  bool get isInterestingReference {
+    return this is! PrefixElement &&
+        enclosingElement3 is CompilationUnitElement;
+  }
 }
diff --git a/pkg/analysis_server/test/services/refactoring/agnostic/change_method_signature_test.dart b/pkg/analysis_server/test/services/refactoring/agnostic/change_method_signature_test.dart
index 6a6edbe..81f96dc 100644
--- a/pkg/analysis_server/test/services/refactoring/agnostic/change_method_signature_test.dart
+++ b/pkg/analysis_server/test/services/refactoring/agnostic/change_method_signature_test.dart
@@ -114,7 +114,7 @@
   }
 
   String _elementToReferenceString(Element element) {
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     var reference = (element as ElementImpl).reference;
     if (reference != null) {
       return _referenceToString(reference);
diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/end_to_end_test.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/end_to_end_test.dart
index c75f6cd..02ecc4e 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/data_driven/end_to_end_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/end_to_end_test.dart
@@ -161,7 +161,7 @@
 import '$importUri';
 
 void f(New o) {}
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void> test_replacedBy() async {
@@ -193,6 +193,6 @@
 int f() {
   return FileMode.read;
 }
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 }
diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/flutter_use_case_test.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/flutter_use_case_test.dart
index 5b32f16..3755483 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/data_driven/flutter_use_case_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/flutter_use_case_test.dart
@@ -95,7 +95,7 @@
 void f() {
   CupertinoAlertDialog(content: 'x');
 }
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void>
@@ -171,7 +171,7 @@
 void f() {
   CupertinoPopupSurface(child: 'x');
 }
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void>
diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/rename_test.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/rename_test.dart
index 0b9e999..d7cde53 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/data_driven/rename_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/rename_test.dart
@@ -125,7 +125,7 @@
 void f() {
   New.c();
 }
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void> test_constructor_unnamed_deprecated() async {
@@ -175,7 +175,7 @@
 void f() {
   New();
 }
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void> test_constructor_unnamed_removed_prefixed() async {
@@ -234,7 +234,7 @@
 import '$importUri';
 
 class C extends New {}
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void> test_inImplements_deprecated() async {
@@ -270,7 +270,7 @@
 import '$importUri';
 
 class C implements New {}
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void> test_inOn_deprecated() async {
@@ -306,7 +306,7 @@
 import '$importUri';
 
 extension E on New {}
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void> test_inTypeAnnotation_deprecated() async {
@@ -342,7 +342,7 @@
 import '$importUri';
 
 void f(New o) {}
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void> test_inTypeArgument_deprecated() async {
@@ -430,7 +430,7 @@
 import '$importUri';
 
 class C with New {}
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void> test_staticField_deprecated() async {
@@ -472,7 +472,7 @@
 import '$importUri';
 
 var s = New.empty;
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 }
 
@@ -693,7 +693,7 @@
 import '$importUri';
 
 var l = New('a').double;
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void> test_staticField_deprecated() async {
@@ -735,7 +735,7 @@
 import '$importUri';
 
 var s = New.empty;
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void> test_staticField_removed_prefixed() async {
@@ -1176,7 +1176,7 @@
 void f() {
   b;
 }
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void> test_topLevel_reference_removed_prefixed() async {
@@ -1417,7 +1417,7 @@
 import '$importUri';
 
 class C with New {}
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void> test_inWith_removed_prefixed() async {
@@ -1515,7 +1515,7 @@
 void f() {
   b();
 }
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void> test_removed_prefixed() async {
@@ -1661,7 +1661,7 @@
 import '$importUri';
 
 void f(New o) {}
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void> test_removed_prefixed() async {
diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/replaced_by_test.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/replaced_by_test.dart
index 1c3f3be..9ff7300 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/data_driven/replaced_by_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/replaced_by_test.dart
@@ -1068,7 +1068,7 @@
 f() {
   expect(true, true);
 }
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 
   Future<void> test_new_element_uris_single() async {
@@ -1102,7 +1102,7 @@
 main() {
   expect(true, true);
 }
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 }
 
diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/sdk_fix_test.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/sdk_fix_test.dart
index fb75558..76c6fdb 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/data_driven/sdk_fix_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/sdk_fix_test.dart
@@ -49,7 +49,7 @@
 import '$importUri';
 
 void f(Bar o) {}
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 }
 
diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/test_use_case_test.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/test_use_case_test.dart
index 506bab3..11e3f25 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/data_driven/test_use_case_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/test_use_case_test.dart
@@ -96,6 +96,6 @@
 main() {
   expect(true, true);
 }
-''', errorFilter: ignoreUnusedImport);
+''');
   }
 }
diff --git a/pkg/analysis_server/test/src/utilities/selection_coverage_test.dart b/pkg/analysis_server/test/src/utilities/selection_coverage_test.dart
index 9806396..7c01034 100644
--- a/pkg/analysis_server/test/src/utilities/selection_coverage_test.dart
+++ b/pkg/analysis_server/test/src/utilities/selection_coverage_test.dart
@@ -211,7 +211,7 @@
         for (var visitedNodeList in visitedNodeLists) {
           unvisitedNodeLists.remove(visitedNodeList);
           var overridden = inheritanceManager.getOverridden2(
-              visitedNodeList.enclosingElement as InterfaceElement,
+              visitedNodeList.enclosingElement3 as InterfaceElement,
               Name(visitedNodeList.library.source.uri, visitedNodeList.name));
           if (overridden != null) {
             unvisitedNodeLists.removeAll(overridden);
diff --git a/pkg/analysis_server/tool/code_completion/completion_metrics.dart b/pkg/analysis_server/tool/code_completion/completion_metrics.dart
index ca44dac..261a012 100644
--- a/pkg/analysis_server/tool/code_completion/completion_metrics.dart
+++ b/pkg/analysis_server/tool/code_completion/completion_metrics.dart
@@ -1589,7 +1589,7 @@
     var entity = expectedCompletion.syntacticEntity;
     var element = _getElement(entity);
     if (element != null) {
-      var parent = element.enclosingElement;
+      var parent = element.enclosingElement3;
       if (parent is InterfaceElement || parent is ExtensionElement) {
         if (_isStatic(element)) {
           return CompletionGroup.staticMember;
diff --git a/pkg/analysis_server/tool/code_completion/flutter_metrics.dart b/pkg/analysis_server/tool/code_completion/flutter_metrics.dart
index 286778c..2b8405c 100644
--- a/pkg/analysis_server/tool/code_completion/flutter_metrics.dart
+++ b/pkg/analysis_server/tool/code_completion/flutter_metrics.dart
@@ -141,7 +141,7 @@
         throw StateError(
             'Unresolved constructor name: ${node.constructorName}');
       }
-      var childWidget = element.enclosingElement.name;
+      var childWidget = element.enclosingElement3.name;
       if (!element.librarySource.uri
           .toString()
           .startsWith('package:flutter/')) {
diff --git a/pkg/analysis_server/tool/code_completion/relevance_metrics.dart b/pkg/analysis_server/tool/code_completion/relevance_metrics.dart
index 70fbcbb..0336f93 100644
--- a/pkg/analysis_server/tool/code_completion/relevance_metrics.dart
+++ b/pkg/analysis_server/tool/code_completion/relevance_metrics.dart
@@ -968,9 +968,9 @@
     data.recordPercentage(
         'Methods with type parameters', node.typeParameters != null);
     var element = node.declaredElement!;
-    if (!element.isStatic && element.enclosingElement is InterfaceElement) {
+    if (!element.isStatic && element.enclosingElement3 is InterfaceElement) {
       var overriddenMembers = inheritanceManager.getOverridden2(
-          element.enclosingElement as InterfaceElement,
+          element.enclosingElement3 as InterfaceElement,
           Name(element.librarySource.uri, element.name));
       if (overriddenMembers != null) {
         // Consider limiting this to the most immediate override. If the
@@ -1406,7 +1406,7 @@
     Element? currentElement = element;
     while (currentElement != enclosingLibrary) {
       depth++;
-      currentElement = currentElement?.enclosingElement;
+      currentElement = currentElement?.enclosingElement3;
     }
     return depth;
   }
@@ -1688,7 +1688,7 @@
     var reference = _leftMostIdentifier(node);
     var element = reference?.staticElement;
     if (element is ParameterElement) {
-      var definingElement = element.enclosingElement!;
+      var definingElement = element.enclosingElement3!;
       var depth = _parameterReferenceDepth(node, definingElement);
       _recordDistance('function depth of referenced parameter', depth);
     } else if (element != null) {
diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md
index c3a150f..8e6fafb 100644
--- a/pkg/analyzer/CHANGELOG.md
+++ b/pkg/analyzer/CHANGELOG.md
@@ -1,5 +1,6 @@
-## 6.9.0
+## 6.9.0-dev
 * `NormalFormalParameter` now implements `AnnotatedNode`.
+* Deprecated `Element.enclosingElement`, use `enclosingElement3`.
 
 ## 6.8.0
 * Add `AnalysisContextCollection.dispose()`. It must be invoked at the end.
diff --git a/pkg/analyzer/lib/dart/element/element.dart b/pkg/analyzer/lib/dart/element/element.dart
index d343e31..5475b12 100644
--- a/pkg/analyzer/lib/dart/element/element.dart
+++ b/pkg/analyzer/lib/dart/element/element.dart
@@ -60,9 +60,13 @@
 /// Clients may not extend, implement or mix-in this class.
 @experimental
 abstract class AugmentationImportElement implements _ExistingElement {
+  @Deprecated('Use enclosingElement3 instead')
   @override
   LibraryOrAugmentationElement get enclosingElement;
 
+  @override
+  LibraryOrAugmentationElement get enclosingElement3;
+
   /// The [LibraryAugmentationElement], if [uri] is a
   /// [DirectiveUriWithAugmentation].
   LibraryAugmentationElement? get importedAugmentation;
@@ -365,9 +369,13 @@
   // TODO(brianwilkerson): Either remove this class or rename it to something
   //  more correct.
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   Element get enclosingElement;
 
+  @override
+  Element get enclosingElement3;
+
   /// Whether the element is a static element.
   ///
   /// A static element is an element that is not associated with a particular
@@ -387,6 +395,7 @@
   List<ClassElement> get classes;
 
   /// The library, or library augmentation that encloses this unit.
+  @Deprecated('Use enclosingElement3 instead')
   @override
   LibraryOrAugmentationElement get enclosingElement;
 
@@ -468,9 +477,13 @@
   @override
   String get displayName;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   InterfaceElement get enclosingElement;
 
+  @override
+  InterfaceElement get enclosingElement3;
+
   /// Whether the constructor is a const constructor.
   bool get isConst;
 
@@ -626,6 +639,7 @@
   ///
   /// This will be `null` if this element is a library because libraries are
   /// the top-level elements in the model.
+  @Deprecated('Use enclosingElement3 instead')
   Element? get enclosingElement;
 
   /// The element that either physically or logically encloses this element.
@@ -1299,9 +1313,13 @@
   @override
   String get displayName;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   Element get enclosingElement;
 
+  @override
+  Element get enclosingElement3;
+
   /// Whether the executable element did not have an explicit return type
   /// specified for it in the original source.
   bool get hasImplicitReturnType;
@@ -1588,9 +1606,13 @@
   @experimental
   AugmentedInstanceElement get augmented;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   CompilationUnitElement get enclosingElement;
 
+  @override
+  CompilationUnitElement get enclosingElement3;
+
   /// The declared fields.
   List<FieldElement> get fields;
 
@@ -1890,10 +1912,14 @@
 ///
 /// Clients may not extend, implement or mix-in this class.
 abstract class LabelElement implements Element {
+  @Deprecated('Use enclosingElement3 instead')
   @override
   ExecutableElement get enclosingElement;
 
   @override
+  ExecutableElement get enclosingElement3;
+
+  @override
   String get name;
 }
 
@@ -2338,6 +2364,9 @@
   @override
   LibraryOrAugmentationElement get enclosingElement;
 
+  @override
+  CompilationUnitElement get enclosingElement3;
+
   /// The imports that share this prefix.
   List<LibraryImportElement> get imports;
 
@@ -2397,9 +2426,13 @@
   @override
   PropertyAccessorElement get declaration;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   Element get enclosingElement;
 
+  @override
+  Element get enclosingElement3;
+
   /// Whether the accessor represents a getter.
   bool get isGetter;
 
@@ -2560,9 +2593,13 @@
   /// a [FunctionType].
   DartType get aliasedType;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   CompilationUnitElement get enclosingElement;
 
+  @override
+  CompilationUnitElement get enclosingElement3;
+
   /// Whether the element is an augmentation.
   ///
   /// If `true`, declaration has the explicit `augment` modifier.
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_analysis.dart b/pkg/analyzer/lib/src/dart/analysis/file_analysis.dart
index ec94826..3f82f5f 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_analysis.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_analysis.dart
@@ -6,6 +6,7 @@
 import 'package:analyzer/src/dart/analysis/file_state.dart';
 import 'package:analyzer/src/dart/ast/ast.dart';
 import 'package:analyzer/src/dart/element/element.dart';
+import 'package:analyzer/src/dart/element/scope.dart';
 import 'package:analyzer/src/ignore_comments/ignore_info.dart';
 
 /// Information about a file being analyzed.
@@ -16,6 +17,7 @@
   final CompilationUnitImpl unit;
   final CompilationUnitElementImpl element;
   final IgnoreInfo ignoreInfo;
+  late ImportsTracking importsTracking;
 
   FileAnalysis({
     required this.file,
diff --git a/pkg/analyzer/lib/src/dart/analysis/index.dart b/pkg/analyzer/lib/src/dart/analysis/index.dart
index fc76594..00ae07b 100644
--- a/pkg/analyzer/lib/src/dart/analysis/index.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/index.dart
@@ -19,7 +19,7 @@
   SimpleIdentifier node,
   Element? element,
 ) {
-  if (element == null || element.enclosingElement != null) {
+  if (element == null || element.enclosingElement3 != null) {
     return element;
   }
 
@@ -64,7 +64,7 @@
 /// Return the [CompilationUnitElement] that should be used for [element].
 /// Throw [StateError] if the [element] is not linked into a unit.
 CompilationUnitElement getUnitElement(Element element) {
-  for (Element? e = element; e != null; e = e.enclosingElement) {
+  for (Element? e = element; e != null; e = e.enclosingElement3) {
     if (e is CompilationUnitElement) {
       return e;
     }
@@ -89,21 +89,21 @@
     String? parameterName;
     if (element is ParameterElement) {
       parameterName = element.name;
-      element = element.enclosingElement!;
+      element = element.enclosingElement3!;
     }
 
     String? classMemberName;
-    if (element.enclosingElement is InterfaceElement ||
-        element.enclosingElement is ExtensionElement) {
+    if (element.enclosingElement3 is InterfaceElement ||
+        element.enclosingElement3 is ExtensionElement) {
       classMemberName = element.name;
-      element = element.enclosingElement!;
+      element = element.enclosingElement3!;
     }
 
     String? unitMemberName;
-    if (element.enclosingElement is CompilationUnitElement) {
+    if (element.enclosingElement3 is CompilationUnitElement) {
       unitMemberName = element.name;
       if (element is ExtensionElement && unitMemberName == null) {
-        var enclosingUnit = element.enclosingElement;
+        var enclosingUnit = element.enclosingElement3;
         var indexOf = enclosingUnit.extensions.indexOf(element);
         unitMemberName = 'extension-$indexOf';
       }
@@ -140,7 +140,7 @@
     } else if (element.isSynthetic) {
       if (elementKind == ElementKind.CONSTRUCTOR) {
         kind = IndexSyntheticElementKind.constructor;
-        element = element.enclosingElement!;
+        element = element.enclosingElement3!;
       } else if (element is FunctionElement &&
           element.name == FunctionElement.LOAD_LIBRARY_NAME) {
         kind = IndexSyntheticElementKind.loadLibrary;
@@ -152,7 +152,7 @@
       } else if (elementKind == ElementKind.GETTER ||
           elementKind == ElementKind.SETTER) {
         var accessor = element as PropertyAccessorElement;
-        Element enclosing = element.enclosingElement;
+        Element enclosing = element.enclosingElement3;
         bool isEnumGetter = enclosing is EnumElement;
         if (isEnumGetter && accessor.name == 'index') {
           kind = IndexSyntheticElementKind.enumIndex;
@@ -169,7 +169,7 @@
           }
         }
       } else if (element is MethodElement) {
-        Element enclosing = element.enclosingElement;
+        Element enclosing = element.enclosingElement3;
         bool isEnumMethod = enclosing is EnumElement;
         if (isEnumMethod && element.name == 'toString') {
           kind = IndexSyntheticElementKind.enumToString;
@@ -518,14 +518,14 @@
         elementKind == ElementKind.TYPE_PARAMETER ||
         elementKind == ElementKind.FUNCTION &&
             element is FunctionElement &&
-            element.enclosingElement is ExecutableElement ||
+            element.enclosingElement3 is ExecutableElement ||
         false) {
       return;
     }
     // Ignore named parameters of synthetic functions, e.g. created for LUB.
     // These functions are not bound to a source, we cannot index them.
     if (elementKind == ElementKind.PARAMETER && element is ParameterElement) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       if (enclosingElement == null || enclosingElement.isSynthetic) {
         return;
       }
@@ -535,7 +535,7 @@
     // named parameters. Ignore them.
     if (elementKind == ElementKind.PARAMETER &&
         element is ParameterElement &&
-        element.enclosingElement is GenericFunctionTypeElement) {
+        element.enclosingElement3 is GenericFunctionTypeElement) {
       return;
     }
     // Add the relation.
@@ -959,7 +959,7 @@
 
     var parent = node.parent;
     if (element != null &&
-        element.enclosingElement is CompilationUnitElement &&
+        element.enclosingElement3 is CompilationUnitElement &&
         // We're only unprefixed when part of a PrefixedIdentifier if we're
         // the left side.
         (parent is! PrefixedIdentifier || parent.prefix == node)) {
@@ -1112,7 +1112,7 @@
       ConstructorElement? constructor) {
     var seenConstructors = <ConstructorElement?>{};
     while (constructor is ConstructorElementImpl && constructor.isSynthetic) {
-      var enclosing = constructor.enclosingElement;
+      var enclosing = constructor.enclosingElement3;
       if (enclosing is ClassElement && enclosing.isMixinApplication) {
         var superInvocation = constructor.constantInitializers
             .whereType<SuperConstructorInvocation>()
diff --git a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
index 7ffa613..22b5348 100644
--- a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
@@ -182,11 +182,18 @@
       _testingData?.recordFlowAnalysisDataForTesting(
           file.uri, flowAnalysisHelper.dataForTesting!);
 
-      var resolverVisitor = ResolverVisitor(_inheritance, _libraryElement,
-          libraryResolutionContext, file.source, _typeProvider, errorListener,
-          featureSet: _libraryElement.featureSet,
-          analysisOptions: _library.file.analysisOptions,
-          flowAnalysisHelper: flowAnalysisHelper);
+      var resolverVisitor = ResolverVisitor(
+        _inheritance,
+        _libraryElement,
+        libraryResolutionContext,
+        file.source,
+        _typeProvider,
+        errorListener,
+        featureSet: _libraryElement.featureSet,
+        analysisOptions: _library.file.analysisOptions,
+        flowAnalysisHelper: flowAnalysisHelper,
+        libraryFragment: unitElement,
+      );
       _testingData?.recordTypeConstraintGenerationDataForTesting(
           file.uri, resolverVisitor.inferenceHelper.dataForTesting!);
 
@@ -498,7 +505,9 @@
 
     // Verify imports.
     {
-      ImportsVerifier verifier = ImportsVerifier();
+      var verifier = ImportsVerifier(
+        fileAnalysis: fileAnalysis,
+      );
       verifier.addImports(unit);
       usedImportedElements.forEach(verifier.removeUsedElements);
       verifier.generateDuplicateExportWarnings(errorReporter);
@@ -618,10 +627,24 @@
       fileElement: _libraryElement.definingCompilationUnit,
     );
 
+    // Configure scopes for all files to track imports usages.
+    // Associate tracking objects with file objects.
+    for (var fileAnalysis in _libraryFiles.values) {
+      var scope = fileAnalysis.element.scope;
+      var tracking = scope.importsTrackingInit();
+      fileAnalysis.importsTracking = tracking;
+    }
+
     for (var fileAnalysis in _libraryFiles.values) {
       _resolveFile(fileAnalysis);
     }
 
+    // Stop tracking usages by scopes.
+    for (var fileAnalysis in _libraryFiles.values) {
+      var scope = fileAnalysis.element.scope;
+      scope.importsTrackingDestroy();
+    }
+
     _computeConstants();
   }
 
@@ -911,11 +934,18 @@
     _testingData?.recordFlowAnalysisDataForTesting(
         fileAnalysis.file.uri, flowAnalysisHelper.dataForTesting!);
 
-    var resolver = ResolverVisitor(_inheritance, _libraryElement,
-        libraryResolutionContext, source, _typeProvider, errorListener,
-        analysisOptions: _library.file.analysisOptions,
-        featureSet: unit.featureSet,
-        flowAnalysisHelper: flowAnalysisHelper);
+    var resolver = ResolverVisitor(
+      _inheritance,
+      _libraryElement,
+      libraryResolutionContext,
+      source,
+      _typeProvider,
+      errorListener,
+      analysisOptions: _library.file.analysisOptions,
+      featureSet: unit.featureSet,
+      flowAnalysisHelper: flowAnalysisHelper,
+      libraryFragment: unitElement,
+    );
     unit.accept(resolver);
     _testingData?.recordTypeConstraintGenerationDataForTesting(
         fileAnalysis.file.uri, resolver.inferenceHelper.dataForTesting!);
diff --git a/pkg/analyzer/lib/src/dart/analysis/search.dart b/pkg/analyzer/lib/src/dart/analysis/search.dart
index 38f5947..20d02eb 100644
--- a/pkg/analyzer/lib/src/dart/analysis/search.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/search.dart
@@ -359,7 +359,7 @@
     } else if (element is PropertyInducingElement) {
       return _searchReferences_Field(element, searchedFiles);
     } else if (kind == ElementKind.FUNCTION || kind == ElementKind.METHOD) {
-      if (element.enclosingElement is ExecutableElement) {
+      if (element.enclosingElement3 is ExecutableElement) {
         return _searchReferences_Local(
             element, (n) => n is Block, searchedFiles);
       }
@@ -531,7 +531,7 @@
     // Prepare the element name.
     String name = element.displayName;
     if (element is ConstructorElement) {
-      name = element.enclosingElement.displayName;
+      name = element.enclosingElement3.displayName;
     }
 
     var elementPath = element.source!.fullName;
@@ -808,7 +808,7 @@
     ));
     if (parameter.isNamed ||
         parameter.isOptionalPositional ||
-        parameter.enclosingElement is ConstructorElement) {
+        parameter.enclosingElement3 is ConstructorElement) {
       results.addAll(await _searchReferences(parameter, searchedFiles));
     }
     return results;
@@ -1108,7 +1108,7 @@
       return;
     }
 
-    var enclosing = element.enclosingElement;
+    var enclosing = element.enclosingElement3;
 
     String? className;
     String? mixinName;
diff --git a/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart b/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
index e59e7bf..623b517 100644
--- a/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
+++ b/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
@@ -480,7 +480,7 @@
     if (initializer != null && (node.isConst || node.isFinal)) {
       var element = node.declaredElement as VariableElementImpl;
       if (element is FieldElement && !element.isStatic) {
-        var enclosingElement = element.enclosingElement;
+        var enclosingElement = element.enclosingElement3;
         if (enclosingElement is ClassElementImpl &&
             !enclosingElement.hasGenerativeConstConstructor) {
           // TODO(kallentu): Evaluate if we need to do this check for inline
diff --git a/pkg/analyzer/lib/src/dart/constant/evaluation.dart b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
index 3ba4a59..88db764 100644
--- a/pkg/analyzer/lib/src/dart/constant/evaluation.dart
+++ b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
@@ -223,7 +223,7 @@
   void computeDependencies(
       ConstantEvaluationTarget constant, ReferenceFinderCallback callback) {
     if (constant is ConstFieldElementImpl && constant.isEnumConstant) {
-      var enclosing = constant.enclosingElement;
+      var enclosing = constant.enclosingElement3;
       if (enclosing is EnumElementImpl) {
         if (enclosing.name == 'values') {
           return;
@@ -283,7 +283,7 @@
             }
           }
         }
-        for (FieldElement field in constant.enclosingElement.fields) {
+        for (FieldElement field in constant.enclosingElement3.fields) {
           // Note: non-static const isn't allowed but we handle it anyway so
           // that we won't be confused by incorrect code.
           if ((field.isFinal || field.isConst) &&
@@ -447,7 +447,7 @@
       return null;
     }
     var typeProvider = constructor.library.typeProvider;
-    if (constructor.enclosingElement == typeProvider.symbolElement) {
+    if (constructor.enclosingElement3 == typeProvider.symbolElement) {
       // The dart:core.Symbol has a const factory constructor that redirects
       // to dart:_internal.Symbol.  That in turn redirects to an external
       // const constructor, which we won't be able to evaluate.
@@ -471,7 +471,7 @@
 
   static _EnumConstant? _enumConstant(VariableElementImpl element) {
     if (element is ConstFieldElementImpl && element.isEnumConstant) {
-      var enum_ = element.enclosingElement;
+      var enum_ = element.enclosingElement3;
       if (enum_ is EnumElementImpl) {
         var index = enum_.constants.indexOf(element);
         assert(index >= 0);
@@ -635,7 +635,7 @@
   @override
   Constant visitBinaryExpression(BinaryExpression node) {
     var operatorElement = node.staticElement;
-    var operatorContainer = operatorElement?.enclosingElement;
+    var operatorContainer = operatorElement?.enclosingElement3;
     switch (operatorContainer) {
       case ExtensionElement():
         return InvalidConstant.forEntity(
@@ -1027,7 +1027,7 @@
       if (element.name == "identical") {
         NodeList<Expression> arguments = node.argumentList.arguments;
         if (arguments.length == 2) {
-          var enclosingElement = element.enclosingElement;
+          var enclosingElement = element.enclosingElement3;
           if (enclosingElement is CompilationUnitElement) {
             LibraryElement library = enclosingElement.library;
             if (library.isDartCore) {
@@ -1142,7 +1142,7 @@
   @override
   Constant visitPrefixExpression(PrefixExpression node) {
     var operatorElement = node.staticElement;
-    var operatorContainer = operatorElement?.enclosingElement;
+    var operatorContainer = operatorElement?.enclosingElement3;
     switch (operatorContainer) {
       case ExtensionElement():
         return InvalidConstant.forEntity(
@@ -1693,7 +1693,7 @@
       return null;
     }
 
-    var propertyContainer = propertyElement?.enclosingElement;
+    var propertyContainer = propertyElement?.enclosingElement3;
     switch (propertyContainer) {
       case ExtensionElement():
         return InvalidConstant.forEntity(
@@ -2487,7 +2487,7 @@
 
   /// Evaluates this constructor call as a factory constructor call.
   Constant evaluateFactoryConstructorCall(List<Expression> arguments) {
-    var definingClass = _constructor.enclosingElement;
+    var definingClass = _constructor.enclosingElement3;
     var argumentCount = arguments.length;
     if (_constructor.name == "fromEnvironment") {
       if (!_checkFromEnvironmentArguments(arguments, definingType)) {
@@ -2618,7 +2618,7 @@
   ///
   /// Returns an [InvalidConstant] if one is found, or `null` otherwise.
   InvalidConstant? _checkFields() {
-    var fields = _constructor.enclosingElement.fields;
+    var fields = _constructor.enclosingElement3.fields;
     for (var field in fields) {
       if ((field.isFinal || field.isConst) &&
           !field.isStatic &&
@@ -3036,7 +3036,7 @@
   }
 
   void _checkTypeParameters() {
-    var typeParameters = _constructor.enclosingElement.typeParameters;
+    var typeParameters = _constructor.enclosingElement3.typeParameters;
     var typeArguments = _typeArguments;
     if (typeParameters.isNotEmpty &&
         typeArguments != null &&
diff --git a/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart b/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart
index 3f5a33f..384ee1e 100644
--- a/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart
+++ b/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart
@@ -232,7 +232,7 @@
     }
 
     if (element is ParameterElement) {
-      var enclosing = element.enclosingElement;
+      var enclosing = element.enclosingElement3;
       if (enclosing is ConstructorElement &&
           isConstConstructorElement(enclosing)) {
         if (node.thisOrAncestorOfType<ConstructorInitializer>() != null) {
diff --git a/pkg/analyzer/lib/src/dart/constant/value.dart b/pkg/analyzer/lib/src/dart/constant/value.dart
index 639be4c..2d83e7a 100644
--- a/pkg/analyzer/lib/src/dart/constant/value.dart
+++ b/pkg/analyzer/lib/src/dart/constant/value.dart
@@ -1510,7 +1510,7 @@
     var type = _object.type;
     if (type is InterfaceType) {
       bool isFromDartCoreObject(ExecutableElement? element) {
-        var enclosing = element?.enclosingElement;
+        var enclosing = element?.enclosingElement3;
         return enclosing is ClassElement && enclosing.isDartCoreObject;
       }
 
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 19c9942..7ecdf01 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -120,12 +120,18 @@
     required this.uri,
   }) : super(null, importKeywordOffset);
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   LibraryOrAugmentationElementImpl get enclosingElement {
     return super.enclosingElement as LibraryOrAugmentationElementImpl;
   }
 
   @override
+  LibraryOrAugmentationElementImpl get enclosingElement3 {
+    return super.enclosingElement3 as LibraryOrAugmentationElementImpl;
+  }
+
+  @override
   LibraryAugmentationElementImpl? get importedAugmentation {
     var uri = this.uri;
     if (uri is DirectiveUriWithAugmentationImpl) {
@@ -376,7 +382,7 @@
   bool get hasNoSuchMethod {
     MethodElement? method = lookUpConcreteMethod(
         FunctionElement.NO_SUCH_METHOD_METHOD_NAME, library);
-    var definingClass = method?.enclosingElement as ClassElement?;
+    var definingClass = method?.enclosingElement3 as ClassElement?;
     return definingClass != null && !definingClass.isDartCoreObject;
   }
 
@@ -849,7 +855,7 @@
   @override
   CompilationUnitElementImpl? get enclosingElement3 {
     if (libraryOrAugmentationElement is LibraryAugmentationElementImpl) {
-      return (libraryOrAugmentationElement.enclosingElement
+      return (libraryOrAugmentationElement.enclosingElement3
               as LibraryOrAugmentationElementImpl)
           .definingCompilationUnit;
     }
@@ -1280,7 +1286,7 @@
 
   @override
   String get displayName {
-    var className = enclosingElement.name;
+    var className = enclosingElement3.name;
     var name = this.name;
     if (name.isNotEmpty) {
       return '$className.$name';
@@ -1307,18 +1313,23 @@
 
   set element(ConstructorElement2 element) => _element = element;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   InterfaceElement get enclosingElement =>
       super.enclosingElement as InterfaceElementImpl;
 
   @override
+  InterfaceElement get enclosingElement3 =>
+      super.enclosingElement3 as InterfaceElementImpl;
+
+  @override
   InstanceFragment? get enclosingFragment =>
-      enclosingElement as InstanceFragment;
+      enclosingElement3 as InstanceFragment;
 
   @override
   bool get hasLiteral {
     if (super.hasLiteral) return true;
-    var enclosingElement = this.enclosingElement;
+    var enclosingElement = enclosingElement3;
     if (enclosingElement is! ExtensionTypeElement) return false;
     return this == enclosingElement.primaryConstructor &&
         enclosingElement.hasLiteral;
@@ -1362,7 +1373,7 @@
 
   @override
   Element get nonSynthetic {
-    return isSynthetic ? enclosingElement : this;
+    return isSynthetic ? enclosingElement3 : this;
   }
 
   @override
@@ -1385,7 +1396,7 @@
       return result as InterfaceType;
     }
 
-    var augmentedDeclaration = enclosingElement.augmented.declaration;
+    var augmentedDeclaration = enclosingElement3.augmented.declaration;
     result = augmentedDeclaration.thisType;
     return _returnType = result as InterfaceType;
   }
@@ -1580,7 +1591,7 @@
       if (library == null) {
         throw StateError(
           '[library: null][this: ($runtimeType) $this]'
-          '[enclosingElement: $enclosingElement]'
+          '[enclosingElement: $enclosingElement3]'
           '[reference: $reference]',
         );
       }
@@ -2014,7 +2025,7 @@
   bool get isDartInternalSince {
     var element = this.element;
     if (element is ConstructorElement) {
-      return element.enclosingElement.name == 'Since' &&
+      return element.enclosingElement3.name == 'Since' &&
           element.library.source.uri.toString() == 'dart:_internal';
     }
     return false;
@@ -2025,7 +2036,7 @@
     var element = this.element;
     if (element is ConstructorElement) {
       return element.library.isDartCore &&
-          element.enclosingElement.name == _deprecatedClassName;
+          element.enclosingElement3.name == _deprecatedClassName;
     } else if (element is PropertyAccessorElement) {
       return element.library.isDartCore &&
           element.name == _deprecatedVariableName;
@@ -2178,7 +2189,7 @@
   }) {
     var element = this.element;
     return element is ConstructorElement &&
-        element.enclosingElement.name == className &&
+        element.enclosingElement3.name == className &&
         element.library.name == libraryName;
   }
 
@@ -2309,6 +2320,7 @@
     _docComment = doc;
   }
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   Element? get enclosingElement => _enclosingElement;
 
@@ -2760,7 +2772,7 @@
 
   @override
   AnalysisSession? get session {
-    return enclosingElement?.session;
+    return enclosingElement3?.session;
   }
 
   @override
@@ -2781,7 +2793,7 @@
 
   @override
   Source? get source {
-    return enclosingElement?.source;
+    return enclosingElement3?.source;
   }
 
   /// Whether to include the [nameOffset] in [identifier] to disambiguiate
@@ -2900,7 +2912,7 @@
   ) {
     Element? element = this;
     while (element != null && !predicate(element)) {
-      element = element.enclosingElement;
+      element = element.enclosingElement3;
     }
     return element as E?;
   }
@@ -2929,9 +2941,16 @@
 
   @override
   E? thisOrAncestorOfType<E extends Element>() {
+    if (E == LibraryElement || E == LibraryElementImpl) {
+      if (enclosingElement3 case LibraryElementImpl library) {
+        return library as E;
+      }
+      return thisOrAncestorOfType<CompilationUnitElementImpl>()?.library as E?;
+    }
+
     Element element = this;
     while (element is! E) {
-      var ancestor = element.enclosingElement;
+      var ancestor = element.enclosingElement3;
       if (ancestor == null) return null;
       element = ancestor;
     }
@@ -3098,7 +3117,11 @@
     Element? ancestor = element;
     while (ancestor != null) {
       components.insert(0, (ancestor as ElementImpl).identifier);
-      ancestor = ancestor.enclosingElement;
+      if (ancestor is CompilationUnitElementImpl) {
+        components.insert(0, ancestor.library.identifier);
+        break;
+      }
+      ancestor = ancestor.enclosingElement3;
     }
     _components = components.toFixedList();
   }
@@ -3300,10 +3323,16 @@
         ...parameters,
       ];
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   Element get enclosingElement => super.enclosingElement!;
 
   @override
+  Element get enclosingElement3 {
+    return super.enclosingElement3!;
+  }
+
+  @override
   bool get hasImplicitReturnType {
     return hasModifier(Modifier.IMPLICIT_TYPE);
   }
@@ -3754,7 +3783,7 @@
   ///
   /// Such fields are `index`, `_name`, and `values`.
   bool get isSyntheticEnumField {
-    return enclosingElement is EnumElementImpl &&
+    return enclosingElement3 is EnumElementImpl &&
         isSynthetic &&
         getter?.isSynthetic == true &&
         setter == null;
@@ -4364,7 +4393,7 @@
 
   @override
   Fragment? get nextFragment {
-    if (enclosingElement is CompilationUnitElement) {
+    if (enclosingElement3 is CompilationUnitElement) {
       // TODO(augmentations): Support the fragment chain.
       throw UnsupportedError('The fragment chain is not yet supported');
     } else {
@@ -4375,7 +4404,7 @@
 
   @override
   Fragment? get previousFragment {
-    if (enclosingElement is CompilationUnitElement) {
+    if (enclosingElement3 is CompilationUnitElement) {
       // TODO(augmentations): Support the fragment chain.
       throw UnsupportedError('The fragment chain is not yet supported');
     } else {
@@ -4387,8 +4416,8 @@
   @override
   bool get _includeNameOffsetInIdentifier {
     return super._includeNameOffsetInIdentifier ||
-        enclosingElement is ExecutableElement ||
-        enclosingElement is VariableElement;
+        enclosingElement3 is ExecutableElement ||
+        enclosingElement3 is VariableElement;
   }
 
   @override
@@ -4638,13 +4667,19 @@
   @override
   InstanceElement2 get element => augmented as InstanceElement2;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   CompilationUnitElementImpl get enclosingElement {
     return super.enclosingElement as CompilationUnitElementImpl;
   }
 
   @override
-  LibraryFragment? get enclosingFragment => enclosingElement;
+  CompilationUnitElementImpl get enclosingElement3 {
+    return super.enclosingElement3 as CompilationUnitElementImpl;
+  }
+
+  @override
+  LibraryFragment? get enclosingFragment => enclosingElement3;
 
   @override
   List<FieldElementImpl> get fields {
@@ -4985,7 +5020,7 @@
         !getter.isAbstract &&
         !getter.isStatic &&
         getter.isAccessibleIn(library) &&
-        getter.enclosingElement != this);
+        getter.enclosingElement3 != this);
   }
 
   ExecutableElement? lookUpInheritedConcreteMember(
@@ -5005,7 +5040,7 @@
         !method.isAbstract &&
         !method.isStatic &&
         method.isAccessibleIn(library) &&
-        method.enclosingElement != this);
+        method.enclosingElement3 != this);
   }
 
   @override
@@ -5015,7 +5050,7 @@
         !setter.isAbstract &&
         !setter.isStatic &&
         setter.isAccessibleIn(library) &&
-        setter.enclosingElement != this);
+        setter.enclosingElement3 != this);
   }
 
   @override
@@ -5024,7 +5059,7 @@
     return _implementationsOfMethod(methodName).firstWhereOrNull((method) =>
         !method.isStatic &&
         method.isAccessibleIn(library) &&
-        method.enclosingElement != this);
+        method.enclosingElement3 != this);
   }
 
   @Deprecated('Use `element.augmented.lookUpMethod`.')
@@ -5246,10 +5281,15 @@
   @override
   String get displayName => name;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   ExecutableElement get enclosingElement =>
       super.enclosingElement as ExecutableElement;
 
+  @override
+  ExecutableElement get enclosingElement3 =>
+      super.enclosingElement3 as ExecutableElement;
+
   /// Return `true` if this label is associated with a `switch` member (`case
   /// ` or`default`).
   bool get isOnSwitchMember => _onSwitchMember;
@@ -6891,7 +6931,7 @@
 
   @override
   InstanceFragment? get enclosingFragment =>
-      enclosingElement as InstanceFragment;
+      enclosingElement3 as InstanceFragment;
 
   /// Set whether this class is abstract.
   set isAbstract(bool isAbstract) {
@@ -6928,8 +6968,8 @@
 
   @override
   Element get nonSynthetic {
-    if (isSynthetic && enclosingElement is EnumElementImpl) {
-      return enclosingElement;
+    if (isSynthetic && enclosingElement3 is EnumElementImpl) {
+      return enclosingElement3;
     }
     return this;
   }
@@ -7233,6 +7273,7 @@
   @override
   String? get documentationComment => null;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   Element? get enclosingElement => null;
 
@@ -7495,9 +7536,13 @@
   /// [offset].
   NonParameterVariableElementImpl(String super.name, super.offset);
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   Element get enclosingElement => super.enclosingElement!;
 
+  @override
+  Element get enclosingElement3 => super.enclosingElement3!;
+
   bool get hasInitializer {
     return hasModifier(Modifier.HAS_INITIALIZER);
   }
@@ -7926,7 +7971,7 @@
 
   @override
   CompilationUnitElementImpl get enclosingUnit {
-    var enclosingLibrary = enclosingElement as LibraryElementImpl;
+    var enclosingLibrary = enclosingElement3 as LibraryElementImpl;
     return enclosingLibrary._definingCompilationUnit;
   }
 
@@ -7975,12 +8020,13 @@
   @override
   String get displayName => name;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   LibraryOrAugmentationElementImpl get enclosingElement =>
       super.enclosingElement as LibraryOrAugmentationElementImpl;
 
   @override
-  LibraryElement2 get enclosingElement2 => enclosingElement as LibraryElement2;
+  LibraryElement2 get enclosingElement2 => enclosingElement3 as LibraryElement2;
 
   @override
   CompilationUnitElementImpl get enclosingElement3 {
@@ -7993,7 +8039,7 @@
 
   @override
   List<LibraryImportElementImpl> get imports {
-    return enclosingElement.libraryImports
+    return enclosingElement3.libraryImports
         .where((import) => import.prefix?.element == this)
         .toList();
   }
@@ -8125,7 +8171,7 @@
 
   @override
   Fragment? get enclosingFragment {
-    var enclosing = enclosingElement;
+    var enclosing = enclosingElement3;
     if (enclosing is InstanceFragment) {
       return enclosing as InstanceFragment;
     } else if (enclosing is CompilationUnitElementImpl) {
@@ -8240,10 +8286,14 @@
     reference?.element = this;
   }
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   Element get enclosingElement => variable2.enclosingElement;
 
   @override
+  Element get enclosingElement3 => variable2.enclosingElement3;
+
+  @override
   bool get hasImplicitReturnType => variable2.hasImplicitType;
 
   @override
@@ -8254,8 +8304,8 @@
     if (!variable2.isSynthetic) {
       return variable2;
     }
-    assert(enclosingElement is EnumElementImpl);
-    return enclosingElement;
+    assert(enclosingElement3 is EnumElementImpl);
+    return enclosingElement3;
   }
 
   @override
@@ -8301,10 +8351,14 @@
     property.setter = this;
   }
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   Element get enclosingElement => variable2.enclosingElement;
 
   @override
+  Element get enclosingElement3 => variable2.enclosingElement3;
+
+  @override
   bool get isSetter => true;
 
   @override
@@ -8387,7 +8441,7 @@
   List<Fragment> get children3 => const [];
 
   @override
-  Fragment? get enclosingFragment => enclosingElement as Fragment;
+  Fragment? get enclosingFragment => enclosingElement3 as Fragment;
 
   @override
   GetterFragment? get getter2 => getter as GetterFragment;
@@ -8424,10 +8478,10 @@
   @override
   Element get nonSynthetic {
     if (isSynthetic) {
-      if (enclosingElement is EnumElementImpl) {
+      if (enclosingElement3 is EnumElementImpl) {
         // TODO(scheglov): remove 'index'?
         if (name == 'index' || name == 'values') {
-          return enclosingElement;
+          return enclosingElement3;
         }
       }
       return (getter ?? setter)!;
@@ -8623,7 +8677,7 @@
 
   @override
   ParameterElement? get superConstructorParameter {
-    var enclosingElement = this.enclosingElement;
+    var enclosingElement = enclosingElement3;
     if (enclosingElement is ConstructorElementImpl) {
       var superConstructor = enclosingElement.superConstructor;
       if (superConstructor != null) {
@@ -8765,11 +8819,16 @@
   TypeAliasElement2 get element =>
       throw UnsupportedError('This is not a fragment');
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   CompilationUnitElement get enclosingElement =>
       super.enclosingElement as CompilationUnitElement;
 
   @override
+  CompilationUnitElement get enclosingElement3 =>
+      super.enclosingElement3 as CompilationUnitElement;
+
+  @override
   LibraryFragment? get enclosingFragment =>
       throw UnsupportedError('This is not a fragment');
 
@@ -9017,7 +9076,7 @@
       return true;
     }
     if (other is TypeParameterElement) {
-      if (other.enclosingElement == null || enclosingElement == null) {
+      if (other.enclosingElement3 == null || enclosingElement3 == null) {
         return identical(other, this);
       }
       return other.location == location;
@@ -9313,7 +9372,7 @@
   Source get librarySource => library.source;
 
   @override
-  Source get source => enclosingElement!.source!;
+  Source get source => enclosingElement3!.source!;
 }
 
 /// Instances of [List]s that are used as "not yet computed" values, they
diff --git a/pkg/analyzer/lib/src/dart/element/extensions.dart b/pkg/analyzer/lib/src/dart/element/extensions.dart
index 47882fe..90e1384 100644
--- a/pkg/analyzer/lib/src/dart/element/extensions.dart
+++ b/pkg/analyzer/lib/src/dart/element/extensions.dart
@@ -33,7 +33,7 @@
         }
       }
     } else if (element is ConstructorElement) {
-      interfaceElement = element.enclosingElement.augmented.declaration;
+      interfaceElement = element.enclosingElement3.augmented.declaration;
     }
     if (interfaceElement == null) {
       return const <TargetKind>{};
@@ -82,21 +82,20 @@
       return true;
     }
 
-    var ancestor = enclosingElement;
+    var ancestor = enclosingElement3;
     if (ancestor is InterfaceElement) {
       if (ancestor.hasDoNotStore) {
         return true;
       }
-      ancestor = ancestor.enclosingElement;
+      ancestor = ancestor.enclosingElement3;
     } else if (ancestor is ExtensionElement) {
       if (ancestor.hasDoNotStore) {
         return true;
       }
-      ancestor = ancestor.enclosingElement;
+      ancestor = ancestor.enclosingElement3;
     }
 
-    return ancestor is CompilationUnitElement &&
-        ancestor.enclosingElement.hasDoNotStore;
+    return ancestor is CompilationUnitElement && ancestor.library.hasDoNotStore;
   }
 
   /// Return `true` if this element is an instance member of a class or mixin.
@@ -110,7 +109,7 @@
     assert(this is! PropertyInducingElement,
         'Check the PropertyAccessorElement instead');
     var this_ = this;
-    var enclosing = this_.enclosingElement;
+    var enclosing = this_.enclosingElement3;
     if (enclosing is InterfaceElement) {
       return this_ is MethodElement && !this_.isStatic ||
           this_ is PropertyAccessorElement && !this_.isStatic;
@@ -134,7 +133,7 @@
 extension ExecutableElementExtension on ExecutableElement {
   /// Whether the enclosing element is the class `Object`.
   bool get isObjectMember {
-    var enclosing = enclosingElement;
+    var enclosing = enclosingElement3;
     return enclosing is ClassElement && enclosing.isDartCoreObject;
   }
 }
diff --git a/pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart b/pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart
index 94919c8..c330854 100644
--- a/pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart
+++ b/pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart
@@ -386,7 +386,7 @@
         continue;
       }
 
-      var class_ = executable.enclosingElement;
+      var class_ = executable.enclosingElement3;
       if (class_ is ClassElement && class_.isDartCoreObject) {
         continue;
       }
@@ -535,7 +535,7 @@
         }
 
         var current = currentList.single;
-        if (candidate.enclosingElement == mixinElement) {
+        if (candidate.enclosingElement3 == mixinElement) {
           namedCandidates[name] = [candidate];
           if (current.kind != candidate.kind) {
             var currentIsGetter = current.kind == ElementKind.GETTER;
@@ -903,7 +903,7 @@
     Name name,
     ExecutableElement executable,
   ) {
-    if (executable.enclosingElement == class_) {
+    if (executable.enclosingElement3 == class_) {
       return executable;
     }
 
@@ -958,6 +958,7 @@
     if (executable is MethodElement) {
       var result = MethodElementImpl(executable.name, -1);
       result.enclosingElement = class_;
+      result.enclosingElement3 = class_;
       result.isSynthetic = true;
       result.parameters = transformedParameters;
       result.prototype = executable;
@@ -970,6 +971,7 @@
       assert(executable.isSetter);
       var result = PropertyAccessorElementImpl(executable.name, -1);
       result.enclosingElement = class_;
+      result.enclosingElement3 = class_;
       result.isSynthetic = true;
       result.parameters = transformedParameters;
       result.prototype = executable;
@@ -978,6 +980,7 @@
       var field = executable.variable2!;
       var resultField = FieldElementImpl(field.name, -1);
       resultField.enclosingElement = class_;
+      resultField.enclosingElement3 = class_;
       resultField.getter = field.getter;
       resultField.setter = executable;
       resultField.type = executable.parameters[0].type;
@@ -1031,6 +1034,7 @@
       var firstMethod = first;
       var result = MethodElementImpl(firstMethod.name, -1);
       result.enclosingElement = targetClass;
+      result.enclosingElement3 = targetClass;
       result.typeParameters = resultType.typeFormals;
       result.returnType = resultType.returnType;
       result.parameters = resultType.parameters;
@@ -1041,6 +1045,7 @@
 
       var result = PropertyAccessorElementImpl(variableName, -1);
       result.enclosingElement = targetClass;
+      result.enclosingElement3 = targetClass;
       result.isGetter = firstAccessor.isGetter;
       result.isSetter = firstAccessor.isSetter;
       result.returnType = resultType.returnType;
@@ -1048,6 +1053,7 @@
 
       var field = FieldElementImpl(variableName, -1);
       field.enclosingElement = targetClass;
+      field.enclosingElement3 = targetClass;
       if (firstAccessor.isGetter) {
         field.getter = result;
         field.type = result.returnType;
@@ -1090,7 +1096,7 @@
   }
 
   static bool _isDeclaredInObject(ExecutableElement element) {
-    var enclosing = element.enclosingElement;
+    var enclosing = element.enclosingElement3;
     return enclosing is ClassElement && enclosing.isDartCoreObject;
   }
 }
diff --git a/pkg/analyzer/lib/src/dart/element/member.dart b/pkg/analyzer/lib/src/dart/element/member.dart
index cc7449e..6f61403 100644
--- a/pkg/analyzer/lib/src/dart/element/member.dart
+++ b/pkg/analyzer/lib/src/dart/element/member.dart
@@ -49,10 +49,14 @@
   @override
   ConstructorElement2 get element => super.element as ConstructorElement2;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   InterfaceElement get enclosingElement => declaration.enclosingElement;
 
   @override
+  InterfaceElement get enclosingElement3 => declaration.enclosingElement3;
+
+  @override
   InstanceFragment? get enclosingFragment =>
       super.enclosingFragment as InstanceFragment?;
 
@@ -454,10 +458,14 @@
   @override
   FieldElement2 get element => (declaration as FieldFragment).element;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   Element get enclosingElement => declaration.enclosingElement;
 
   @override
+  Element get enclosingElement3 => declaration.enclosingElement3;
+
+  @override
   Fragment? get enclosingFragment =>
       (declaration as FieldFragment).enclosingFragment;
 
@@ -599,10 +607,14 @@
   @override
   FunctionElement get declaration => super.declaration as FunctionElement;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   Element get enclosingElement => declaration.enclosingElement;
 
   @override
+  Element get enclosingElement3 => declaration.enclosingElement3;
+
+  @override
   bool get isDartCoreIdentical => declaration.isDartCoreIdentical;
 
   @override
@@ -655,6 +667,7 @@
   @override
   String? get documentationComment => _declaration.documentationComment;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   Element? get enclosingElement => _declaration.enclosingElement;
 
@@ -898,10 +911,14 @@
   @override
   MethodElement2 get element => super.element as MethodElement2;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   Element get enclosingElement => declaration.enclosingElement;
 
   @override
+  Element get enclosingElement3 => declaration.enclosingElement3;
+
+  @override
   InstanceFragment? get enclosingFragment =>
       super.enclosingFragment as InstanceFragment?;
 
@@ -1001,10 +1018,14 @@
   @override
   String? get defaultValueCode => declaration.defaultValueCode;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   Element? get enclosingElement => declaration.enclosingElement;
 
   @override
+  Element? get enclosingElement3 => declaration.enclosingElement3;
+
+  @override
   bool get hasDefaultValue => declaration.hasDefaultValue;
 
   @override
@@ -1145,10 +1166,14 @@
   PropertyAccessorElement get declaration =>
       super.declaration as PropertyAccessorElement;
 
+  @Deprecated('Use enclosingElement3 instead')
   @override
   Element get enclosingElement => declaration.enclosingElement;
 
   @override
+  Element get enclosingElement3 => declaration.enclosingElement3;
+
+  @override
   bool get isGetter => declaration.isGetter;
 
   @override
diff --git a/pkg/analyzer/lib/src/dart/element/name_union.dart b/pkg/analyzer/lib/src/dart/element/name_union.dart
index 1fed550..2d057fe 100644
--- a/pkg/analyzer/lib/src/dart/element/name_union.dart
+++ b/pkg/analyzer/lib/src/dart/element/name_union.dart
@@ -106,7 +106,7 @@
 
   @override
   void visitElement(Element element) {
-    var enclosing = element.enclosingElement;
+    var enclosing = element.enclosingElement3;
     if (enclosing is CompilationUnitElement ||
         element is FieldElement ||
         element is MethodElement ||
diff --git a/pkg/analyzer/lib/src/dart/element/scope.dart b/pkg/analyzer/lib/src/dart/element/scope.dart
index c9d4229..6f4def7 100644
--- a/pkg/analyzer/lib/src/dart/element/scope.dart
+++ b/pkg/analyzer/lib/src/dart/element/scope.dart
@@ -109,6 +109,85 @@
   }
 }
 
+/// Tracking information for all import in [CompilationUnitElementImpl].
+class ImportsTracking {
+  /// Tracking information for each import prefix.
+  final Map<PrefixElementImpl?, ImportsTrackingOfPrefix> map;
+
+  ImportsTracking({
+    required this.map,
+  });
+
+  void notifyExtensionUsed(ExtensionElement element) {
+    for (var tracking in map.values) {
+      tracking.notifyExtensionUsed(element);
+    }
+  }
+}
+
+class ImportsTrackingOfPrefix {
+  final PrefixScope scope;
+  final Map<Element, List<LibraryImportElementImpl>> elementImports;
+  final Set<LibraryImportElementImpl> usedImports = {};
+
+  /// This flag is set to `true` when there is a compile-time error reported
+  /// against the group of imports with this import prefix. Specifically,
+  /// currently there are two errors:
+  ///
+  /// 1. Unresolved identifier.
+  /// 2. Using import prefix itself, without `.identifier` after it.
+  ///
+  /// When this happens, we don't want to report unused imports.
+  bool hasErrorReported = false;
+
+  /// We set it temporarily to `false` while resolving combinators.
+  bool active = true;
+
+  ImportsTrackingOfPrefix({
+    required this.scope,
+    required this.elementImports,
+  });
+
+  void lookupResult(Element? element) {
+    if (!active) {
+      return;
+    }
+
+    if (element == null) {
+      return;
+    }
+
+    if (element is MultiplyDefinedElement) {
+      notifyErrorReported();
+      return;
+    }
+
+    // SAFETY: if we have `element`, it is from a local import.
+    var imports = elementImports[element]!;
+    usedImports.addAll(imports);
+  }
+
+  /// We cannot resolve something, mark this group of imports as affected.
+  void notifyErrorReported() {
+    if (active) {
+      hasErrorReported = true;
+    }
+  }
+
+  void notifyExtensionUsed(ExtensionElement element) {
+    var imports = elementImports[element];
+    if (imports != null) {
+      usedImports.addAll(imports);
+    } else {
+      // We include into `accessibleExtensions` elements from parents.
+      // So, it is possible that the element is not from this scope.
+      // In this case we notify the parent tracker.
+      var parentTracking = scope.parent?._importsTracking;
+      parentTracking?.notifyExtensionUsed(element);
+    }
+  }
+}
+
 /// The scope defined by an instance element.
 class InstanceScope extends EnclosedScope {
   InstanceScope(super.parent, InstanceElement element) {
@@ -177,13 +256,22 @@
   /// The cached result for [accessibleExtensions].
   List<ExtensionElement>? _extensions;
 
+  /// This field is set temporarily while resolving all files of a library.
+  /// So, we can track which elements were actually returned, and which imports
+  /// in which file (including enclosing files) provided these elements.
+  ///
+  /// When we are done, we remove the tracker, so that it does not use memory
+  /// when we are not resolving files of this library.
+  ImportsTracking? _importsTracking;
+
   factory LibraryFragmentScope(CompilationUnitElementImpl fragment) {
+    var parent = fragment.enclosingElement3?.scope;
     return LibraryFragmentScope._(
-      parent: fragment.enclosingElement3?.scope,
+      parent: parent,
       fragment: fragment,
       noPrefixScope: PrefixScope(
         libraryElement: fragment.library,
-        parent: null,
+        parent: parent?.noPrefixScope,
         libraryImports: fragment.libraryImports,
         prefix: null,
       ),
@@ -217,6 +305,34 @@
     }.toFixedList();
   }
 
+  // TODO(scheglov): this is kludge.
+  // We should not use the fragment scope for resolving combinators.
+  // We should use the export scope of the imported library.
+  void importsTrackingActive(bool value) {
+    if (_importsTracking case var importsTracking?) {
+      for (var tracking in importsTracking.map.values) {
+        tracking.active = value;
+      }
+    }
+  }
+
+  void importsTrackingDestroy() {
+    noPrefixScope.importsTrackingDestroy();
+    for (var prefixElement in _prefixElements.values) {
+      prefixElement.scope.importsTrackingDestroy();
+    }
+  }
+
+  ImportsTracking importsTrackingInit() {
+    return _importsTracking = ImportsTracking(
+      map: {
+        null: noPrefixScope.importsTrackingInit(),
+        for (var prefixElement in _prefixElements.values)
+          prefixElement: prefixElement.scope.importsTrackingInit(),
+      },
+    );
+  }
+
   @override
   ScopeLookupResult lookup(String id) {
     // Try declarations of the whole library.
@@ -230,10 +346,14 @@
       return importResult;
     }
 
-    // No parent, no result.
+    // No result.
     return ScopeLookupResultImpl(null, null);
   }
 
+  void notifyExtensionUsed(ExtensionElement element) {
+    _importsTracking?.notifyExtensionUsed(element);
+  }
+
   PrefixScope? _getParentPrefixScope(PrefixElementImpl prefix) {
     var isDeferred = prefix.imports.any((import) {
       return import.prefix is DeferredImportElementPrefix;
@@ -266,12 +386,7 @@
     }
 
     // Try the parent's combined import scope.
-    var parentResult = parent?._lookupCombined(id);
-    if (parentResult != null) {
-      return parentResult;
-    }
-
-    return null;
+    return parent?._lookupCombined(id);
   }
 
   ScopeLookupResult? _lookupLibrary(String id) {
@@ -310,6 +425,9 @@
   final LibraryElementImpl libraryElement;
   final PrefixScope? parent;
 
+  final List<LibraryImportElementImpl> _importElements = [];
+  final Map<Element, List<LibraryImportElementImpl>> _elementImports = {};
+
   final Map<String, Element> _getters = {};
   final Map<String, Element> _setters = {};
   Set<String>? _settersFromDeprecatedExport;
@@ -317,40 +435,54 @@
   final Set<ExtensionElement> _extensions = {};
   LibraryElement? _deferredLibrary;
 
+  ImportsTrackingOfPrefix? _importsTracking;
+
   PrefixScope({
     required this.libraryElement,
     required this.parent,
-    required List<LibraryImportElement> libraryImports,
+    required List<LibraryImportElementImpl> libraryImports,
     required PrefixElement? prefix,
   }) {
     var elementFactory = libraryElement.session.elementFactory;
     for (var import in libraryImports) {
       var importedUri = import.uri;
-      if (importedUri is DirectiveUriWithLibrary &&
+      if (importedUri is DirectiveUriWithLibraryImpl &&
           import.prefix?.element == prefix) {
+        _importElements.add(import);
         var importedLibrary = importedUri.library;
-        if (importedLibrary is LibraryElementImpl) {
-          var combinators = import.combinators.build();
-          for (var exportedReference in importedLibrary.exportedReferences) {
-            var reference = exportedReference.reference;
-            if (combinators.allows(reference.name)) {
-              var element = elementFactory.elementOfReference(reference)!;
-              if (_shouldAdd(importedLibrary, element)) {
-                _add(
-                  element,
-                  importedLibrary.isFromDeprecatedExport(exportedReference),
-                );
-              }
+        var combinators = import.combinators.build();
+        for (var exportedReference in importedLibrary.exportedReferences) {
+          var reference = exportedReference.reference;
+          var id = reference.name;
+          if (combinators.allows(id)) {
+            var element = elementFactory.elementOfReference(reference)!;
+            if (_shouldAdd(importedLibrary, element)) {
+              (_elementImports[element] ??= []).add(import);
+              _add(
+                element,
+                importedLibrary.isFromDeprecatedExport(exportedReference),
+              );
             }
           }
-          if (import.prefix is DeferredImportElementPrefix) {
-            _deferredLibrary ??= importedLibrary;
-          }
+        }
+        if (import.prefix is DeferredImportElementPrefix) {
+          _deferredLibrary ??= importedLibrary;
         }
       }
     }
   }
 
+  void importsTrackingDestroy() {
+    _importsTracking = null;
+  }
+
+  ImportsTrackingOfPrefix importsTrackingInit() {
+    return _importsTracking = ImportsTrackingOfPrefix(
+      scope: this,
+      elementImports: _elementImports,
+    );
+  }
+
   @override
   ScopeLookupResult lookup(String id) {
     var deferredLibrary = _deferredLibrary;
@@ -361,6 +493,8 @@
     var getter = _getters[id];
     var setter = _setters[id];
     if (getter != null || setter != null) {
+      _importsTracking?.lookupResult(getter);
+      _importsTracking?.lookupResult(setter);
       return PrefixScopeLookupResult(
         getter,
         setter,
@@ -373,9 +507,18 @@
       return parent.lookup(id);
     }
 
+    _importsTracking?.notifyErrorReported();
     return ScopeLookupResultImpl(null, null);
   }
 
+  /// This method is invoked when the import prefix is used by itself,
+  /// without the `.identifier` after it. This is a compile-time error that
+  /// we expect the user to fix first, and we don't want to report unused
+  /// imports until then.
+  void notifyErrorReported() {
+    _importsTracking?.notifyErrorReported();
+  }
+
   void _add(Element element, bool isFromDeprecatedExport) {
     if (element is PropertyAccessorElement && element.isSetter) {
       _addTo(
diff --git a/pkg/analyzer/lib/src/dart/element/since_sdk_version.dart b/pkg/analyzer/lib/src/dart/element/since_sdk_version.dart
index 056e116..9b74825 100644
--- a/pkg/analyzer/lib/src/dart/element/since_sdk_version.dart
+++ b/pkg/analyzer/lib/src/dart/element/since_sdk_version.dart
@@ -29,8 +29,15 @@
     }
 
     var specified = _specifiedVersion(element);
-    var enclosing = element.enclosingElement?.sinceSdkVersion;
-    return specified.maxWith(enclosing);
+    if (element.enclosingElement3 case var enclosingElement?) {
+      var enclosing = enclosingElement.sinceSdkVersion;
+      return specified.maxWith(enclosing);
+    } else if (element.library case var libraryElement?) {
+      var enclosing = libraryElement.sinceSdkVersion;
+      return specified.maxWith(enclosing);
+    } else {
+      return specified;
+    }
   }
 
   /// Returns the maximal specified `@Since()` version from the [annotations].
diff --git a/pkg/analyzer/lib/src/dart/element/type_system.dart b/pkg/analyzer/lib/src/dart/element/type_system.dart
index 1d249fe..e911d35 100644
--- a/pkg/analyzer/lib/src/dart/element/type_system.dart
+++ b/pkg/analyzer/lib/src/dart/element/type_system.dart
@@ -1879,8 +1879,8 @@
     // If the method being invoked comes from an extension, don't refine the
     // type because we can only make guarantees about methods defined in the
     // SDK, and the numeric methods we refine are all instance methods.
-    if (methodElement.enclosingElement is ExtensionElement ||
-        methodElement.enclosingElement is ExtensionTypeElement) {
+    if (methodElement.enclosingElement3 is ExtensionElement ||
+        methodElement.enclosingElement3 is ExtensionTypeElement) {
       return currentType;
     }
 
@@ -1981,8 +1981,8 @@
     // If the method being invoked comes from an extension, don't refine the
     // type because we can only make guarantees about methods defined in the
     // SDK, and the numeric methods we refine are all instance methods.
-    if (methodElement.enclosingElement is ExtensionElement ||
-        methodElement.enclosingElement is ExtensionTypeElement) {
+    if (methodElement.enclosingElement3 is ExtensionElement ||
+        methodElement.enclosingElement3 is ExtensionTypeElement) {
       return currentType;
     }
 
diff --git a/pkg/analyzer/lib/src/dart/micro/utils.dart b/pkg/analyzer/lib/src/dart/micro/utils.dart
index c1cefd0..3977c01 100644
--- a/pkg/analyzer/lib/src/dart/micro/utils.dart
+++ b/pkg/analyzer/lib/src/dart/micro/utils.dart
@@ -42,7 +42,7 @@
     ConstructorElement? constructor) {
   var seenConstructors = <ConstructorElement?>{};
   while (constructor is ConstructorElementImpl && constructor.isSynthetic) {
-    var enclosing = constructor.enclosingElement;
+    var enclosing = constructor.enclosingElement3;
     if (enclosing is ClassElement && enclosing.isMixinApplication) {
       var superInvocation = constructor.constantInitializers
           .whereType<SuperConstructorInvocation>()
@@ -72,7 +72,7 @@
     String prefix,
     Element element,
     Map<LibraryImportElement, Set<Element>> importElementsMap) {
-  if (element.enclosingElement is! CompilationUnitElement) {
+  if (element.enclosingElement3 is! CompilationUnitElement) {
     return null;
   }
   var usedLibrary = element.library;
@@ -309,7 +309,7 @@
         length = 0;
       }
       references.add(MatchInfo(offset, length, kind));
-    } else if (e != null && e.enclosingElement == element) {
+    } else if (e != null && e.enclosingElement3 == element) {
       kind = MatchKind.REFERENCE;
       offset = node.offset;
       length = element.nameLength;
diff --git a/pkg/analyzer/lib/src/dart/resolver/comment_reference_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/comment_reference_resolver.dart
index 5092d92..4a5372b 100644
--- a/pkg/analyzer/lib/src/dart/resolver/comment_reference_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/comment_reference_resolver.dart
@@ -5,6 +5,7 @@
 import 'package:analyzer/dart/element/element.dart';
 import 'package:analyzer/dart/element/type.dart';
 import 'package:analyzer/src/dart/ast/ast.dart';
+import 'package:analyzer/src/dart/element/element.dart';
 import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
 import 'package:analyzer/src/dart/element/type_provider.dart';
 import 'package:analyzer/src/dart/element/type_system.dart';
@@ -143,6 +144,12 @@
     var lookupResult = identifier.scopeLookupResult!;
     var element = lookupResult.getter ?? lookupResult.setter;
 
+    // Usually referencing just an import prefix is an error.
+    // But we allow this in documentation comments.
+    if (element is PrefixElementImpl) {
+      element.scope.notifyErrorReported();
+    }
+
     if (element == null) {
       InterfaceType enclosingType;
       var enclosingClass = _resolver.enclosingClass;
diff --git a/pkg/analyzer/lib/src/dart/resolver/constructor_reference_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/constructor_reference_resolver.dart
index 1d12599..b18832c 100644
--- a/pkg/analyzer/lib/src/dart/resolver/constructor_reference_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/constructor_reference_resolver.dart
@@ -30,7 +30,7 @@
     node.constructorName.accept(_resolver);
     var element = node.constructorName.staticElement;
     if (element != null && !element.isFactory) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       if (enclosingElement is ClassElement && enclosingElement.isAbstract) {
         _resolver.errorReporter.atNode(
           node,
diff --git a/pkg/analyzer/lib/src/dart/resolver/extension_member_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/extension_member_resolver.dart
index bcf7695..124c1be 100644
--- a/pkg/analyzer/lib/src/dart/resolver/extension_member_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/extension_member_resolver.dart
@@ -96,12 +96,20 @@
     }
 
     if (extensions.length == 1) {
-      return extensions[0].asResolutionResult;
+      var instantiated = extensions[0];
+      _resolver.libraryFragment.scope.notifyExtensionUsed(
+        instantiated.extension,
+      );
+      return instantiated.asResolutionResult;
     }
 
     var mostSpecific = _chooseMostSpecific(extensions);
     if (mostSpecific.length == 1) {
-      return mostSpecific.first.asResolutionResult;
+      var instantiated = mostSpecific.first;
+      _resolver.libraryFragment.scope.notifyExtensionUsed(
+        instantiated.extension,
+      );
+      return instantiated.asResolutionResult;
     }
 
     // The most specific extension is ambiguous.
diff --git a/pkg/analyzer/lib/src/dart/resolver/function_reference_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/function_reference_resolver.dart
index 7bc59c9..38b99be 100644
--- a/pkg/analyzer/lib/src/dart/resolver/function_reference_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/function_reference_resolver.dart
@@ -175,7 +175,7 @@
     ExecutableElement element, {
     required bool implicitReceiver,
   }) {
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     if (implicitReceiver) {
       if (_resolver.enclosingExtension != null) {
         _resolver.errorReporter.atNode(
diff --git a/pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart
index 45af99b..372def2 100644
--- a/pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart
@@ -206,7 +206,7 @@
     ExecutableElement element,
     bool nullReceiver,
   ) {
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     if (nullReceiver) {
       if (_resolver.enclosingExtension != null) {
         _resolver.errorReporter.atNode(
@@ -265,7 +265,11 @@
     );
   }
 
-  void _reportPrefixIdentifierNotFollowedByDot(SimpleIdentifier target) {
+  void _reportPrefixIdentifierNotFollowedByDot(
+    SimpleIdentifier target,
+    PrefixElementImpl prefixElement,
+  ) {
+    prefixElement.scope.notifyErrorReported();
     _resolver.errorReporter.atNode(
       target,
       CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT,
@@ -586,10 +590,10 @@
         return _rewriteAsFunctionExpressionInvocation(node, targetType);
       }
       // TODO(scheglov): This is a questionable distinction.
-      if (element is PrefixElement) {
+      if (element is PrefixElementImpl) {
         _setInvalidTypeResolution(node,
             whyNotPromotedList: whyNotPromotedList, contextType: contextType);
-        _reportPrefixIdentifierNotFollowedByDot(nameNode);
+        _reportPrefixIdentifierNotFollowedByDot(nameNode, element);
         return null;
       }
       _reportInvocationOfNonFunction(node, whyNotPromotedList,
@@ -618,8 +622,8 @@
       // or is static, then we do not keep searching for the getter; this
       // setter represents the property being accessed (erroneously).
       var noGetterIsPossible =
-          element.enclosingElement is CompilationUnitElement ||
-              element.enclosingElement is ExtensionElement ||
+          element.enclosingElement3 is CompilationUnitElement ||
+              element.enclosingElement3 is ExtensionElement ||
               (element is ExecutableElement && element.isStatic);
       if (noGetterIsPossible) {
         nameNode.staticElement = element;
@@ -953,7 +957,7 @@
       functionExpression = node.methodName;
       var element = node.methodName.staticElement;
       if (element is ExecutableElement &&
-          element.enclosingElement is InstanceElement &&
+          element.enclosingElement3 is InstanceElement &&
           !element.isStatic) {
         targetType = _resolver.flowAnalysis.flow
                 ?.propertyGet(
diff --git a/pkg/analyzer/lib/src/dart/resolver/named_type_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/named_type_resolver.dart
index fcdfe0c..af1309b 100644
--- a/pkg/analyzer/lib/src/dart/resolver/named_type_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/named_type_resolver.dart
@@ -264,6 +264,9 @@
       );
       return _verifyTypeAliasForContext(node, element, type);
     } else if (_isInstanceCreation(node)) {
+      if (element is PrefixElementImpl) {
+        element.scope.notifyErrorReported();
+      }
       _ErrorHelper(errorReporter).reportNewWithNonType(node);
       return InvalidTypeImpl.instance;
     } else if (element is DynamicElementImpl) {
@@ -602,7 +605,7 @@
 
     if (element is LocalVariableElement ||
         (element is FunctionElement &&
-            element.enclosingElement is ExecutableElement)) {
+            element.enclosingElement3 is ExecutableElement)) {
       errorReporter.reportError(
         DiagnosticFactory().referencedBeforeDeclaration(
           errorReporter.source,
@@ -614,6 +617,9 @@
     }
 
     if (element != null) {
+      if (element is PrefixElementImpl) {
+        element.scope.notifyErrorReported();
+      }
       var errorRange = _getErrorRange(node);
       errorReporter.atOffset(
         offset: errorRange.offset,
diff --git a/pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart
index c9c34c4..e599c38 100644
--- a/pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart
@@ -325,7 +325,7 @@
           CompileTimeErrorCode.EXTENSION_OVERRIDE_ACCESS_TO_STATIC_MEMBER,
         );
       } else {
-        var enclosingElement = element.enclosingElement;
+        var enclosingElement = element.enclosingElement3;
         if (enclosingElement is ExtensionElement &&
             enclosingElement.name == null) {
           _resolver.errorReporter.atNode(
diff --git a/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart b/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart
index 4074b857..6d384f3 100644
--- a/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart
@@ -55,6 +55,7 @@
 
   void enclose(ElementImpl element) {
     element.enclosingElement = _element;
+    element.enclosingElement3 = _element;
   }
 }
 
@@ -1973,7 +1974,9 @@
             .map((e) => e.inconsistency),
       ),
     )
+      // ignore: deprecated_member_use_from_same_package
       ..enclosingElement = first.enclosingElement
+      ..enclosingElement3 = first.enclosingElement3
       ..type = InvalidTypeImpl.instance;
   }
 }
diff --git a/pkg/analyzer/lib/src/dart/resolver/simple_identifier_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/simple_identifier_resolver.dart
index 5a8a6fd..46bbe5c 100644
--- a/pkg/analyzer/lib/src/dart/resolver/simple_identifier_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/simple_identifier_resolver.dart
@@ -198,7 +198,8 @@
         !identical(element, enclosingClass)) {
       // This error is now reported by the parser.
       element = null;
-    } else if (element is PrefixElement && !_isValidAsPrefix(node)) {
+    } else if (element is PrefixElementImpl && !_isValidAsPrefix(node)) {
+      element.scope.notifyErrorReported();
       errorReporter.atNode(
         node,
         CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT,
diff --git a/pkg/analyzer/lib/src/diagnostic/diagnostic_factory.dart b/pkg/analyzer/lib/src/diagnostic/diagnostic_factory.dart
index a4e8ef8..760996f 100644
--- a/pkg/analyzer/lib/src/diagnostic/diagnostic_factory.dart
+++ b/pkg/analyzer/lib/src/diagnostic/diagnostic_factory.dart
@@ -306,9 +306,9 @@
       errorCode: errorCode,
       arguments: [
         memberName,
-        member.enclosingElement.name!,
+        member.enclosingElement3.name!,
         member.type,
-        superMember.enclosingElement.name!,
+        superMember.enclosingElement3.name!,
         superMember.type,
       ],
       contextMessages: [
diff --git a/pkg/analyzer/lib/src/error/annotation_verifier.dart b/pkg/analyzer/lib/src/error/annotation_verifier.dart
index 1e02d89..35c45f9 100644
--- a/pkg/analyzer/lib/src/error/annotation_verifier.dart
+++ b/pkg/analyzer/lib/src/error/annotation_verifier.dart
@@ -138,7 +138,7 @@
         }
       }
     } else if (parent is ConstructorDeclaration) {
-      var class_ = parent.declaredElement!.enclosingElement;
+      var class_ = parent.declaredElement!.enclosingElement3;
       if (class_.isPrivate || parentElementIsPrivate) {
         _errorReporter.atNode(
           node.name,
@@ -165,7 +165,7 @@
         var invokedElement = element.element!;
         var name = invokedElement.name;
         if (invokedElement is ConstructorElement) {
-          var className = invokedElement.enclosingElement.name;
+          var className = invokedElement.enclosingElement3.name;
           if (name!.isEmpty) {
             name = className;
           } else {
@@ -383,7 +383,7 @@
         var declaredElement = parent.declaredElement!;
         if (element.isVisibleForOverriding &&
             (!declaredElement.isInstanceMember ||
-                declaredElement.enclosingElement is ExtensionTypeElement)) {
+                declaredElement.enclosingElement3 is ExtensionTypeElement)) {
           reportInvalidVisibleForOverriding();
         }
 
diff --git a/pkg/analyzer/lib/src/error/assignment_verifier.dart b/pkg/analyzer/lib/src/error/assignment_verifier.dart
index c77e909..dffc063 100644
--- a/pkg/analyzer/lib/src/error/assignment_verifier.dart
+++ b/pkg/analyzer/lib/src/error/assignment_verifier.dart
@@ -63,7 +63,8 @@
         node,
         CompileTimeErrorCode.ASSIGNMENT_TO_METHOD,
       );
-    } else if (recovery is PrefixElement) {
+    } else if (recovery is PrefixElementImpl) {
+      recovery.scope.notifyErrorReported();
       _errorReporter.atNode(
         node,
         CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT,
@@ -83,7 +84,7 @@
         _errorReporter.atNode(
           node,
           CompileTimeErrorCode.ASSIGNMENT_TO_FINAL_NO_SETTER,
-          arguments: [variable.name, variable.enclosingElement.displayName],
+          arguments: [variable.name, variable.enclosingElement3.displayName],
         );
       } else {
         _errorReporter.atNode(
diff --git a/pkg/analyzer/lib/src/error/best_practices_verifier.dart b/pkg/analyzer/lib/src/error/best_practices_verifier.dart
index bc3bf9c..8d71817 100644
--- a/pkg/analyzer/lib/src/error/best_practices_verifier.dart
+++ b/pkg/analyzer/lib/src/error/best_practices_verifier.dart
@@ -382,7 +382,7 @@
           var element = field.declaredElement;
           if (element is PropertyAccessorElement || element is FieldElement) {
             Name name = Name(_currentLibrary.source.uri, element!.name);
-            var enclosingElement = element.enclosingElement!;
+            var enclosingElement = element.enclosingElement3!;
             var enclosingDeclaration = enclosingElement is InstanceElement
                 ? enclosingElement.augmented.declaration
                 : enclosingElement;
@@ -414,7 +414,7 @@
             WarningCode.INVALID_OVERRIDE_OF_NON_VIRTUAL_MEMBER,
             arguments: [
               field.name.lexeme,
-              overriddenElement.enclosingElement.displayName
+              overriddenElement.enclosingElement3.displayName
             ],
           );
         }
@@ -568,7 +568,7 @@
   void visitMethodDeclaration(MethodDeclaration node) {
     bool wasInDoNotStoreMember = _inDoNotStoreMember;
     var element = node.declaredElement!;
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     var enclosingDeclaration = enclosingElement is InstanceElement
         ? enclosingElement.augmented.declaration
         : enclosingElement;
@@ -612,7 +612,7 @@
           WarningCode.INVALID_OVERRIDE_OF_NON_VIRTUAL_MEMBER,
           arguments: [
             node.name.lexeme,
-            overriddenElement.enclosingElement.displayName
+            overriddenElement.enclosingElement3.displayName
           ],
         );
       }
@@ -1242,7 +1242,7 @@
         SimpleIdentifier name = invocation.methodName;
         if (name.name == FunctionElement.NO_SUCH_METHOD_METHOD_NAME) {
           var methodElement = name.staticElement;
-          var classElement = methodElement?.enclosingElement;
+          var classElement = methodElement?.enclosingElement3;
           return methodElement is MethodElement &&
               classElement is ClassElement &&
               !classElement.isDartCoreObject;
@@ -1842,7 +1842,7 @@
   void _checkForOtherInvalidAccess(AstNode node, Element element) {
     var hasProtected = element.isProtected;
     if (hasProtected) {
-      var definingClass = element.enclosingElement as InterfaceElement;
+      var definingClass = element.enclosingElement3 as InterfaceElement;
       if (_hasTypeOrSuperType(_enclosingClass, definingClass)) {
         return;
       }
@@ -1869,7 +1869,7 @@
     // annotation present.
     var (name, errorEntity) = _getIdentifierNameAndErrorEntity(node, element);
 
-    var definingClass = element.enclosingElement;
+    var definingClass = element.enclosingElement3;
     if (definingClass == null) {
       return;
     }
@@ -1965,7 +1965,7 @@
         return true;
       }
     }
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     if (_hasVisibleForTemplate(enclosingElement)) {
       return true;
     }
@@ -1982,7 +1982,7 @@
         return true;
       }
     }
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     if (enclosingElement != null &&
         _hasVisibleOutsideTemplate(enclosingElement)) {
       return true;
diff --git a/pkg/analyzer/lib/src/error/correct_override.dart b/pkg/analyzer/lib/src/error/correct_override.dart
index 28c03768..b7f3fda 100644
--- a/pkg/analyzer/lib/src/error/correct_override.dart
+++ b/pkg/analyzer/lib/src/error/correct_override.dart
@@ -131,9 +131,9 @@
             CompileTimeErrorCode.INVALID_OVERRIDE,
             arguments: [
               _thisMember.name,
-              _thisMember.enclosingElement.name!,
+              _thisMember.enclosingElement3.name!,
               _thisMember.type,
-              superMember.enclosingElement.name!,
+              superMember.enclosingElement3.name!,
               superMember.type,
             ],
           );
@@ -144,7 +144,7 @@
 
   List<_SuperMember> _superMembers() {
     var classHierarchy = _session.classHierarchy;
-    var classElement = _thisMember.enclosingElement as InterfaceElementImpl;
+    var classElement = _thisMember.enclosingElement3 as InterfaceElementImpl;
     var interfaces = classHierarchy.implementedInterfaces(classElement);
 
     var superMembers = <_SuperMember>[];
@@ -272,5 +272,6 @@
 
   _SuperParameter(this.element, this.type);
 
-  ExecutableElement get member => element.enclosingElement as ExecutableElement;
+  ExecutableElement get member =>
+      element.enclosingElement3 as ExecutableElement;
 }
diff --git a/pkg/analyzer/lib/src/error/dead_code_verifier.dart b/pkg/analyzer/lib/src/error/dead_code_verifier.dart
index 367ccc3..2c8a649 100644
--- a/pkg/analyzer/lib/src/error/dead_code_verifier.dart
+++ b/pkg/analyzer/lib/src/error/dead_code_verifier.dart
@@ -591,7 +591,8 @@
 
 extension on FunctionElement {
   bool get isLocal =>
-      enclosingElement is FunctionElement || enclosingElement is MethodElement;
+      enclosingElement3 is FunctionElement ||
+      enclosingElement3 is MethodElement;
 }
 
 extension DoStatementExtension on DoStatement {
diff --git a/pkg/analyzer/lib/src/error/deprecated_member_use_verifier.dart b/pkg/analyzer/lib/src/error/deprecated_member_use_verifier.dart
index 12b26de..5ecb605 100644
--- a/pkg/analyzer/lib/src/error/deprecated_member_use_verifier.dart
+++ b/pkg/analyzer/lib/src/error/deprecated_member_use_verifier.dart
@@ -279,7 +279,7 @@
   /// Return `true` if [element] is a [ParameterElement] declared in [node].
   static bool _isLocalParameter(Element? element, AstNode? node) {
     if (element is ParameterElement) {
-      var definingFunction = element.enclosingElement as ExecutableElement;
+      var definingFunction = element.enclosingElement3 as ExecutableElement;
 
       for (; node != null; node = node.parent) {
         if (node is ConstructorDeclaration) {
diff --git a/pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart b/pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart
index 97ee5a1..868862d 100644
--- a/pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart
+++ b/pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart
@@ -598,7 +598,7 @@
           arguments: [
             declarationElement.displayName,
             baseName,
-            inherited.enclosingElement.displayName,
+            inherited.enclosingElement3.displayName,
           ],
         );
       }
@@ -620,7 +620,7 @@
           arguments: [
             declarationElement.displayName,
             baseName,
-            inherited.enclosingElement.displayName,
+            inherited.enclosingElement3.displayName,
           ],
         );
       }
diff --git a/pkg/analyzer/lib/src/error/getter_setter_types_verifier.dart b/pkg/analyzer/lib/src/error/getter_setter_types_verifier.dart
index d5da2fe..0354359 100644
--- a/pkg/analyzer/lib/src/error/getter_setter_types_verifier.dart
+++ b/pkg/analyzer/lib/src/error/getter_setter_types_verifier.dart
@@ -49,28 +49,28 @@
           var setterType = setter.parameters[0].type;
           if (!_typeSystem.isSubtypeOf(getterType, setterType)) {
             Element errorElement;
-            if (getter.enclosingElement == element) {
+            if (getter.enclosingElement3 == element) {
               if (element is ExtensionTypeElement &&
                   element.representation.getter == getter) {
                 errorElement = setter;
               } else {
                 errorElement = getter;
               }
-            } else if (setter.enclosingElement == element) {
+            } else if (setter.enclosingElement3 == element) {
               errorElement = setter;
             } else {
               errorElement = element;
             }
 
             var getterName = getter.displayName;
-            if (getter.enclosingElement != element) {
-              var getterClassName = getter.enclosingElement.displayName;
+            if (getter.enclosingElement3 != element) {
+              var getterClassName = getter.enclosingElement3.displayName;
               getterName = '$getterClassName.$getterName';
             }
 
             var setterName = setter.displayName;
-            if (setter.enclosingElement != element) {
-              var setterClassName = setter.enclosingElement.displayName;
+            if (setter.enclosingElement3 != element) {
+              var setterClassName = setter.enclosingElement3.displayName;
               setterName = '$setterClassName.$setterName';
             }
 
diff --git a/pkg/analyzer/lib/src/error/imports_verifier.dart b/pkg/analyzer/lib/src/error/imports_verifier.dart
index 8265591..5f6df8f 100644
--- a/pkg/analyzer/lib/src/error/imports_verifier.dart
+++ b/pkg/analyzer/lib/src/error/imports_verifier.dart
@@ -5,7 +5,9 @@
 import 'package:analyzer/dart/ast/visitor.dart';
 import 'package:analyzer/dart/element/element.dart';
 import 'package:analyzer/error/listener.dart';
+import 'package:analyzer/src/dart/analysis/file_analysis.dart';
 import 'package:analyzer/src/dart/ast/ast.dart';
+import 'package:analyzer/src/dart/element/element.dart';
 import 'package:analyzer/src/dart/resolver/scope.dart';
 import 'package:analyzer/src/error/codes.dart';
 import 'package:analyzer/src/summary2/combinator.dart';
@@ -107,7 +109,7 @@
 
   void _recordIfExtensionMember(Element? element) {
     if (element != null) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       if (enclosingElement is ExtensionElement) {
         _recordUsedExtension(enclosingElement);
       }
@@ -208,14 +210,14 @@
     if (_recordPrefixMap(identifier, element)) {
       return;
     }
-    var enclosingElement = element.enclosingElement;
-    if (enclosingElement is CompilationUnitElement) {
+    var enclosingElement = element.enclosingElement3;
+    if (element is PrefixElement) {
+      usedElements.prefixMap.putIfAbsent(element, () => <Element>[]);
+    } else if (enclosingElement is CompilationUnitElement) {
       _recordUsedElement(element);
     } else if (enclosingElement is ExtensionElement) {
       _recordUsedExtension(enclosingElement);
       return;
-    } else if (element is PrefixElement) {
-      usedElements.prefixMap.putIfAbsent(element, () => <Element>[]);
     } else if (element is MultiplyDefinedElement) {
       // If the element is multiply defined then call this method recursively
       // for each of the conflicting elements.
@@ -241,6 +243,8 @@
 /// this logic built up in this class could be used for such an action in the
 /// future.
 class ImportsVerifier {
+  final FileAnalysis fileAnalysis;
+
   /// All [ImportDirective]s of the current library.
   final List<ImportDirectiveImpl> _allImports = [];
 
@@ -296,6 +300,10 @@
   final Map<NamespaceDirective, List<SimpleIdentifier>>
       _duplicateShownNamesMap = {};
 
+  ImportsVerifier({
+    required this.fileAnalysis,
+  });
+
   void addImports(CompilationUnit node) {
     var importsWithLibraries = <_NamespaceDirective>[];
     var exportsWithLibraries = <_NamespaceDirective>[];
@@ -431,37 +439,41 @@
     verifier.reportImports(errorReporter);
   }
 
-  /// Report an [HintCode.UNUSED_IMPORT] hint for each unused import.
-  ///
-  /// Only call this method after all of the compilation units have been visited
-  /// by this visitor.
-  ///
-  /// @param errorReporter the error reporter used to report the set of
-  ///        [HintCode.UNUSED_IMPORT] hints
+  /// Report [WarningCode.UNUSED_IMPORT] for each unused import.
   void generateUnusedImportHints(ErrorReporter errorReporter) {
-    int length = _unusedImports.length;
-    for (int i = 0; i < length; i++) {
-      ImportDirective unusedImport = _unusedImports[i];
-      // Check that the imported URI exists and isn't dart:core
-      var importElement = unusedImport.element;
-      if (importElement != null) {
-        var libraryElement = importElement.importedLibrary;
-        if (libraryElement == null ||
-            libraryElement.isDartCore ||
-            libraryElement.isSynthetic) {
+    for (var importDirective in fileAnalysis.unit.directives) {
+      if (importDirective is ImportDirectiveImpl) {
+        var importElement = importDirective.element!;
+        var prefixElement = importElement.prefix?.element;
+        var tracking = fileAnalysis.importsTracking.map[prefixElement]!;
+
+        // If there are errors reported against this group (by import prefix)
+        // of imports, then it does not matter which imports are used.
+        if (tracking.hasErrorReported) {
           continue;
         }
+
+        if (importElement.uri case DirectiveUriWithLibraryImpl uri) {
+          // Ignore explicit dart:core import.
+          if (uri.library.isDartCore) {
+            continue;
+          }
+
+          // The URI target does not exist, reported this elsewhere.
+          if (uri.library.isSynthetic) {
+            continue;
+          }
+
+          var isUsed = tracking.usedImports.contains(importElement);
+          if (!isUsed) {
+            errorReporter.atNode(
+              importDirective.uri,
+              WarningCode.UNUSED_IMPORT,
+              arguments: [uri.relativeUriString],
+            );
+          }
+        }
       }
-      StringLiteral uri = unusedImport.uri;
-      // We can safely assume that `uri.stringValue` is non-`null`, because the
-      // only way for it to be `null` is if the import contains a string
-      // interpolation, in which case the import wouldn't have resolved and
-      // would not have been included in [_unusedImports].
-      errorReporter.atNode(
-        uri,
-        WarningCode.UNUSED_IMPORT,
-        arguments: [uri.stringValue!],
-      );
     }
   }
 
diff --git a/pkg/analyzer/lib/src/error/inheritance_override.dart b/pkg/analyzer/lib/src/error/inheritance_override.dart
index 251c348..a1eb318 100644
--- a/pkg/analyzer/lib/src/error/inheritance_override.dart
+++ b/pkg/analyzer/lib/src/error/inheritance_override.dart
@@ -692,7 +692,7 @@
       ) {
         var member = concreteMap[Name(libraryUri, memberName)];
         if (member != null) {
-          var enclosingClass = member.enclosingElement as InterfaceElement;
+          var enclosingClass = member.enclosingElement3 as InterfaceElement;
           if (enclosingClass is! ClassElement || filter(enclosingClass)) {
             reporter.atToken(
               classNameToken,
@@ -733,7 +733,7 @@
         reporter.atToken(
           classNameToken,
           CompileTimeErrorCode.ILLEGAL_ENUM_VALUES_INHERITANCE,
-          arguments: [inherited.enclosingElement.name!],
+          arguments: [inherited.enclosingElement3.name!],
         );
       }
     }
@@ -857,13 +857,13 @@
         CompileTimeErrorCode.INCONSISTENT_INHERITANCE_GETTER_AND_METHOD,
         arguments: [
           name.name,
-          conflict.getter.enclosingElement.name!,
-          conflict.method.enclosingElement.name!
+          conflict.getter.enclosingElement3.name!,
+          conflict.method.enclosingElement3.name!
         ],
       );
     } else if (conflict is CandidatesConflict) {
       var candidatesStr = conflict.candidates.map((candidate) {
-        var className = candidate.enclosingElement.name;
+        var className = candidate.enclosingElement3.name;
         var typeStr = candidate.type.getDisplayString();
         return '$className.${name.name} ($typeStr)';
       }).join(', ');
@@ -897,7 +897,7 @@
       }
 
       var elementName = element.displayName;
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       var enclosingName = enclosingElement.displayName;
       var description = "$prefix$enclosingName.$elementName";
 
diff --git a/pkg/analyzer/lib/src/error/must_call_super_verifier.dart b/pkg/analyzer/lib/src/error/must_call_super_verifier.dart
index acc6574..8a9db45 100644
--- a/pkg/analyzer/lib/src/error/must_call_super_verifier.dart
+++ b/pkg/analyzer/lib/src/error/must_call_super_verifier.dart
@@ -28,11 +28,11 @@
 
     if (element is MethodElement && _hasConcreteSuperMethod(element)) {
       _verifySuperIsCalled(
-          node, overridden.name, overridden.enclosingElement.name);
+          node, overridden.name, overridden.enclosingElement3.name);
       return;
     }
 
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     if (enclosingElement is! ClassElement) {
       return;
     }
@@ -42,7 +42,7 @@
           .lookUpInheritedConcreteGetter(element.name, element.library);
       if (inheritedConcreteGetter != null) {
         _verifySuperIsCalled(
-            node, overridden.name, overridden.enclosingElement.name);
+            node, overridden.name, overridden.enclosingElement3.name);
       }
       return;
     }
@@ -57,7 +57,7 @@
         if (name.endsWith('=')) {
           name = name.substring(0, name.length - 1);
         }
-        _verifySuperIsCalled(node, name, overridden.enclosingElement.name);
+        _verifySuperIsCalled(node, name, overridden.enclosingElement3.name);
       }
     }
   }
@@ -73,10 +73,10 @@
   ExecutableElement? _findOverriddenMemberWithMustCallSuper(
       ExecutableElement element) {
     //Element member = node.declaredElement;
-    if (element.enclosingElement is! InterfaceElement) {
+    if (element.enclosingElement3 is! InterfaceElement) {
       return null;
     }
-    var classElement = element.enclosingElement as InterfaceElement;
+    var classElement = element.enclosingElement3 as InterfaceElement;
     String name = element.name;
 
     // Walk up the type hierarchy from [classElement], ignoring direct
@@ -118,7 +118,7 @@
 
   /// Returns whether [node] overrides a concrete method.
   bool _hasConcreteSuperMethod(ExecutableElement element) {
-    var classElement = element.enclosingElement as InterfaceElement;
+    var classElement = element.enclosingElement3 as InterfaceElement;
     String name = element.name;
 
     if (classElement.supertype.isConcrete(name)) {
diff --git a/pkg/analyzer/lib/src/error/type_arguments_verifier.dart b/pkg/analyzer/lib/src/error/type_arguments_verifier.dart
index 18bac09..4d250c58 100644
--- a/pkg/analyzer/lib/src/error/type_arguments_verifier.dart
+++ b/pkg/analyzer/lib/src/error/type_arguments_verifier.dart
@@ -96,7 +96,7 @@
       return;
     }
 
-    var enumElement = constructorElement.enclosingElement;
+    var enumElement = constructorElement.enclosingElement3;
     var typeParameters = enumElement.typeParameters;
 
     var typeArgumentList = node.arguments?.typeArguments;
diff --git a/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart b/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart
index 65794e8..1bcde72 100644
--- a/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart
+++ b/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart
@@ -303,7 +303,7 @@
           usedElements.addElement(parameter);
         }
       }
-      var enclosingElement = element?.enclosingElement;
+      var enclosingElement = element?.enclosingElement3;
       if (element == null) {
         if (isIdentifierRead) {
           usedElements.unresolvedReadMembers.add(node.name);
@@ -800,7 +800,7 @@
     if (element.isPrivate) {
       return false;
     }
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
 
     if (enclosingElement is EnumElement) {
       if (element is ConstructorElement && element.isGenerative) {
@@ -828,7 +828,7 @@
     bool elementIsStaticVariable =
         element is VariableElement && element.isStatic;
     if (element.isPublic) {
-      if (_isPrivateClassOrExtension(element.enclosingElement!) &&
+      if (_isPrivateClassOrExtension(element.enclosingElement3!) &&
           elementIsStaticVariable) {
         // Public static fields of private classes, mixins, and extensions are
         // inaccessible from outside the library in which they are declared.
@@ -865,7 +865,7 @@
         element is FunctionElement && !element.isStatic) {
       // local variable or function
     } else if (element is ParameterElement) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       // Only report unused parameters of constructors, methods, and functions.
       if (enclosingElement is! ConstructorElement &&
           enclosingElement is! FunctionElement &&
@@ -877,7 +877,7 @@
         return true;
       }
       if (enclosingElement is ConstructorElement &&
-          enclosingElement.enclosingElement.typeParameters.isNotEmpty) {
+          enclosingElement.enclosingElement3.typeParameters.isNotEmpty) {
         // There is an issue matching arguments of instance creation
         // expressions for generic classes with parameters, so for now,
         // consider every parameter of a constructor of a generic class
@@ -944,7 +944,7 @@
   }
 
   Iterable<ExecutableElement> _overriddenElements(Element element) {
-    var fragment = element.enclosingElement;
+    var fragment = element.enclosingElement3;
     if (fragment is InterfaceElement) {
       var enclosingElement = fragment.augmented.declaration;
       Name name = Name(_libraryUri, element.name!);
@@ -1017,7 +1017,7 @@
     // constructor in the class. A single unused, private constructor may serve
     // the purpose of preventing the class from being extended. In serving this
     // purpose, the constructor is "used."
-    if (element.enclosingElement.constructors.length > 1 &&
+    if (element.enclosingElement3.constructors.length > 1 &&
         !_isUsedMember(element)) {
       _reportErrorForElement(
           WarningCode.UNUSED_ELEMENT, element, [element.displayName]);
@@ -1183,5 +1183,6 @@
 
 extension on FunctionElement {
   bool get isLocal =>
-      enclosingElement is FunctionElement || enclosingElement is MethodElement;
+      enclosingElement3 is FunctionElement ||
+      enclosingElement3 is MethodElement;
 }
diff --git a/pkg/analyzer/lib/src/generated/element_resolver.dart b/pkg/analyzer/lib/src/generated/element_resolver.dart
index 41d6ae9..5460c10 100644
--- a/pkg/analyzer/lib/src/generated/element_resolver.dart
+++ b/pkg/analyzer/lib/src/generated/element_resolver.dart
@@ -376,7 +376,7 @@
     } else {
       if (element.isFactory &&
           // Check if we've reported [NO_GENERATIVE_CONSTRUCTORS_IN_SUPERCLASS].
-          !element.enclosingElement.constructors
+          !element.enclosingElement3.constructors
               .every((constructor) => constructor.isFactory)) {
         _errorReporter.atNode(
           node,
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index 4594966..d0e882fdf 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -129,7 +129,7 @@
   }
 
   static bool _inFactoryConstructor(Element? element) {
-    var enclosing = element?.enclosingElement;
+    var enclosing = element?.enclosingElement3;
     if (enclosing == null) {
       return false;
     }
@@ -140,7 +140,7 @@
   }
 
   static bool _inStaticMethod(Element? element) {
-    var enclosing = element?.enclosingElement;
+    var enclosing = element?.enclosingElement3;
     if (enclosing == null) {
       return false;
     }
@@ -950,7 +950,7 @@
   @override
   void visitFunctionDeclaration(covariant FunctionDeclarationImpl node) {
     var element = node.declaredElement!;
-    if (element.enclosingElement is! CompilationUnitElement) {
+    if (element.enclosingElement3 is! CompilationUnitElement) {
       _hiddenElements!.declare(element);
     }
 
@@ -2175,7 +2175,7 @@
         errorReporter.atNode(
           highlightedNode,
           CompileTimeErrorCode.ASSIGNMENT_TO_FINAL_NO_SETTER,
-          arguments: [variable.name, variable.enclosingElement.displayName],
+          arguments: [variable.name, variable.enclosingElement3.displayName],
         );
       } else {
         errorReporter.atNode(
@@ -2394,7 +2394,7 @@
             arguments: [
               enclosingClass.displayName,
               name,
-              inherited.enclosingElement.displayName,
+              inherited.enclosingElement3.displayName,
             ],
           );
         }
@@ -2422,7 +2422,7 @@
           arguments: [
             enclosingClass.displayName,
             name,
-            inherited.enclosingElement.displayName
+            inherited.enclosingElement3.displayName
           ],
         );
       }
@@ -2455,7 +2455,7 @@
           arguments: [
             enclosingClass.displayName,
             name,
-            inherited.enclosingElement.displayName,
+            inherited.enclosingElement3.displayName,
           ],
         );
         conflictingDeclaredNames.add(name);
@@ -2470,7 +2470,7 @@
           arguments: [
             enclosingClass.displayName,
             name,
-            inherited.enclosingElement.displayName
+            inherited.enclosingElement3.displayName
           ],
         );
         conflictingDeclaredNames.add(name);
@@ -2503,8 +2503,8 @@
                 message: formatList(
                   "The method is inherited from the {0} '{1}'.",
                   [
-                    method.enclosingElement.kind.displayName,
-                    method.enclosingElement.name,
+                    method.enclosingElement3.kind.displayName,
+                    method.enclosingElement3.name,
                   ],
                 ),
                 offset: method.nameOffset,
@@ -2516,8 +2516,8 @@
                 message: formatList(
                   "The setter is inherited from the {0} '{1}'.",
                   [
-                    setter.enclosingElement.kind.displayName,
-                    setter.enclosingElement.name,
+                    setter.enclosingElement3.kind.displayName,
+                    setter.enclosingElement3.name,
                   ],
                 ),
                 offset: setter.nameOffset,
@@ -2843,12 +2843,12 @@
       errorReporter.atNode(
         constructor.returnType,
         CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN_WITH_FIELD,
-        arguments: ["'${field.enclosingElement.name}.${field.name}'"],
+        arguments: ["'${field.enclosingElement3.name}.${field.name}'"],
       );
       return true;
     } else if (instanceFields.length > 1) {
       var fieldNames = instanceFields
-          .map((field) => "'${field.enclosingElement.name}.${field.name}'")
+          .map((field) => "'${field.enclosingElement3.name}.${field.name}'")
           .join(', ');
       errorReporter.atNode(
         constructor.returnType,
@@ -2887,7 +2887,7 @@
     errorReporter.atNode(
       errorNode,
       CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER,
-      arguments: [element.enclosingElement.displayName],
+      arguments: [element.enclosingElement3.displayName],
     );
     return true;
   }
@@ -2905,7 +2905,7 @@
       return;
     }
     // check if there is non-final field
-    var classElement = constructorElement.enclosingElement;
+    var classElement = constructorElement.enclosingElement3;
     if (classElement is! ClassElement || !classElement.hasNonFinalField) {
       return;
     }
@@ -3453,7 +3453,7 @@
     void report(String memberName, List<ExecutableElement> candidates) {
       var contextMessages = candidates.map<DiagnosticMessage>((executable) {
         var nonSynthetic = executable.nonSynthetic;
-        var container = executable.enclosingElement as InterfaceElement;
+        var container = executable.enclosingElement3 as InterfaceElement;
         return DiagnosticMessageImpl(
           filePath: executable.source.fullName,
           offset: nonSynthetic.nameOffset,
@@ -3838,7 +3838,7 @@
         // OK, instance member
         return;
       }
-      Element enclosingElement = element.enclosingElement;
+      Element enclosingElement = element.enclosingElement3;
       if (enclosingElement is ExtensionElement) {
         if (target is ExtensionOverride) {
           // OK, target is an extension override
@@ -3951,7 +3951,7 @@
     var constructorElement = node.staticElement;
     if (constructorElement != null &&
         constructorElement.isGenerative &&
-        constructorElement.enclosingElement is EnumElement) {
+        constructorElement.enclosingElement3 is EnumElement) {
       if (_currentLibrary.featureSet.isEnabled(Feature.enhanced_enums)) {
         errorReporter.atNode(
           node,
@@ -3994,7 +3994,7 @@
       return;
     }
     // not a class member
-    Element enclosingElement = element.enclosingElement;
+    Element enclosingElement = element.enclosingElement3;
     if (enclosingElement is! InterfaceElement &&
         enclosingElement is! ExtensionElement) {
       return;
@@ -4123,7 +4123,7 @@
 
   void _checkForMainFunction1(Token nameToken, Element declaredElement) {
     // We should only check exported declarations, i.e. top-level.
-    if (declaredElement.enclosingElement is! CompilationUnitElement) {
+    if (declaredElement.enclosingElement3 is! CompilationUnitElement) {
       return;
     }
 
@@ -4537,7 +4537,7 @@
             arguments: [
               name,
               namedType.name2.lexeme,
-              inheritedMember.enclosingElement.name!
+              inheritedMember.enclosingElement3.name!
             ],
           );
           return true;
@@ -5112,7 +5112,7 @@
       redirectedElement,
       redirectedConstructor,
     );
-    var redirectedClass = redirectedElement?.enclosingElement;
+    var redirectedClass = redirectedElement?.enclosingElement3;
     if (redirectedClass is ClassElement &&
         redirectedClass.isAbstract &&
         redirectedElement != null &&
@@ -5421,7 +5421,7 @@
   }) {
     if (_enclosingExecutable.inStaticMethod || _isInStaticVariableDeclaration) {
       if (element is TypeParameterElement &&
-          element.enclosingElement is InstanceElement) {
+          element.enclosingElement3 is InstanceElement) {
         // The class's type parameters are not in scope for static methods.
         // However all other type parameters are legal (e.g. the static method's
         // type parameters, or a local function's type parameters).
@@ -5663,7 +5663,7 @@
       return;
     }
 
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     if (enclosingElement == null) {
       return;
     }
@@ -6687,7 +6687,7 @@
       var element = annotation.element;
       if (element is! ConstructorElementImpl) continue;
 
-      var macroElement = element.enclosingElement;
+      var macroElement = element.enclosingElement3;
       if (macroElement is! ClassElementImpl) continue;
       if (!macroElement.isMacro) continue;
 
diff --git a/pkg/analyzer/lib/src/generated/exhaustiveness.dart b/pkg/analyzer/lib/src/generated/exhaustiveness.dart
index eba893e..a4923c1 100644
--- a/pkg/analyzer/lib/src/generated/exhaustiveness.dart
+++ b/pkg/analyzer/lib/src/generated/exhaustiveness.dart
@@ -57,7 +57,7 @@
 
   @override
   void writeEnumValue(FieldElement value, String name) {
-    var enumElement = value.enclosingElement;
+    var enumElement = value.enclosingElement3;
     if (enumElement is! EnumElement) {
       isComplete = false;
       return;
@@ -99,7 +99,7 @@
 
   @override
   String getEnumElementName(FieldElement enumField) {
-    return '${enumField.enclosingElement.name}.${enumField.name}';
+    return '${enumField.enclosingElement3.name}.${enumField.name}';
   }
 
   @override
@@ -550,12 +550,12 @@
         Element? element = field.element;
         DartType? extensionPropertyType;
         if (element is PropertyAccessorElement &&
-            (element.enclosingElement is ExtensionElement ||
-                element.enclosingElement is ExtensionTypeElement)) {
+            (element.enclosingElement3 is ExtensionElement ||
+                element.enclosingElement3 is ExtensionTypeElement)) {
           extensionPropertyType = element.returnType;
         } else if (element is ExecutableElement &&
-            (element.enclosingElement is ExtensionElement ||
-                element.enclosingElement is ExtensionTypeElement)) {
+            (element.enclosingElement3 is ExtensionElement ||
+                element.enclosingElement3 is ExtensionTypeElement)) {
           extensionPropertyType = element.type;
         }
         if (extensionPropertyType != null) {
diff --git a/pkg/analyzer/lib/src/generated/ffi_verifier.dart b/pkg/analyzer/lib/src/generated/ffi_verifier.dart
index 3e4911f..93d45fc 100644
--- a/pkg/analyzer/lib/src/generated/ffi_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/ffi_verifier.dart
@@ -247,7 +247,7 @@
   void visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
     var element = node.staticElement;
     if (element is MethodElement) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       if (enclosingElement.isAllocatorExtension &&
           element.name == _allocateExtensionMethodName) {
         _validateAllocate(node);
@@ -260,7 +260,7 @@
   void visitIndexExpression(IndexExpression node) {
     var element = node.staticElement;
     if (element is MethodElement) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       if (enclosingElement.isNativeStructPointerExtension ||
           enclosingElement.isNativeStructArrayExtension ||
           enclosingElement.isNativeUnionPointerExtension ||
@@ -275,7 +275,7 @@
   @override
   void visitInstanceCreationExpression(InstanceCreationExpression node) {
     var constructor = node.constructorName.staticElement;
-    var class_ = constructor?.enclosingElement;
+    var class_ = constructor?.enclosingElement3;
     if (class_.isStructSubclass || class_.isUnionSubclass) {
       if (!constructor!.isFactory) {
         _errorReporter.atNode(
@@ -331,7 +331,7 @@
   void visitMethodInvocation(MethodInvocation node) {
     var element = node.methodName.staticElement;
     if (element is MethodElement) {
-      Element enclosingElement = element.enclosingElement;
+      Element enclosingElement = element.enclosingElement3;
       if (enclosingElement.isPointer) {
         if (element.name == 'fromFunction') {
           _validateFromFunction(node, element);
@@ -356,7 +356,7 @@
         }
       }
     } else if (element is FunctionElement) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       if (enclosingElement is CompilationUnitElement) {
         if (element.library.name == 'dart.ffi') {
           if (element.name == 'sizeOf') {
@@ -372,7 +372,7 @@
   void visitPrefixedIdentifier(PrefixedIdentifier node) {
     var element = node.staticElement;
     if (element != null) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       if (enclosingElement.isNativeStructPointerExtension ||
           enclosingElement.isNativeUnionPointerExtension) {
         if (element.name == 'ref') {
@@ -391,7 +391,7 @@
   void visitPropertyAccess(PropertyAccess node) {
     var element = node.propertyName.staticElement;
     if (element != null) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       if (enclosingElement.isNativeStructPointerExtension ||
           enclosingElement.isNativeUnionPointerExtension) {
         if (element.name == 'ref') {
@@ -629,7 +629,7 @@
       // Receiver can only be Pointer if the class extends
       // NativeFieldWrapperClass1.
       if (ffiSignature.normalParameterTypes[0].isPointer) {
-        var cls = declarationElement.enclosingElement as InterfaceElement;
+        var cls = declarationElement.enclosingElement3 as InterfaceElement;
         if (!_extendsNativeFieldWrapperClass1(cls.thisType)) {
           _errorReporter.atToken(
             errorToken,
@@ -937,7 +937,7 @@
   _PrimitiveDartType _typeForAnnotation(Annotation annotation) {
     var element = annotation.element;
     if (element is ConstructorElement) {
-      String name = element.enclosingElement.name;
+      String name = element.enclosingElement3.name;
       if (_primitiveIntegerNativeTypes.contains(name)) {
         return _PrimitiveDartType.int;
       } else if (_primitiveDoubleNativeTypes.contains(name)) {
@@ -1046,8 +1046,8 @@
     if (parent is MethodInvocation &&
         parent.methodName.staticElement is MethodElement &&
         parent.methodName.name == "cast" &&
-        parent.methodName.staticElement?.enclosingElement is ClassElement &&
-        parent.methodName.staticElement!.enclosingElement.isPointer) {
+        parent.methodName.staticElement?.enclosingElement3 is ClassElement &&
+        parent.methodName.staticElement!.enclosingElement3.isPointer) {
       parent = parent.parent;
     }
     var grandParent = parent?.parent;
@@ -1064,7 +1064,7 @@
   void _validateAddressPrefixedIdentifier(PrefixedIdentifier node) {
     var errorNode = node.identifier;
     _validateAddressPosition(node, errorNode);
-    var extensionName = node.staticElement?.enclosingElement?.name;
+    var extensionName = node.staticElement?.enclosingElement3?.name;
     var receiver = node.prefix;
     _validateAddressReceiver(node, extensionName, receiver, errorNode);
   }
@@ -1072,7 +1072,8 @@
   void _validateAddressPropertyAccess(PropertyAccess node) {
     var errorNode = node.propertyName;
     _validateAddressPosition(node, errorNode);
-    var extensionName = node.propertyName.staticElement?.enclosingElement?.name;
+    var extensionName =
+        node.propertyName.staticElement?.enclosingElement3?.name;
     var receiver = node.target;
     _validateAddressReceiver(node, extensionName, receiver, errorNode);
   }
@@ -1149,7 +1150,7 @@
     List<Annotation> extraAnnotations = [];
     for (Annotation annotation in annotations) {
       if (annotation.element.ffiClass != null ||
-          annotation.element?.enclosingElement.isAbiSpecificIntegerSubclass ==
+          annotation.element?.enclosingElement3.isAbiSpecificIntegerSubclass ==
               true) {
         if (requiredFound) {
           extraAnnotations.add(annotation);
@@ -1487,7 +1488,7 @@
         }
         var arrayDimensions = declaredType.arrayDimensions;
         var fieldElement = node.fields.variables.first.declaredElement;
-        var lastElement = (fieldElement?.enclosingElement as ClassElement?)
+        var lastElement = (fieldElement?.enclosingElement3 as ClassElement?)
             ?.fields
             .reversed
             .where((field) {
@@ -2069,7 +2070,7 @@
     var element = this.element;
     return element is ConstructorElement &&
         element.ffiClass != null &&
-        element.enclosingElement.name ==
+        element.enclosingElement3.name ==
             FfiVerifier._abiSpecificIntegerMappingClassName;
   }
 
@@ -2077,14 +2078,14 @@
     var element = this.element;
     return element is ConstructorElement &&
         element.ffiClass != null &&
-        element.enclosingElement.name == 'Array';
+        element.enclosingElement3.name == 'Array';
   }
 
   bool get isPacked {
     var element = this.element;
     return element is ConstructorElement &&
         element.ffiClass != null &&
-        element.enclosingElement.name == 'Packed';
+        element.enclosingElement3.name == 'Packed';
   }
 }
 
@@ -2131,7 +2132,7 @@
     var element = this.element;
     return element is ConstructorElement &&
         element.ffiClass != null &&
-        element.enclosingElement.name == 'Array';
+        element.enclosingElement3.name == 'Array';
     // Note: this is 'Array' instead of '_ArraySize' because it finds the
     // forwarding factory instead of the forwarded constructor.
   }
@@ -2156,7 +2157,7 @@
     var element = this.element;
     return element is ConstructorElement &&
         element.ffiClass != null &&
-        element.enclosingElement.name == 'Packed';
+        element.enclosingElement3.name == 'Packed';
   }
 
   int? get packedMemberAlignment {
@@ -2225,7 +2226,7 @@
   ClassElement? get ffiClass {
     var element = this;
     if (element is ConstructorElement) {
-      element = element.enclosingElement;
+      element = element.enclosingElement3;
     }
     if (element is ClassElement && element.isFfiClass) {
       return element;
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 75248ca..75fb5c0 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -86,6 +86,7 @@
 import 'package:analyzer/src/generated/variable_type_provider.dart';
 import 'package:analyzer/src/task/inference_error.dart';
 import 'package:analyzer/src/util/ast_data_extractor.dart';
+import 'package:analyzer/src/utilities/extensions/object.dart';
 
 /// Function determining which source files should have inference logging
 /// enabled.
@@ -134,6 +135,9 @@
   /// The element for the library containing the compilation unit being visited.
   final LibraryElementImpl definingLibrary;
 
+  /// The library fragment being visited.
+  final CompilationUnitElementImpl libraryFragment;
+
   /// The context shared between different units of the same library.
   final LibraryResolutionContext libraryResolutionContext;
 
@@ -304,39 +308,43 @@
   // TODO(paulberry): make [featureSet] a required parameter (this will be a
   // breaking change).
   ResolverVisitor(
-      InheritanceManager3 inheritanceManager,
-      LibraryElementImpl definingLibrary,
-      LibraryResolutionContext libraryResolutionContext,
-      Source source,
-      TypeProvider typeProvider,
-      AnalysisErrorListener errorListener,
-      {required FeatureSet featureSet,
-      required AnalysisOptionsImpl analysisOptions,
-      required FlowAnalysisHelper flowAnalysisHelper})
-      : this._(
-            inheritanceManager,
-            definingLibrary,
-            libraryResolutionContext,
-            source,
-            definingLibrary.typeSystem,
-            typeProvider as TypeProviderImpl,
-            errorListener,
-            featureSet,
-            analysisOptions,
-            flowAnalysisHelper);
+    InheritanceManager3 inheritanceManager,
+    LibraryElementImpl definingLibrary,
+    LibraryResolutionContext libraryResolutionContext,
+    Source source,
+    TypeProvider typeProvider,
+    AnalysisErrorListener errorListener, {
+    required CompilationUnitElementImpl libraryFragment,
+    required FeatureSet featureSet,
+    required AnalysisOptionsImpl analysisOptions,
+    required FlowAnalysisHelper flowAnalysisHelper,
+  }) : this._(
+          inheritanceManager,
+          definingLibrary,
+          libraryResolutionContext,
+          source,
+          definingLibrary.typeSystem,
+          typeProvider as TypeProviderImpl,
+          errorListener,
+          featureSet,
+          analysisOptions,
+          flowAnalysisHelper,
+          libraryFragment: libraryFragment,
+        );
 
   ResolverVisitor._(
-      this.inheritance,
-      this.definingLibrary,
-      this.libraryResolutionContext,
-      this.source,
-      this.typeSystem,
-      this.typeProvider,
-      AnalysisErrorListener errorListener,
-      FeatureSet featureSet,
-      this.analysisOptions,
-      this.flowAnalysis)
-      : errorReporter = ErrorReporter(errorListener, source),
+    this.inheritance,
+    this.definingLibrary,
+    this.libraryResolutionContext,
+    this.source,
+    this.typeSystem,
+    this.typeProvider,
+    AnalysisErrorListener errorListener,
+    FeatureSet featureSet,
+    this.analysisOptions,
+    this.flowAnalysis, {
+    required this.libraryFragment,
+  })  : errorReporter = ErrorReporter(errorListener, source),
         _featureSet = featureSet,
         genericMetadataIsEnabled =
             definingLibrary.featureSet.isEnabled(Feature.generic_metadata),
@@ -4984,6 +4992,17 @@
   }
 
   @override
+  void visitHideCombinator(HideCombinator node) {
+    var scope = nameScope.ifTypeOrNull<LibraryFragmentScope>();
+    scope?.importsTrackingActive(false);
+    try {
+      super.visitHideCombinator(node);
+    } finally {
+      scope?.importsTrackingActive(true);
+    }
+  }
+
+  @override
   void visitIfElement(covariant IfElementImpl node) {
     _visitIf(node);
   }
@@ -5010,6 +5029,9 @@
   }
 
   @override
+  void visitLibraryIdentifier(LibraryIdentifier node) {}
+
+  @override
   void visitMethodDeclaration(covariant MethodDeclarationImpl node) {
     node.body.localVariableInfo = _localVariableInfo;
     node.metadata.accept(this);
@@ -5102,6 +5124,17 @@
   }
 
   @override
+  void visitShowCombinator(ShowCombinator node) {
+    var scope = nameScope.ifTypeOrNull<LibraryFragmentScope>();
+    scope?.importsTrackingActive(false);
+    try {
+      super.visitShowCombinator(node);
+    } finally {
+      scope?.importsTrackingActive(true);
+    }
+  }
+
+  @override
   void visitSimpleIdentifier(covariant SimpleIdentifierImpl node) {
     // Ignore if already resolved - declaration or type.
     if (node.inDeclarationContext()) {
@@ -5109,6 +5142,12 @@
     }
     // Ignore if qualified.
     var parent = node.parent;
+    if (parent is ConstructorName && parent.name == node) {
+      return;
+    }
+    if (parent is Label && parent.parent is NamedExpression) {
+      return;
+    }
     var scopeLookupResult = nameScope.lookup(node.name);
     node.scopeLookupResult = scopeLookupResult;
     // Ignore if it cannot be a reference to a local variable.
@@ -5120,9 +5159,6 @@
         parent.fieldName == node) {
       return;
     }
-    if (parent is ConstructorName) {
-      return;
-    }
     if (parent is Label) {
       return;
     }
@@ -5613,7 +5649,7 @@
           addConflictMessage(
               conflictingElement: field,
               kind: 'non-promotable field',
-              enclosingElement: field.enclosingElement,
+              enclosingElement: field.enclosingElement3,
               link:
                   NonPromotionDocumentationLink.conflictingNonPromotableField);
         }
@@ -5621,7 +5657,7 @@
           addConflictMessage(
               conflictingElement: getter,
               kind: 'getter',
-              enclosingElement: getter.enclosingElement,
+              enclosingElement: getter.enclosingElement3,
               link: NonPromotionDocumentationLink.conflictingGetter);
         }
         for (var nsmClass in fieldNameInfo.conflictingNsmClasses) {
diff --git a/pkg/analyzer/lib/src/lint/linter.dart b/pkg/analyzer/lib/src/lint/linter.dart
index f03bc46..02a2395 100644
--- a/pkg/analyzer/lib/src/lint/linter.dart
+++ b/pkg/analyzer/lib/src/lint/linter.dart
@@ -487,7 +487,7 @@
   bool get canBeConst {
     var element = declaredElement!;
 
-    var classElement = element.enclosingElement;
+    var classElement = element.enclosingElement3;
     if (classElement is ClassElement && classElement.hasNonFinalField) {
       return false;
     }
diff --git a/pkg/analyzer/lib/src/summary2/ast_resolver.dart b/pkg/analyzer/lib/src/summary2/ast_resolver.dart
index cc8dbbf..aab408f 100644
--- a/pkg/analyzer/lib/src/summary2/ast_resolver.dart
+++ b/pkg/analyzer/lib/src/summary2/ast_resolver.dart
@@ -58,6 +58,7 @@
     featureSet: _featureSet,
     analysisOptions: analysisOptions,
     flowAnalysisHelper: _flowAnalysis,
+    libraryFragment: _unitElement,
   );
 
   AstResolver(
diff --git a/pkg/analyzer/lib/src/summary2/bundle_reader.dart b/pkg/analyzer/lib/src/summary2/bundle_reader.dart
index 218d5ce..3410103 100644
--- a/pkg/analyzer/lib/src/summary2/bundle_reader.dart
+++ b/pkg/analyzer/lib/src/summary2/bundle_reader.dart
@@ -298,7 +298,7 @@
     ResolutionReader reader,
     ElementImpl element,
   ) {
-    var enclosing = element.enclosingElement;
+    var enclosing = element.enclosingElement3;
     if (enclosing is InstanceElement) {
       reader._addTypeParameters(enclosing.typeParameters);
     } else if (enclosing is CompilationUnitElement) {
@@ -377,7 +377,7 @@
   @override
   void _read(element, reader) {
     element.metadata = reader._readAnnotationList(
-      unitElement: element.enclosingElement,
+      unitElement: element.enclosingElement3,
     );
     _readTypeParameters(reader, element.typeParameters);
     element.supertype = reader._readOptionalInterfaceType();
@@ -420,7 +420,7 @@
   @override
   void _read(element, reader) {
     element.metadata = reader._readAnnotationList(
-      unitElement: element.enclosingElement,
+      unitElement: element.enclosingElement3,
     );
     _readTypeParameters(reader, element.typeParameters);
     element.augmentationTargetAny = reader.readElement() as ElementImpl?;
@@ -460,7 +460,7 @@
   @override
   void _read(element, reader) {
     element.metadata = reader._readAnnotationList(
-      unitElement: element.enclosingElement,
+      unitElement: element.enclosingElement3,
     );
     _readTypeParameters(reader, element.typeParameters);
     element.interfaces = reader._readInterfaceTypeList();
@@ -1963,7 +1963,7 @@
   @override
   void _read(element, reader) {
     element.metadata = reader._readAnnotationList(
-      unitElement: element.enclosingElement,
+      unitElement: element.enclosingElement3,
     );
     _readTypeParameters(reader, element.typeParameters);
     element.macroDiagnostics = reader.readMacroDiagnostics();
@@ -2076,7 +2076,7 @@
     }
 
     if (memberFlags == Tag.MemberWithTypeArguments) {
-      var enclosing = element.enclosingElement as InstanceElement;
+      var enclosing = element.enclosingElement3 as InstanceElement;
 
       var declaration = enclosing.augmented.declaration;
       var declarationTypeParameters = declaration.typeParameters;
diff --git a/pkg/analyzer/lib/src/summary2/bundle_writer.dart b/pkg/analyzer/lib/src/summary2/bundle_writer.dart
index 12c63a4..e0e0e19 100644
--- a/pkg/analyzer/lib/src/summary2/bundle_writer.dart
+++ b/pkg/analyzer/lib/src/summary2/bundle_writer.dart
@@ -1151,7 +1151,7 @@
       return const [];
     }
 
-    var enclosing = declaration.enclosingElement;
+    var enclosing = declaration.enclosingElement3;
     if (enclosing is InstanceElement) {
       var typeParameters = enclosing.typeParameters;
       if (typeParameters.isEmpty) {
diff --git a/pkg/analyzer/lib/src/summary2/library_builder.dart b/pkg/analyzer/lib/src/summary2/library_builder.dart
index ebc9134..f9324b6 100644
--- a/pkg/analyzer/lib/src/summary2/library_builder.dart
+++ b/pkg/analyzer/lib/src/summary2/library_builder.dart
@@ -672,7 +672,7 @@
     }
 
     for (var fieldElement in finalInstanceFields) {
-      var enclosing = fieldElement.enclosingElement;
+      var enclosing = fieldElement.enclosingElement3;
       var augmented = enclosing.ifTypeOrNull<ClassElementImpl>()?.augmented;
       if (augmented == null) continue;
       if (!withConstConstructors.contains(augmented.declaration)) {
diff --git a/pkg/analyzer/lib/src/summary2/macro_application.dart b/pkg/analyzer/lib/src/summary2/macro_application.dart
index c1fea88..4264285 100644
--- a/pkg/analyzer/lib/src/summary2/macro_application.dart
+++ b/pkg/analyzer/lib/src/summary2/macro_application.dart
@@ -889,7 +889,7 @@
       if (targetElement != null) {
         var applicationElement = application.target.element;
         if (!identical(applicationElement, targetElement) &&
-            !identical(applicationElement.enclosingElement, targetElement)) {
+            !identical(applicationElement.enclosingElement3, targetElement)) {
           continue;
         }
       }
diff --git a/pkg/analyzer/lib/src/summary2/macro_cache.dart b/pkg/analyzer/lib/src/summary2/macro_cache.dart
index af195ca..c91591bc 100644
--- a/pkg/analyzer/lib/src/summary2/macro_cache.dart
+++ b/pkg/analyzer/lib/src/summary2/macro_cache.dart
@@ -508,13 +508,13 @@
         sink.writeEnum(_ElementLocationKind.dynamic);
       case ParameterElement():
         sink.writeEnum(_ElementLocationKind.formalParameter);
-        var executable = element.enclosingElement as ExecutableElement;
+        var executable = element.enclosingElement3 as ExecutableElement;
         var index = executable.parameters.indexOf(element);
         _writeElement(executable);
         sink.writeUInt30(index);
       case TypeParameterElement():
         sink.writeEnum(_ElementLocationKind.typeParameter);
-        var executable = element.enclosingElement as ExecutableElement;
+        var executable = element.enclosingElement3 as ExecutableElement;
         var index = executable.typeParameters.indexOf(element);
         _writeElement(executable);
         sink.writeUInt30(index);
diff --git a/pkg/analyzer/lib/src/summary2/macro_declarations.dart b/pkg/analyzer/lib/src/summary2/macro_declarations.dart
index 4d54724..b12db88 100644
--- a/pkg/analyzer/lib/src/summary2/macro_declarations.dart
+++ b/pkg/analyzer/lib/src/summary2/macro_declarations.dart
@@ -226,7 +226,7 @@
           kind: macro.IdentifierKind.staticInstanceMember,
           name: element.name,
           uri: element.library.source.uri,
-          staticScope: element.enclosingElement.name,
+          staticScope: element.enclosingElement3.name,
         );
       case DynamicElementImpl():
         return macro.ResolvedIdentifier(
@@ -248,7 +248,7 @@
             kind: macro.IdentifierKind.staticInstanceMember,
             name: element.name,
             uri: element.library.source.uri,
-            staticScope: element.enclosingElement.name,
+            staticScope: element.enclosingElement3.name,
           );
         } else {
           return macro.ResolvedIdentifier(
@@ -278,7 +278,7 @@
             kind: macro.IdentifierKind.staticInstanceMember,
             name: element.name,
             uri: element.library.source.uri,
-            staticScope: element.enclosingElement.name,
+            staticScope: element.enclosingElement3.name,
           );
         } else {
           return macro.ResolvedIdentifier(
@@ -296,7 +296,7 @@
           staticScope: null,
         );
       case PropertyAccessorElement():
-        if (element.enclosingElement is CompilationUnitElement) {
+        if (element.enclosingElement3 is CompilationUnitElement) {
           return macro.ResolvedIdentifier(
             kind: macro.IdentifierKind.topLevelMember,
             name: element.name,
@@ -308,7 +308,7 @@
             kind: macro.IdentifierKind.staticInstanceMember,
             name: element.name,
             uri: element.library.source.uri,
-            staticScope: element.enclosingElement.name,
+            staticScope: element.enclosingElement3.name,
           );
         } else {
           return macro.ResolvedIdentifier(
@@ -679,7 +679,7 @@
       case MethodElementImpl():
         return methodElement(element);
       case PropertyAccessorElementImpl():
-        if (element.enclosingElement is CompilationUnitElement) {
+        if (element.enclosingElement3 is CompilationUnitElement) {
           return functionElement(element);
         } else {
           return methodElement(element);
@@ -920,7 +920,7 @@
   EnumValueDeclarationImpl _enumConstantElement(
     FieldElementImpl element,
   ) {
-    var enclosing = element.enclosingElement as EnumElementImpl;
+    var enclosing = element.enclosingElement3 as EnumElementImpl;
     return EnumValueDeclarationImpl(
       id: macro.RemoteInstance.uniqueId,
       identifier: identifier(element),
@@ -1718,7 +1718,7 @@
   macro.EnumValueDeclarationImpl _enumConstantDeclaration(
     FieldElementImpl element,
   ) {
-    var enclosing = element.enclosingElement as EnumElementImpl;
+    var enclosing = element.enclosingElement3 as EnumElementImpl;
     return EnumValueDeclarationImpl(
       id: macro.RemoteInstance.uniqueId,
       identifier: _declaredIdentifier2(element.name, element),
@@ -2508,7 +2508,7 @@
   /// is not an invalid augmentation, return the declaration - the start of
   /// the augmentation chain.
   InstanceElement get enclosingInstanceElement {
-    var enclosing = enclosingElement as InstanceElement;
+    var enclosing = enclosingElement3 as InstanceElement;
     return enclosing.augmented.declaration;
   }
 }
diff --git a/pkg/analyzer/lib/src/summary2/top_level_inference.dart b/pkg/analyzer/lib/src/summary2/top_level_inference.dart
index 43510e4..acfb791 100644
--- a/pkg/analyzer/lib/src/summary2/top_level_inference.dart
+++ b/pkg/analyzer/lib/src/summary2/top_level_inference.dart
@@ -250,7 +250,7 @@
     _inferring.add(this);
     _status = _InferenceStatus.beingInferred;
 
-    var enclosingElement = _element.enclosingElement;
+    var enclosingElement = _element.enclosingElement3;
     var enclosingInterfaceElement = enclosingElement
         .ifTypeOrNull<InterfaceElement>()
         ?.augmented
diff --git a/pkg/analyzer/lib/src/task/strong_mode.dart b/pkg/analyzer/lib/src/task/strong_mode.dart
index 7d1e221..1e31261 100644
--- a/pkg/analyzer/lib/src/task/strong_mode.dart
+++ b/pkg/analyzer/lib/src/task/strong_mode.dart
@@ -391,7 +391,7 @@
       }
     }
 
-    var classElement = constructor.enclosingElement;
+    var classElement = constructor.enclosingElement3;
     if (classElement is ClassElementImpl && classElement.isMixinApplication) {
       _inferMixinApplicationConstructor(classElement, constructor);
     }
@@ -439,7 +439,7 @@
           var conflict = conflicts.single;
           if (conflict is CandidatesConflict) {
             conflictExplanation = conflict.candidates.map((candidate) {
-              var className = candidate.enclosingElement.name;
+              var className = candidate.enclosingElement3.name;
               var typeStr = candidate.type.getDisplayString();
               return '$className.${name.name} ($typeStr)';
             }).join(', ');
@@ -596,7 +596,7 @@
       overridden = overridden.declaration;
 
       // Skip Object itself.
-      var enclosingElement = overridden.enclosingElement;
+      var enclosingElement = overridden.enclosingElement3;
       if (enclosingElement is ClassElement &&
           enclosingElement.isDartCoreObject) {
         continue;
diff --git a/pkg/analyzer/lib/src/util/ast_data_extractor.dart b/pkg/analyzer/lib/src/util/ast_data_extractor.dart
index 2b3ef32..5f00d8c 100644
--- a/pkg/analyzer/lib/src/util/ast_data_extractor.dart
+++ b/pkg/analyzer/lib/src/util/ast_data_extractor.dart
@@ -8,7 +8,7 @@
 import 'package:analyzer/dart/element/element.dart';
 
 MemberId computeMemberId(Element element) {
-  var enclosingElement = element.enclosingElement;
+  var enclosingElement = element.enclosingElement3;
   if (enclosingElement is CompilationUnitElement) {
     var memberName = element.name!;
     if (element is PropertyAccessorElement && element.isSetter) {
diff --git a/pkg/analyzer/lib/src/utilities/extensions/element.dart b/pkg/analyzer/lib/src/utilities/extensions/element.dart
index 1c0ece0..d53fc51 100644
--- a/pkg/analyzer/lib/src/utilities/extensions/element.dart
+++ b/pkg/analyzer/lib/src/utilities/extensions/element.dart
@@ -36,7 +36,7 @@
   bool get isProtected {
     var self = this;
     if (self is PropertyAccessorElement &&
-        self.enclosingElement is InterfaceElement) {
+        self.enclosingElement3 is InterfaceElement) {
       if (self.hasProtected) {
         return true;
       }
@@ -46,7 +46,7 @@
       }
     }
     if (self is MethodElement &&
-        self.enclosingElement is InterfaceElement &&
+        self.enclosingElement3 is InterfaceElement &&
         self.hasProtected) {
       return true;
     }
diff --git a/pkg/analyzer/lib/src/wolf/ir/ast_to_ir.dart b/pkg/analyzer/lib/src/wolf/ir/ast_to_ir.dart
index 13f3a9f..a64a711 100644
--- a/pkg/analyzer/lib/src/wolf/ir/ast_to_ir.dart
+++ b/pkg/analyzer/lib/src/wolf/ir/ast_to_ir.dart
@@ -706,7 +706,7 @@
     var target = node.target;
     var methodElement = node.methodName.staticElement;
     switch (methodElement) {
-      case FunctionElement(enclosingElement: CompilationUnitElement()):
+      case FunctionElement(enclosingElement3: CompilationUnitElement()):
         assert(!node.isNullAware);
         _handleInvocationArgs(
             argumentList: node.argumentList,
diff --git a/pkg/analyzer/lib/src/wolf/ir/call_descriptor.dart b/pkg/analyzer/lib/src/wolf/ir/call_descriptor.dart
index 9553133..6439197 100644
--- a/pkg/analyzer/lib/src/wolf/ir/call_descriptor.dart
+++ b/pkg/analyzer/lib/src/wolf/ir/call_descriptor.dart
@@ -25,7 +25,7 @@
   String get name => element.name;
 
   @override
-  String toString() => switch (element.enclosingElement) {
+  String toString() => switch (element.enclosingElement3) {
         InstanceElement(name: var typeName) =>
           '${typeName ?? '<unnamed>'}.${element.name}',
         _ => element.name
diff --git a/pkg/analyzer/test/generated/element_resolver_test.dart b/pkg/analyzer/test/generated/element_resolver_test.dart
index a45ebc3f..083181a 100644
--- a/pkg/analyzer/test/generated/element_resolver_test.dart
+++ b/pkg/analyzer/test/generated/element_resolver_test.dart
@@ -35,7 +35,7 @@
       expect(name3, isNull);
       if (annotationElement is ConstructorElement) {
         expect(annotationElement, same(name2.staticElement));
-        expect(annotationElement.enclosingElement, name1.staticElement);
+        expect(annotationElement.enclosingElement3, name1.staticElement);
         expect(annotationElement.displayName, 'A.named');
         expect(annotationElement.parameters, isEmpty);
       } else {
@@ -61,7 +61,7 @@
       expect(name3.staticElement!.displayName, 'A.named');
       if (annotationElement is ConstructorElement) {
         expect(annotationElement, same(name3.staticElement));
-        expect(annotationElement.enclosingElement, name2.staticElement);
+        expect(annotationElement.enclosingElement3, name2.staticElement);
         expect(annotationElement.displayName, 'A.named');
         expect(annotationElement.parameters, isEmpty);
       } else {
@@ -87,7 +87,7 @@
       expect(name3.staticElement!.displayName, 'V');
       if (annotationElement is PropertyAccessorElement) {
         expect(annotationElement, same(name3.staticElement));
-        expect(annotationElement.enclosingElement, name2.staticElement);
+        expect(annotationElement.enclosingElement3, name2.staticElement);
         expect(annotationElement.displayName, 'V');
       } else {
         fail('Expected "annotationElement" is PropertyAccessorElement, '
@@ -110,7 +110,7 @@
       expect(name2.staticElement!.displayName, 'A');
       expect(name3, isNull);
       if (annotationElement is ConstructorElement) {
-        expect(annotationElement.enclosingElement, name2.staticElement);
+        expect(annotationElement.enclosingElement3, name2.staticElement);
         expect(annotationElement.displayName, 'A');
         expect(annotationElement.parameters, isEmpty);
       } else {
@@ -135,7 +135,7 @@
       expect(name3, isNull);
       if (annotationElement is PropertyAccessorElement) {
         expect(annotationElement, same(name2.staticElement));
-        expect(annotationElement.enclosingElement, name1.staticElement);
+        expect(annotationElement.enclosingElement3, name1.staticElement);
         expect(annotationElement.displayName, 'V');
       } else {
         fail('Expected "annotationElement" is PropertyAccessorElement, '
@@ -157,7 +157,7 @@
       expect(name2, isNull);
       expect(name3, isNull);
       if (annotationElement is ConstructorElement) {
-        expect(annotationElement.enclosingElement, name1.staticElement);
+        expect(annotationElement.enclosingElement3, name1.staticElement);
         expect(annotationElement.displayName, 'A');
         expect(annotationElement.parameters, isEmpty);
       } else {
@@ -179,7 +179,7 @@
       expect(name3, isNull);
       if (annotationElement is PropertyAccessorElement) {
         expect(annotationElement, same(name1.staticElement));
-        expect(annotationElement.enclosingElement, isCompilationUnitElement);
+        expect(annotationElement.enclosingElement3, isCompilationUnitElement);
         expect(annotationElement.displayName, 'V');
       } else {
         fail('Expected "annotationElement" is PropertyAccessorElement, '
@@ -201,7 +201,7 @@
       expect(name3, isNull);
       if (annotationElement is PropertyAccessorElement) {
         expect(annotationElement, same(name2.staticElement));
-        expect(annotationElement.enclosingElement, isCompilationUnitElement);
+        expect(annotationElement.enclosingElement3, isCompilationUnitElement);
         expect(annotationElement.displayName, 'V');
       } else {
         fail('Expected "annotationElement" is PropertyAccessorElement, '
diff --git a/pkg/analyzer/test/generated/elements_types_mixin.dart b/pkg/analyzer/test/generated/elements_types_mixin.dart
index acfe7e4..d03cba2 100644
--- a/pkg/analyzer/test/generated/elements_types_mixin.dart
+++ b/pkg/analyzer/test/generated/elements_types_mixin.dart
@@ -137,6 +137,7 @@
     element.isAugmentation = isAugmentation;
     element.isSealed = isSealed;
     element.enclosingElement = testLibrary.definingCompilationUnit;
+    element.enclosingElement3 = testLibrary.definingCompilationUnit;
     element.typeParameters = typeParameters;
     element.supertype = superType ?? typeProvider.objectType;
     element.interfaces = interfaces;
@@ -169,6 +170,7 @@
   }) {
     var element = EnumElementImpl(name, 0);
     element.enclosingElement = testLibrary.definingCompilationUnit;
+    element.enclosingElement3 = testLibrary.definingCompilationUnit;
     element.fields = constants;
     return element;
   }
@@ -190,6 +192,7 @@
     element.augmented.extendedType = extendedType;
     element.isAugmentation = isAugmentation;
     element.enclosingElement = testLibrary.definingCompilationUnit;
+    element.enclosingElement3 = testLibrary.definingCompilationUnit;
     element.typeParameters = typeParameters;
     element.methods = methods;
     return element;
@@ -204,6 +207,7 @@
   }) {
     var element = ExtensionTypeElementImpl(name, -1);
     element.enclosingElement = testLibrary.definingCompilationUnit;
+    element.enclosingElement3 = testLibrary.definingCompilationUnit;
     element.typeParameters = typeParameters;
     element.interfaces = interfaces;
 
@@ -414,6 +418,7 @@
     var element = MixinElementImpl(name, 0);
     element.isAugmentation = isAugmentation;
     element.enclosingElement = testLibrary.definingCompilationUnit;
+    element.enclosingElement3 = testLibrary.definingCompilationUnit;
     element.typeParameters = typeParameters;
     element.superclassConstraints = constraints ?? [typeProvider.objectType];
     element.interfaces = interfaces;
@@ -567,6 +572,7 @@
   }) {
     var element = TypeAliasElementImpl(name, 0);
     element.enclosingElement = testLibrary.definingCompilationUnit;
+    element.enclosingElement3 = testLibrary.definingCompilationUnit;
     element.typeParameters = typeParameters;
     element.aliasedType = aliasedType;
     return element;
diff --git a/pkg/analyzer/test/generated/non_error_resolver_test.dart b/pkg/analyzer/test/generated/non_error_resolver_test.dart
index 68da327..236dbdf 100644
--- a/pkg/analyzer/test/generated/non_error_resolver_test.dart
+++ b/pkg/analyzer/test/generated/non_error_resolver_test.dart
@@ -1391,7 +1391,7 @@
 
     var x = findNode.namedExpression('arg: true');
     var y = x.staticParameterElement!;
-    expect(y.enclosingElement, isNotNull);
+    expect(y.enclosingElement3, isNotNull);
     expect(y.declaration, findElement.parameter('arg'));
   }
 
@@ -1406,7 +1406,7 @@
 
     var x = findNode.namedExpression('arg: true');
     var y = x.staticParameterElement!;
-    expect(y.enclosingElement, isNotNull);
+    expect(y.enclosingElement3, isNotNull);
     expect(y.declaration, findElement.parameter('arg'));
   }
 
@@ -1471,7 +1471,7 @@
 ''');
     var x = findNode.namedExpression('arg: true');
     var y = x.staticParameterElement!;
-    expect(y.enclosingElement, isNotNull);
+    expect(y.enclosingElement3, isNotNull);
     expect(y.declaration, findElement.parameter('arg'));
   }
 
@@ -1484,7 +1484,7 @@
 ''');
     var x = findNode.namedExpression('arg: true');
     var y = x.staticParameterElement!;
-    expect(y.enclosingElement, isNotNull);
+    expect(y.enclosingElement3, isNotNull);
     expect(y.declaration, findElement.parameter('arg'));
   }
 
@@ -1501,7 +1501,7 @@
 
     var x = findNode.namedExpression('arg: true');
     var y = x.staticParameterElement!;
-    expect(y.enclosingElement, isNotNull);
+    expect(y.enclosingElement3, isNotNull);
     expect(y.declaration, findElement.parameter('arg'));
   }
 
@@ -1518,7 +1518,7 @@
 
     var x = findNode.namedExpression('arg: true');
     var y = x.staticParameterElement!;
-    expect(y.enclosingElement, isNotNull);
+    expect(y.enclosingElement3, isNotNull);
     expect(y.declaration, findElement.parameter('arg'));
   }
 
diff --git a/pkg/analyzer/test/id_tests/inheritance_test.dart b/pkg/analyzer/test/id_tests/inheritance_test.dart
index 95e6126..e6623de 100644
--- a/pkg/analyzer/test/id_tests/inheritance_test.dart
+++ b/pkg/analyzer/test/id_tests/inheritance_test.dart
@@ -93,7 +93,7 @@
       for (var name in interface.map.keys) {
         var executable = interface.map[name]!;
 
-        var enclosingClass = executable.enclosingElement as InterfaceElement;
+        var enclosingClass = executable.enclosingElement3 as InterfaceElement;
         if (enclosingClass is ClassElement && enclosingClass.isDartCoreObject) {
           continue;
         }
diff --git a/pkg/analyzer/test/src/dart/analysis/driver_test.dart b/pkg/analyzer/test/src/dart/analysis/driver_test.dart
index 0fa72e8..3d9fa1c 100644
--- a/pkg/analyzer/test/src/dart/analysis/driver_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/driver_test.dart
@@ -2237,7 +2237,6 @@
     flags: exists isLibrary
     errors
       25 +1 UNDEFINED_CLASS
-      7 +8 UNUSED_IMPORT
 [stream]
   ResolvedUnitResult #1
 [status] idle
diff --git a/pkg/analyzer/test/src/dart/analysis/search_test.dart b/pkg/analyzer/test/src/dart/analysis/search_test.dart
index 7ad9dea..6859bb6 100644
--- a/pkg/analyzer/test/src/dart/analysis/search_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/search_test.dart
@@ -3285,7 +3285,7 @@
     }
 
     String elementToReferenceString(Element element) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       var reference = (element as ElementImpl).reference;
       if (reference != null) {
         return referenceToString(reference);
diff --git a/pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart b/pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart
index 4f1ff20..f63df80 100644
--- a/pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart
+++ b/pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart
@@ -2774,7 +2774,7 @@
 
   void _assertExecutable(ExecutableElement? element, String? expected) {
     if (expected != null && element != null) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
 
       var type = element.type;
       var typeStr = typeString(type);
@@ -2784,7 +2784,7 @@
 
       if (element is PropertyAccessorElement) {
         var variable = element.variable2!;
-        expect(variable.enclosingElement, same(element.enclosingElement));
+        expect(variable.enclosingElement3, same(element.enclosingElement3));
         expect(variable.name, element.displayName);
         if (element.isGetter) {
           expect(variable.type, element.returnType);
@@ -2865,7 +2865,7 @@
       var element = entry.value;
       var type = element.type;
 
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement3;
       if (enclosingElement.name == 'Object') continue;
 
       var typeStr = type.getDisplayString();
diff --git a/pkg/analyzer/test/src/dart/element/name_union_test.dart b/pkg/analyzer/test/src/dart/element/name_union_test.dart
index 243fec6..4898ee6 100644
--- a/pkg/analyzer/test/src/dart/element/name_union_test.dart
+++ b/pkg/analyzer/test/src/dart/element/name_union_test.dart
@@ -48,7 +48,7 @@
 
   @override
   void visitElement(Element element) {
-    var enclosing = element.enclosingElement;
+    var enclosing = element.enclosingElement3;
     if (enclosing is CompilationUnitElement ||
         element is FieldElement ||
         element is MethodElement ||
diff --git a/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart b/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
index 175ba7b..b2cc427 100644
--- a/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
@@ -2112,7 +2112,6 @@
   math?.loadLibrary();
 }
 ''', [
-      error(WarningCode.UNUSED_IMPORT, 7, 11),
       error(CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, 49, 4),
     ]);
 
diff --git a/pkg/analyzer/test/src/dart/resolution/resolution.dart b/pkg/analyzer/test/src/dart/resolution/resolution.dart
index 0106207..1e25971 100644
--- a/pkg/analyzer/test/src/dart/resolution/resolution.dart
+++ b/pkg/analyzer/test/src/dart/resolution/resolution.dart
@@ -191,7 +191,7 @@
   }
 
   void assertEnclosingElement(Element element, Element expectedEnclosing) {
-    expect(element.enclosingElement, expectedEnclosing);
+    expect(element.enclosingElement3, expectedEnclosing);
   }
 
   Future<void> assertErrorsInCode(
@@ -339,7 +339,7 @@
   ) {
     var actualMapString = Map.fromEntries(
       substitution.map.entries.where((entry) {
-        return entry.key.enclosingElement is! ExecutableElement;
+        return entry.key.enclosingElement3 is! ExecutableElement;
       }).map((entry) {
         return MapEntry(
           entry.key.name,
diff --git a/pkg/analyzer/test/src/dart/resolution/type_inference/inference_update_1_test.dart b/pkg/analyzer/test/src/dart/resolution/type_inference/inference_update_1_test.dart
index a8919a7..e44412b 100644
--- a/pkg/analyzer/test/src/dart/resolution/type_inference/inference_update_1_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/type_inference/inference_update_1_test.dart
@@ -70,8 +70,8 @@
       assertType(findElement.localVar('a').type, 'int');
       assertType(findElement.parameter('x').type, 'int');
       assertType(findElement.parameter('y').type, 'int');
-      expect(
-          findNode.binary('x + y').staticElement!.enclosingElement.name, 'num');
+      expect(findNode.binary('x + y').staticElement!.enclosingElement3.name,
+          'num');
     } else {
       await assertErrorsInCode(code, [
         error(WarningCode.UNUSED_LOCAL_VARIABLE, 32, 1),
@@ -137,7 +137,7 @@
         findElement.localVar('a').type, _isEnabled ? 'int' : 'InvalidType');
     assertType(findElement.parameter('x').type, _isEnabled ? 'int' : 'Object?');
     assertType(findElement.parameter('y').type, 'int');
-    expect(findNode.binary('+ y').staticElement?.enclosingElement.name,
+    expect(findNode.binary('+ y').staticElement?.enclosingElement3.name,
         _isEnabled ? 'num' : null);
   }
 
@@ -301,7 +301,7 @@
     assertType(findElement.localVar('a').type, 'int?');
     assertType(findElement.parameter('x').type, 'int?');
     assertType(findElement.parameter('y').type, 'int');
-    expect(findNode.binary('+ y').staticElement!.enclosingElement.name, 'num');
+    expect(findNode.binary('+ y').staticElement!.enclosingElement3.name, 'num');
   }
 
   test_horizontal_inference_unnecessary_due_to_explicit_parameter_type_named() async {
@@ -318,7 +318,7 @@
     assertType(findElement.localVar('a').type, 'int?');
     assertType(findElement.parameter('x').type, 'int?');
     assertType(findElement.parameter('y').type, 'int');
-    expect(findNode.binary('+ y').staticElement!.enclosingElement.name, 'num');
+    expect(findNode.binary('+ y').staticElement!.enclosingElement3.name, 'num');
   }
 
   test_horizontal_inference_unnecessary_due_to_no_dependency() async {
diff --git a/pkg/analyzer/test/src/diagnostics/prefix_identifier_not_followed_by_dot_test.dart b/pkg/analyzer/test/src/diagnostics/prefix_identifier_not_followed_by_dot_test.dart
index 40bcb1b..68813dd 100644
--- a/pkg/analyzer/test/src/diagnostics/prefix_identifier_not_followed_by_dot_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/prefix_identifier_not_followed_by_dot_test.dart
@@ -132,7 +132,6 @@
   p?.loadLibrary();
 }
 ''', [
-      error(WarningCode.UNUSED_IMPORT, 7, 10),
       error(CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, 41, 1),
     ]);
   }
diff --git a/pkg/analyzer/test/src/diagnostics/unused_import_test.dart b/pkg/analyzer/test/src/diagnostics/unused_import_test.dart
index 9e45b31..dc1e091 100644
--- a/pkg/analyzer/test/src/diagnostics/unused_import_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/unused_import_test.dart
@@ -315,6 +315,30 @@
 ''');
   }
 
+  test_extension_instance_method_inPart() async {
+    newFile('$testPackageLibPath/a.dart', r'''
+extension E on int {
+  void foo() {}
+}
+''');
+
+    var b = newFile('$testPackageLibPath/b.dart', r'''
+import 'a.dart';
+part 'c.dart';
+''');
+
+    var c = newFile('$testPackageLibPath/c.dart', r'''
+part of 'b.dart';
+
+void f() {
+  0.foo();
+}
+''');
+
+    await assertErrorsInFile2(b, []);
+    await assertErrorsInFile2(c, []);
+  }
+
   test_extension_instance_operator_binary() async {
     newFile('$testPackageLibPath/lib1.dart', r'''
 extension E on String {
@@ -475,6 +499,52 @@
     ]);
   }
 
+  test_noPrefix_constructorName_name() async {
+    await assertErrorsInCode(r'''
+import 'dart:async';
+
+class A {
+  A.foo();
+}
+
+void f() {
+  A.foo();
+}
+''', [
+      error(WarningCode.UNUSED_IMPORT, 7, 12),
+    ]);
+  }
+
+  test_noPrefix_named_argument() async {
+    await assertErrorsInCode(r'''
+import 'dart:math';
+
+void f() {
+  Duration(seconds: 0);
+}
+''', [
+      error(WarningCode.UNUSED_IMPORT, 7, 11),
+    ]);
+  }
+
+  test_prefixed_commentReference_prefix() async {
+    await assertNoErrorsInCode(r'''
+import 'dart:math' as math;
+
+/// [math]
+void f() {}
+''');
+  }
+
+  test_prefixed_commentReference_prefixClass() async {
+    await assertNoErrorsInCode(r'''
+import 'dart:math' as math;
+
+/// [math.Random]
+void f() {}
+''');
+  }
+
   test_show() async {
     newFile('$testPackageLibPath/lib1.dart', r'''
 class A {}
diff --git a/pkg/analyzer/test/src/summary/element_text.dart b/pkg/analyzer/test/src/summary/element_text.dart
index d0e9a7d..1b0f5cf 100644
--- a/pkg/analyzer/test/src/summary/element_text.dart
+++ b/pkg/analyzer/test/src/summary/element_text.dart
@@ -408,7 +408,7 @@
 
       var superConstructor = f.superConstructor;
       if (superConstructor != null) {
-        var enclosingElement = superConstructor.enclosingElement;
+        var enclosingElement = superConstructor.enclosingElement3;
         if (enclosingElement is ClassElement &&
             !enclosingElement.isDartCoreObject) {
           _elementPrinter.writeNamedElement(
@@ -437,7 +437,7 @@
 
     if (f.isSynthetic) {
       expect(f.nameOffset, -1);
-      expect(f.nonSynthetic, same(f.enclosingElement));
+      expect(f.nonSynthetic, same(f.enclosingElement3));
     } else {
       expect(f.nameOffset, isPositive);
     }
@@ -1597,7 +1597,7 @@
   });
 
   void writeLibraryElement(LibraryElementImpl e) {
-    expect(e.enclosingElement, isNull);
+    expect(e.enclosingElement3, isNull);
 
     _sink.writelnWithIndent('library');
     _sink.withIndent(() {
@@ -1893,7 +1893,7 @@
 
       var superConstructor = e.superConstructor;
       if (superConstructor != null) {
-        var enclosingElement = superConstructor.enclosingElement;
+        var enclosingElement = superConstructor.enclosingElement3;
         if (enclosingElement is ClassElement &&
             !enclosingElement.isDartCoreObject) {
           _elementPrinter.writeNamedElement(
@@ -1922,7 +1922,7 @@
 
     if (e.isSynthetic) {
       expect(e.nameOffset, -1);
-      expect(e.nonSynthetic, same(e.enclosingElement));
+      expect(e.nonSynthetic, same(e.enclosingElement3));
     } else {
       expect(e.nameOffset, isPositive);
     }
@@ -1947,6 +1947,7 @@
   void _writeEnclosingElement(ElementImpl e) {
     _elementPrinter.writeNamedElement(
       'enclosingElement',
+      // ignore: deprecated_member_use_from_same_package
       e.enclosingElement,
     );
 
@@ -1977,7 +1978,7 @@
           e.enclosingElement3,
         );
       default:
-        expect(e.enclosingElement3, same(e.enclosingElement));
+        expect(e.enclosingElement3, same(e.enclosingElement3));
     }
   }
 
@@ -2556,9 +2557,9 @@
       _writeAugmentation(e);
     });
 
-    if (e.isSynthetic && e.enclosingElement is EnumElementImpl) {
+    if (e.isSynthetic && e.enclosingElement3 is EnumElementImpl) {
       expect(e.name, 'toString');
-      expect(e.nonSynthetic, same(e.enclosingElement));
+      expect(e.nonSynthetic, same(e.enclosingElement3));
     } else {
       _assertNonSyntheticElementSelf(e);
     }
@@ -2619,7 +2620,7 @@
   void _writeParameterElement(ParameterElement e) {
     e as ParameterElementImpl;
 
-    if (e.isNamed && e.enclosingElement is ExecutableElement) {
+    if (e.isNamed && e.enclosingElement3 is ExecutableElement) {
       expect(e.reference, isNotNull);
     } else {
       expect(e.reference, isNull);
@@ -2708,7 +2709,7 @@
 
     var variable = e.variable2;
     if (variable != null) {
-      var variableEnclosing = variable.enclosingElement;
+      var variableEnclosing = variable.enclosingElement3;
       if (variableEnclosing is CompilationUnitElement) {
         expect(variableEnclosing.topLevelVariables, contains(variable));
       } else if (variableEnclosing is InterfaceElement) {
diff --git a/pkg/analyzer/test/src/summary/elements/augmentation_import_test.dart b/pkg/analyzer/test/src/summary/elements/augmentation_import_test.dart
index 172ee2b..ac70bba 100644
--- a/pkg/analyzer/test/src/summary/elements/augmentation_import_test.dart
+++ b/pkg/analyzer/test/src/summary/elements/augmentation_import_test.dart
@@ -100,7 +100,7 @@
 
     var import_0 = library.augmentationImports[0];
     var augmentation = import_0.importedAugmentation!;
-    expect(augmentation.enclosingElement, same(library));
+    expect(augmentation.enclosingElement3, same(library));
   }
 
   test_library_augmentationImports_depthFirst() async {
@@ -175,7 +175,7 @@
 
     var import_0 = library.augmentationImports[0];
     var augmentation = import_0.importedAugmentation!;
-    expect(augmentation.enclosingElement, same(library));
+    expect(augmentation.enclosingElement3, same(library));
   }
 
   test_library_augmentationImports_noRelativeUriStr() async {
diff --git a/pkg/analyzer/test/src/summary/elements/type_alias_test.dart b/pkg/analyzer/test/src/summary/elements/type_alias_test.dart
index 1057a0c..022aaaf 100644
--- a/pkg/analyzer/test/src/summary/elements/type_alias_test.dart
+++ b/pkg/analyzer/test/src/summary/elements/type_alias_test.dart
@@ -298,14 +298,14 @@
 
     var T = F.typeParameters[0];
     expect(T.name, 'T');
-    expect(T.enclosingElement, same(F));
+    expect(T.enclosingElement3, same(F));
 
     var function = F.aliasedElement as GenericFunctionTypeElement;
-    expect(function.enclosingElement, same(F));
+    expect(function.enclosingElement3, same(F));
 
     var a = function.parameters[0];
     expect(a.name, 'a');
-    expect(a.enclosingElement, same(function));
+    expect(a.enclosingElement3, same(function));
   }
 
   test_functionTypeAlias_type_element() async {
@@ -695,18 +695,18 @@
 
     var T = F.typeParameters[0];
     expect(T.name, 'T');
-    expect(T.enclosingElement, same(F));
+    expect(T.enclosingElement3, same(F));
 
     var function = F.aliasedElement as GenericFunctionTypeElement;
-    expect(function.enclosingElement, same(F));
+    expect(function.enclosingElement3, same(F));
 
     var U = function.typeParameters[0];
     expect(U.name, 'U');
-    expect(U.enclosingElement, same(function));
+    expect(U.enclosingElement3, same(function));
 
     var a = function.parameters[0];
     expect(a.name, 'a');
-    expect(a.enclosingElement, same(function));
+    expect(a.enclosingElement3, same(function));
   }
 
   test_genericTypeAlias_recursive() async {
diff --git a/pkg/analyzer/test/src/summary/macro_test.dart b/pkg/analyzer/test/src/summary/macro_test.dart
index 9b57759..5b6446d 100644
--- a/pkg/analyzer/test/src/summary/macro_test.dart
+++ b/pkg/analyzer/test/src/summary/macro_test.dart
@@ -19871,7 +19871,7 @@
   void forCodeOptimizer() {
     filter = (obj) {
       if (obj is CompilationUnitElement) {
-        return obj.enclosingElement is LibraryAugmentationElement;
+        return obj.enclosingElement3 is LibraryAugmentationElement;
       }
       return true;
     };
diff --git a/pkg/analyzer/test/src/utilities/extensions/analysis_session_test.dart b/pkg/analyzer/test/src/utilities/extensions/analysis_session_test.dart
index 681b92e..ad09b8a 100644
--- a/pkg/analyzer/test/src/utilities/extensions/analysis_session_test.dart
+++ b/pkg/analyzer/test/src/utilities/extensions/analysis_session_test.dart
@@ -52,8 +52,10 @@
     var classOne = findClass(libraryOne, 'C');
     var classTwo = findClass(libraryTwo, 'C');
 
-    expect(await getElement(classOne.location!), classOne);
-    expect(await getElement(classTwo.location!), classTwo);
+    var c1 = await getElement(classOne.location!);
+    var c2 = await getElement(classTwo.location!);
+    expect(c1, classOne);
+    expect(c2, classTwo);
   }
 
   void test_invalid() async {
diff --git a/pkg/analyzer/test/src/wolf/ir/ast_to_ir_test.dart b/pkg/analyzer/test/src/wolf/ir/ast_to_ir_test.dart
index c426c24..ad6e387 100644
--- a/pkg/analyzer/test/src/wolf/ir/ast_to_ir_test.dart
+++ b/pkg/analyzer/test/src/wolf/ir/ast_to_ir_test.dart
@@ -1875,7 +1875,8 @@
     CallHandler? handler;
     switch (callDescriptor) {
       case ElementCallDescriptor(:var name, :var element):
-        if (element.enclosingElement case InstanceElement(name: var typeName)) {
+        if (element.enclosingElement3
+            case InstanceElement(name: var typeName)) {
           name = '${typeName ?? '<unnamed>'}.$name';
         }
         handler = _test._callHandlers[name];
diff --git a/pkg/analyzer/test/util/element_printer.dart b/pkg/analyzer/test/util/element_printer.dart
index efd9e90..446df69 100644
--- a/pkg/analyzer/test/util/element_printer.dart
+++ b/pkg/analyzer/test/util/element_printer.dart
@@ -148,7 +148,7 @@
   }
 
   String _elementToReferenceString(Element element) {
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     var reference = (element as ElementImpl).reference;
     if (reference != null) {
       return _referenceToString(reference);
diff --git a/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart b/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart
index 938f4c4..ad9a996 100644
--- a/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart
+++ b/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart
@@ -681,7 +681,7 @@
 
   @override
   void writeReference(Element element) {
-    if (element.enclosingElement is CompilationUnitElement) {
+    if (element.enclosingElement3 is CompilationUnitElement) {
       _writeLibraryReference(element);
     }
     write(element.displayName);
@@ -1092,10 +1092,10 @@
     if (type is TypeParameterType) {
       _initializeEnclosingElements();
       var element = type.element;
-      var enclosing = element.enclosingElement;
+      var enclosing = element.enclosingElement3;
       while (enclosing is GenericFunctionTypeElement ||
           enclosing is ParameterElement) {
-        enclosing = enclosing!.enclosingElement;
+        enclosing = enclosing!.enclosingElement3;
       }
       if (enclosing == _enclosingExecutable ||
           enclosing == _enclosingClass ||
diff --git a/pkg/analyzer_plugin/lib/src/utilities/completion/element_suggestion_builder.dart b/pkg/analyzer_plugin/lib/src/utilities/completion/element_suggestion_builder.dart
index 127cb49..7d683d3 100644
--- a/pkg/analyzer_plugin/lib/src/utilities/completion/element_suggestion_builder.dart
+++ b/pkg/analyzer_plugin/lib/src/utilities/completion/element_suggestion_builder.dart
@@ -70,7 +70,7 @@
           // Pair getter/setter by updating the existing suggestion
           if (existingSuggestion != null) {
             var getter = element.isGetter ? suggestion : existingSuggestion;
-            var elemKind = element.enclosingElement is ClassElement
+            var elemKind = element.enclosingElement3 is ClassElement
                 ? protocol.ElementKind.FIELD
                 : protocol.ElementKind.TOP_LEVEL_VARIABLE;
             existingSuggestion.element = protocol.Element(
diff --git a/pkg/analyzer_plugin/lib/src/utilities/completion/suggestion_builder.dart b/pkg/analyzer_plugin/lib/src/utilities/completion/suggestion_builder.dart
index e456b13..b0a84a7 100644
--- a/pkg/analyzer_plugin/lib/src/utilities/completion/suggestion_builder.dart
+++ b/pkg/analyzer_plugin/lib/src/utilities/completion/suggestion_builder.dart
@@ -94,7 +94,7 @@
     suggestion.docSummary = getDartDocSummary(doc);
 
     suggestion.element = converter.convertElement(element);
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     if (enclosingElement is ClassElement) {
       suggestion.declaringType = enclosingElement.displayName;
     }
diff --git a/pkg/analyzer_plugin/lib/utilities/analyzer_converter.dart b/pkg/analyzer_plugin/lib/utilities/analyzer_converter.dart
index f564f70..93e2f8f 100644
--- a/pkg/analyzer_plugin/lib/utilities/analyzer_converter.dart
+++ b/pkg/analyzer_plugin/lib/utilities/analyzer_converter.dart
@@ -178,7 +178,7 @@
         // in either or both of these cases?
         ) {
       var type = element.type;
-      if (type is InterfaceType && type.element == element.enclosingElement) {
+      if (type is InterfaceType && type.element == element.enclosingElement3) {
         return plugin.ElementKind.ENUM_CONSTANT;
       }
     }
@@ -320,7 +320,7 @@
     var currentElement = this;
     for (;
         currentElement != null;
-        currentElement = currentElement.enclosingElement) {
+        currentElement = currentElement.enclosingElement3) {
       if (currentElement is analyzer.CompilationUnitElement) {
         return currentElement;
       } else if (currentElement is analyzer.LibraryOrAugmentationElement) {
diff --git a/pkg/analyzer_plugin/lib/utilities/navigation/navigation_dart.dart b/pkg/analyzer_plugin/lib/utilities/navigation/navigation_dart.dart
index f78d815..2efa902 100644
--- a/pkg/analyzer_plugin/lib/utilities/navigation/navigation_dart.dart
+++ b/pkg/analyzer_plugin/lib/utilities/navigation/navigation_dart.dart
@@ -190,7 +190,7 @@
   void visitAnnotation(Annotation node) {
     var element = node.element;
     if (element is ConstructorElement && element.isSynthetic) {
-      element = element.enclosingElement;
+      element = element.enclosingElement3;
     }
     var name = node.name;
     if (name is PrefixedIdentifier) {
@@ -526,7 +526,7 @@
       RedirectingConstructorInvocation node) {
     Element? element = node.staticElement;
     if (element != null && element.isSynthetic) {
-      element = element.enclosingElement;
+      element = element.enclosingElement3;
     }
     // add region
     computer._addRegionForToken(node.thisKeyword, element);
@@ -564,7 +564,7 @@
   void visitSuperConstructorInvocation(SuperConstructorInvocation node) {
     Element? element = node.staticElement;
     if (element != null && element.isSynthetic) {
-      element = element.enclosingElement;
+      element = element.enclosingElement3;
     }
     // add region
     computer._addRegionForToken(node.superKeyword, element);
diff --git a/pkg/analyzer_plugin/test/src/utilities/completion/completion_target_test.dart b/pkg/analyzer_plugin/test/src/utilities/completion/completion_target_test.dart
index 2b5d087..734c401 100644
--- a/pkg/analyzer_plugin/test/src/utilities/completion/completion_target_test.dart
+++ b/pkg/analyzer_plugin/test/src/utilities/completion/completion_target_test.dart
@@ -960,7 +960,7 @@
   }
 
   static String _executableNameStr(ExecutableElement executable) {
-    var executableEnclosing = executable.enclosingElement;
+    var executableEnclosing = executable.enclosingElement3;
     if (executableEnclosing is CompilationUnitElement) {
       return executable.name;
     } else if (executable is ConstructorElement) {
diff --git a/pkg/linter/lib/src/ast.dart b/pkg/linter/lib/src/ast.dart
index 78dfd61..87c9773 100644
--- a/pkg/linter/lib/src/ast.dart
+++ b/pkg/linter/lib/src/ast.dart
@@ -305,10 +305,10 @@
   if (expression is SimpleIdentifier) {
     var staticElement = expression.staticElement;
     if (staticElement is PropertyAccessorElement) {
-      var enclosingElement = getter.declaredElement?.enclosingElement;
+      var enclosingElement = getter.declaredElement?.enclosingElement3;
       // Skipping library level getters, test that the enclosing element is
       // the same
-      if (staticElement.enclosingElement == enclosingElement) {
+      if (staticElement.enclosingElement3 == enclosingElement) {
         var variable = staticElement.variable2;
         if (variable != null) {
           return staticElement.isSynthetic && variable.isPrivate;
diff --git a/pkg/linter/lib/src/extensions.dart b/pkg/linter/lib/src/extensions.dart
index af1efa9..68722c8 100644
--- a/pkg/linter/lib/src/extensions.dart
+++ b/pkg/linter/lib/src/extensions.dart
@@ -271,7 +271,7 @@
     required String constructorName,
   }) =>
       library.name == uri &&
-      enclosingElement.name == className &&
+      enclosingElement3.name == className &&
       name == constructorName;
 }
 
@@ -555,7 +555,7 @@
     if (name == null) {
       return false;
     }
-    var parentElement = declaredElement?.enclosingElement;
+    var parentElement = declaredElement?.enclosingElement3;
     if (parentElement is! InterfaceElement) {
       return false;
     }
@@ -581,7 +581,7 @@
     if (declaredElement == null) {
       return null;
     }
-    var parent = declaredElement.enclosingElement;
+    var parent = declaredElement.enclosingElement3;
     if (parent is InterfaceElement) {
       return parent.augmented
           .lookUpGetter(name: name.lexeme, library: declaredElement.library);
@@ -597,7 +597,7 @@
     if (declaredElement == null) {
       return null;
     }
-    var parent = declaredElement.enclosingElement;
+    var parent = declaredElement.enclosingElement3;
     if (parent is InterfaceElement) {
       return parent.lookUpInheritedConcreteGetter(
           name.lexeme, declaredElement.library);
@@ -609,7 +609,7 @@
   MethodElement? lookUpInheritedConcreteMethod() {
     var declaredElement = this.declaredElement;
     if (declaredElement != null) {
-      var parent = declaredElement.enclosingElement;
+      var parent = declaredElement.enclosingElement3;
       if (parent is InterfaceElement) {
         return parent.lookUpInheritedConcreteMethod(
             name.lexeme, declaredElement.library);
@@ -622,7 +622,7 @@
   PropertyAccessorElement? lookUpInheritedConcreteSetter() {
     var declaredElement = this.declaredElement;
     if (declaredElement != null) {
-      var parent = declaredElement.enclosingElement;
+      var parent = declaredElement.enclosingElement3;
       if (parent is InterfaceElement) {
         return parent.lookUpInheritedConcreteSetter(
             name.lexeme, declaredElement.library);
@@ -635,7 +635,7 @@
   MethodElement? lookUpInheritedMethod() {
     var declaredElement = this.declaredElement;
     if (declaredElement != null) {
-      var parent = declaredElement.enclosingElement;
+      var parent = declaredElement.enclosingElement3;
       if (parent is InterfaceElement) {
         return parent.lookUpInheritedMethod(
             name.lexeme, declaredElement.library);
diff --git a/pkg/linter/lib/src/rules/avoid_classes_with_only_static_members.dart b/pkg/linter/lib/src/rules/avoid_classes_with_only_static_members.dart
index 580f270..596c9a7 100644
--- a/pkg/linter/lib/src/rules/avoid_classes_with_only_static_members.dart
+++ b/pkg/linter/lib/src/rules/avoid_classes_with_only_static_members.dart
@@ -85,7 +85,7 @@
     var interface = context.inheritanceManager.getInterface(element);
     var map = interface.map;
     for (var member in map.values) {
-      var enclosingElement = member.enclosingElement;
+      var enclosingElement = member.enclosingElement3;
       if (enclosingElement is ClassElement &&
           !enclosingElement.isDartCoreObject) {
         return;
diff --git a/pkg/linter/lib/src/rules/avoid_implementing_value_types.dart b/pkg/linter/lib/src/rules/avoid_implementing_value_types.dart
index 6227d4e..443759d 100644
--- a/pkg/linter/lib/src/rules/avoid_implementing_value_types.dart
+++ b/pkg/linter/lib/src/rules/avoid_implementing_value_types.dart
@@ -130,7 +130,7 @@
 
   static bool _overridesEquals(InterfaceElement element) {
     var method = element.lookUpConcreteMethod('==', element.library);
-    var enclosing = method?.enclosingElement;
+    var enclosing = method?.enclosingElement3;
     return enclosing is ClassElement && !enclosing.isDartCoreObject;
   }
 }
diff --git a/pkg/linter/lib/src/rules/avoid_type_to_string.dart b/pkg/linter/lib/src/rules/avoid_type_to_string.dart
index 517b0c6..a2b62e8 100644
--- a/pkg/linter/lib/src/rules/avoid_type_to_string.dart
+++ b/pkg/linter/lib/src/rules/avoid_type_to_string.dart
@@ -124,7 +124,7 @@
   }
 
   bool _isSimpleIdDeclByCoreObj(SimpleIdentifier simpleIdentifier) {
-    var encloser = simpleIdentifier.staticElement?.enclosingElement;
+    var encloser = simpleIdentifier.staticElement?.enclosingElement3;
     return encloser is ClassElement && encloser.isDartCoreObject;
   }
 
diff --git a/pkg/linter/lib/src/rules/deprecated_consistency.dart b/pkg/linter/lib/src/rules/deprecated_consistency.dart
index 4a6ac9c6..7e774a2 100644
--- a/pkg/linter/lib/src/rules/deprecated_consistency.dart
+++ b/pkg/linter/lib/src/rules/deprecated_consistency.dart
@@ -88,7 +88,7 @@
   void visitConstructorDeclaration(ConstructorDeclaration node) {
     var constructorElement = node.declaredElement;
     if (constructorElement != null &&
-        constructorElement.enclosingElement.hasDeprecated &&
+        constructorElement.enclosingElement3.hasDeprecated &&
         !constructorElement.hasDeprecated) {
       var nodeToAnnotate = node.name ?? node.returnType;
       rule.reportLintForOffset(nodeToAnnotate.offset, nodeToAnnotate.length,
diff --git a/pkg/linter/lib/src/rules/invalid_runtime_check_with_js_interop_types.dart b/pkg/linter/lib/src/rules/invalid_runtime_check_with_js_interop_types.dart
index 60c52bd..88bca2f 100644
--- a/pkg/linter/lib/src/rules/invalid_runtime_check_with_js_interop_types.dart
+++ b/pkg/linter/lib/src/rules/invalid_runtime_check_with_js_interop_types.dart
@@ -160,7 +160,7 @@
     var annotationElement = annotation.element;
     if (annotationElement is ConstructorElement &&
         isFromLibrary(annotationElement.library, _dartJsInteropUri) &&
-        annotationElement.enclosingElement.name == 'JS') {
+        annotationElement.enclosingElement3.name == 'JS') {
       hasJS = true;
       dartJsInterop = annotationElement.library;
     } else if (annotationElement is PropertyAccessorElement &&
diff --git a/pkg/linter/lib/src/rules/library_annotations.dart b/pkg/linter/lib/src/rules/library_annotations.dart
index f72ebe4..1f4ae00 100644
--- a/pkg/linter/lib/src/rules/library_annotations.dart
+++ b/pkg/linter/lib/src/rules/library_annotations.dart
@@ -120,7 +120,7 @@
   }) {
     var element = this.element;
     return element is ConstructorElement &&
-        element.enclosingElement.name == className &&
+        element.enclosingElement3.name == className &&
         element.library.name == libraryName;
   }
 }
diff --git a/pkg/linter/lib/src/rules/missing_whitespace_between_adjacent_strings.dart b/pkg/linter/lib/src/rules/missing_whitespace_between_adjacent_strings.dart
index 5181f82..f65d0d7 100644
--- a/pkg/linter/lib/src/rules/missing_whitespace_between_adjacent_strings.dart
+++ b/pkg/linter/lib/src/rules/missing_whitespace_between_adjacent_strings.dart
@@ -91,7 +91,7 @@
   static bool _isRegExpInstanceCreation(AstNode? node) {
     if (node is InstanceCreationExpression) {
       var constructorElement = node.constructorName.staticElement;
-      return constructorElement?.enclosingElement.name == 'RegExp';
+      return constructorElement?.enclosingElement3.name == 'RegExp';
     }
     return false;
   }
diff --git a/pkg/linter/lib/src/rules/overridden_fields.dart b/pkg/linter/lib/src/rules/overridden_fields.dart
index c782b08..0c14cea 100644
--- a/pkg/linter/lib/src/rules/overridden_fields.dart
+++ b/pkg/linter/lib/src/rules/overridden_fields.dart
@@ -133,7 +133,7 @@
         var overriddenField = _getOverriddenMember(declaredField);
         if (overriddenField != null && !overriddenField.isAbstract) {
           rule.reportLintForToken(variable.name,
-              arguments: [overriddenField.enclosingElement.displayName]);
+              arguments: [overriddenField.enclosingElement3.displayName]);
         }
       }
     }
@@ -158,7 +158,7 @@
 
     bool containsOverriddenMember(InterfaceType i) =>
         i.accessors.any(isOverriddenMember);
-    var enclosingElement = member.enclosingElement;
+    var enclosingElement = member.enclosingElement3;
     if (enclosingElement is! InterfaceElement) {
       return null;
     }
diff --git a/pkg/linter/lib/src/rules/prefer_asserts_in_initializer_lists.dart b/pkg/linter/lib/src/rules/prefer_asserts_in_initializer_lists.dart
index 3e103b3..c1e812b 100644
--- a/pkg/linter/lib/src/rules/prefer_asserts_in_initializer_lists.dart
+++ b/pkg/linter/lib/src/rules/prefer_asserts_in_initializer_lists.dart
@@ -84,12 +84,12 @@
 
   bool _hasAccessor(PropertyAccessorElement element) {
     var classes = classAndSuperClasses?.classes;
-    return classes != null && classes.contains(element.enclosingElement);
+    return classes != null && classes.contains(element.enclosingElement3);
   }
 
   bool _hasMethod(MethodElement element) {
     var classes = classAndSuperClasses?.classes;
-    return classes != null && classes.contains(element.enclosingElement);
+    return classes != null && classes.contains(element.enclosingElement3);
   }
 
   bool _paramMatchesField(
diff --git a/pkg/linter/lib/src/rules/prefer_const_constructors.dart b/pkg/linter/lib/src/rules/prefer_const_constructors.dart
index fed5d6f..873e8e4 100644
--- a/pkg/linter/lib/src/rules/prefer_const_constructors.dart
+++ b/pkg/linter/lib/src/rules/prefer_const_constructors.dart
@@ -91,7 +91,7 @@
     // Handled by an analyzer warning.
     if (element.hasLiteral) return;
 
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     if (enclosingElement is ClassElement && enclosingElement.isDartCoreObject) {
       // Skip lint for `new Object()`, because it can be used for ID creation.
       return;
diff --git a/pkg/linter/lib/src/rules/prefer_const_constructors_in_immutables.dart b/pkg/linter/lib/src/rules/prefer_const_constructors_in_immutables.dart
index db43133..52b1a3c 100644
--- a/pkg/linter/lib/src/rules/prefer_const_constructors_in_immutables.dart
+++ b/pkg/linter/lib/src/rules/prefer_const_constructors_in_immutables.dart
@@ -72,7 +72,7 @@
     if (element == null) return;
     if (element.isConst) return;
     if (node.body is! EmptyFunctionBody) return;
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     if (enclosingElement.isMacro) return;
     if (enclosingElement.mixins.isNotEmpty) return;
     if (!_hasImmutableAnnotation(enclosingElement)) return;
@@ -112,7 +112,7 @@
     if (declaredElement == null) {
       return false;
     }
-    var clazz = declaredElement.enclosingElement;
+    var clazz = declaredElement.enclosingElement3;
     // Constructor with super-initializer.
     var superInvocation =
         node.initializers.whereType<SuperConstructorInvocation>().firstOrNull;
diff --git a/pkg/linter/lib/src/rules/prefer_final_fields.dart b/pkg/linter/lib/src/rules/prefer_final_fields.dart
index 37840fa..a967af8 100644
--- a/pkg/linter/lib/src/rules/prefer_final_fields.dart
+++ b/pkg/linter/lib/src/rules/prefer_final_fields.dart
@@ -212,7 +212,7 @@
 
 extension on VariableElement {
   bool get overridesField {
-    var enclosingElement = this.enclosingElement;
+    var enclosingElement = enclosingElement3;
     if (enclosingElement is! InterfaceElement) return false;
 
     var library = this.library;
diff --git a/pkg/linter/lib/src/rules/prefer_for_elements_to_map_fromIterable.dart b/pkg/linter/lib/src/rules/prefer_for_elements_to_map_fromIterable.dart
index 8735e93..3def94e 100644
--- a/pkg/linter/lib/src/rules/prefer_for_elements_to_map_fromIterable.dart
+++ b/pkg/linter/lib/src/rules/prefer_for_elements_to_map_fromIterable.dart
@@ -83,7 +83,7 @@
     var element = creation.constructorName.staticElement;
     if (element == null ||
         element.name != 'fromIterable' ||
-        element.enclosingElement != context.typeProvider.mapElement) {
+        element.enclosingElement3 != context.typeProvider.mapElement) {
       return;
     }
 
diff --git a/pkg/linter/lib/src/rules/prefer_initializing_formals.dart b/pkg/linter/lib/src/rules/prefer_initializing_formals.dart
index 14fe0fd..2e42c88 100644
--- a/pkg/linter/lib/src/rules/prefer_initializing_formals.dart
+++ b/pkg/linter/lib/src/rules/prefer_initializing_formals.dart
@@ -161,8 +161,8 @@
           !leftElement.isPrivate &&
           leftElement is FieldElement &&
           !leftElement.isSynthetic &&
-          leftElement.enclosingElement ==
-              node.declaredElement?.enclosingElement &&
+          leftElement.enclosingElement3 ==
+              node.declaredElement?.enclosingElement3 &&
           parameters.contains(rightElement) &&
           (!parametersUsedMoreThanOnce.contains(rightElement) &&
                   !(rightElement as ParameterElement).isNamed ||
diff --git a/pkg/linter/lib/src/rules/prefer_is_not_empty.dart b/pkg/linter/lib/src/rules/prefer_is_not_empty.dart
index 794baf4..71dd0eb 100644
--- a/pkg/linter/lib/src/rules/prefer_is_not_empty.dart
+++ b/pkg/linter/lib/src/rules/prefer_is_not_empty.dart
@@ -87,7 +87,7 @@
     }
 
     // Element should also support "isNotEmpty".
-    var propertyTarget = propertyElement.enclosingElement;
+    var propertyTarget = propertyElement.enclosingElement3;
     if (propertyTarget == null ||
         getChildren(propertyTarget, 'isNotEmpty').isEmpty) {
       return;
diff --git a/pkg/linter/lib/src/rules/unawaited_futures.dart b/pkg/linter/lib/src/rules/unawaited_futures.dart
index bb7ae3c..e399333 100644
--- a/pkg/linter/lib/src/rules/unawaited_futures.dart
+++ b/pkg/linter/lib/src/rules/unawaited_futures.dart
@@ -126,7 +126,7 @@
   bool _isMapPutIfAbsentInvocation(Expression expr) =>
       expr is MethodInvocation &&
       expr.methodName.name == 'putIfAbsent' &&
-      _isMapClass(expr.methodName.staticElement?.enclosingElement);
+      _isMapClass(expr.methodName.staticElement?.enclosingElement3);
 
   void _visit(Expression expr) {
     if ((expr.staticType?.isDartAsyncFuture ?? false) &&
diff --git a/pkg/linter/lib/src/rules/unnecessary_null_aware_operator_on_extension_on_nullable.dart b/pkg/linter/lib/src/rules/unnecessary_null_aware_operator_on_extension_on_nullable.dart
index e22a5a1..216c9b2 100644
--- a/pkg/linter/lib/src/rules/unnecessary_null_aware_operator_on_extension_on_nullable.dart
+++ b/pkg/linter/lib/src/rules/unnecessary_null_aware_operator_on_extension_on_nullable.dart
@@ -72,8 +72,8 @@
             ? node
                 .thisOrAncestorOfType<AssignmentExpression>()
                 ?.writeElement
-                ?.enclosingElement
-            : node.staticElement?.enclosingElement)) {
+                ?.enclosingElement3
+            : node.staticElement?.enclosingElement3)) {
       rule.reportLintForToken(node.question);
     }
   }
@@ -82,7 +82,7 @@
   void visitMethodInvocation(MethodInvocation node) {
     if (node.isNullAware &&
         _isExtensionOnNullableType(
-            node.methodName.staticElement?.enclosingElement)) {
+            node.methodName.staticElement?.enclosingElement3)) {
       rule.reportLintForToken(node.operator);
     }
   }
@@ -93,8 +93,8 @@
       var realParent = node.thisOrAncestorMatching(
           (p) => p != node && p is! ParenthesizedExpression);
       if (_isExtensionOnNullableType(realParent is AssignmentExpression
-          ? realParent.writeElement?.enclosingElement
-          : node.propertyName.staticElement?.enclosingElement)) {
+          ? realParent.writeElement?.enclosingElement3
+          : node.propertyName.staticElement?.enclosingElement3)) {
         rule.reportLintForToken(node.operator);
       }
     }
diff --git a/pkg/linter/lib/src/rules/unnecessary_overrides.dart b/pkg/linter/lib/src/rules/unnecessary_overrides.dart
index 6bf8fd6..579a625 100644
--- a/pkg/linter/lib/src/rules/unnecessary_overrides.dart
+++ b/pkg/linter/lib/src/rules/unnecessary_overrides.dart
@@ -220,7 +220,7 @@
   ExecutableElement? getInheritedElement(MethodDeclaration node) {
     var element = node.declaredElement;
     if (element == null) return null;
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     if (enclosingElement is! InterfaceElement) return null;
     return enclosingElement.thisType.lookUpGetter2(
       element.name,
@@ -247,7 +247,7 @@
     var element = node.declaredElement;
     if (element == null) return null;
 
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     if (enclosingElement is! InterfaceElement) return null;
 
     var augmented = enclosingElement.augmented;
@@ -279,7 +279,7 @@
   ExecutableElement? getInheritedElement(node) {
     var element = node.declaredElement;
     if (element == null) return null;
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     if (enclosingElement is! InterfaceElement) return null;
     return enclosingElement.thisType.lookUpMethod2(
       element.name,
@@ -326,7 +326,7 @@
   ExecutableElement? getInheritedElement(node) {
     var element = node.declaredElement;
     if (element == null) return null;
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     if (enclosingElement is! InterfaceElement) return null;
     return enclosingElement.thisType.lookUpSetter2(
       node.name.lexeme,
diff --git a/pkg/linter/lib/src/rules/unnecessary_parenthesis.dart b/pkg/linter/lib/src/rules/unnecessary_parenthesis.dart
index c354210..9fd065c 100644
--- a/pkg/linter/lib/src/rules/unnecessary_parenthesis.dart
+++ b/pkg/linter/lib/src/rules/unnecessary_parenthesis.dart
@@ -147,7 +147,7 @@
         // Parentheses are required to stop null-aware shorting, which then
         // allows an extension getter, which extends a nullable type, to be
         // called on a `null` value.
-        var target = parent.propertyName.staticElement?.enclosingElement;
+        var target = parent.propertyName.staticElement?.enclosingElement3;
         if (target is ExtensionElement &&
             typeSystem.isNullable(target.extendedType)) {
           return;
@@ -162,7 +162,7 @@
         // Parentheses are required to stop null-aware shorting, which then
         // allows an extension method, which extends a nullable type, to be
         // called on a `null` value.
-        var target = parent.methodName.staticElement?.enclosingElement;
+        var target = parent.methodName.staticElement?.enclosingElement3;
         if (target is ExtensionElement &&
             typeSystem.isNullable(target.extendedType)) {
           return;
diff --git a/pkg/linter/lib/src/rules/unnecessary_this.dart b/pkg/linter/lib/src/rules/unnecessary_this.dart
index ef3c07c..ae6935f 100644
--- a/pkg/linter/lib/src/rules/unnecessary_this.dart
+++ b/pkg/linter/lib/src/rules/unnecessary_this.dart
@@ -133,7 +133,7 @@
     //  - prevents us from going up to the library scope;
     //  - the requested element must be inherited, or from an extension.
     if (result.isDifferentName) {
-      var enclosing = result.element?.enclosingElement;
+      var enclosing = result.element?.enclosingElement3;
       return enclosing is ClassElement;
     }
 
diff --git a/pkg/linter/lib/src/rules/unreachable_from_main.dart b/pkg/linter/lib/src/rules/unreachable_from_main.dart
index 461a49d..927e213 100644
--- a/pkg/linter/lib/src/rules/unreachable_from_main.dart
+++ b/pkg/linter/lib/src/rules/unreachable_from_main.dart
@@ -401,8 +401,8 @@
   void _addDeclaration(Element element) {
     // First add the enclosing top-level declaration.
     var enclosingTopLevelElement = element.thisOrAncestorMatching((a) =>
-        a.enclosingElement == null ||
-        a.enclosingElement is CompilationUnitElement);
+        a.enclosingElement3 == null ||
+        a.enclosingElement3 is CompilationUnitElement);
     var enclosingTopLevelDeclaration = declarationMap[enclosingTopLevelElement];
     if (enclosingTopLevelDeclaration != null) {
       declarations.add(enclosingTopLevelDeclaration);
@@ -413,7 +413,7 @@
     if (element.isPrivate) {
       return;
     }
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement3;
     if (enclosingElement == null || enclosingElement.isPrivate) {
       return;
     }
diff --git a/pkg/linter/lib/src/rules/unsafe_html.dart b/pkg/linter/lib/src/rules/unsafe_html.dart
index 1cacae0..ab95e01 100644
--- a/pkg/linter/lib/src/rules/unsafe_html.dart
+++ b/pkg/linter/lib/src/rules/unsafe_html.dart
@@ -93,7 +93,7 @@
     if (leftPart is SimpleIdentifier) {
       var leftPartElement = node.writeElement;
       if (leftPartElement == null) return;
-      var enclosingElement = leftPartElement.enclosingElement;
+      var enclosingElement = leftPartElement.enclosingElement3;
       if (enclosingElement is ClassElement) {
         _checkAssignment(enclosingElement.thisType, leftPart, node);
       }
@@ -133,7 +133,7 @@
       // Implicit `this` target.
       var methodElement = node.methodName.staticElement;
       if (methodElement == null) return;
-      var enclosingElement = methodElement.enclosingElement;
+      var enclosingElement = methodElement.enclosingElement3;
       if (enclosingElement is ClassElement) {
         type = enclosingElement.thisType;
       } else {
diff --git a/pkg/linter/lib/src/rules/use_build_context_synchronously.dart b/pkg/linter/lib/src/rules/use_build_context_synchronously.dart
index 1126929..d174aa0 100644
--- a/pkg/linter/lib/src/rules/use_build_context_synchronously.dart
+++ b/pkg/linter/lib/src/rules/use_build_context_synchronously.dart
@@ -1390,7 +1390,7 @@
     var self = this;
 
     if (self is PropertyAccessorElement) {
-      var enclosingElement = self.enclosingElement;
+      var enclosingElement = self.enclosingElement3;
       if (enclosingElement is InterfaceElement && isState(enclosingElement)) {
         // The BuildContext object is the field on Flutter's State class.
         // This object can only be guarded by async gaps with a mounted
diff --git a/pkg/linter/lib/src/rules/use_enums.dart b/pkg/linter/lib/src/rules/use_enums.dart
index ecba9f4..8d275bc 100644
--- a/pkg/linter/lib/src/rules/use_enums.dart
+++ b/pkg/linter/lib/src/rules/use_enums.dart
@@ -98,7 +98,7 @@
     var constructorElement = node.constructorName.staticElement;
     return constructorElement != null &&
         !constructorElement.isFactory &&
-        constructorElement.enclosingElement == classElement;
+        constructorElement.enclosingElement3 == classElement;
   }
 }
 
@@ -223,7 +223,7 @@
           var constructorElement = initializer.constructorName.staticElement;
           if (constructorElement == null) continue;
           if (constructorElement.isFactory) continue;
-          if (constructorElement.enclosingElement != classElement) continue;
+          if (constructorElement.enclosingElement3 != classElement) continue;
           if (fieldElement.computeConstantValue() == null) continue;
 
           candidateConstants.add(field);
diff --git a/pkg/linter/lib/src/rules/use_key_in_widget_constructors.dart b/pkg/linter/lib/src/rules/use_key_in_widget_constructors.dart
index 47a20a6..d37191f 100644
--- a/pkg/linter/lib/src/rules/use_key_in_widget_constructors.dart
+++ b/pkg/linter/lib/src/rules/use_key_in_widget_constructors.dart
@@ -79,7 +79,7 @@
     if (constructorElement == null) {
       return;
     }
-    var classElement = constructorElement.enclosingElement;
+    var classElement = constructorElement.enclosingElement3;
     if (constructorElement.isPublic &&
         !constructorElement.isFactory &&
         classElement.isPublic &&
diff --git a/pkg/linter/lib/src/rules/use_named_constants.dart b/pkg/linter/lib/src/rules/use_named_constants.dart
index 39c4db0..effbd36 100644
--- a/pkg/linter/lib/src/rules/use_named_constants.dart
+++ b/pkg/linter/lib/src/rules/use_named_constants.dart
@@ -70,7 +70,7 @@
         //   static const a = A();
         //   static const b = A();
         // }
-        if (nodeField?.enclosingElement == element) return;
+        if (nodeField?.enclosingElement3 == element) return;
 
         var library = (node.root as CompilationUnit).declaredElement?.library;
         if (library == null) return;
diff --git a/pkg/linter/lib/src/rules/valid_regexps.dart b/pkg/linter/lib/src/rules/valid_regexps.dart
index 9d02de6..1b6d494 100644
--- a/pkg/linter/lib/src/rules/valid_regexps.dart
+++ b/pkg/linter/lib/src/rules/valid_regexps.dart
@@ -55,7 +55,7 @@
 
   @override
   void visitInstanceCreationExpression(InstanceCreationExpression node) {
-    var element = node.constructorName.staticElement?.enclosingElement;
+    var element = node.constructorName.staticElement?.enclosingElement3;
     if (element?.name == 'RegExp' && element?.library.name == 'dart.core') {
       var args = node.argumentList.arguments;
       if (args.isEmpty) {
diff --git a/pkg/linter/test/rules/conditional_uri_does_not_exist_test.dart b/pkg/linter/test/rules/conditional_uri_does_not_exist_test.dart
index efbda36..f6ba5f8 100644
--- a/pkg/linter/test/rules/conditional_uri_does_not_exist_test.dart
+++ b/pkg/linter/test/rules/conditional_uri_does_not_exist_test.dart
@@ -29,7 +29,6 @@
     if (dart.library.async) 'dart:missing_2';
 ''',
       [
-        error(WarningCode.UNUSED_IMPORT, 7, 2),
         lint(35, 16, messageContains: 'dart:missing_1'),
         lint(120, 16, messageContains: 'dart:missing_2'),
       ],
@@ -47,7 +46,6 @@
     if (dart.library.async) 'missing_2.dart';
 ''',
       [
-        error(WarningCode.UNUSED_IMPORT, 7, 2),
         lint(35, 16, messageContains: 'missing_1.dart'),
         lint(121, 16, messageContains: 'missing_2.dart'),
       ],
@@ -63,7 +61,6 @@
     if (dart.library.io) 'package:foo/missing_2.dart';
 ''',
       [
-        error(WarningCode.UNUSED_IMPORT, 7, 2),
         lint(35, 29, messageContains: 'missing_1.dart'),
         lint(142, 28, messageContains: 'missing_2.dart'),
       ],
diff --git a/pkg/linter/test/rules/use_key_in_widget_constructors_test.dart b/pkg/linter/test/rules/use_key_in_widget_constructors_test.dart
index 831b608..e669505 100644
--- a/pkg/linter/test/rules/use_key_in_widget_constructors_test.dart
+++ b/pkg/linter/test/rules/use_key_in_widget_constructors_test.dart
@@ -22,8 +22,8 @@
 
   test_augmentedConstructor_noKey() async {
     newFile('$testPackageLibPath/a.dart', r'''
-import augment 'test.dart';
 import 'package:flutter/widgets.dart';
+part 'test.dart';
 
 class W extends StatelessWidget {
   W();
@@ -34,9 +34,7 @@
 ''');
 
     await assertNoDiagnostics(r'''
-augment library 'a.dart';
-
-import 'package:flutter/widgets.dart';
+part of 'a.dart';
 
 augment class W {
   augment const W();
@@ -84,8 +82,8 @@
 
   test_constructorInAugmentedClass_noKeyParam() async {
     newFile('$testPackageLibPath/a.dart', r'''
-import augment 'test.dart';
 import 'package:flutter/widgets.dart';
+part 'test.dart';
 
 class W extends StatelessWidget {
   @override
@@ -94,15 +92,13 @@
 ''');
 
     await assertDiagnostics(r'''
-augment library 'a.dart';
-
-import 'package:flutter/widgets.dart';
+part of 'a.dart';
 
 augment class W {
   const W();
 }
 ''', [
-      lint(93, 1),
+      lint(45, 1),
     ]);
   }
 
diff --git a/pkg/linter/tool/checks/rules/visit_registered_nodes.dart b/pkg/linter/tool/checks/rules/visit_registered_nodes.dart
index 402d1e9..ec244ff 100644
--- a/pkg/linter/tool/checks/rules/visit_registered_nodes.dart
+++ b/pkg/linter/tool/checks/rules/visit_registered_nodes.dart
@@ -104,7 +104,7 @@
     // Unifying and Generalizing visitors are doing the right thing.)
     // For now we flag methods inherited from SimpleAstVisitor since they
     // surely don't do anything.
-    return method?.enclosingElement.name != 'SimpleAstVisitor';
+    return method?.enclosingElement3.name != 'SimpleAstVisitor';
   }
 
   @override
diff --git a/tools/VERSION b/tools/VERSION
index 1647ec2..d7c6c49 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
 MAJOR 3
 MINOR 6
 PATCH 0
-PRERELEASE 205
+PRERELEASE 206
 PRERELEASE_PATCH 0