Version 2.19.0-12.0.dev

Merge commit '2f3269faa17567d05b338c03f221281962965d49' into 'dev'
diff --git a/pkg/analysis_server/lib/src/cider/rename.dart b/pkg/analysis_server/lib/src/cider/rename.dart
index 6f666d1..73f1716 100644
--- a/pkg/analysis_server/lib/src/cider/rename.dart
+++ b/pkg/analysis_server/lib/src/cider/rename.dart
@@ -65,7 +65,7 @@
 
   void _analyzePossibleConflicts(
       ConstructorElement element, RefactoringStatus result, String newName) {
-    var parentClass = element.enclosingElement;
+    var parentClass = element.enclosingElement2;
     // 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.enclosingElement2.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 classElement = element.enclosingElement;
+    var classElement = element.enclosingElement2;
 
     var fileResolver = canRename._fileResolver;
     var libraryPath = classElement!.library!.source.fullName;
@@ -382,7 +382,7 @@
   }
 
   bool _canRenameElement(Element element) {
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement2;
     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 188f29b..ceb8a33 100644
--- a/pkg/analysis_server/lib/src/computer/computer_call_hierarchy.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_call_hierarchy.dart
@@ -104,7 +104,7 @@
         codeRange = _codeRangeForElement(element),
         file = element.source!.fullName,
         kind = CallHierarchyKind.forElement(element) {
-    final enclosingElement = element.enclosingElement;
+    final enclosingElement = element.enclosingElement2;
     final 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 1026b0a..21db001 100644
--- a/pkg/analysis_server/lib/src/computer/computer_color.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_color.dart
@@ -83,7 +83,7 @@
 
     final constructor = expression.constructorName;
     final staticElement = constructor.staticElement;
-    final classElement = staticElement?.enclosingElement;
+    final classElement = staticElement?.enclosingElement2;
     final className = classElement?.name;
     final constructorName = constructor.name?.name;
     final 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 4e25d41..b74240d 100644
--- a/pkg/analysis_server/lib/src/computer/computer_highlights.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_highlights.dart
@@ -305,7 +305,7 @@
     var parent = node.parent;
     var isInvocation = parent is MethodInvocation && parent.methodName == node;
     HighlightRegionType type;
-    var isTopLevel = element.enclosingElement is CompilationUnitElement;
+    var isTopLevel = element.enclosingElement2 is CompilationUnitElement;
     if (node.inDeclarationContext()) {
       type = isTopLevel
           ? HighlightRegionType.TOP_LEVEL_FUNCTION_DECLARATION
@@ -334,7 +334,7 @@
       return false;
     }
     // getter or setter
-    var isTopLevel = element.enclosingElement is CompilationUnitElement;
+    var isTopLevel = element.enclosingElement2 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 e16e3078..3ca0f28 100644
--- a/pkg/analysis_server/lib/src/computer/computer_hover.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_hover.dart
@@ -71,7 +71,7 @@
         hover.elementKind = element.kind.displayName;
         hover.isDeprecated = element.hasDeprecated;
         // not local element
-        if (element.enclosingElement is! ExecutableElement) {
+        if (element.enclosingElement2 is! ExecutableElement) {
           // containing class
           var containingClass = element.thisOrAncestorOfType<ClassElement>();
           if (containingClass != null && containingClass != element) {
@@ -152,7 +152,7 @@
       element = element.field;
     }
     if (element is ParameterElement) {
-      element = element.enclosingElement;
+      element = element.enclosingElement2;
     }
     if (element == null) {
       // This can happen when the code is invalid, such as having a field formal
@@ -197,9 +197,9 @@
     var result =
         dartdocInfo.processDartdoc(rawDoc, includeSummary: includeSummary);
 
-    var documentedElementClass = documentedElement.enclosingElement;
+    var documentedElementClass = documentedElement.enclosingElement2;
     if (documentedElementClass != null &&
-        documentedElementClass != element.enclosingElement) {
+        documentedElementClass != element.enclosingElement2) {
       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 61e3abb..28b0ad5 100644
--- a/pkg/analysis_server/lib/src/computer/computer_outline.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_outline.dart
@@ -521,7 +521,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.enclosingElement2;
     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 eff224d..d55a4c6 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 ClassElement) {
+  if (element.enclosingElement2 is ClassElement) {
     return _OverriddenElementsFinder(element).find();
   }
   return OverriddenElements(element, <Element>[], <Element>[]);
@@ -109,7 +109,7 @@
   final Set<ClassElement> _visited = <ClassElement>{};
 
   factory _OverriddenElementsFinder(Element seed) {
-    var class_ = seed.enclosingElement as ClassElement;
+    var class_ = seed.enclosingElement2 as ClassElement;
     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 85352f0..bed6b92 100644
--- a/pkg/analysis_server/lib/src/computer/imported_elements_computer.dart
+++ b/pkg/analysis_server/lib/src/computer/imported_elements_computer.dart
@@ -82,7 +82,7 @@
         !_isConstructorDeclarationReturnType(node)) {
       var nodeElement = node.writeOrReadElement;
       if (nodeElement != null &&
-          nodeElement.enclosingElement is CompilationUnitElement) {
+          nodeElement.enclosingElement2 is CompilationUnitElement) {
         var nodeLibrary = nodeElement.library;
         var path = nodeLibrary?.definingCompilationUnit.source.fullName;
         if (path == null) {
diff --git a/pkg/analysis_server/lib/src/protocol_server.dart b/pkg/analysis_server/lib/src/protocol_server.dart
index 23790f4..1b25da7 100644
--- a/pkg/analysis_server/lib/src/protocol_server.dart
+++ b/pkg/analysis_server/lib/src/protocol_server.dart
@@ -215,7 +215,7 @@
 OverriddenMember newOverriddenMember_fromEngine(engine.Element member,
     {required bool withNullability}) {
   var element = convertElement(member, withNullability: withNullability);
-  var className = member.enclosingElement!.displayName;
+  var className = member.enclosingElement2!.displayName;
   return OverriddenMember(element, className);
 }
 
@@ -277,7 +277,7 @@
     return element;
   }
 
-  var enclosingElement = element.enclosingElement;
+  var enclosingElement = element.enclosingElement2;
   if (enclosingElement is engine.LibraryElement) {
     element = enclosingElement;
   }
diff --git a/pkg/analysis_server/lib/src/search/element_references.dart b/pkg/analysis_server/lib/src/search/element_references.dart
index afccf67..57d16bf 100644
--- a/pkg/analysis_server/lib/src/search/element_references.dart
+++ b/pkg/analysis_server/lib/src/search/element_references.dart
@@ -73,6 +73,6 @@
     if (element is ConstructorElement) {
       return false;
     }
-    return element.enclosingElement is ClassElement;
+    return element.enclosingElement2 is ClassElement;
   }
 }
diff --git a/pkg/analysis_server/lib/src/search/type_hierarchy.dart b/pkg/analysis_server/lib/src/search/type_hierarchy.dart
index 5dc00b9..7064baa 100644
--- a/pkg/analysis_server/lib/src/search/type_hierarchy.dart
+++ b/pkg/analysis_server/lib/src/search/type_hierarchy.dart
@@ -35,10 +35,10 @@
     Element? element = _pivotElement;
     if (_pivotElement is FieldElement) {
       _pivotFieldFinal = (_pivotElement as FieldElement).isFinal;
-      element = _pivotElement.enclosingElement;
+      element = _pivotElement.enclosingElement2;
     }
     if (_pivotElement is ExecutableElement) {
-      element = _pivotElement.enclosingElement;
+      element = _pivotElement.enclosingElement2;
     }
     if (element is ClassElement) {
       _pivotClass = element;
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/local_library_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/local_library_contributor.dart
index 8581f4f..536ba29 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/local_library_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/local_library_contributor.dart
@@ -90,7 +90,7 @@
     if (element.isOperator) {
       return;
     }
-    if (element.enclosingElement is! CompilationUnitElement) {
+    if (element.enclosingElement2 is! CompilationUnitElement) {
       return;
     }
     var returnType = element.returnType;
@@ -115,7 +115,7 @@
   @override
   void visitPropertyAccessorElement(PropertyAccessorElement element) {
     if (opType.includeReturnValueSuggestions) {
-      var parent = element.enclosingElement;
+      var parent = element.enclosingElement2;
       if (parent is ClassElement || parent is ExtensionElement) {
         builder.suggestAccessor(element, inheritanceDistance: 0.0);
       } else {
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/local_reference_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/local_reference_contributor.dart
index 3eb06e2..c6be580 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/local_reference_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/local_reference_contributor.dart
@@ -258,7 +258,7 @@
           .thisOrAncestorOfType<ClassDeclaration>();
       var enclosingElement = enclosingClass?.declaredElement;
       if (enclosingElement != null) {
-        var enclosingElement = field.enclosingElement;
+        var enclosingElement = field.enclosingElement2;
         if (enclosingElement is ClassElement) {
           inheritanceDistance = request.featureComputer
               .inheritanceDistanceFeature(enclosingElement, enclosingElement);
@@ -333,7 +333,7 @@
       var enclosingClass = request.target.containingNode
           .thisOrAncestorOfType<ClassDeclaration>();
       if (enclosingClass != null) {
-        var enclosingElement = element?.enclosingElement;
+        var enclosingElement = element?.enclosingElement2;
         if (enclosingElement is ClassElement) {
           inheritanceDistance = request.featureComputer
               .inheritanceDistanceFeature(
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 71845bb..e35e291 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
@@ -409,7 +409,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;
+    var enclosingClass = constructor.enclosingElement2;
     var className = enclosingClass.name;
     if (className.isEmpty) {
       return;
@@ -457,10 +457,10 @@
     } else if (element is ExtensionElement) {
       suggestExtension(element, kind: kind);
     } else if (element is FunctionElement &&
-        element.enclosingElement is CompilationUnitElement) {
+        element.enclosingElement2 is CompilationUnitElement) {
       suggestTopLevelFunction(element, kind: kind);
     } else if (element is PropertyAccessorElement &&
-        element.enclosingElement is CompilationUnitElement) {
+        element.enclosingElement2 is CompilationUnitElement) {
       suggestTopLevelPropertyAccessor(element);
     } else if (element is TypeAliasElement) {
       suggestTypeAlias(element);
@@ -473,7 +473,7 @@
   /// referenced using a prefix, then the [prefix] should be provided.
   void suggestEnumConstant(FieldElement constant, {String? prefix}) {
     var constantName = constant.name;
-    var enumElement = constant.enclosingElement;
+    var enumElement = constant.enclosingElement2;
     var enumName = enumElement.name;
     var completion = '$enumName.$constantName';
     var relevance =
@@ -705,7 +705,7 @@
       inheritanceDistance: inheritanceDistance,
     );
 
-    var enclosingElement = method.enclosingElement;
+    var enclosingElement = method.enclosingElement2;
     if (method.name == 'setState' &&
         enclosingElement is ClassElement &&
         flutter.isExactState(enclosingElement)) {
@@ -777,10 +777,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.enclosingElement2;
     // If appendColon is false, default values should never be appended.
     if (element is ConstructorElement && appendColon) {
-      if (Flutter.instance.isWidget(element.enclosingElement)) {
+      if (Flutter.instance.isWidget(element.enclosingElement2)) {
         // Don't bother with nullability. It won't affect default list values.
         var defaultValue =
             getDefaultStringParameterValue(parameter, withNullability: false);
@@ -1009,9 +1009,9 @@
   void suggestTopLevelPropertyAccessor(PropertyAccessorElement accessor,
       {String? prefix}) {
     assert(
-        accessor.enclosingElement is CompilationUnitElement,
+        accessor.enclosingElement2 is CompilationUnitElement,
         'Enclosing element of ${accessor.runtimeType} is '
-        '${accessor.enclosingElement.runtimeType}.');
+        '${accessor.enclosingElement2.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
@@ -1061,7 +1061,7 @@
   /// referenced using a prefix, then the [prefix] should be provided.
   void suggestTopLevelVariable(TopLevelVariableElement variable,
       {String? prefix}) {
-    assert(variable.enclosingElement is CompilationUnitElement);
+    assert(variable.enclosingElement2 is CompilationUnitElement);
     var relevance =
         _computeTopLevelRelevance(variable, elementType: variable.type);
     _addBuilder(
@@ -1294,7 +1294,7 @@
       withNullability: _isNonNullableByDefault,
     );
 
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement2;
 
     String? declaringType;
     if (enclosingElement is ClassElement) {
@@ -1353,7 +1353,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.enclosingElement2;
     if (enclosing is ClassElement) {
       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 35d0f87..48f22d7 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
@@ -61,7 +61,7 @@
             getter.isSynthetic &&
             !getter.variable.isSynthetic &&
             getter.variable.setter == null &&
-            getter.enclosingElement is ClassElement) {
+            getter.enclosingElement2 is ClassElement) {
           var declarationResult =
               await sessionHelper.getElementDeclaration(getter.variable);
           if (declarationResult == null) {
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 1582f94..65d4118 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
@@ -43,7 +43,7 @@
     }
 
     final target_final = target;
-    var declaringElement = invokedElement.enclosingElement;
+    var declaringElement = invokedElement.enclosingElement2;
 
     if (declaringElement is ClassElement) {
       _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 51b500c..e774946 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
@@ -80,7 +80,7 @@
     var constructorElement = node.constructorName.staticElement;
     return constructorElement != null &&
         !constructorElement.isFactory &&
-        constructorElement.enclosingElement == classElement;
+        constructorElement.enclosingElement2 == classElement;
   }
 }
 
@@ -571,7 +571,7 @@
                       initializer.constructorName.staticElement;
                   if (constructorElement != null &&
                       !constructorElement.isFactory &&
-                      constructorElement.enclosingElement == classElement) {
+                      constructorElement.enclosingElement2 == 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 d530aef..2ba17f8 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
@@ -97,7 +97,7 @@
 
   void _addElement(Element? element) {
     if (element is ExecutableElement) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement2;
       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 26e9f45..2bafd70 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
@@ -46,7 +46,7 @@
       if (element == null) {
         return;
       }
-      var enclosing = element.enclosingElement;
+      var enclosing = element.enclosingElement2;
       if (enclosing is ClassElement) {
         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 cc2ed4d..bc4aefd 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
@@ -43,7 +43,7 @@
       return;
     }
     // should have "isNotEmpty"
-    var propertyTarget = propertyElement.enclosingElement;
+    var propertyTarget = propertyElement.enclosingElement2;
     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 68c1434..85057d8 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
@@ -41,7 +41,7 @@
     var element = creation.constructorName.staticElement;
     if (element == null ||
         element.name != 'fromIterable' ||
-        element.enclosingElement != typeProvider.mapElement) {
+        element.enclosingElement2 != 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 769ed53..3062776 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
@@ -163,7 +163,7 @@
     }
 
     // prepare target ClassDeclaration
-    var targetElement = constructorElement.enclosingElement;
+    var targetElement = constructorElement.enclosingElement2;
     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 c646e6f..15517dc 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
@@ -309,7 +309,7 @@
     }
     var element = node.staticElement;
     if (element is ExecutableElement &&
-        element.enclosingElement == widgetClassElement &&
+        element.enclosingElement2 == 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 c061f38..dcbc524 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
@@ -315,7 +315,7 @@
     }
     var element = node.staticElement;
     if (element is ExecutableElement &&
-        element.enclosingElement == widgetClassElement &&
+        element.enclosingElement2 == widgetClassElement &&
         !elementsToMove.contains(element)) {
       var parent = node.parent;
       if (parent is PrefixedIdentifier) {
@@ -358,7 +358,7 @@
   void visitMethodInvocation(MethodInvocation node) {
     var methodElement = node.methodName.staticElement?.declaration;
     if (methodElement is ClassMemberElement) {
-      var classElement = methodElement.enclosingElement;
+      var classElement = methodElement.enclosingElement2;
       if (classElement is ClassElement &&
           Flutter.instance.isExactState(classElement) &&
           !FlutterConvertToStatelessWidget._isDefaultOverride(
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 e667453..71b2377 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
@@ -45,7 +45,7 @@
     }
 
     // It must be a field declaration.
-    if (getter.enclosingElement is! ClassElement) {
+    if (getter.enclosingElement2 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 07e51bb..8b178ef 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
@@ -40,7 +40,7 @@
       return;
     }
 
-    var enclosingElement = memberElement.enclosingElement;
+    var enclosingElement = memberElement.enclosingElement2;
     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 9d880a9..f18ab8c 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
@@ -28,7 +28,7 @@
       return;
     }
 
-    if (!accessor.isGetter || accessor.enclosingElement is! ClassElement) {
+    if (!accessor.isGetter || accessor.enclosingElement2 is! ClassElement) {
       // 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 e88e5cc..b606c9f 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
@@ -201,7 +201,7 @@
         );
       }
     } else if (parent is SuperConstructorInvocation) {
-      var superclassName = parent.staticElement?.enclosingElement.name;
+      var superclassName = parent.staticElement?.enclosingElement2.name;
       if (superclassName != null) {
         _addMatcher(
           components: [parent.constructorName?.name ?? '', superclassName],
@@ -502,7 +502,7 @@
       }
     }
     if (element != null) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement2;
       if (enclosingElement is ClassElement) {
         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 7522efe..2493049 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
@@ -122,7 +122,7 @@
   ExecutableElement? overriddenElement() {
     var element = declaredElement;
     if (element != null) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement2;
       if (enclosingElement is ClassElement) {
         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 051e3fd..5f85fc8 100644
--- a/pkg/analysis_server/lib/src/services/correction/namespace.dart
+++ b/pkg/analysis_server/lib/src/services/correction/namespace.dart
@@ -42,7 +42,7 @@
     String prefix,
     Element element,
     Map<LibraryImportElement, Set<Element>> importElementsMap) {
-  if (element.enclosingElement is! CompilationUnitElement) {
+  if (element.enclosingElement2 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 2edef19..bd14c30 100644
--- a/pkg/analysis_server/lib/src/services/correction/util.dart
+++ b/pkg/analysis_server/lib/src/services/correction/util.dart
@@ -220,7 +220,7 @@
 String getElementQualifiedName(Element element) {
   var kind = element.kind;
   if (kind == ElementKind.FIELD || kind == ElementKind.METHOD) {
-    return '${element.enclosingElement!.displayName}.${element.displayName}';
+    return '${element.enclosingElement2!.displayName}.${element.displayName}';
   } else if (kind == ElementKind.LIBRARY) {
     // Libraries may not have names, so use a path relative to the context root.
     final session = element.session!;
@@ -1380,7 +1380,7 @@
   /// Checks if [element] is visible in [targetExecutableElement] or
   /// [targetClassElement].
   bool _isTypeParameterVisible(TypeParameterElement element) {
-    var enclosing = element.enclosingElement;
+    var enclosing = element.enclosingElement2;
     return identical(enclosing, targetExecutableElement) ||
         identical(enclosing, targetClassElement);
   }
diff --git a/pkg/analysis_server/lib/src/services/flutter/property.dart b/pkg/analysis_server/lib/src/services/flutter/property.dart
index 416aaeb..4f3d763 100644
--- a/pkg/analysis_server/lib/src/services/flutter/property.dart
+++ b/pkg/analysis_server/lib/src/services/flutter/property.dart
@@ -463,7 +463,7 @@
       var constructor = propertyExpression.constructorName.staticElement;
       if (flutter != null &&
           constructor != null &&
-          constructor.enclosingElement == classEdgeInsets) {
+          constructor.enclosingElement2 == classEdgeInsets) {
         var arguments = propertyExpression.argumentList.arguments;
         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 77da5dda..0a1c223 100644
--- a/pkg/analysis_server/lib/src/services/flutter/widget_descriptions.dart
+++ b/pkg/analysis_server/lib/src/services/flutter/widget_descriptions.dart
@@ -278,7 +278,7 @@
     constructorElement ??= classDescription?.constructor;
     if (constructorElement == null) return;
 
-    var classElement = constructorElement.enclosingElement;
+    var classElement = constructorElement.enclosingElement2;
     if (!classesBeingProcessed.add(classElement)) return;
 
     var existingNamed = <String>{};
@@ -520,7 +520,7 @@
   }
 
   protocol.FlutterWidgetPropertyValueEnumItem _toEnumItem(FieldElement field) {
-    var classElement = field.enclosingElement as ClassElement;
+    var classElement = field.enclosingElement2 as ClassElement;
     var libraryUriStr = '${classElement.library.source.uri}';
     var documentation = getFieldDocumentation(field);
 
@@ -546,7 +546,7 @@
       if (element is PropertyAccessorElement && element.isGetter) {
         var field = element.variable;
         if (field is FieldElement && field.isStatic) {
-          var enclosingClass = field.enclosingElement as ClassElement;
+          var enclosingClass = field.enclosingElement2 as ClassElement;
           if (field.isEnumConstant ||
               _flutter.isExactAlignment(enclosingClass) ||
               _flutter.isExactAlignmentDirectional(enclosingClass)) {
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 e64fb09..f1483f5 100644
--- a/pkg/analysis_server/lib/src/services/kythe/kythe_visitors.dart
+++ b/pkg/analysis_server/lib/src/services/kythe/kythe_visitors.dart
@@ -28,7 +28,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.enclosingElement2.name;
   var constructorName = element.name;
   if (constructorName.isNotEmpty) {
     name = '$name.$constructorName';
@@ -723,13 +723,13 @@
       // We can't call _handleRefEdge as the anchor node has already been
       // written out.
       var enclosingEltVName = _vNameFromElement(
-          constructorElement.enclosingElement, schema.RECORD_KIND);
+          constructorElement.enclosingElement2, schema.RECORD_KIND);
       var anchorVName =
           _vNameAnchor(constructorName.offset, constructorName.end);
       addEdge(anchorVName, schema.REF_EDGE, enclosingEltVName);
 
       // TODO(jwren): investigate
-      //   assert (element.enclosingElement != null);
+      //   assert (element.enclosingElement2 != null);
     }
     // visit children
     _safelyVisitList(constructorName.type.typeArguments?.arguments);
@@ -1422,7 +1422,7 @@
   @override
   StringBuffer visitElement(Element element) {
     assert(element is! MultiplyInheritedExecutableElement);
-    var enclosingElt = element.enclosingElement!;
+    var enclosingElt = element.enclosingElement2!;
     var buffer = enclosingElt.accept(this)!;
     if (buffer.isNotEmpty) {
       buffer.write('#');
@@ -1454,7 +1454,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.enclosingElement2!.accept(this)!
       ..write('.')
       ..write(element.name);
   }
diff --git a/pkg/analysis_server/lib/src/services/refactoring/convert_getter_to_method.dart b/pkg/analysis_server/lib/src/services/refactoring/convert_getter_to_method.dart
index e226e3e..dcbe33c8 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/convert_getter_to_method.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/convert_getter_to_method.dart
@@ -46,15 +46,15 @@
   Future<SourceChange> createChange() async {
     change = SourceChange(refactoringName);
     // function
-    if (element.enclosingElement is CompilationUnitElement) {
+    if (element.enclosingElement2 is CompilationUnitElement) {
       await _updateElementDeclaration(element);
       await _updateElementReferences(element);
     }
     // method
     var field = element.variable;
     if (field is FieldElement &&
-        (field.enclosingElement is ClassElement ||
-            field.enclosingElement is ExtensionElement)) {
+        (field.enclosingElement2 is ClassElement ||
+            field.enclosingElement2 is ExtensionElement)) {
       var elements = await getHierarchyMembers(searchEngine, field);
       await Future.forEach(elements, (ClassMemberElement member) async {
         if (member is FieldElement) {
diff --git a/pkg/analysis_server/lib/src/services/refactoring/convert_method_to_getter.dart b/pkg/analysis_server/lib/src/services/refactoring/convert_method_to_getter.dart
index dd6724c..4a1812c 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/convert_method_to_getter.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/convert_method_to_getter.dart
@@ -72,7 +72,7 @@
   RefactoringStatus _checkElement() {
     // check Element type
     if (element is FunctionElement) {
-      if (element.enclosingElement is! CompilationUnitElement) {
+      if (element.enclosingElement2 is! CompilationUnitElement) {
         return RefactoringStatus.fatal(
             'Only top-level functions can be converted to getters.');
       }
diff --git a/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart b/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
index 5a7c1e9..4dfd72a 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
@@ -38,7 +38,7 @@
   if (element is LocalVariableElement ||
       element is ParameterElement ||
       element is FunctionElement &&
-          element.enclosingElement is! CompilationUnitElement) {
+          element.enclosingElement2 is! CompilationUnitElement) {
     return element;
   }
   return null;
diff --git a/pkg/analysis_server/lib/src/services/refactoring/extract_widget.dart b/pkg/analysis_server/lib/src/services/refactoring/extract_widget.dart
index d807a1d..c85b15d 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/extract_widget.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/extract_widget.dart
@@ -654,7 +654,7 @@
         enclosingClass,
         ...enclosingClass.allSupertypes.map((t) => t.element)
       ];
-      return enclosingClasses.contains(element.enclosingElement);
+      return enclosingClasses.contains(element.enclosingElement2);
     }
     return false;
   }
diff --git a/pkg/analysis_server/lib/src/services/refactoring/inline_method.dart b/pkg/analysis_server/lib/src/services/refactoring/inline_method.dart
index 00cd08f..235172d 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/inline_method.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/inline_method.dart
@@ -212,7 +212,7 @@
 
   @override
   String? get className {
-    var classElement = _methodElement?.enclosingElement;
+    var classElement = _methodElement?.enclosingElement2;
     if (classElement is ClassElement) {
       return classElement.displayName;
     }
@@ -805,13 +805,13 @@
     } else {
       return;
     }
-    if (element.enclosingElement is! ClassElement) {
+    if (element.enclosingElement2 is! ClassElement) {
       return;
     }
     // record the implicit static or instance reference
     var offset = node.offset;
     if (element.isStatic) {
-      var className = element.enclosingElement.displayName;
+      var className = element.enclosingElement2.displayName;
       result.addImplicitClassNameOffset(className, offset);
     } else {
       result.addImplicitThisOffset(offset);
diff --git a/pkg/analysis_server/lib/src/services/refactoring/refactoring.dart b/pkg/analysis_server/lib/src/services/refactoring/refactoring.dart
index c542a1c..b85a9ff 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/refactoring.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/refactoring.dart
@@ -406,7 +406,7 @@
     if (element is PropertyAccessorElement) {
       element = element.variable;
     }
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement2;
     if (enclosingElement is CompilationUnitElement) {
       return RenameUnitMemberRefactoringImpl(workspace, resolvedUnit, element);
     }
diff --git a/pkg/analysis_server/lib/src/services/refactoring/rename_class_member.dart b/pkg/analysis_server/lib/src/services/refactoring/rename_class_member.dart
index ce85fb8..d7bd902 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/rename_class_member.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/rename_class_member.dart
@@ -168,7 +168,7 @@
     var declarations = await searchEngine.searchMemberDeclarations(name);
     for (var declaration in declarations) {
       var nameElement = getSyntheticAccessorVariable(declaration.element);
-      var nameClass = nameElement.enclosingElement;
+      var nameClass = nameElement.enclosingElement2;
       // the renamed Element shadows a member of a superclass
       if (superClasses.contains(nameClass)) {
         result.addError(
@@ -276,7 +276,7 @@
     var subClasses = await searchEngine.searchAllSubtypes(elementClass);
     // check shadowing of class names
     for (var element in elements) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement2;
       if (enclosingElement is ClassElement && enclosingElement.name == name) {
         result.addError(
           'Renamed ${elementKind.displayName} has the same name as the '
diff --git a/pkg/analysis_server/lib/src/services/refactoring/rename_constructor.dart b/pkg/analysis_server/lib/src/services/refactoring/rename_constructor.dart
index 5e7e7bc..01ce273 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/rename_constructor.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/rename_constructor.dart
@@ -82,7 +82,7 @@
   }
 
   void _analyzePossibleConflicts(RefactoringStatus result) {
-    var parentClass = element.enclosingElement;
+    var parentClass = element.enclosingElement2;
     // 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 '
@@ -107,7 +107,7 @@
   }
 
   Future<void> _replaceSynthetic() async {
-    var classElement = element.enclosingElement;
+    var classElement = element.enclosingElement2;
 
     var result = await AnalysisSessionHelper(session)
         .getElementDeclaration(classElement);
diff --git a/pkg/analysis_server/lib/src/services/refactoring/rename_unit_member.dart b/pkg/analysis_server/lib/src/services/refactoring/rename_unit_member.dart
index 0614497..eb53d12 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/rename_unit_member.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/rename_unit_member.dart
@@ -214,7 +214,7 @@
     var declarations = await searchEngine.searchMemberDeclarations(name);
     for (var declaration in declarations) {
       var member = declaration.element;
-      var declaringClass = member.enclosingElement as ClassElement;
+      var declaringClass = member.enclosingElement2 as ClassElement;
       var memberReferences = await searchEngine.searchReferences(member);
       for (var memberReference in memberReferences) {
         var refElement = memberReference.element;
diff --git a/pkg/analysis_server/lib/src/services/search/hierarchy.dart b/pkg/analysis_server/lib/src/services/search/hierarchy.dart
index eda9ad4..0776411 100644
--- a/pkg/analysis_server/lib/src/services/search/hierarchy.dart
+++ b/pkg/analysis_server/lib/src/services/search/hierarchy.dart
@@ -82,7 +82,7 @@
     SearchEngine searchEngine, ClassMemberElement member) async {
   Set<ClassMemberElement> result = HashSet<ClassMemberElement>();
   // extension member
-  var enclosingElement = member.enclosingElement;
+  var enclosingElement = member.enclosingElement2;
   if (enclosingElement is ExtensionElement) {
     result.add(member);
     return Future.value(result);
@@ -126,7 +126,7 @@
 Future<List<ParameterElement>> getHierarchyNamedParameters(
     SearchEngine searchEngine, ParameterElement element) async {
   if (element.isNamed) {
-    var method = element.enclosingElement;
+    var method = element.enclosingElement2;
     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 bfe5606..28512dd 100644
--- a/pkg/analysis_server/lib/src/utilities/extensions/element.dart
+++ b/pkg/analysis_server/lib/src/utilities/extensions/element.dart
@@ -30,12 +30,12 @@
     if (hasDeprecated) {
       return true;
     }
-    var ancestor = enclosingElement;
+    var ancestor = enclosingElement2;
     if (ancestor is ClassElement) {
       if (ancestor.hasDeprecated) {
         return true;
       }
-      ancestor = ancestor.enclosingElement;
+      ancestor = ancestor.enclosingElement2;
     }
     return ancestor is CompilationUnitElement &&
         ancestor.enclosingElement2.hasDeprecated;
@@ -46,7 +46,7 @@
     var current = this;
     while (true) {
       yield current;
-      var enclosing = current.enclosingElement;
+      var enclosing = current.enclosingElement2;
       if (enclosing == null) {
         break;
       }
@@ -69,7 +69,7 @@
     if (name != 'cast') {
       return false;
     }
-    var definingClass = enclosingElement;
+    var definingClass = enclosingElement2;
     if (definingClass is! ClassElement) {
       return false;
     }
@@ -85,7 +85,7 @@
     if (name != 'toList') {
       return false;
     }
-    var definingClass = enclosingElement;
+    var definingClass = enclosingElement2;
     if (definingClass is! ClassElement) {
       return false;
     }
diff --git a/pkg/analysis_server/lib/src/utilities/flutter.dart b/pkg/analysis_server/lib/src/utilities/flutter.dart
index f423152..c425391 100644
--- a/pkg/analysis_server/lib/src/utilities/flutter.dart
+++ b/pkg/analysis_server/lib/src/utilities/flutter.dart
@@ -192,7 +192,7 @@
 
   /// Return the presentation for the given Flutter `Widget` creation [node].
   String? getWidgetPresentationText(InstanceCreationExpression node) {
-    var element = node.constructorName.staticElement?.enclosingElement;
+    var element = node.constructorName.staticElement?.enclosingElement2;
     if (!isWidget(element)) {
       return null;
     }
@@ -504,7 +504,7 @@
   /// Return `true` if the given [expr] is a constructor invocation for a
   /// class that has the Flutter class `Widget` as a superclass.
   bool isWidgetCreation(InstanceCreationExpression? expr) {
-    var element = expr?.constructorName.staticElement?.enclosingElement;
+    var element = expr?.constructorName.staticElement?.enclosingElement2;
     return isWidget(element);
   }
 
diff --git a/pkg/analysis_server/test/plugin/protocol_dart_test.dart b/pkg/analysis_server/test/plugin/protocol_dart_test.dart
index cccd6c9..a0e22e1 100644
--- a/pkg/analysis_server/test/plugin/protocol_dart_test.dart
+++ b/pkg/analysis_server/test/plugin/protocol_dart_test.dart
@@ -255,7 +255,7 @@
       expect(element.parameters, isNull);
       expect(element.returnType, '_E1');
       // TODO(danrubel) determine why enum constant is not marked as deprecated
-      //engine.ClassElement classElement = engineElement.enclosingElement;
+      //engine.ClassElement classElement = engineElement.enclosingElement2;
       //expect(classElement.isDeprecated, isTrue);
       expect(
           element.flags,
diff --git a/pkg/analysis_server/tool/code_completion/completion_metrics.dart b/pkg/analysis_server/tool/code_completion/completion_metrics.dart
index 3cd822f..2bc9c51 100644
--- a/pkg/analysis_server/tool/code_completion/completion_metrics.dart
+++ b/pkg/analysis_server/tool/code_completion/completion_metrics.dart
@@ -1699,7 +1699,7 @@
     var entity = expectedCompletion.syntacticEntity;
     var element = _getElement(entity);
     if (element != null) {
-      var parent = element.enclosingElement;
+      var parent = element.enclosingElement2;
       if (parent is ClassElement || 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 edab701..6bba840 100644
--- a/pkg/analysis_server/tool/code_completion/flutter_metrics.dart
+++ b/pkg/analysis_server/tool/code_completion/flutter_metrics.dart
@@ -144,7 +144,7 @@
         throw StateError(
             'Unresolved constructor name: ${node.constructorName}');
       }
-      var childWidget = element.enclosingElement.name;
+      var childWidget = element.enclosingElement2.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 c13b51a..8683e81 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 ClassElement) {
+    if (!element.isStatic && element.enclosingElement2 is ClassElement) {
       var overriddenMembers = inheritanceManager.getOverridden2(
-          element.enclosingElement as ClassElement,
+          element.enclosingElement2 as ClassElement,
           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?.enclosingElement2;
     }
     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.enclosingElement2!;
       var depth = _parameterReferenceDepth(node, definingElement);
       _recordDistance('function depth of referenced parameter', depth);
     } else if (element is LocalVariableElement) {
diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md
index c84f8ed..1b1265e 100644
--- a/pkg/analyzer/CHANGELOG.md
+++ b/pkg/analyzer/CHANGELOG.md
@@ -1,6 +1,9 @@
 ## 4.3.0-dev
 * Deprecated `Directive.keyword`, use corresponding `xyzToken` in specific directives.
 * Deprecated `LibraryElement.parts`, use `parts2` instead.
+* Deprecated `LibraryElement.exports`, use `libraryexports` instead.
+* Deprecated `LibraryElement.imports`, use `libraryImports` instead.
+* Deprecated `Element.enclosingElement`, use `enclosingElement2` instead.
 
 ## 4.2.0
 * Update SDK constraints to `>=2.17.0 <3.0.0`.
diff --git a/pkg/analyzer/lib/dart/element/element.dart b/pkg/analyzer/lib/dart/element/element.dart
index f71d02c..b14447a 100644
--- a/pkg/analyzer/lib/dart/element/element.dart
+++ b/pkg/analyzer/lib/dart/element/element.dart
@@ -57,9 +57,13 @@
 /// Clients may not extend, implement or mix-in this class.
 @experimental
 abstract class AugmentationImportElement implements _ExistingElement {
+  @Deprecated('Use enclosingElement2 instead')
   @override
   LibraryOrAugmentationElement get enclosingElement;
 
+  @override
+  LibraryOrAugmentationElement get enclosingElement2;
+
   /// Returns the [LibraryAugmentationElement], if [uri] is a
   /// [DirectiveUriWithAugmentation].
   LibraryAugmentationElement? get importedAugmentation;
@@ -95,9 +99,13 @@
   @override
   String get displayName;
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
   CompilationUnitElement get enclosingElement;
 
+  @override
+  CompilationUnitElement get enclosingElement2;
+
   /// Return a list containing all of the fields declared in this class.
   List<FieldElement> get fields;
 
@@ -392,9 +400,13 @@
   // TODO(brianwilkerson) Either remove this class or rename it to something
   //  more correct.
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
   Element get enclosingElement;
 
+  @override
+  Element get enclosingElement2;
+
   /// Return `true` if this element is a static element. A static element is an
   /// element that is not associated with a particular instance, but rather with
   /// an entire library or class.
@@ -413,11 +425,12 @@
   /// unit.
   List<ClassElement> get classes;
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
   LibraryElement get enclosingElement;
 
   /// Return the library, or library augmentation that encloses this unit.
-  @experimental
+  @override
   LibraryOrAugmentationElement get enclosingElement2;
 
   /// Return a list containing all of the enums contained in this compilation
@@ -473,9 +486,13 @@
   @override
   String get displayName;
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
   ClassElement get enclosingElement;
 
+  @override
+  ClassElement get enclosingElement2;
+
   /// Return `true` if this constructor is a const constructor.
   bool get isConst;
 
@@ -619,8 +636,14 @@
   /// Return the element that either physically or logically encloses this
   /// element. This will be `null` if this element is a library because
   /// libraries are the top-level elements in the model.
+  @Deprecated('Use enclosingElement2 instead')
   Element? get enclosingElement;
 
+  /// Return the element that either physically or logically encloses this
+  /// element. This will be `null` if this element is a library because
+  /// libraries are the top-level elements in the model.
+  Element? get enclosingElement2;
+
   /// Return `true` if this element has an annotation of the form
   /// `@alwaysThrows`.
   bool get hasAlwaysThrows;
@@ -1172,9 +1195,13 @@
   @override
   String get displayName;
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
   Element get enclosingElement;
 
+  @override
+  Element get enclosingElement2;
+
   /// Return `true` if this executable element did not have an explicit return
   /// type specified for it in the original source.
   bool get hasImplicitReturnType;
@@ -1236,9 +1263,13 @@
   /// declared in this extension.
   List<PropertyAccessorElement> get accessors;
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
   CompilationUnitElement get enclosingElement;
 
+  @override
+  CompilationUnitElement get enclosingElement2;
+
   /// Return the type that is extended by this extension.
   DartType get extendedType;
 
@@ -1408,10 +1439,14 @@
 ///
 /// Clients may not extend, implement or mix-in this class.
 abstract class LabelElement implements Element {
+  @Deprecated('Use enclosingElement2 instead')
   @override
   ExecutableElement get enclosingElement;
 
   @override
+  ExecutableElement get enclosingElement2;
+
+  @override
   String get name;
 }
 
@@ -1814,11 +1849,12 @@
 ///
 /// Clients may not extend, implement or mix-in this class.
 abstract class PrefixElement implements _ExistingElement {
+  @Deprecated('Use enclosingElement2 instead')
   @override
   LibraryElement get enclosingElement;
 
   /// Return the library, or library augmentation that encloses this element.
-  @experimental
+  @override
   LibraryOrAugmentationElement get enclosingElement2;
 
   /// Return the imports that share this prefix.
@@ -1874,9 +1910,13 @@
   @override
   PropertyAccessorElement get declaration;
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
   Element get enclosingElement;
 
+  @override
+  Element get enclosingElement2;
+
   /// Return `true` if this accessor represents a getter.
   bool get isGetter;
 
@@ -1993,10 +2033,14 @@
   /// a [FunctionType].
   DartType get aliasedType;
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
   CompilationUnitElement get enclosingElement;
 
   @override
+  CompilationUnitElement get enclosingElement2;
+
+  @override
   String get name;
 
   /// Produces the type resulting from instantiating this typedef with the given
diff --git a/pkg/analyzer/lib/src/dart/analysis/index.dart b/pkg/analyzer/lib/src/dart/analysis/index.dart
index 5660f03..7ea2d0c 100644
--- a/pkg/analyzer/lib/src/dart/analysis/index.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/index.dart
@@ -18,7 +18,7 @@
   SimpleIdentifier node,
   Element? element,
 ) {
-  if (element == null || element.enclosingElement != null) {
+  if (element == null || element.enclosingElement2 != null) {
     return element;
   }
 
@@ -63,7 +63,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.enclosingElement2) {
     if (e is CompilationUnitElement) {
       return e;
     }
@@ -88,21 +88,21 @@
     String? parameterName;
     if (element is ParameterElement) {
       parameterName = element.name;
-      element = element.enclosingElement!;
+      element = element.enclosingElement2!;
     }
 
     String? classMemberName;
-    if (element.enclosingElement is ClassElement ||
-        element.enclosingElement is ExtensionElement) {
+    if (element.enclosingElement2 is ClassElement ||
+        element.enclosingElement2 is ExtensionElement) {
       classMemberName = element.name;
-      element = element.enclosingElement!;
+      element = element.enclosingElement2!;
     }
 
     String? unitMemberName;
-    if (element.enclosingElement is CompilationUnitElement) {
+    if (element.enclosingElement2 is CompilationUnitElement) {
       unitMemberName = element.name;
       if (element is ExtensionElement && unitMemberName == null) {
-        var enclosingUnit = element.enclosingElement;
+        var enclosingUnit = element.enclosingElement2;
         var indexOf = enclosingUnit.extensions.indexOf(element);
         unitMemberName = 'extension-$indexOf';
       }
@@ -139,7 +139,7 @@
     } else if (element.isSynthetic) {
       if (elementKind == ElementKind.CONSTRUCTOR) {
         kind = IndexSyntheticElementKind.constructor;
-        element = element.enclosingElement!;
+        element = element.enclosingElement2!;
       } else if (element is FunctionElement &&
           element.name == FunctionElement.LOAD_LIBRARY_NAME) {
         kind = IndexSyntheticElementKind.loadLibrary;
@@ -151,7 +151,7 @@
       } else if (elementKind == ElementKind.GETTER ||
           elementKind == ElementKind.SETTER) {
         var accessor = element as PropertyAccessorElement;
-        Element enclosing = element.enclosingElement;
+        Element enclosing = element.enclosingElement2;
         bool isEnumGetter = enclosing is ClassElement && enclosing.isEnum;
         if (isEnumGetter && accessor.name == 'index') {
           kind = IndexSyntheticElementKind.enumIndex;
@@ -166,7 +166,7 @@
           element = accessor.variable;
         }
       } else if (element is MethodElement) {
-        Element enclosing = element.enclosingElement;
+        Element enclosing = element.enclosingElement2;
         bool isEnumMethod = enclosing is ClassElement && enclosing.isEnum;
         if (isEnumMethod && element.name == 'toString') {
           kind = IndexSyntheticElementKind.enumToString;
@@ -491,14 +491,14 @@
         elementKind == ElementKind.TYPE_PARAMETER ||
         elementKind == ElementKind.FUNCTION &&
             element is FunctionElement &&
-            element.enclosingElement is ExecutableElement ||
+            element.enclosingElement2 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.enclosingElement2;
       if (enclosingElement == null || enclosingElement.isSynthetic) {
         return;
       }
@@ -508,7 +508,7 @@
     // named parameters. Ignore them.
     if (elementKind == ElementKind.PARAMETER &&
         element is ParameterElement &&
-        element.enclosingElement is GenericFunctionTypeElement) {
+        element.enclosingElement2 is GenericFunctionTypeElement) {
       return;
     }
     // Add the relation.
@@ -999,7 +999,7 @@
       ConstructorElement? constructor) {
     var seenConstructors = <ConstructorElement?>{};
     while (constructor is ConstructorElementImpl && constructor.isSynthetic) {
-      var enclosing = constructor.enclosingElement;
+      var enclosing = constructor.enclosingElement2;
       if (enclosing.isMixinApplication) {
         var superInvocation = constructor.constantInitializers
             .whereType<SuperConstructorInvocation>()
diff --git a/pkg/analyzer/lib/src/dart/analysis/results.dart b/pkg/analyzer/lib/src/dart/analysis/results.dart
index 223e40d..124c052 100644
--- a/pkg/analyzer/lib/src/dart/analysis/results.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/results.dart
@@ -178,7 +178,7 @@
     required this.resolvedNodes,
   });
 
-  LibraryElement get libraryElement => unitElement.enclosingElement;
+  LibraryElement get libraryElement => unitElement.library;
 }
 
 class ResolvedLibraryResultImpl extends AnalysisResultImpl
diff --git a/pkg/analyzer/lib/src/dart/analysis/search.dart b/pkg/analyzer/lib/src/dart/analysis/search.dart
index d78196b..3eb1e38 100644
--- a/pkg/analyzer/lib/src/dart/analysis/search.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/search.dart
@@ -257,7 +257,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.enclosingElement2 is ExecutableElement) {
         return _searchReferences_Local(
             element, (n) => n is Block, searchedFiles);
       }
@@ -405,7 +405,7 @@
     // Prepare the element name.
     String name = element.displayName;
     if (element is ConstructorElement) {
-      name = element.enclosingElement.displayName;
+      name = element.enclosingElement2.displayName;
     }
 
     // Prepare the list of files that reference the element name.
@@ -654,7 +654,7 @@
     ));
     if (parameter.isNamed ||
         parameter.isOptionalPositional ||
-        parameter.enclosingElement is ConstructorElement) {
+        parameter.enclosingElement2 is ConstructorElement) {
       results.addAll(await _searchReferences(parameter, searchedFiles));
     }
     return results;
@@ -914,7 +914,7 @@
       return;
     }
 
-    var enclosing = element.enclosingElement;
+    var enclosing = element.enclosingElement2;
 
     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 d51f9d9..2095651 100644
--- a/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
+++ b/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
@@ -373,7 +373,7 @@
       // lookup for ==
       var method = element.lookUpConcreteMethod("==", _currentLibrary);
       if (method == null ||
-          (method.enclosingElement as ClassElement).isDartCoreObject) {
+          (method.enclosingElement2 as ClassElement).isDartCoreObject) {
         return false;
       }
       // there is == that we don't like
diff --git a/pkg/analyzer/lib/src/dart/constant/evaluation.dart b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
index 5b205c4..3449496 100644
--- a/pkg/analyzer/lib/src/dart/constant/evaluation.dart
+++ b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
@@ -198,7 +198,7 @@
   void computeDependencies(
       ConstantEvaluationTarget constant, ReferenceFinderCallback callback) {
     if (constant is ConstFieldElementImpl && constant.isEnumConstant) {
-      var enclosing = constant.enclosingElement;
+      var enclosing = constant.enclosingElement2;
       if (enclosing is EnumElementImpl) {
         if (enclosing.name == 'values') {
           return;
@@ -258,7 +258,7 @@
             }
           }
         }
-        for (FieldElement field in constant.enclosingElement.fields) {
+        for (FieldElement field in constant.enclosingElement2.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) &&
@@ -372,7 +372,7 @@
       return null;
     }
     var typeProvider = constructor.library.typeProvider;
-    if (constructor.enclosingElement == typeProvider.symbolElement) {
+    if (constructor.enclosingElement2 == 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.
@@ -396,7 +396,7 @@
 
   static _EnumConstant? _enumConstant(VariableElementImpl element) {
     if (element is ConstFieldElementImpl && element.isEnumConstant) {
-      var enum_ = element.enclosingElement;
+      var enum_ = element.enclosingElement2;
       if (enum_ is EnumElementImpl) {
         var index = enum_.constants.indexOf(element);
         assert(index >= 0);
@@ -873,7 +873,7 @@
       if (element.name == "identical") {
         NodeList<Expression> arguments = node.argumentList.arguments;
         if (arguments.length == 2) {
-          var enclosingElement = element.enclosingElement;
+          var enclosingElement = element.enclosingElement2;
           if (enclosingElement is CompilationUnitElement) {
             LibraryElement library = enclosingElement.library;
             if (library.isDartCore) {
@@ -1427,7 +1427,7 @@
       return false;
     }
     return identifier.name == 'length' &&
-        identifier.staticElement?.enclosingElement is! ExtensionElement;
+        identifier.staticElement?.enclosingElement2 is! ExtensionElement;
   }
 
   void _reportNotPotentialConstants(AstNode node) {
@@ -2129,7 +2129,7 @@
     List<Expression> arguments, {
     required bool isNullSafe,
   }) {
-    ClassElement definingClass = _constructor.enclosingElement;
+    ClassElement definingClass = _constructor.enclosingElement2;
     var argumentCount = arguments.length;
     if (_constructor.name == "fromEnvironment") {
       if (!_checkFromEnvironmentArguments(arguments, definingType)) {
@@ -2232,7 +2232,7 @@
   }
 
   void _checkFields() {
-    var fields = _constructor.enclosingElement.fields;
+    var fields = _constructor.enclosingElement2.fields;
     for (var field in fields) {
       if ((field.isFinal || field.isConst) &&
           !field.isStatic &&
@@ -2521,7 +2521,7 @@
   }
 
   void _checkTypeParameters() {
-    var typeParameters = _constructor.enclosingElement.typeParameters;
+    var typeParameters = _constructor.enclosingElement2.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 6c13da9..284072f 100644
--- a/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart
+++ b/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart
@@ -227,7 +227,7 @@
     }
 
     if (element is ParameterElement) {
-      var enclosing = element.enclosingElement;
+      var enclosing = element.enclosingElement2;
       if (enclosing is ConstructorElement &&
           isConstConstructorElement(enclosing)) {
         if (node.thisOrAncestorOfType<ConstructorInitializer>() != null) {
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 63cdbaa..471c997 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -103,11 +103,17 @@
   @override
   String get displayName => name;
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
   CompilationUnitElementImpl get enclosingElement {
     return _enclosingElement as CompilationUnitElementImpl;
   }
 
+  @override
+  CompilationUnitElementImpl get enclosingElement2 {
+    return _enclosingElement as CompilationUnitElementImpl;
+  }
+
   /// Set the fields contained in this class to the given [fields].
   set fields(List<FieldElement> fields) {
     assert(!isMixinApplication);
@@ -314,7 +320,7 @@
               !getter.isAbstract &&
               !getter.isStatic &&
               getter.isAccessibleIn2(library) &&
-              getter.enclosingElement != this));
+              getter.enclosingElement2 != this));
 
   ExecutableElement? lookUpInheritedConcreteMember(
       String name, LibraryElement library) {
@@ -334,7 +340,7 @@
               !method.isAbstract &&
               !method.isStatic &&
               method.isAccessibleIn2(library) &&
-              method.enclosingElement != this));
+              method.enclosingElement2 != this));
 
   @override
   PropertyAccessorElement? lookUpInheritedConcreteSetter(
@@ -344,7 +350,7 @@
               !setter.isAbstract &&
               !setter.isStatic &&
               setter.isAccessibleIn2(library) &&
-              setter.enclosingElement != this));
+              setter.enclosingElement2 != this));
 
   @override
   MethodElement? lookUpInheritedMethod(
@@ -353,7 +359,7 @@
           (MethodElement method) =>
               !method.isStatic &&
               method.isAccessibleIn2(library) &&
-              method.enclosingElement != this));
+              method.enclosingElement2 != this));
 
   @override
   MethodElement? lookUpMethod(String methodName, LibraryElement library) =>
@@ -539,9 +545,15 @@
     required this.uri,
   }) : super(null, importKeywordOffset);
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
   LibraryOrAugmentationElementImpl get enclosingElement {
-    return super.enclosingElement as LibraryOrAugmentationElementImpl;
+    return super.enclosingElement2 as LibraryOrAugmentationElementImpl;
+  }
+
+  @override
+  LibraryOrAugmentationElementImpl get enclosingElement2 {
+    return super.enclosingElement2 as LibraryOrAugmentationElementImpl;
   }
 
   @override
@@ -690,7 +702,7 @@
   bool get hasNoSuchMethod {
     MethodElement? method = lookUpConcreteMethod(
         FunctionElement.NO_SUCH_METHOD_METHOD_NAME, library);
-    var definingClass = method?.enclosingElement as ClassElement?;
+    var definingClass = method?.enclosingElement2 as ClassElement?;
     return definingClass != null && !definingClass.isDartCoreObject;
   }
 
@@ -1115,13 +1127,14 @@
     _classes = classes;
   }
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
   LibraryElement get enclosingElement =>
-      super.enclosingElement as LibraryElement;
+      super.enclosingElement2 as LibraryElement;
 
   @override
   LibraryOrAugmentationElement get enclosingElement2 =>
-      super.enclosingElement as LibraryOrAugmentationElement;
+      super.enclosingElement2 as LibraryOrAugmentationElement;
 
   @override
   CompilationUnitElementImpl get enclosingUnit {
@@ -1198,7 +1211,7 @@
   }
 
   @override
-  AnalysisSession get session => enclosingElement.session;
+  AnalysisSession get session => enclosingElement2.session;
 
   @override
   List<TopLevelVariableElement> get topLevelVariables {
@@ -1366,7 +1379,7 @@
 
   @override
   String get displayName {
-    var className = enclosingElement.name;
+    var className = enclosingElement2.name;
     var name = this.name;
     if (name.isNotEmpty) {
       return '$className.$name';
@@ -1375,9 +1388,14 @@
     }
   }
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
   AbstractClassElementImpl get enclosingElement =>
-      super.enclosingElement as AbstractClassElementImpl;
+      super.enclosingElement2 as AbstractClassElementImpl;
+
+  @override
+  AbstractClassElementImpl get enclosingElement2 =>
+      super.enclosingElement2 as AbstractClassElementImpl;
 
   @override
   bool get isConst {
@@ -1414,7 +1432,7 @@
 
   @override
   Element get nonSynthetic {
-    return isSynthetic ? enclosingElement : this;
+    return isSynthetic ? enclosingElement2 : this;
   }
 
   @override
@@ -1439,7 +1457,7 @@
 
   @override
   InterfaceType get returnTypeInternal {
-    return (_returnType ??= enclosingElement.thisType) as InterfaceType;
+    return (_returnType ??= enclosingElement2.thisType) as InterfaceType;
   }
 
   ConstructorElement? get superConstructor {
@@ -1568,7 +1586,7 @@
       if (library == null) {
         throw StateError(
           '[library: null][this: ($runtimeType) $this]'
-          '[enclosingElement: $enclosingElement]'
+          '[enclosingElement2: $enclosingElement2]'
           '[reference: $reference]',
         );
       }
@@ -1936,7 +1954,7 @@
     final element = this.element;
     if (element is ConstructorElement) {
       return element.library.isDartCore &&
-          element.enclosingElement.name == _DEPRECATED_CLASS_NAME;
+          element.enclosingElement2.name == _DEPRECATED_CLASS_NAME;
     } else if (element is PropertyAccessorElement) {
       return element.library.isDartCore &&
           element.name == _DEPRECATED_VARIABLE_NAME;
@@ -2063,7 +2081,7 @@
   }) {
     final element = this.element;
     return element is ConstructorElement &&
-        element.enclosingElement.name == className &&
+        element.enclosingElement2.name == className &&
         element.library.name == libraryName;
   }
 
@@ -2177,6 +2195,7 @@
     _docComment = doc;
   }
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
   Element? get enclosingElement => _enclosingElement;
 
@@ -2185,6 +2204,9 @@
     _enclosingElement = element as ElementImpl?;
   }
 
+  @override
+  Element? get enclosingElement2 => _enclosingElement;
+
   /// Return the enclosing unit element (which might be the same as `this`), or
   /// `null` if this element is not contained in any compilation unit.
   CompilationUnitElementImpl get enclosingUnit {
@@ -2521,12 +2543,12 @@
 
   @override
   AnalysisSession? get session {
-    return enclosingElement?.session;
+    return enclosingElement2?.session;
   }
 
   @override
   Source? get source {
-    return enclosingElement?.source;
+    return enclosingElement2?.source;
   }
 
   /// Return the context to resolve type parameters in, or `null` if neither
@@ -2634,7 +2656,7 @@
   ) {
     Element? element = this;
     while (element != null && !predicate(element)) {
-      element = element.enclosingElement;
+      element = element.enclosingElement2;
     }
     return element as E?;
   }
@@ -2646,7 +2668,7 @@
       if (element is CompilationUnitElement) {
         element = element.enclosingElement2;
       } else {
-        element = element.enclosingElement;
+        element = element.enclosingElement2;
       }
     }
     return element as E?;
@@ -2725,12 +2747,7 @@
     Element? ancestor = element;
     while (ancestor != null) {
       components.insert(0, (ancestor as ElementImpl).identifier);
-      if (ancestor is CompilationUnitElementImpl) {
-        // TODO(scheglov) switch everything to `enclosingElement2`.
-        ancestor = ancestor.enclosingElement2;
-      } else {
-        ancestor = ancestor.enclosingElement;
-      }
+      ancestor = ancestor.enclosingElement2;
     }
     _components = components;
   }
@@ -2974,8 +2991,12 @@
   /// [offset].
   ExecutableElementImpl(String super.name, super.offset, {super.reference});
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
-  Element get enclosingElement => super.enclosingElement!;
+  Element get enclosingElement => super.enclosingElement2!;
+
+  @override
+  Element get enclosingElement2 => super.enclosingElement2!;
 
   @override
   bool get hasImplicitReturnType {
@@ -3247,12 +3268,18 @@
   @override
   String get displayName => name ?? '';
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
   CompilationUnitElementImpl get enclosingElement {
     return _enclosingElement as CompilationUnitElementImpl;
   }
 
   @override
+  CompilationUnitElementImpl get enclosingElement2 {
+    return super.enclosingElement2 as CompilationUnitElementImpl;
+  }
+
+  @override
   DartType get extendedType =>
       ElementTypeProvider.current.getExtendedType(this);
 
@@ -3444,7 +3471,7 @@
   ///
   /// Such fields are `index`, `_name`, and `values`.
   bool get isSyntheticEnumField {
-    return enclosingElement is EnumElementImpl &&
+    return enclosingElement2 is EnumElementImpl &&
         isSynthetic &&
         getter?.isSynthetic == true &&
         setter == null;
@@ -3512,7 +3539,7 @@
   @override
   String get identifier {
     String identifier = super.identifier;
-    Element? enclosing = enclosingElement;
+    Element? enclosing = enclosingElement2;
     if (enclosing is ExecutableElement || enclosing is VariableElement) {
       identifier += "@$nameOffset";
     }
@@ -3780,9 +3807,14 @@
   @override
   String get displayName => name;
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
   ExecutableElement get enclosingElement =>
-      super.enclosingElement as ExecutableElement;
+      super.enclosingElement2 as ExecutableElement;
+
+  @override
+  ExecutableElement get enclosingElement2 =>
+      super.enclosingElement2 as ExecutableElement;
 
   /// Return `true` if this label is associated with a `switch` member (`case
   /// ` or`default`).
@@ -4738,8 +4770,8 @@
 
   @override
   Element get nonSynthetic {
-    if (isSynthetic && enclosingElement is EnumElementImpl) {
-      return enclosingElement;
+    if (isSynthetic && enclosingElement2 is EnumElementImpl) {
+      return enclosingElement2;
     }
     return this;
   }
@@ -4977,6 +5009,9 @@
   Element? get enclosingElement => null;
 
   @override
+  Element? get enclosingElement2 => null;
+
+  @override
   bool get hasAlwaysThrows => false;
 
   @override
@@ -5201,8 +5236,12 @@
   /// [offset].
   NonParameterVariableElementImpl(String super.name, super.offset);
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
-  Element get enclosingElement => super.enclosingElement!;
+  Element get enclosingElement => super.enclosingElement2!;
+
+  @override
+  Element get enclosingElement2 => super.enclosingElement2!;
 
   bool get hasInitializer {
     return hasModifier(Modifier.HAS_INITIALIZER);
@@ -5472,7 +5511,7 @@
 
   @override
   CompilationUnitElementImpl get enclosingUnit {
-    var enclosingLibrary = enclosingElement as LibraryElementImpl;
+    var enclosingLibrary = enclosingElement2 as LibraryElementImpl;
     return enclosingLibrary._definingCompilationUnit;
   }
 
@@ -5506,11 +5545,11 @@
   @Deprecated('Use enclosingElement2 instead')
   @override
   LibraryElement get enclosingElement =>
-      super.enclosingElement as LibraryElement;
+      super.enclosingElement2 as LibraryElement;
 
   @override
   LibraryOrAugmentationElementImpl get enclosingElement2 =>
-      super.enclosingElement as LibraryOrAugmentationElementImpl;
+      super.enclosingElement2 as LibraryOrAugmentationElementImpl;
 
   @Deprecated('Use imports2 instead')
   @override
@@ -5671,8 +5710,12 @@
     reference?.element = this;
   }
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
-  Element get enclosingElement => variable.enclosingElement!;
+  Element get enclosingElement => variable.enclosingElement2!;
+
+  @override
+  Element get enclosingElement2 => variable.enclosingElement2!;
 
   @override
   bool get hasImplicitReturnType => variable.hasImplicitType;
@@ -5686,8 +5729,8 @@
     if (!variable.isSynthetic) {
       return variable;
     }
-    assert(enclosingElement is EnumElementImpl);
-    return enclosingElement;
+    assert(enclosingElement2 is EnumElementImpl);
+    return enclosingElement2;
   }
 
   @override
@@ -5732,8 +5775,12 @@
     property.setter = this;
   }
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
-  Element get enclosingElement => variable.enclosingElement!;
+  Element get enclosingElement => variable.enclosingElement2!;
+
+  @override
+  Element get enclosingElement2 => variable.enclosingElement2!;
 
   @override
   bool get isSetter => true;
@@ -5831,10 +5878,10 @@
   @override
   Element get nonSynthetic {
     if (isSynthetic) {
-      if (enclosingElement is EnumElementImpl) {
+      if (enclosingElement2 is EnumElementImpl) {
         // TODO(scheglov) remove 'index'?
         if (name == 'index' || name == 'values') {
-          return enclosingElement;
+          return enclosingElement2;
         }
       }
       return (getter ?? setter)!;
@@ -5975,16 +6022,16 @@
 
   @override
   ParameterElement? get superConstructorParameter {
-    final enclosingElement = this.enclosingElement;
-    if (enclosingElement is ConstructorElementImpl) {
-      var superConstructor = enclosingElement.superConstructor;
+    final enclosingElement2 = this.enclosingElement2;
+    if (enclosingElement2 is ConstructorElementImpl) {
+      var superConstructor = enclosingElement2.superConstructor;
       if (superConstructor != null) {
         var superParameters = superConstructor.parameters;
         if (isNamed) {
           return superParameters
               .firstWhereOrNull((e) => e.isNamed && e.name == name);
         } else {
-          var index = indexIn(enclosingElement);
+          var index = indexIn(enclosingElement2);
           var positionalSuperParameters =
               superParameters.where((e) => e.isPositional).toList();
           if (index >= 0 && index < positionalSuperParameters.length) {
@@ -6085,9 +6132,14 @@
   @override
   String get displayName => name;
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
   CompilationUnitElement get enclosingElement =>
-      super.enclosingElement as CompilationUnitElement;
+      super.enclosingElement2 as CompilationUnitElement;
+
+  @override
+  CompilationUnitElement get enclosingElement2 =>
+      super.enclosingElement2 as CompilationUnitElement;
 
   /// Returns whether this alias is a "proper rename" of [aliasedClass], as
   /// defined in the constructor-tearoffs specification.
@@ -6327,7 +6379,7 @@
       return true;
     }
     if (other is TypeParameterElement) {
-      if (other.enclosingElement == null || enclosingElement == null) {
+      if (other.enclosingElement2 == null || enclosingElement2 == null) {
         return identical(other, this);
       }
       return other.location == location;
@@ -6557,7 +6609,7 @@
   String? get documentationComment => base.documentationComment;
 
   @override
-  Element? get enclosingElement => base.enclosingElement;
+  Element? get enclosingElement => base.enclosingElement2;
 
   @override
   bool get hasAlwaysThrows => base.hasAlwaysThrows;
@@ -6723,7 +6775,7 @@
   Source get librarySource => library.source;
 
   @override
-  Source get source => enclosingElement!.source!;
+  Source get source => enclosingElement2!.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 f5c453d..6b256a0 100644
--- a/pkg/analyzer/lib/src/dart/element/extensions.dart
+++ b/pkg/analyzer/lib/src/dart/element/extensions.dart
@@ -25,7 +25,7 @@
         }
       }
     } else if (element is ConstructorElement) {
-      classElement = element.enclosingElement;
+      classElement = element.enclosingElement2;
     }
     if (classElement == null) {
       return const <TargetKind>{};
@@ -68,17 +68,17 @@
       return true;
     }
 
-    var ancestor = enclosingElement;
+    var ancestor = enclosingElement2;
     if (ancestor is ClassElement) {
       if (ancestor.hasDoNotStore) {
         return true;
       }
-      ancestor = ancestor.enclosingElement;
+      ancestor = ancestor.enclosingElement2;
     } else if (ancestor is ExtensionElement) {
       if (ancestor.hasDoNotStore) {
         return true;
       }
-      ancestor = ancestor.enclosingElement;
+      ancestor = ancestor.enclosingElement2;
     }
 
     return ancestor is CompilationUnitElement &&
@@ -94,7 +94,7 @@
   /// [PropertyAccessorElement]s.
   bool get isInstanceMember {
     var this_ = this;
-    var enclosing = this_.enclosingElement;
+    var enclosing = this_.enclosingElement2;
     if (enclosing is ClassElement) {
       return this_ is MethodElement && !this_.isStatic ||
           this_ is PropertyAccessorElement && !this_.isStatic;
@@ -105,7 +105,7 @@
 
 extension ExecutableElementExtension on ExecutableElement {
   bool get isEnumConstructor {
-    return this is ConstructorElement && enclosingElement is EnumElementImpl;
+    return this is ConstructorElement && enclosingElement2 is EnumElementImpl;
   }
 }
 
diff --git a/pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart b/pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart
index 49737ae..9768db4 100644
--- a/pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart
+++ b/pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart
@@ -366,7 +366,7 @@
         continue;
       }
 
-      var class_ = executable.enclosingElement;
+      var class_ = executable.enclosingElement2;
       if (class_ is ClassElement && class_.isDartCoreObject) {
         continue;
       }
@@ -518,7 +518,7 @@
         }
 
         var current = currentList.single;
-        if (candidate.enclosingElement == mixinElement) {
+        if (candidate.enclosingElement2 == mixinElement) {
           namedCandidates[name] = [
             isNonNullableByDefault
                 ? candidate
@@ -714,7 +714,7 @@
     Name name,
     ExecutableElement executable,
   ) {
-    if (executable.enclosingElement == class_) {
+    if (executable.enclosingElement2 == class_) {
       return executable;
     }
 
@@ -902,7 +902,7 @@
   }
 
   static bool _isDeclaredInObject(ExecutableElement element) {
-    var enclosing = element.enclosingElement;
+    var enclosing = element.enclosingElement2;
     return enclosing is ClassElement &&
         enclosing.supertype == null &&
         !enclosing.isMixin;
diff --git a/pkg/analyzer/lib/src/dart/element/member.dart b/pkg/analyzer/lib/src/dart/element/member.dart
index 2455528..cbe9d70 100644
--- a/pkg/analyzer/lib/src/dart/element/member.dart
+++ b/pkg/analyzer/lib/src/dart/element/member.dart
@@ -37,8 +37,12 @@
   @override
   String get displayName => declaration.displayName;
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
-  ClassElement get enclosingElement => declaration.enclosingElement;
+  ClassElement get enclosingElement => declaration.enclosingElement2;
+
+  @override
+  ClassElement get enclosingElement2 => declaration.enclosingElement2;
 
   @override
   bool get isConst => declaration.isConst;
@@ -332,8 +336,12 @@
   @override
   String get displayName => declaration.displayName;
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
-  Element get enclosingElement => declaration.enclosingElement;
+  Element get enclosingElement => declaration.enclosingElement2;
+
+  @override
+  Element get enclosingElement2 => declaration.enclosingElement2;
 
   @override
   PropertyAccessorElement? get getter {
@@ -423,7 +431,11 @@
   FunctionElement get declaration => super.declaration as FunctionElement;
 
   @override
-  Element get enclosingElement => declaration.enclosingElement;
+  Element get enclosingElement => declaration.enclosingElement2;
+
+  @Deprecated('Use enclosingElement2 instead')
+  @override
+  Element get enclosingElement2 => declaration.enclosingElement2;
 
   @override
   bool get isDartCoreIdentical => declaration.isDartCoreIdentical;
@@ -480,8 +492,12 @@
   @override
   String? get documentationComment => _declaration.documentationComment;
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
-  Element? get enclosingElement => _declaration.enclosingElement;
+  Element? get enclosingElement => _declaration.enclosingElement2;
+
+  @override
+  Element? get enclosingElement2 => _declaration.enclosingElement2;
 
   @override
   bool get hasAlwaysThrows => _declaration.hasAlwaysThrows;
@@ -761,8 +777,12 @@
   @override
   MethodElement get declaration => super.declaration as MethodElement;
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
-  Element get enclosingElement => declaration.enclosingElement;
+  Element get enclosingElement => declaration.enclosingElement2;
+
+  @override
+  Element get enclosingElement2 => declaration.enclosingElement2;
 
   @override
   String get name => declaration.name;
@@ -845,8 +865,12 @@
   @override
   String? get defaultValueCode => declaration.defaultValueCode;
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
-  Element? get enclosingElement => declaration.enclosingElement;
+  Element? get enclosingElement => declaration.enclosingElement2;
+
+  @override
+  Element? get enclosingElement2 => declaration.enclosingElement2;
 
   @override
   bool get hasDefaultValue => declaration.hasDefaultValue;
@@ -980,8 +1004,12 @@
   PropertyAccessorElement get declaration =>
       super.declaration as PropertyAccessorElement;
 
+  @Deprecated('Use enclosingElement2 instead')
   @override
-  Element get enclosingElement => declaration.enclosingElement;
+  Element get enclosingElement => declaration.enclosingElement2;
+
+  @override
+  Element get enclosingElement2 => declaration.enclosingElement2;
 
   @override
   bool get isGetter => declaration.isGetter;
diff --git a/pkg/analyzer/lib/src/dart/element/type_system.dart b/pkg/analyzer/lib/src/dart/element/type_system.dart
index 9fc03c6..3faa7fb 100644
--- a/pkg/analyzer/lib/src/dart/element/type_system.dart
+++ b/pkg/analyzer/lib/src/dart/element/type_system.dart
@@ -1696,7 +1696,7 @@
     // 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) {
+    if (methodElement.enclosingElement2 is ExtensionElement) {
       return currentType;
     }
 
@@ -1800,7 +1800,7 @@
     // 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) {
+    if (methodElement.enclosingElement2 is ExtensionElement) {
       return currentType;
     }
 
diff --git a/pkg/analyzer/lib/src/dart/micro/utils.dart b/pkg/analyzer/lib/src/dart/micro/utils.dart
index 52b1ab6..c5113f7 100644
--- a/pkg/analyzer/lib/src/dart/micro/utils.dart
+++ b/pkg/analyzer/lib/src/dart/micro/utils.dart
@@ -43,7 +43,7 @@
     ConstructorElement? constructor) {
   var seenConstructors = <ConstructorElement?>{};
   while (constructor is ConstructorElementImpl && constructor.isSynthetic) {
-    var enclosing = constructor.enclosingElement;
+    var enclosing = constructor.enclosingElement2;
     if (enclosing.isMixinApplication) {
       var superInvocation = constructor.constantInitializers
           .whereType<SuperConstructorInvocation>()
@@ -73,7 +73,7 @@
     String prefix,
     Element element,
     Map<LibraryImportElement, Set<Element>> importElementsMap) {
-  if (element.enclosingElement is! CompilationUnitElement) {
+  if (element.enclosingElement2 is! CompilationUnitElement) {
     return null;
   }
   var usedLibrary = element.library;
@@ -310,7 +310,7 @@
         length = 0;
       }
       references.add(MatchInfo(offset, length, kind));
-    } else if (e != null && e.enclosingElement == element) {
+    } else if (e != null && e.enclosingElement2 == element) {
       kind = MatchKind.REFERENCE;
       offset = node.offset;
       length = element.nameLength;
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 db7e1df..339f8df 100644
--- a/pkg/analyzer/lib/src/dart/resolver/constructor_reference_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/constructor_reference_resolver.dart
@@ -31,7 +31,7 @@
     var element = node.constructorName.staticElement;
     if (element != null &&
         !element.isFactory &&
-        element.enclosingElement.isAbstract) {
+        element.enclosingElement2.isAbstract) {
       _resolver.errorReporter.reportErrorForNode(
         CompileTimeErrorCode
             .TEAROFF_OF_GENERATIVE_CONSTRUCTOR_OF_ABSTRACT_CLASS,
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 e8801b0..dba662f 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.enclosingElement2;
     if (implicitReceiver) {
       if (_resolver.enclosingExtension != null) {
         _resolver.errorReporter.reportErrorForNode(
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 13368ab..ac88021 100644
--- a/pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart
@@ -220,7 +220,7 @@
     ExecutableElement element,
     bool nullReceiver,
   ) {
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement2;
     if (nullReceiver) {
       if (_resolver.enclosingExtension != null) {
         _resolver.errorReporter.reportErrorForNode(
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 63e41ad..cc95ced 100644
--- a/pkg/analyzer/lib/src/dart/resolver/named_type_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/named_type_resolver.dart
@@ -568,7 +568,7 @@
 
     if (element is LocalVariableElement ||
         (element is FunctionElement &&
-            element.enclosingElement is ExecutableElement)) {
+            element.enclosingElement2 is ExecutableElement)) {
       errorReporter.reportError(
         DiagnosticFactory().referencedBeforeDeclaration(
           errorReporter.source,
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 6ddcf05..fd96f2e 100644
--- a/pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart
@@ -291,7 +291,7 @@
           propertyName,
         );
       } else {
-        var enclosingElement = element.enclosingElement;
+        var enclosingElement = element.enclosingElement2;
         if (enclosingElement is ExtensionElement &&
             enclosingElement.name == null) {
           _resolver.errorReporter.reportErrorForNode(
diff --git a/pkg/analyzer/lib/src/diagnostic/diagnostic_factory.dart b/pkg/analyzer/lib/src/diagnostic/diagnostic_factory.dart
index 6681a49..9726e9f 100644
--- a/pkg/analyzer/lib/src/diagnostic/diagnostic_factory.dart
+++ b/pkg/analyzer/lib/src/diagnostic/diagnostic_factory.dart
@@ -79,14 +79,14 @@
       ExecutableElement superMember) {
     errorCode ??= CompileTimeErrorCode.INVALID_OVERRIDE;
     // Elements enclosing members that can participate in overrides are always
-    // named, so we can safely assume `_thisMember.enclosingElement.name` and
-    // `superMember.enclosingElement.name` are non-`null`.
+    // named, so we can safely assume `_thisMember.enclosingElement2.name` and
+    // `superMember.enclosingElement2.name` are non-`null`.
     return AnalysisError(
         source, errorNode.offset, errorNode.length, errorCode, [
       member.name,
-      member.enclosingElement.name!,
+      member.enclosingElement2.name!,
       member.type,
-      superMember.enclosingElement.name!,
+      superMember.enclosingElement2.name!,
       superMember.type,
     ], [
       // Only include the context location for INVALID_OVERRIDE because for
diff --git a/pkg/analyzer/lib/src/error/assignment_verifier.dart b/pkg/analyzer/lib/src/error/assignment_verifier.dart
index 97cbefd..4e7b029 100644
--- a/pkg/analyzer/lib/src/error/assignment_verifier.dart
+++ b/pkg/analyzer/lib/src/error/assignment_verifier.dart
@@ -91,7 +91,7 @@
         _errorReporter.reportErrorForNode(
           CompileTimeErrorCode.ASSIGNMENT_TO_FINAL_NO_SETTER,
           node,
-          [variable.name, variable.enclosingElement.displayName],
+          [variable.name, variable.enclosingElement2.displayName],
         );
       } else {
         _errorReporter.reportErrorForNode(
diff --git a/pkg/analyzer/lib/src/error/best_practices_verifier.dart b/pkg/analyzer/lib/src/error/best_practices_verifier.dart
index c5f4ab8..5ec9188 100644
--- a/pkg/analyzer/lib/src/error/best_practices_verifier.dart
+++ b/pkg/analyzer/lib/src/error/best_practices_verifier.dart
@@ -171,7 +171,7 @@
           }
         }
       } else if (parent is ConstructorDeclaration) {
-        var class_ = parent.declaredElement!.enclosingElement;
+        var class_ = parent.declaredElement!.enclosingElement2;
         if (class_.isPrivate || (parentElement?.isPrivate ?? false)) {
           _errorReporter.reportErrorForNode(
               HintCode.INVALID_INTERNAL_ANNOTATION, node, []);
@@ -301,7 +301,7 @@
         var invokedElement = element.element!;
         var name = invokedElement.name;
         if (invokedElement is ConstructorElement) {
-          var className = invokedElement.enclosingElement.name;
+          var className = invokedElement.enclosingElement2.name;
           if (name!.isEmpty) {
             name = className;
           } else {
@@ -449,7 +449,7 @@
           final element = field.declaredElement;
           if (element is PropertyAccessorElement || element is FieldElement) {
             Name name = Name(_currentLibrary.source.uri, element!.name);
-            Element enclosingElement = element.enclosingElement!;
+            Element enclosingElement = element.enclosingElement2!;
             if (enclosingElement is ClassElement) {
               var overridden = _inheritanceManager
                   .getMember2(enclosingElement, name, forSuper: true);
@@ -471,11 +471,11 @@
             _hasNonVirtualAnnotation(overriddenElement)) {
           // Overridden members are always inside classes or mixins, which are
           // always named, so we can safely assume
-          // `overriddenElement.enclosingElement.name` is non-`null`.
+          // `overriddenElement.enclosingElement2.name` is non-`null`.
           _errorReporter.reportErrorForNode(
               HintCode.INVALID_OVERRIDE_OF_NON_VIRTUAL_MEMBER, field.name, [
             field.name.name,
-            overriddenElement.enclosingElement.displayName
+            overriddenElement.enclosingElement2.displayName
           ]);
         }
         if (!_invalidAccessVerifier._inTestDirectory) {
@@ -618,7 +618,7 @@
   void visitMethodDeclaration(MethodDeclaration node) {
     bool wasInDoNotStoreMember = _inDoNotStoreMember;
     var element = node.declaredElement!;
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement2;
 
     Name name = Name(_currentLibrary.source.uri, element.name);
 
@@ -665,11 +665,11 @@
           _hasNonVirtualAnnotation(overriddenElement)) {
         // Overridden members are always inside classes or mixins, which are
         // always named, so we can safely assume
-        // `overriddenElement.enclosingElement.name` is non-`null`.
+        // `overriddenElement.enclosingElement2.name` is non-`null`.
         _errorReporter.reportErrorForNode(
             HintCode.INVALID_OVERRIDE_OF_NON_VIRTUAL_MEMBER,
             node.name,
-            [node.name.name, overriddenElement.enclosingElement.displayName]);
+            [node.name.name, overriddenElement.enclosingElement2.displayName]);
       }
 
       super.visitMethodDeclaration(node);
@@ -1439,7 +1439,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?.enclosingElement2;
           return methodElement is MethodElement &&
               classElement is ClassElement &&
               !classElement.isDartCoreObject;
@@ -1943,7 +1943,7 @@
       SimpleIdentifier identifier, Element element) {
     bool hasProtected = _hasProtected(element);
     if (hasProtected) {
-      var definingClass = element.enclosingElement as ClassElement;
+      var definingClass = element.enclosingElement2 as ClassElement;
       if (_hasTypeOrSuperType(_enclosingClass, definingClass)) {
         return;
       }
@@ -1982,7 +1982,7 @@
       node = identifier;
     }
 
-    var definingClass = element.enclosingElement;
+    var definingClass = element.enclosingElement2;
     if (hasProtected) {
       _errorReporter.reportErrorForNode(
           HintCode.INVALID_USE_OF_PROTECTED_MEMBER,
@@ -2038,12 +2038,12 @@
 
   bool _hasProtected(Element element) {
     if (element is PropertyAccessorElement &&
-        element.enclosingElement is ClassElement &&
+        element.enclosingElement2 is ClassElement &&
         (element.hasProtected || element.variable.hasProtected)) {
       return true;
     }
     if (element is MethodElement &&
-        element.enclosingElement is ClassElement &&
+        element.enclosingElement2 is ClassElement &&
         element.hasProtected) {
       return true;
     }
diff --git a/pkg/analyzer/lib/src/error/correct_override.dart b/pkg/analyzer/lib/src/error/correct_override.dart
index 2169256..609bc46 100644
--- a/pkg/analyzer/lib/src/error/correct_override.dart
+++ b/pkg/analyzer/lib/src/error/correct_override.dart
@@ -123,16 +123,16 @@
           var superMember = superParameter.member;
           // Elements enclosing members that can participate in overrides are
           // always named, so we can safely assume
-          // `_thisMember.enclosingElement.name` and
-          // `superMember.enclosingElement.name` are non-`null`.
+          // `_thisMember.enclosingElement2.name` and
+          // `superMember.enclosingElement2.name` are non-`null`.
           errorReporter.reportErrorForNode(
             CompileTimeErrorCode.INVALID_OVERRIDE,
             errorNode,
             [
               _thisMember.name,
-              _thisMember.enclosingElement.name!,
+              _thisMember.enclosingElement2.name!,
               _thisMember.type,
-              superMember.enclosingElement.name!,
+              superMember.enclosingElement2.name!,
               superMember.type,
             ],
           );
@@ -143,7 +143,7 @@
 
   List<_SuperMember> _superMembers() {
     var classHierarchy = _session.classHierarchy;
-    var classElement = _thisMember.enclosingElement as ClassElement;
+    var classElement = _thisMember.enclosingElement2 as ClassElement;
     var interfaces = classHierarchy.implementedInterfaces(classElement);
 
     var superMembers = <_SuperMember>[];
@@ -271,5 +271,6 @@
 
   _SuperParameter(this.element, this.type);
 
-  ExecutableElement get member => element.enclosingElement as ExecutableElement;
+  ExecutableElement get member =>
+      element.enclosingElement2 as ExecutableElement;
 }
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 82de45d..240e440 100644
--- a/pkg/analyzer/lib/src/error/deprecated_member_use_verifier.dart
+++ b/pkg/analyzer/lib/src/error/deprecated_member_use_verifier.dart
@@ -169,7 +169,7 @@
       // TODO(jwren) We should modify ConstructorElement.getDisplayName(),
       // or have the logic centralized elsewhere, instead of doing this logic
       // here.
-      displayName = element.enclosingElement.displayName;
+      displayName = element.enclosingElement2.displayName;
       if (element.displayName.isNotEmpty) {
         displayName = "$displayName.${element.displayName}";
       }
@@ -268,7 +268,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.enclosingElement2 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 a44e297..9687d8c 100644
--- a/pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart
+++ b/pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart
@@ -141,7 +141,7 @@
             [
               enumElement.displayName,
               baseName,
-              inherited.enclosingElement.displayName,
+              inherited.enclosingElement2.displayName,
             ],
           );
         }
@@ -168,7 +168,7 @@
             [
               enumElement.displayName,
               baseName,
-              inherited.enclosingElement.displayName,
+              inherited.enclosingElement2.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 f835414..469f0f5 100644
--- a/pkg/analyzer/lib/src/error/getter_setter_types_verifier.dart
+++ b/pkg/analyzer/lib/src/error/getter_setter_types_verifier.dart
@@ -53,23 +53,23 @@
           var setterType = setter.parameters[0].type;
           if (!_match(getterType, setterType)) {
             Element errorElement;
-            if (getter.enclosingElement == classElement) {
+            if (getter.enclosingElement2 == classElement) {
               errorElement = getter;
-            } else if (setter.enclosingElement == classElement) {
+            } else if (setter.enclosingElement2 == classElement) {
               errorElement = setter;
             } else {
               errorElement = classElement;
             }
 
             var getterName = getter.displayName;
-            if (getter.enclosingElement != classElement) {
-              var getterClassName = getter.enclosingElement.displayName;
+            if (getter.enclosingElement2 != classElement) {
+              var getterClassName = getter.enclosingElement2.displayName;
               getterName = '$getterClassName.$getterName';
             }
 
             var setterName = setter.displayName;
-            if (setter.enclosingElement != classElement) {
-              var setterClassName = setter.enclosingElement.displayName;
+            if (setter.enclosingElement2 != classElement) {
+              var setterClassName = setter.enclosingElement2.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 4c990ff..66afde0 100644
--- a/pkg/analyzer/lib/src/error/imports_verifier.dart
+++ b/pkg/analyzer/lib/src/error/imports_verifier.dart
@@ -94,7 +94,7 @@
 
   void _recordIfExtensionMember(Element? element) {
     if (element != null) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement2;
       if (enclosingElement is ExtensionElement) {
         _recordUsedExtension(enclosingElement);
       }
@@ -165,7 +165,7 @@
     if (_recordPrefixMap(identifier, element)) {
       return;
     }
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement2;
     if (enclosingElement is CompilationUnitElement) {
       _recordUsedElement(element);
     } else if (enclosingElement is ExtensionElement) {
diff --git a/pkg/analyzer/lib/src/error/inheritance_override.dart b/pkg/analyzer/lib/src/error/inheritance_override.dart
index e0deb86..bd71971 100644
--- a/pkg/analyzer/lib/src/error/inheritance_override.dart
+++ b/pkg/analyzer/lib/src/error/inheritance_override.dart
@@ -529,7 +529,7 @@
                     .INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED,
                 derivedOptionalNodes[i],
                 [
-                  baseExecutable.enclosingElement.displayName,
+                  baseExecutable.enclosingElement2.displayName,
                   baseExecutable.displayName,
                   name
                 ],
@@ -558,7 +558,7 @@
                   .INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL,
               derivedOptionalNodes[i],
               [
-                baseExecutable.enclosingElement.displayName,
+                baseExecutable.enclosingElement2.displayName,
                 baseExecutable.displayName
               ],
             );
@@ -675,7 +675,7 @@
       ) {
         var member = concreteMap[Name(libraryUri, memberName)];
         if (member != null) {
-          var enclosingClass = member.enclosingElement;
+          var enclosingClass = member.enclosingElement2;
           if (enclosingClass is ClassElement && filter(enclosingClass)) {
             reporter.reportErrorForNode(
               CompileTimeErrorCode.ILLEGAL_CONCRETE_ENUM_MEMBER_INHERITANCE,
@@ -716,7 +716,7 @@
         reporter.reportErrorForNode(
           CompileTimeErrorCode.ILLEGAL_ENUM_VALUES_INHERITANCE,
           classNameNode,
-          [inherited.enclosingElement.name!],
+          [inherited.enclosingElement2.name!],
         );
       }
     }
@@ -792,20 +792,20 @@
     if (conflict is GetterMethodConflict) {
       // Members that participate in inheritance are always enclosed in named
       // elements so it is safe to assume that
-      // `conflict.getter.enclosingElement.name` and
-      // `conflict.method.enclosingElement.name` are both non-`null`.
+      // `conflict.getter.enclosingElement2.name` and
+      // `conflict.method.enclosingElement2.name` are both non-`null`.
       reporter.reportErrorForNode(
         CompileTimeErrorCode.INCONSISTENT_INHERITANCE_GETTER_AND_METHOD,
         node,
         [
           name.name,
-          conflict.getter.enclosingElement.name!,
-          conflict.method.enclosingElement.name!
+          conflict.getter.enclosingElement2.name!,
+          conflict.method.enclosingElement2.name!
         ],
       );
     } else if (conflict is CandidatesConflict) {
       var candidatesStr = conflict.candidates.map((candidate) {
-        var className = candidate.enclosingElement.name;
+        var className = candidate.enclosingElement2.name;
         var typeStr = candidate.type.getDisplayString(
           withNullability: _isNonNullableByDefault,
         );
@@ -844,7 +844,7 @@
       }
 
       var elementName = element.displayName;
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement2;
       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 e66ab21..3ce9a09 100644
--- a/pkg/analyzer/lib/src/error/must_call_super_verifier.dart
+++ b/pkg/analyzer/lib/src/error/must_call_super_verifier.dart
@@ -28,17 +28,17 @@
 
     if (element is MethodElement && _hasConcreteSuperMethod(element)) {
       _verifySuperIsCalled(
-          node, overridden.name, overridden.enclosingElement.name);
+          node, overridden.name, overridden.enclosingElement2.name);
       return;
     }
 
-    var enclosingElement = element.enclosingElement as ClassElement;
+    var enclosingElement = element.enclosingElement2 as ClassElement;
     if (element is PropertyAccessorElement && element.isGetter) {
       var inheritedConcreteGetter = enclosingElement
           .lookUpInheritedConcreteGetter(element.name, element.library);
       if (inheritedConcreteGetter != null) {
         _verifySuperIsCalled(
-            node, overridden.name, overridden.enclosingElement.name);
+            node, overridden.name, overridden.enclosingElement2.name);
       }
       return;
     }
@@ -53,7 +53,7 @@
         if (name.endsWith('=')) {
           name = name.substring(0, name.length - 1);
         }
-        _verifySuperIsCalled(node, name, overridden.enclosingElement.name);
+        _verifySuperIsCalled(node, name, overridden.enclosingElement2.name);
       }
     }
   }
@@ -69,10 +69,10 @@
   ExecutableElement? _findOverriddenMemberWithMustCallSuper(
       ExecutableElement element) {
     //Element member = node.declaredElement;
-    if (element.enclosingElement is! ClassElement) {
+    if (element.enclosingElement2 is! ClassElement) {
       return null;
     }
-    var classElement = element.enclosingElement as ClassElement;
+    var classElement = element.enclosingElement2 as ClassElement;
     String name = element.name;
 
     // Walk up the type hierarchy from [classElement], ignoring direct
@@ -109,7 +109,7 @@
 
   /// Returns whether [node] overrides a concrete method.
   bool _hasConcreteSuperMethod(ExecutableElement element) {
-    var classElement = element.enclosingElement as ClassElement;
+    var classElement = element.enclosingElement2 as ClassElement;
     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 aadad6e..c2c2f51 100644
--- a/pkg/analyzer/lib/src/error/type_arguments_verifier.dart
+++ b/pkg/analyzer/lib/src/error/type_arguments_verifier.dart
@@ -97,7 +97,7 @@
       return;
     }
 
-    var enumElement = constructorElement.enclosingElement;
+    var enumElement = constructorElement.enclosingElement2;
     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 216f128..aab0059 100644
--- a/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart
+++ b/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart
@@ -257,7 +257,7 @@
           usedElements.addElement(parameter);
         }
       }
-      var enclosingElement = element?.enclosingElement;
+      var enclosingElement = element?.enclosingElement2;
       if (element == null) {
         if (isIdentifierRead) {
           usedElements.unresolvedReadMembers.add(node.name);
@@ -516,7 +516,7 @@
     if (element.isPrivate) {
       return false;
     }
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement2;
 
     if (enclosingElement is ClassElement) {
       if (enclosingElement.isEnum) {
@@ -544,7 +544,7 @@
     bool elementIsStaticVariable =
         element is VariableElement && element.isStatic;
     if (element.isPublic) {
-      if (_isPrivateClassOrExtension(element.enclosingElement!) &&
+      if (_isPrivateClassOrExtension(element.enclosingElement2!) &&
           elementIsStaticVariable) {
         // Public static fields of private classes, mixins, and extensions are
         // inaccessible from outside the library in which they are declared.
@@ -581,7 +581,7 @@
         element is FunctionElement && !element.isStatic) {
       // local variable or function
     } else if (element is ParameterElement) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement2;
       // Only report unused parameters of constructors, methods, and functions.
       if (enclosingElement is! ConstructorElement &&
           enclosingElement is! FunctionElement &&
@@ -593,7 +593,7 @@
         return true;
       }
       if (enclosingElement is ConstructorElement &&
-          enclosingElement.enclosingElement.typeParameters.isNotEmpty) {
+          enclosingElement.enclosingElement2.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
@@ -647,7 +647,7 @@
   }
 
   Iterable<ExecutableElement> _overriddenElements(Element element) {
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement2;
     if (enclosingElement is ClassElement) {
       Name name = Name(_libraryUri, element.name!);
       var overridden =
@@ -729,7 +729,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.enclosingElement2.constructors.length > 1 &&
         !_isUsedMember(element)) {
       _reportErrorForElement(
           HintCode.UNUSED_ELEMENT, element, [element.displayName]);
diff --git a/pkg/analyzer/lib/src/generated/element_resolver.dart b/pkg/analyzer/lib/src/generated/element_resolver.dart
index 6656aef..8cb650a 100644
--- a/pkg/analyzer/lib/src/generated/element_resolver.dart
+++ b/pkg/analyzer/lib/src/generated/element_resolver.dart
@@ -357,7 +357,7 @@
     } else {
       if (element.isFactory &&
           // Check if we've reported [NO_GENERATIVE_CONSTRUCTORS_IN_SUPERCLASS].
-          !element.enclosingElement.constructors
+          !element.enclosingElement2.constructors
               .every((constructor) => constructor.isFactory)) {
         _errorReporter.reportErrorForNode(
             CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, node, [element]);
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index 2df59bb..9bce035 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -117,7 +117,7 @@
   }
 
   static bool _inFactoryConstructor(Element? element) {
-    var enclosing = element?.enclosingElement;
+    var enclosing = element?.enclosingElement2;
     if (enclosing == null) {
       return false;
     }
@@ -128,7 +128,7 @@
   }
 
   static bool _inStaticMethod(Element? element) {
-    var enclosing = element?.enclosingElement;
+    var enclosing = element?.enclosingElement2;
     if (enclosing == null) {
       return false;
     }
@@ -746,7 +746,7 @@
   @override
   void visitFunctionDeclaration(FunctionDeclaration node) {
     ExecutableElement functionElement = node.declaredElement!;
-    if (functionElement.enclosingElement is! CompilationUnitElement) {
+    if (functionElement.enclosingElement2 is! CompilationUnitElement) {
       _hiddenElements!.declare(functionElement);
     }
 
@@ -1624,7 +1624,7 @@
         errorReporter.reportErrorForNode(
           CompileTimeErrorCode.ASSIGNMENT_TO_FINAL_NO_SETTER,
           highlightedNode,
-          [variable.name, variable.enclosingElement.displayName],
+          [variable.name, variable.enclosingElement2.displayName],
         );
       } else {
         errorReporter.reportErrorForNode(
@@ -1797,14 +1797,14 @@
             CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, method, [
           _enclosingClass!.displayName,
           name,
-          inherited.enclosingElement.displayName,
+          inherited.enclosingElement2.displayName,
         ]);
       } else if (inherited is PropertyAccessorElement) {
         errorReporter.reportErrorForElement(
             CompileTimeErrorCode.CONFLICTING_METHOD_AND_FIELD, method, [
           _enclosingClass!.displayName,
           name,
-          inherited.enclosingElement.displayName
+          inherited.enclosingElement2.displayName
         ]);
       }
     }
@@ -1824,14 +1824,14 @@
             CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, accessor, [
           _enclosingClass!.displayName,
           name,
-          inherited.enclosingElement.displayName,
+          inherited.enclosingElement2.displayName,
         ]);
       } else if (inherited is MethodElement) {
         errorReporter.reportErrorForElement(
             CompileTimeErrorCode.CONFLICTING_FIELD_AND_METHOD, accessor, [
           _enclosingClass!.displayName,
           name,
-          inherited.enclosingElement.displayName
+          inherited.enclosingElement2.displayName
         ]);
       }
     }
@@ -2089,11 +2089,11 @@
       errorReporter.reportErrorForNode(
           CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN_WITH_FIELD,
           constructor.returnType,
-          ["'${field.enclosingElement.name}.${field.name}'"]);
+          ["'${field.enclosingElement2.name}.${field.name}'"]);
       return true;
     } else if (instanceFields.length > 1) {
       var fieldNames = instanceFields
-          .map((field) => "'${field.enclosingElement.name}.${field.name}'")
+          .map((field) => "'${field.enclosingElement2.name}.${field.name}'")
           .join(', ');
       errorReporter.reportErrorForNode(
           CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN_WITH_FIELDS,
@@ -2117,7 +2117,7 @@
         errorReporter.reportErrorForNode(
             CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER,
             initializer,
-            [element.enclosingElement.displayName]);
+            [element.enclosingElement2.displayName]);
         return true;
       }
     }
@@ -2155,7 +2155,7 @@
       return;
     }
     // check if there is non-final field
-    ClassElement classElement = constructorElement.enclosingElement;
+    ClassElement classElement = constructorElement.enclosingElement2;
     if (!classElement.hasNonFinalField) {
       return;
     }
@@ -2921,7 +2921,7 @@
         // OK, instance member
         return;
       }
-      Element enclosingElement = element.enclosingElement;
+      Element enclosingElement = element.enclosingElement2;
       if (enclosingElement is ExtensionElement) {
         if (target is ExtensionOverride) {
           // OK, target is an extension override
@@ -3003,7 +3003,7 @@
     var constructorElement = node.staticElement;
     if (constructorElement != null &&
         constructorElement.isGenerative &&
-        constructorElement.enclosingElement.isEnum) {
+        constructorElement.enclosingElement2.isEnum) {
       if (_currentLibrary.featureSet.isEnabled(Feature.enhanced_enums)) {
         errorReporter.reportErrorForNode(
           CompileTimeErrorCode.INVALID_REFERENCE_TO_GENERATIVE_ENUM_CONSTRUCTOR,
@@ -3046,7 +3046,7 @@
       return;
     }
     // not a class member
-    Element enclosingElement = element.enclosingElement;
+    Element enclosingElement = element.enclosingElement2;
     if (enclosingElement is! ClassElement &&
         enclosingElement is! ExtensionElement) {
       return;
@@ -3182,7 +3182,7 @@
     var element = nameNode.staticElement!;
 
     // We should only check exported declarations, i.e. top-level.
-    if (element.enclosingElement is! CompilationUnitElement) {
+    if (element.enclosingElement2 is! CompilationUnitElement) {
       return;
     }
 
@@ -3496,14 +3496,14 @@
         );
         if (inheritedMember != null) {
           // Inherited members are always contained inside named elements, so we
-          // can safely assume `inheritedMember.enclosingElement.name` is
+          // can safely assume `inheritedMember.enclosingElement2.name` is
           // non-`null`.
           errorReporter.reportErrorForNode(
               CompileTimeErrorCode.PRIVATE_COLLISION_IN_MIXIN_APPLICATION,
               namedType, [
             name,
             namedType.name.name,
-            inheritedMember.enclosingElement.name!
+            inheritedMember.enclosingElement2.name!
           ]);
           return true;
         }
@@ -4032,7 +4032,7 @@
       redirectedElement,
       redirectedConstructor,
     );
-    var redirectedClass = redirectedElement?.enclosingElement;
+    var redirectedClass = redirectedElement?.enclosingElement2;
     if (redirectedClass is ClassElement &&
         redirectedClass.isAbstract &&
         redirectedElement != null &&
@@ -4323,7 +4323,7 @@
     if (_enclosingExecutable.inStaticMethod || _isInStaticVariableDeclaration) {
       var element = identifier.staticElement;
       if (element is TypeParameterElement &&
-          element.enclosingElement is ClassElement) {
+          element.enclosingElement2 is ClassElement) {
         // 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).
@@ -4565,7 +4565,7 @@
     if (element == null || element is TypeParameterElement) {
       return;
     }
-    var enclosingElement = element.enclosingElement;
+    var enclosingElement = element.enclosingElement2;
     if (identical(enclosingElement, _enclosingClass)) {
       return;
     }
diff --git a/pkg/analyzer/lib/src/generated/ffi_verifier.dart b/pkg/analyzer/lib/src/generated/ffi_verifier.dart
index 5758264..43b4217 100644
--- a/pkg/analyzer/lib/src/generated/ffi_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/ffi_verifier.dart
@@ -202,7 +202,7 @@
   void visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
     var element = node.staticElement;
     if (element is MethodElement) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement2;
       if (enclosingElement.isAllocatorExtension &&
           element.name == _allocateExtensionMethodName) {
         _validateAllocate(node);
@@ -215,7 +215,7 @@
   void visitIndexExpression(IndexExpression node) {
     var element = node.staticElement;
     if (element is MethodElement) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement2;
       if (enclosingElement.isNativeStructPointerExtension ||
           enclosingElement.isNativeStructArrayExtension) {
         if (element.name == '[]') {
@@ -228,7 +228,7 @@
   @override
   void visitInstanceCreationExpression(InstanceCreationExpression node) {
     var constructor = node.constructorName.staticElement;
-    var class_ = constructor?.enclosingElement;
+    var class_ = constructor?.enclosingElement2;
     if (class_.isStructSubclass || class_.isUnionSubclass) {
       _errorReporter.reportErrorForNode(
         FfiCode.CREATION_OF_STRUCT_OR_UNION,
@@ -253,7 +253,7 @@
   void visitMethodInvocation(MethodInvocation node) {
     var element = node.methodName.staticElement;
     if (element is MethodElement) {
-      Element enclosingElement = element.enclosingElement;
+      Element enclosingElement = element.enclosingElement2;
       if (enclosingElement.isPointer) {
         if (element.name == 'fromFunction') {
           _validateFromFunction(node, element);
@@ -270,7 +270,7 @@
         }
       }
     } else if (element is FunctionElement) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement2;
       if (enclosingElement is CompilationUnitElement) {
         if (element.library.name == 'dart.ffi') {
           if (element.name == 'sizeOf') {
@@ -286,7 +286,7 @@
   void visitPrefixedIdentifier(PrefixedIdentifier node) {
     var element = node.staticElement;
     if (element != null) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement2;
       if (enclosingElement.isNativeStructPointerExtension) {
         if (element.name == 'ref') {
           _validateRefPrefixedIdentifier(node);
@@ -300,7 +300,7 @@
   void visitPropertyAccess(PropertyAccess node) {
     var element = node.propertyName.staticElement;
     if (element != null) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement2;
       if (enclosingElement.isNativeStructPointerExtension) {
         if (element.name == 'ref') {
           _validateRefPropertyAccess(node);
@@ -356,7 +356,7 @@
         // Receiver can only be Pointer if the class extends
         // NativeFieldWrapperClass1.
         if (ffiSignature.normalParameterTypes[0].isPointer) {
-          final cls = declarationElement.enclosingElement as ClassElement;
+          final cls = declarationElement.enclosingElement2 as ClassElement;
           if (!_extendsNativeFieldWrapperClass1(cls.thisType)) {
             _errorReporter.reportErrorForNode(
                 FfiCode
@@ -585,7 +585,7 @@
   _PrimitiveDartType _typeForAnnotation(Annotation annotation) {
     var element = annotation.element;
     if (element is ConstructorElement) {
-      String name = element.enclosingElement.name;
+      String name = element.enclosingElement2.name;
       if (_primitiveIntegerNativeTypes.contains(name)) {
         return _PrimitiveDartType.int;
       } else if (_primitiveDoubleNativeTypes.contains(name)) {
@@ -698,7 +698,7 @@
     List<Annotation> extraAnnotations = [];
     for (Annotation annotation in annotations) {
       if (annotation.element.ffiClass != null ||
-          annotation.element?.enclosingElement.isAbiSpecificIntegerSubclass ==
+          annotation.element?.enclosingElement2.isAbiSpecificIntegerSubclass ==
               true) {
         if (requiredFound) {
           extraAnnotations.add(annotation);
@@ -1243,7 +1243,7 @@
     final element = this.element;
     return element is ConstructorElement &&
         element.ffiClass != null &&
-        element.enclosingElement.name ==
+        element.enclosingElement2.name ==
             FfiVerifier._abiSpecificIntegerMappingClassName;
   }
 
@@ -1251,21 +1251,21 @@
     final element = this.element;
     return element is ConstructorElement &&
         element.ffiClass != null &&
-        element.enclosingElement.name == 'Array';
+        element.enclosingElement2.name == 'Array';
   }
 
   bool get isFfiNative {
     final element = this.element;
     return element is ConstructorElement &&
         element.ffiClass != null &&
-        element.enclosingElement.name == 'FfiNative';
+        element.enclosingElement2.name == 'FfiNative';
   }
 
   bool get isPacked {
     final element = this.element;
     return element is ConstructorElement &&
         element.ffiClass != null &&
-        element.enclosingElement.name == 'Packed';
+        element.enclosingElement2.name == 'Packed';
   }
 }
 
@@ -1309,7 +1309,7 @@
     final element = this.element;
     return element is ConstructorElement &&
         element.ffiClass != null &&
-        element.enclosingElement.name == 'Array';
+        element.enclosingElement2.name == 'Array';
     // Note: this is 'Array' instead of '_ArraySize' because it finds the
     // forwarding factory instead of the forwarded constructor.
   }
@@ -1318,7 +1318,7 @@
     final element = this.element;
     return element is ConstructorElement &&
         element.ffiClass != null &&
-        element.enclosingElement.name == 'Packed';
+        element.enclosingElement2.name == 'Packed';
   }
 
   int? get packedMemberAlignment {
@@ -1333,7 +1333,7 @@
   ClassElement? get ffiClass {
     var element = this;
     if (element is ConstructorElement) {
-      element = element.enclosingElement;
+      element = element.enclosingElement2;
     }
     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 d11f10f..f4793da 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -3605,7 +3605,7 @@
       if (node.inSetterContext()) {
         _localVariableInfo.potentiallyMutatedInScope.add(element);
         if (_enclosingClosure != null &&
-            element.enclosingElement != _enclosingClosure) {
+            element.enclosingElement2 != _enclosingClosure) {
           _localVariableInfo.potentiallyMutatedInClosure.add(element);
         }
       }
diff --git a/pkg/analyzer/lib/src/lint/linter.dart b/pkg/analyzer/lib/src/lint/linter.dart
index 275cde4..1541169 100644
--- a/pkg/analyzer/lib/src/lint/linter.dart
+++ b/pkg/analyzer/lib/src/lint/linter.dart
@@ -338,7 +338,7 @@
   bool canBeConstConstructor(covariant ConstructorDeclarationImpl node) {
     var element = node.declaredElement!;
 
-    ClassElement classElement = element.enclosingElement;
+    ClassElement classElement = element.enclosingElement2;
     if (classElement.hasNonFinalField) return false;
 
     var oldKeyword = node.constKeyword;
diff --git a/pkg/analyzer/lib/src/summary2/bundle_reader.dart b/pkg/analyzer/lib/src/summary2/bundle_reader.dart
index a19950d..9467514 100644
--- a/pkg/analyzer/lib/src/summary2/bundle_reader.dart
+++ b/pkg/analyzer/lib/src/summary2/bundle_reader.dart
@@ -200,7 +200,7 @@
     ResolutionReader reader,
     ElementImpl element,
   ) {
-    var enclosing = element.enclosingElement;
+    var enclosing = element.enclosingElement2;
     if (enclosing is ClassElement) {
       reader._addTypeParameters(enclosing.typeParameters);
     } else if (enclosing is CompilationUnitElement) {
@@ -268,7 +268,7 @@
   @override
   void _read(element, reader) {
     element.metadata = reader._readAnnotationList(
-      unitElement: element.enclosingElement,
+      unitElement: element.enclosingElement2,
     );
     _readTypeParameters(reader, element.typeParameters);
     element.supertype = reader._readOptionalInterfaceType();
@@ -292,7 +292,7 @@
   @override
   void _read(element, reader) {
     element.metadata = reader._readAnnotationList(
-      unitElement: element.enclosingElement,
+      unitElement: element.enclosingElement2,
     );
     _readTypeParameters(reader, element.typeParameters);
     element.extendedType = reader.readRequiredType();
@@ -1550,7 +1550,7 @@
   @override
   void _read(element, reader) {
     element.metadata = reader._readAnnotationList(
-      unitElement: element.enclosingElement,
+      unitElement: element.enclosingElement2,
     );
     _readTypeParameters(reader, element.typeParameters);
     element.superclassConstraints = reader._readInterfaceTypeList();
@@ -1634,7 +1634,7 @@
       // TODO(scheglov) why to check for empty? If we have this flags.
       if (arguments.isNotEmpty) {
         var typeParameters =
-            (element.enclosingElement as TypeParameterizedElement)
+            (element.enclosingElement2 as TypeParameterizedElement)
                 .typeParameters;
         var substitution = Substitution.fromPairs(typeParameters, arguments);
         element =
diff --git a/pkg/analyzer/lib/src/summary2/bundle_writer.dart b/pkg/analyzer/lib/src/summary2/bundle_writer.dart
index e3364eb..004008b 100644
--- a/pkg/analyzer/lib/src/summary2/bundle_writer.dart
+++ b/pkg/analyzer/lib/src/summary2/bundle_writer.dart
@@ -847,7 +847,7 @@
       return const [];
     }
 
-    var enclosing = declaration.enclosingElement;
+    var enclosing = declaration.enclosingElement2;
     if (enclosing is TypeParameterizedElement) {
       if (enclosing is! ClassElement && enclosing is! ExtensionElement) {
         return const <DartType>[];
diff --git a/pkg/analyzer/lib/src/summary2/macro_declarations.dart b/pkg/analyzer/lib/src/summary2/macro_declarations.dart
index bfe0b62..8a7f6e6 100644
--- a/pkg/analyzer/lib/src/summary2/macro_declarations.dart
+++ b/pkg/analyzer/lib/src/summary2/macro_declarations.dart
@@ -110,7 +110,7 @@
 
   FieldDeclarationImpl _fieldElement(FieldElement element) {
     assert(!_fieldMap.containsKey(element));
-    final enclosingClass = element.enclosingElement as ClassElement;
+    final enclosingClass = element.enclosingElement2 as ClassElement;
     return FieldDeclarationImpl(
       id: macro.RemoteInstance.uniqueId,
       identifier: identifier(element),
diff --git a/pkg/analyzer/lib/src/summary2/top_level_inference.dart b/pkg/analyzer/lib/src/summary2/top_level_inference.dart
index d9e2f98..dd7cae3 100644
--- a/pkg/analyzer/lib/src/summary2/top_level_inference.dart
+++ b/pkg/analyzer/lib/src/summary2/top_level_inference.dart
@@ -174,7 +174,7 @@
       }
     }
 
-    var classElement = _constructor.enclosingElement;
+    var classElement = _constructor.enclosingElement2;
     if (classElement.isMixinApplication) {
       var superType = classElement.supertype;
       if (superType != null) {
@@ -285,7 +285,7 @@
 
     _set.add(element);
 
-    if (element.enclosingElement.typeParameters.isNotEmpty) {
+    if (element.enclosingElement2.typeParameters.isNotEmpty) {
       node.argumentList.accept(this);
     }
   }
@@ -526,7 +526,7 @@
   }
 
   void _resolveInitializer({required bool forDependencies}) {
-    var enclosingElement = _element.enclosingElement;
+    var enclosingElement = _element.enclosingElement2;
     var enclosingClassElement =
         enclosingElement is ClassElement ? enclosingElement : null;
     var astResolver = AstResolver(_walker._linker, _unitElement, _scope,
diff --git a/pkg/analyzer/lib/src/task/strong_mode.dart b/pkg/analyzer/lib/src/task/strong_mode.dart
index bd67df2..038c167 100644
--- a/pkg/analyzer/lib/src/task/strong_mode.dart
+++ b/pkg/analyzer/lib/src/task/strong_mode.dart
@@ -424,7 +424,7 @@
           var conflict = conflicts.single;
           if (conflict is CandidatesConflict) {
             conflictExplanation = conflict.candidates.map((candidate) {
-              var className = candidate.enclosingElement.name;
+              var className = candidate.enclosingElement2.name;
               var typeStr = candidate.type.getDisplayString(
                 withNullability: typeSystem.isNonNullableByDefault,
               );
@@ -540,7 +540,7 @@
       overridden = overridden.declaration;
 
       // Skip Object itself.
-      var enclosingElement = overridden.enclosingElement;
+      var enclosingElement = overridden.enclosingElement2;
       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 18dec74..6574c92 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.enclosingElement2;
   if (enclosingElement is CompilationUnitElement) {
     var memberName = element.name!;
     if (element is PropertyAccessorElement && element.isSetter) {
diff --git a/pkg/analyzer/test/generated/element_resolver_test.dart b/pkg/analyzer/test/generated/element_resolver_test.dart
index d34a268..ae995c2 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.enclosingElement2, 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.enclosingElement2, 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.enclosingElement2, 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.enclosingElement2, 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.enclosingElement2, 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.enclosingElement2, 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.enclosingElement2, 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.enclosingElement2, isCompilationUnitElement);
         expect(annotationElement.displayName, 'V');
       } else {
         fail('Expected "annotationElement" is PropertyAccessorElement, '
diff --git a/pkg/analyzer/test/generated/non_error_resolver_test.dart b/pkg/analyzer/test/generated/non_error_resolver_test.dart
index 66ec302..21ddaaf 100644
--- a/pkg/analyzer/test/generated/non_error_resolver_test.dart
+++ b/pkg/analyzer/test/generated/non_error_resolver_test.dart
@@ -1458,7 +1458,7 @@
 ''');
     var x = findNode.namedExpression('arg: true');
     var y = x.staticParameterElement!;
-    expect(y.enclosingElement, isNotNull);
+    expect(y.enclosingElement2, 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.enclosingElement2, isNotNull);
     expect(y.declaration, findElement.parameter('arg'));
   }
 
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index 1ccc8bb..86cbe1c 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -74,7 +74,7 @@
 
     var constructor = findElement.unnamedConstructor('C');
     var x = findElement.localFunction('x');
-    expect(x.enclosingElement, constructor);
+    expect(x.enclosingElement2, constructor);
   }
 }
 
diff --git a/pkg/analyzer/test/id_tests/inheritance_test.dart b/pkg/analyzer/test/id_tests/inheritance_test.dart
index 8e08527..8dc008f 100644
--- a/pkg/analyzer/test/id_tests/inheritance_test.dart
+++ b/pkg/analyzer/test/id_tests/inheritance_test.dart
@@ -102,7 +102,7 @@
       for (var name in interface.map.keys) {
         var executable = interface.map[name]!;
 
-        var enclosingClass = executable.enclosingElement as ClassElement;
+        var enclosingClass = executable.enclosingElement2 as ClassElement;
         if (enclosingClass.isDartCoreObject) continue;
 
         var id = MemberId.internal(
diff --git a/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart b/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart
index f1e8277..3a0d6d5 100644
--- a/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart
@@ -978,7 +978,7 @@
           forInvocation.argumentList.arguments[0] as FunctionExpression;
 
       var closureElement = closure.declaredElement as FunctionElementImpl;
-      expect(closureElement.enclosingElement, same(mainElement));
+      expect(closureElement.enclosingElement2, same(mainElement));
 
       ParameterElement itemElement = closureElement.parameters[0];
       itemElement1 = itemElement;
@@ -1019,7 +1019,7 @@
           forInvocation.argumentList.arguments[0] as FunctionExpression;
 
       var closureElement = closure.declaredElement as FunctionElementImpl;
-      expect(closureElement.enclosingElement, same(mainElement));
+      expect(closureElement.enclosingElement2, same(mainElement));
 
       ParameterElement itemElement = closureElement.parameters[0];
       expect(itemElement, isNot(same(itemElement1)));
@@ -1062,7 +1062,7 @@
     assertType(closure, 'List<T> Function<T>()');
 
     var closureElement = closure.declaredElement as FunctionElementImpl;
-    expect(closureElement.enclosingElement, findElement.function('main'));
+    expect(closureElement.enclosingElement2, findElement.function('main'));
     assertType(closureElement.returnType, 'List<T>');
     expect(closureElement.parameters, isEmpty);
 
@@ -1708,7 +1708,7 @@
 
     var methodElement = invocation.methodName.staticElement as MethodElement;
     expect(methodElement.name, 'toString');
-    expect(methodElement.enclosingElement, same(objectElement));
+    expect(methodElement.enclosingElement2, same(objectElement));
   }
 
   test_error_unresolvedTypeAnnotation() async {
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 4840c69..eb4f3fb 100644
--- a/pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart
+++ b/pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart
@@ -1416,7 +1416,7 @@
 
   void _assertExecutable(ExecutableElement? element, String? expected) {
     if (expected != null && element != null) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement2;
 
       var type = element.type;
       var typeStr = typeString(type);
@@ -1426,7 +1426,7 @@
 
       if (element is PropertyAccessorElement) {
         var variable = element.variable;
-        expect(variable.enclosingElement, same(element.enclosingElement));
+        expect(variable.enclosingElement2, same(element.enclosingElement2));
         expect(variable.name, element.displayName);
         if (element.isGetter) {
           expect(variable.type, element.returnType);
@@ -1508,7 +1508,7 @@
       var element = entry.value;
       var type = element.type;
 
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement2;
       if (enclosingElement.name == 'Object') continue;
 
       var typeStr = type.getDisplayString(withNullability: false);
diff --git a/pkg/analyzer/test/src/dart/resolution/resolution.dart b/pkg/analyzer/test/src/dart/resolution/resolution.dart
index 7ff2297..0872e4c 100644
--- a/pkg/analyzer/test/src/dart/resolution/resolution.dart
+++ b/pkg/analyzer/test/src/dart/resolution/resolution.dart
@@ -214,7 +214,7 @@
   }
 
   void assertEnclosingElement(Element element, Element expectedEnclosing) {
-    expect(element.enclosingElement, expectedEnclosing);
+    expect(element.enclosingElement2, expectedEnclosing);
   }
 
   Future<void> assertErrorsInCode(
@@ -500,7 +500,7 @@
   ) {
     var actualMapString = Map.fromEntries(
       substitution.map.entries.where((entry) {
-        return entry.key.enclosingElement is! ExecutableElement;
+        return entry.key.enclosingElement2 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 df511ab..87e173b 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
@@ -64,8 +64,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!.enclosingElement2.name,
+          'num');
     } else {
       await assertErrorsInCode(code, [
         error(HintCode.UNUSED_LOCAL_VARIABLE, 32, 1),
@@ -130,7 +130,7 @@
     assertType(findElement.localVar('a').type, _isEnabled ? 'int' : 'dynamic');
     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?.enclosingElement2.name,
         _isEnabled ? 'num' : null);
   }
 
@@ -294,7 +294,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!.enclosingElement2.name, 'num');
   }
 
   test_horizontal_inference_unnecessary_due_to_explicit_parameter_type_named() async {
@@ -311,7 +311,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!.enclosingElement2.name, 'num');
   }
 
   test_horizontal_inference_unnecessary_due_to_no_dependency() async {
diff --git a/pkg/analyzer/test/src/summary/element_text.dart b/pkg/analyzer/test/src/summary/element_text.dart
index 314b7e6..523f45b 100644
--- a/pkg/analyzer/test/src/summary/element_text.dart
+++ b/pkg/analyzer/test/src/summary/element_text.dart
@@ -194,8 +194,8 @@
 
     expect(accessor.variable, same(property));
 
-    var propertyEnclosing = property.enclosingElement;
-    expect(accessor.enclosingElement, same(propertyEnclosing));
+    var propertyEnclosing = property.enclosingElement2;
+    expect(accessor.enclosingElement2, same(propertyEnclosing));
 
     if (propertyEnclosing is CompilationUnitElement) {
       expect(propertyEnclosing.accessors, contains(accessor));
@@ -373,7 +373,7 @@
       var classReference = reference.parent!.parent!;
       // We need this `if` for duplicate declarations.
       // The reference might be filled by another declaration.
-      if (identical(classReference.element, e.enclosingElement)) {
+      if (identical(classReference.element, e.enclosingElement2)) {
         expect(reference.element, same(e));
       }
     }
@@ -410,7 +410,7 @@
 
       var superConstructor = e.superConstructor;
       if (superConstructor != null) {
-        if (!superConstructor.enclosingElement.isDartCoreObject) {
+        if (!superConstructor.enclosingElement2.isDartCoreObject) {
           _writeElementReference('superConstructor', superConstructor);
         }
       }
@@ -428,7 +428,7 @@
 
     if (e.isSynthetic) {
       expect(e.nameOffset, -1);
-      expect(e.nonSynthetic, same(e.enclosingElement));
+      expect(e.nonSynthetic, same(e.enclosingElement2));
     } else {
       if (!e.isTempAugmentation) {
         expect(e.nameOffset, isPositive);
@@ -674,9 +674,9 @@
       _writeNonSyntheticElement(e);
     });
 
-    if (e.isSynthetic && e.enclosingElement is EnumElementImpl) {
+    if (e.isSynthetic && e.enclosingElement2 is EnumElementImpl) {
       expect(e.name, 'toString');
-      expect(e.nonSynthetic, same(e.enclosingElement));
+      expect(e.nonSynthetic, same(e.enclosingElement2));
     } else {
       _assertNonSyntheticElementSelf(e);
     }
@@ -781,7 +781,7 @@
     PropertyInducingElement variable = e.variable;
     expect(variable, isNotNull);
 
-    var variableEnclosing = variable.enclosingElement;
+    var variableEnclosing = variable.enclosingElement2;
     if (variableEnclosing is CompilationUnitElement) {
       expect(variableEnclosing.topLevelVariables, contains(variable));
     } else if (variableEnclosing is ClassElement) {
diff --git a/pkg/analyzer/test/src/summary/elements_test.dart b/pkg/analyzer/test/src/summary/elements_test.dart
index 6742fe3..c80647b 100644
--- a/pkg/analyzer/test/src/summary/elements_test.dart
+++ b/pkg/analyzer/test/src/summary/elements_test.dart
@@ -21975,14 +21975,14 @@
 
     var T = F.typeParameters[0];
     expect(T.name, 'T');
-    expect(T.enclosingElement, same(F));
+    expect(T.enclosingElement2, same(F));
 
     var function = F.aliasedElement as GenericFunctionTypeElement;
-    expect(function.enclosingElement, same(F));
+    expect(function.enclosingElement2, same(F));
 
     var a = function.parameters[0];
     expect(a.name, 'a');
-    expect(a.enclosingElement, same(function));
+    expect(a.enclosingElement2, same(function));
   }
 
   test_functionTypeAlias_type_element() async {
@@ -23147,18 +23147,18 @@
 
     var T = F.typeParameters[0];
     expect(T.name, 'T');
-    expect(T.enclosingElement, same(F));
+    expect(T.enclosingElement2, same(F));
 
     var function = F.aliasedElement as GenericFunctionTypeElement;
-    expect(function.enclosingElement, same(F));
+    expect(function.enclosingElement2, same(F));
 
     var U = function.typeParameters[0];
     expect(U.name, 'U');
-    expect(U.enclosingElement, same(function));
+    expect(U.enclosingElement2, same(function));
 
     var a = function.parameters[0];
     expect(a.name, 'a');
-    expect(a.enclosingElement, same(function));
+    expect(a.enclosingElement2, same(function));
   }
 
   test_genericTypeAlias_recursive() async {
@@ -26333,7 +26333,7 @@
 
     final import_0 = library.augmentationImports[0];
     final augmentation = import_0.importedAugmentation!;
-    expect(augmentation.enclosingElement, same(library));
+    expect(augmentation.enclosingElement2, same(library));
   }
 
   test_library_augmentationImports_noRelativeUriStr() async {
diff --git a/pkg/analyzer/test/src/summary/resolved_ast_printer.dart b/pkg/analyzer/test/src/summary/resolved_ast_printer.dart
index 52d0d26..7dae515 100644
--- a/pkg/analyzer/test/src/summary/resolved_ast_printer.dart
+++ b/pkg/analyzer/test/src/summary/resolved_ast_printer.dart
@@ -1285,7 +1285,7 @@
   }
 
   String _elementToReferenceString(Element element) {
-    final enclosingElement = element.enclosingElement;
+    final enclosingElement = element.enclosingElement2;
     final 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 73f7454..edba42a 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
@@ -692,7 +692,7 @@
 
   @override
   void writeReference(Element element) {
-    if (element.enclosingElement is CompilationUnitElement) {
+    if (element.enclosingElement2 is CompilationUnitElement) {
       _writeLibraryReference(element);
     }
     write(element.displayName);
@@ -1111,10 +1111,10 @@
     if (type is TypeParameterType) {
       _initializeEnclosingElements();
       var element = type.element;
-      var enclosing = element.enclosingElement;
+      var enclosing = element.enclosingElement2;
       while (enclosing is GenericFunctionTypeElement ||
           enclosing is ParameterElement) {
-        enclosing = enclosing!.enclosingElement;
+        enclosing = enclosing!.enclosingElement2;
       }
       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..e0a02d4 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.enclosingElement2 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 e452d3d..f3446c6 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.enclosingElement2;
     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 eb3d905..8d281e6 100644
--- a/pkg/analyzer_plugin/lib/utilities/analyzer_converter.dart
+++ b/pkg/analyzer_plugin/lib/utilities/analyzer_converter.dart
@@ -225,7 +225,7 @@
         // so should it return isEnumConstant = true?
         // Or should we return ElementKind.ENUM_CONSTANT here
         // in either or both of these cases?
-        element.type.element == element.enclosingElement) {
+        element.type.element == element.enclosingElement2) {
       return plugin.ElementKind.ENUM_CONSTANT;
     }
     return convertElementKind(element.kind);
@@ -324,15 +324,15 @@
     if (currentElement is analyzer.CompilationUnitElement) {
       return currentElement;
     }
-    if (currentElement.enclosingElement is analyzer.LibraryElement) {
-      currentElement = currentElement.enclosingElement;
+    if (currentElement.enclosingElement2 is analyzer.LibraryElement) {
+      currentElement = currentElement.enclosingElement2;
     }
     if (currentElement is analyzer.LibraryElement) {
       return currentElement.definingCompilationUnit;
     }
     for (;
         currentElement != null;
-        currentElement = currentElement.enclosingElement) {
+        currentElement = currentElement.enclosingElement2) {
       if (currentElement is analyzer.CompilationUnitElement) {
         return currentElement;
       }
diff --git a/pkg/analyzer_plugin/lib/utilities/navigation/navigation_dart.dart b/pkg/analyzer_plugin/lib/utilities/navigation/navigation_dart.dart
index de32a21..c58c3e2 100644
--- a/pkg/analyzer_plugin/lib/utilities/navigation/navigation_dart.dart
+++ b/pkg/analyzer_plugin/lib/utilities/navigation/navigation_dart.dart
@@ -146,7 +146,7 @@
   void visitAnnotation(Annotation node) {
     var element = node.element;
     if (element is ConstructorElement && element.isSynthetic) {
-      element = element.enclosingElement;
+      element = element.enclosingElement2;
     }
     var name = node.name;
     if (name is PrefixedIdentifier) {
@@ -434,7 +434,7 @@
       RedirectingConstructorInvocation node) {
     Element? element = node.staticElement;
     if (element != null && element.isSynthetic) {
-      element = element.enclosingElement;
+      element = element.enclosingElement2;
     }
     // add region
     computer._addRegionForToken(node.thisKeyword, element);
@@ -453,7 +453,7 @@
   void visitSuperConstructorInvocation(SuperConstructorInvocation node) {
     Element? element = node.staticElement;
     if (element != null && element.isSynthetic) {
-      element = element.enclosingElement;
+      element = element.enclosingElement2;
     }
     // 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 c48664f..3613ca6 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.enclosingElement2;
     if (executableEnclosing is CompilationUnitElement) {
       return executable.name;
     } else if (executable is ConstructorElement) {
diff --git a/pkg/analyzer_plugin/test/utilities/analyzer_converter_test.dart b/pkg/analyzer_plugin/test/utilities/analyzer_converter_test.dart
index 87403be..612c664 100644
--- a/pkg/analyzer_plugin/test/utilities/analyzer_converter_test.dart
+++ b/pkg/analyzer_plugin/test/utilities/analyzer_converter_test.dart
@@ -325,7 +325,7 @@
       expect(element.parameters, isNull);
       expect(element.returnType, '_E1');
       // TODO(danrubel) determine why enum constant is not marked as deprecated
-      //analyzer.ClassElement classElement = engineElement.enclosingElement;
+      //analyzer.ClassElement classElement = engineElement.enclosingElement2;
       //expect(classElement.isDeprecated, isTrue);
       expect(
           element.flags,
diff --git a/pkg/nnbd_migration/lib/instrumentation.dart b/pkg/nnbd_migration/lib/instrumentation.dart
index 4326006..62ecd1f 100644
--- a/pkg/nnbd_migration/lib/instrumentation.dart
+++ b/pkg/nnbd_migration/lib/instrumentation.dart
@@ -37,7 +37,7 @@
   factory CodeReference.fromElement(Element element) {
     var unitElement = element.thisOrAncestorOfType<CompilationUnitElement>();
     if (unitElement == null) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement2;
       if (enclosingElement is LibraryElement) {
         unitElement = enclosingElement.definingCompilationUnit;
       } else {
@@ -76,7 +76,7 @@
       if (elementName != null) {
         parts.add(elementName);
       }
-      element = element.enclosingElement;
+      element = element.enclosingElement2;
     }
     if (parts.isEmpty) return null;
     return parts.reversed.join('.');
diff --git a/pkg/nnbd_migration/lib/src/decorated_type.dart b/pkg/nnbd_migration/lib/src/decorated_type.dart
index 3139e2a..33556b2 100644
--- a/pkg/nnbd_migration/lib/src/decorated_type.dart
+++ b/pkg/nnbd_migration/lib/src/decorated_type.dart
@@ -184,8 +184,8 @@
     // We'll be storing the type parameter bounds in
     // [_decoratedTypeParameterBounds] so the type parameter needs to have an
     // enclosing element of `null`.
-    assert(parameter.enclosingElement == null,
-        '$parameter should not have parent ${parameter.enclosingElement}');
+    assert(parameter.enclosingElement2 == null,
+        '$parameter should not have parent ${parameter.enclosingElement2}');
   }
 
   /// If `this` represents an interface type, returns the substitution necessary
@@ -415,7 +415,7 @@
             Map<TypeParameterElement, DecoratedType>.from(substitution);
         for (int i = 0; i < typeFormals.length; i++) {
           // Check if it's a fresh type variable.
-          if (undecoratedResult.typeFormals[i].enclosingElement == null) {
+          if (undecoratedResult.typeFormals[i].enclosingElement2 == null) {
             substitution[typeFormals[i]] =
                 DecoratedType._forTypeParameterSubstitution(
                     undecoratedResult.typeFormals[i]);
@@ -542,7 +542,7 @@
   final _parentedBounds = <TypeParameterElement, DecoratedType?>{};
 
   DecoratedType? get(TypeParameterElement element) {
-    if (element.enclosingElement == null) {
+    if (element.enclosingElement2 == null) {
       return _orphanBounds[element];
     } else {
       return _parentedBounds[element];
@@ -550,7 +550,7 @@
   }
 
   void put(TypeParameterElement element, DecoratedType? bounds) {
-    if (element.enclosingElement == null) {
+    if (element.enclosingElement2 == null) {
       _orphanBounds[element] = bounds;
     } else {
       _parentedBounds[element] = bounds;
diff --git a/pkg/nnbd_migration/lib/src/edge_builder.dart b/pkg/nnbd_migration/lib/src/edge_builder.dart
index a77e967..d992ce5 100644
--- a/pkg/nnbd_migration/lib/src/edge_builder.dart
+++ b/pkg/nnbd_migration/lib/src/edge_builder.dart
@@ -279,7 +279,7 @@
     Map<TypeParameterElement, DecoratedType?>? substitution;
     Element? baseElement = element.declaration;
     if (targetType != null) {
-      var enclosingElement = baseElement!.enclosingElement;
+      var enclosingElement = baseElement!.enclosingElement2;
       if (enclosingElement is ClassElement) {
         if (targetType.type.explicitBound is InterfaceType &&
             enclosingElement.typeParameters.isNotEmpty) {
@@ -473,8 +473,8 @@
       var assignee =
           getWriteOrReadElement(node.leftHandSide as SimpleIdentifier)!;
       var enclosingElementOfCurrentFunction =
-          _currentFunctionExpression!.declaredElement!.enclosingElement;
-      if (enclosingElementOfCurrentFunction == assignee.enclosingElement) {
+          _currentFunctionExpression!.declaredElement!.enclosingElement2;
+      if (enclosingElementOfCurrentFunction == assignee.enclosingElement2) {
         // [node]'s enclosing function is a function expression passed directly
         // to a call to the test package's `setUp` function, and [node] is an
         // assignment to a variable declared in the same scope as the call to
@@ -840,7 +840,7 @@
         // Nothing to do; assume the implicit default value of `null` will never
         // be reached.
       } else {
-        var enclosingElement = declaredElement.enclosingElement;
+        var enclosingElement = declaredElement.enclosingElement2;
         if (enclosingElement is ConstructorElement &&
             enclosingElement.isFactory &&
             enclosingElement.redirectedConstructor != null) {
@@ -1206,7 +1206,7 @@
   DecoratedType visitInstanceCreationExpression(
       InstanceCreationExpression node) {
     var callee = node.constructorName.staticElement!;
-    var typeParameters = callee.enclosingElement.typeParameters;
+    var typeParameters = callee.enclosingElement2.typeParameters;
     Iterable<DartType?> typeArgumentTypes;
     List<DecoratedType> decoratedTypeArguments;
     var typeArguments = node.constructorName.type.typeArguments;
@@ -1387,7 +1387,7 @@
       } else {
         targetType = _handleTarget(target, node.methodName.name, callee);
       }
-    } else if (target == null && callee!.enclosingElement is ClassElement) {
+    } else if (target == null && callee!.enclosingElement2 is ClassElement) {
       targetType = _thisOrSuper(node);
       _checkThisNotNull(targetType, node);
     }
@@ -1794,13 +1794,13 @@
     } else if (staticElement is FunctionElement ||
         staticElement is MethodElement ||
         staticElement is ConstructorElement) {
-      if (staticElement!.enclosingElement is ClassElement) {
+      if (staticElement!.enclosingElement2 is ClassElement) {
         targetType = _thisOrSuper(node);
       }
       result =
           getOrComputeElementType(node, staticElement, targetType: targetType);
     } else if (staticElement is PropertyAccessorElement) {
-      if (staticElement.enclosingElement is ClassElement) {
+      if (staticElement.enclosingElement2 is ClassElement) {
         targetType = _thisOrSuper(node);
       }
       var elementType =
@@ -1815,8 +1815,8 @@
     } else if (staticElement == null) {
       assert(node.toString() == 'void', "${node.toString()} != 'void'");
       result = _makeNullableVoidType(node);
-    } else if (staticElement.enclosingElement is ClassElement &&
-        (staticElement.enclosingElement as ClassElement).isEnum) {
+    } else if (staticElement.enclosingElement2 is ClassElement &&
+        (staticElement.enclosingElement2 as ClassElement).isEnum) {
       result = getOrComputeElementType(node, staticElement);
     } else {
       // TODO(paulberry)
@@ -1882,7 +1882,7 @@
     var nullabilityNode = NullabilityNode.forInferredType(target);
     var class_ = node.thisOrAncestorOfType<ClassDeclaration>()!;
     var decoratedSupertype = _decoratedClassHierarchy!.getDecoratedSupertype(
-        class_.declaredElement!, callee.enclosingElement);
+        class_.declaredElement!, callee.enclosingElement2);
     var typeArguments = decoratedSupertype.typeArguments;
     Iterable<DartType?> typeArgumentTypes;
     typeArgumentTypes = typeArguments.map((t) => t!.type);
@@ -1890,7 +1890,7 @@
         typeArguments: typeArguments);
     var calleeType =
         getOrComputeElementType(node, callee, targetType: createdType);
-    var constructorTypeParameters = callee.enclosingElement.typeParameters;
+    var constructorTypeParameters = callee.enclosingElement2.typeParameters;
 
     _handleInvocationArguments(
         node,
@@ -1998,7 +1998,7 @@
         }
       }
       var type = _variables!.decoratedElementType(declaredElement);
-      var enclosingElement = declaredElement.enclosingElement;
+      var enclosingElement = declaredElement.enclosingElement2;
       if (!declaredElement.isStatic && enclosingElement is ClassElement) {
         var overriddenElements = _inheritanceManager.getOverridden2(
             enclosingElement,
@@ -2562,7 +2562,7 @@
   void _handleConstructorRedirection(
       FormalParameterList parameters, ConstructorName redirectedConstructor) {
     var callee = redirectedConstructor.staticElement!.declaration;
-    var redirectedClass = callee.enclosingElement;
+    var redirectedClass = callee.enclosingElement2;
     var calleeType = _variables!.decoratedElementType(callee);
     var typeArguments = redirectedConstructor.type.typeArguments;
     var typeArgumentTypes =
@@ -2581,7 +2581,7 @@
     if (node.argumentList.arguments.isNotEmpty &&
         callee is ExecutableElement &&
         callee.isStatic) {
-      var enclosingElement = callee.enclosingElement;
+      var enclosingElement = callee.enclosingElement2;
       if (enclosingElement is ClassElement) {
         if (callee.name == 'checkNotNull' &&
                 enclosingElement.name == 'ArgumentError' &&
@@ -2624,7 +2624,7 @@
     _addParametersToFlowAnalysis(parameters);
     // Push a scope of post-dominated declarations on the stack.
     _postDominatedLocals.pushScope(elements: declaredElement.parameters);
-    if (declaredElement.enclosingElement is ExtensionElement) {
+    if (declaredElement.enclosingElement2 is ExtensionElement) {
       _postDominatedLocals.add(_extensionThis);
     }
     try {
@@ -2639,7 +2639,7 @@
         _handleConstructorRedirection(parameters!, redirectedConstructor);
       }
       if (declaredElement is! ConstructorElement) {
-        var enclosingElement = declaredElement.enclosingElement;
+        var enclosingElement = declaredElement.enclosingElement2;
         if (enclosingElement is ClassElement) {
           var overriddenElements = _inheritanceManager.getOverridden2(
               enclosingElement,
@@ -2725,7 +2725,7 @@
       ClassElement classElement,
       Element overriddenElement) {
     overriddenElement = overriddenElement.declaration!;
-    var overriddenClass = overriddenElement.enclosingElement as ClassElement;
+    var overriddenClass = overriddenElement.enclosingElement2 as ClassElement;
     var decoratedSupertype = _decoratedClassHierarchy!
         .getDecoratedSupertype(classElement, overriddenClass);
     var substitution = decoratedSupertype.asSubstitution;
@@ -2826,7 +2826,7 @@
       ClassElement classElement,
       Element overriddenElement) {
     overriddenElement = overriddenElement.declaration!;
-    var overriddenClass = overriddenElement.enclosingElement as ClassElement;
+    var overriddenClass = overriddenElement.enclosingElement2 as ClassElement;
     var decoratedSupertype = _decoratedClassHierarchy!
         .getDecoratedSupertype(classElement, overriddenClass);
     var substitution = decoratedSupertype.asSubstitution;
@@ -2958,13 +2958,13 @@
     Map<TypeParameterElement, DecoratedType?> getterSubstitution = const {};
     Map<TypeParameterElement, DecoratedType?> setterSubstitution = const {};
     if (class_ != null) {
-      var getterClass = getter.enclosingElement as ClassElement;
+      var getterClass = getter.enclosingElement2 as ClassElement;
       if (!identical(class_, getterClass)) {
         getterSubstitution = _decoratedClassHierarchy!
             .getDecoratedSupertype(class_, getterClass)
             .asSubstitution;
       }
-      var setterClass = setter.enclosingElement as ClassElement;
+      var setterClass = setter.enclosingElement2 as ClassElement;
       if (!identical(class_, setterClass)) {
         setterSubstitution = _decoratedClassHierarchy!
             .getDecoratedSupertype(class_, setterClass)
@@ -3218,7 +3218,7 @@
     if (isDeclaredOnObject(name)) {
       return _dispatch(target);
     } else if ((callee is MethodElement || callee is PropertyAccessorElement) &&
-        callee!.enclosingElement is ExtensionElement) {
+        callee!.enclosingElement2 is ExtensionElement) {
       // Extension methods can be called on a `null` target, when the `on` type
       // of the extension is nullable.  Note: we don't need to check whether the
       // target type is assignable to the extended type; that is done in
diff --git a/pkg/nnbd_migration/lib/src/fix_builder.dart b/pkg/nnbd_migration/lib/src/fix_builder.dart
index 0f2f6ac..b4c14e7 100644
--- a/pkg/nnbd_migration/lib/src/fix_builder.dart
+++ b/pkg/nnbd_migration/lib/src/fix_builder.dart
@@ -467,7 +467,7 @@
           return variable.typeInternal;
         }
         if (variable is ParameterElement) {
-          var enclosingElement = variable.enclosingElement;
+          var enclosingElement = variable.enclosingElement2;
           if (enclosingElement is PropertyAccessorElement &&
               enclosingElement.isSynthetic) {
             // This is the parameter of a synthetic getter, so it has the same
@@ -503,7 +503,7 @@
   /// on a nullable type without introducing a null check).
   bool isNullableExtensionMember(Element? element) {
     if (element != null) {
-      var enclosingElement = element.enclosingElement;
+      var enclosingElement = element.enclosingElement2;
       if (enclosingElement is ExtensionElement) {
         return _fixBuilder!._typeSystem
             .isPotentiallyNullable(enclosingElement.extendedType);
@@ -1223,7 +1223,7 @@
       var nullabilityNode =
           _fixBuilder._variables!.decoratedElementType(element!).node!;
       if (!nullabilityNode.isNullable) {
-        var enclosingElement = element.enclosingElement;
+        var enclosingElement = element.enclosingElement2;
         if (enclosingElement is ConstructorElement &&
             enclosingElement.isFactory &&
             enclosingElement.redirectedConstructor != null &&
@@ -1336,8 +1336,8 @@
     // Change an existing `@required` annotation into a `required` keyword if
     // possible.
     final element = parameter.declaredElement!;
-    final method = element.enclosingElement!;
-    final cls = method.enclosingElement!;
+    final method = element.enclosingElement2!;
+    final cls = method.enclosingElement2!;
     var info = AtomicEditInfo(
         NullabilityFixDescription.addRequired(
             cls.name, method.name, element.name),
diff --git a/pkg/nnbd_migration/lib/src/node_builder.dart b/pkg/nnbd_migration/lib/src/node_builder.dart
index e9b8d09..7ac2f62 100644
--- a/pkg/nnbd_migration/lib/src/node_builder.dart
+++ b/pkg/nnbd_migration/lib/src/node_builder.dart
@@ -707,7 +707,7 @@
     for (var annotation in metadata) {
       var element = annotation.element;
       if (element is ConstructorElement) {
-        var name = element.enclosingElement.name;
+        var name = element.enclosingElement2.name;
         if (_isAngularUri(element.librarySource.uri)) {
           if (name == 'ViewChild' || name == 'ContentChild') {
             return _AngularAnnotation.child;
@@ -749,7 +749,7 @@
         // Constructors have no explicit return type annotation, so use the
         // implicit return type.
         decoratedReturnType = _createDecoratedTypeForClass(
-            declaredElement.enclosingElement, parameters!.parent);
+            declaredElement.enclosingElement2, parameters!.parent);
         instrumentation?.implicitReturnType(source, node, decoratedReturnType);
       } else {
         // Inferred return type.
@@ -850,7 +850,7 @@
     for (var annotation in node.metadata) {
       var element = annotation.element;
       if (element is ConstructorElement &&
-          element.enclosingElement.name == 'Optional' &&
+          element.enclosingElement2.name == 'Optional' &&
           _isAngularUri(element.librarySource.uri)) {
         _graph.makeNullable(
             decoratedType!.node!, AngularAnnotationOrigin(source, node));
diff --git a/pkg/nnbd_migration/lib/src/nullability_node_target.dart b/pkg/nnbd_migration/lib/src/nullability_node_target.dart
index 38833b9..8f6eb6e 100644
--- a/pkg/nnbd_migration/lib/src/nullability_node_target.dart
+++ b/pkg/nnbd_migration/lib/src/nullability_node_target.dart
@@ -15,7 +15,7 @@
     } else {
       parts.add(name);
     }
-    element = element.enclosingElement;
+    element = element.enclosingElement2;
   }
   if (parts.isEmpty) {
     assert(false, 'Could not compute a name for $element');
diff --git a/pkg/nnbd_migration/lib/src/utilities/built_value_transformer.dart b/pkg/nnbd_migration/lib/src/utilities/built_value_transformer.dart
index c4ed06f..85a14aa 100644
--- a/pkg/nnbd_migration/lib/src/utilities/built_value_transformer.dart
+++ b/pkg/nnbd_migration/lib/src/utilities/built_value_transformer.dart
@@ -13,7 +13,7 @@
           var element = annotation.element;
           if (element is PropertyAccessorElement &&
               element.name == 'nullable') {
-            if (element.enclosingElement is CompilationUnitElement) {
+            if (element.enclosingElement2 is CompilationUnitElement) {
               if (element.library.source.uri.toString() ==
                   'package:built_value/built_value.dart') {
                 return annotation;
diff --git a/pkg/nnbd_migration/lib/src/utilities/where_not_null_transformer.dart b/pkg/nnbd_migration/lib/src/utilities/where_not_null_transformer.dart
index cc27031..997bf46 100644
--- a/pkg/nnbd_migration/lib/src/utilities/where_not_null_transformer.dart
+++ b/pkg/nnbd_migration/lib/src/utilities/where_not_null_transformer.dart
@@ -139,7 +139,7 @@
     if (element is MethodElement) {
       if (element.isStatic) return false;
       if (element.name != 'where') return false;
-      var enclosingElement = element.declaration.enclosingElement;
+      var enclosingElement = element.declaration.enclosingElement2;
       if (enclosingElement is ClassElement) {
         // If the class is `Iterable` or a subtype of it, we consider the user
         // to be calling a transformable method.
diff --git a/pkg/nnbd_migration/lib/src/utilities/where_or_null_transformer.dart b/pkg/nnbd_migration/lib/src/utilities/where_or_null_transformer.dart
index d276ad5..edf4027 100644
--- a/pkg/nnbd_migration/lib/src/utilities/where_or_null_transformer.dart
+++ b/pkg/nnbd_migration/lib/src/utilities/where_or_null_transformer.dart
@@ -104,7 +104,7 @@
       if (element.isStatic) return null;
       var replacementName = _replacementNames[element.name];
       if (replacementName == null) return null;
-      var enclosingElement = element.declaration.enclosingElement;
+      var enclosingElement = element.declaration.enclosingElement2;
       if (enclosingElement is ClassElement) {
         // If the class is `Iterable` or a subtype of it, we consider the user
         // to be calling a transformable method.
diff --git a/pkg/nnbd_migration/lib/src/variables.dart b/pkg/nnbd_migration/lib/src/variables.dart
index 7aa0764..4258fad 100644
--- a/pkg/nnbd_migration/lib/src/variables.dart
+++ b/pkg/nnbd_migration/lib/src/variables.dart
@@ -125,7 +125,7 @@
   /// nullabilities.
   DecoratedType? decoratedTypeParameterBound(TypeParameterElement typeParameter,
       {bool allowNullUnparentedBounds = false}) {
-    var enclosingElement = typeParameter.enclosingElement;
+    var enclosingElement = typeParameter.enclosingElement2;
     var decoratedType =
         DecoratedTypeParameterBounds.current!.get(typeParameter);
     if (enclosingElement == null) {
@@ -431,7 +431,7 @@
   bool _isLoadLibraryElement(Element element) =>
       element.isSynthetic &&
       element is FunctionElement &&
-      element.enclosingElement is LibraryElement &&
+      element.enclosingElement2 is LibraryElement &&
       element.name == 'loadLibrary';
 
   /// Inverts the logic of [uniqueIdentifierForSpan], producing an (offset, end)
diff --git a/pkg/nnbd_migration/test/node_builder_test.dart b/pkg/nnbd_migration/test/node_builder_test.dart
index 22ea76b..07fe1b9 100644
--- a/pkg/nnbd_migration/test/node_builder_test.dart
+++ b/pkg/nnbd_migration/test/node_builder_test.dart
@@ -1033,7 +1033,7 @@
 }
 ''');
     var functionExpressionElement =
-        findNode.simpleParameter('int i').declaredElement!.enclosingElement!;
+        findNode.simpleParameter('int i').declaredElement!.enclosingElement2!;
     var decoratedType =
         variables!.decoratedElementType(functionExpressionElement);
     expect(decoratedType.positionalParameters![0],
@@ -1050,7 +1050,7 @@
 }
 ''');
     var functionExpressionElement =
-        findNode.simpleParameter('int i').declaredElement!.enclosingElement!;
+        findNode.simpleParameter('int i').declaredElement!.enclosingElement2!;
     var decoratedType =
         variables!.decoratedElementType(functionExpressionElement);
     expect(
diff --git a/tools/VERSION b/tools/VERSION
index 9dd910b..1e7230c 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
 MAJOR 2
 MINOR 19
 PATCH 0
-PRERELEASE 11
+PRERELEASE 12
 PRERELEASE_PATCH 0
\ No newline at end of file