diff --git a/pkg/analysis_server/lib/src/cider/rename.dart b/pkg/analysis_server/lib/src/cider/rename.dart index 6f666d17844..73f171657ea 100644 --- a/pkg/analysis_server/lib/src/cider/rename.dart +++ b/pkg/analysis_server/lib/src/cider/rename.dart @@ -65,7 +65,7 @@ class CanRenameResponse { 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 @@ class CheckNameResponse { 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 @@ class CheckNameResponse { Future _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 @@ class CiderRenameComputer { } 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 188f29b5bc6..ceb8a33e308 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 @@ class CallHierarchyItem { 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 1026b0a941a..21db001b4a3 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 @@ class ColorComputer { 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 4e25d411a85..b74240d024f 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 @@ class DartUnitHighlightsComputer { 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 @@ class DartUnitHighlightsComputer { 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 e16e30780fd..3ca0f28668c 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 @@ class DartUnitHoverComputer { 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(); if (containingClass != null && containingClass != element) { @@ -152,7 +152,7 @@ class DartUnitHoverComputer { 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 @@ class DartUnitHoverComputer { 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 61e3abb36e1..28b0ad587b3 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 @@ class _FunctionBodyOutlinesVisitor extends RecursiveAstVisitor { /// 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 eff224d3225..d55a4c6b022 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 @@ import 'package:analyzer/dart/element/element.dart'; /// 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, [], []); @@ -109,7 +109,7 @@ class _OverriddenElementsFinder { final Set _visited = {}; 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 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 85352f07c0e..bed6b9260a3 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 @@ class _Visitor extends UnifyingAstVisitor { !_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 23790f4543c..1b25da7fbe2 100644 --- a/pkg/analysis_server/lib/src/protocol_server.dart +++ b/pkg/analysis_server/lib/src/protocol_server.dart @@ -215,7 +215,7 @@ Location newLocation_fromUnit( 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 @@ engine.CompilationUnitElement _getUnitElement(engine.Element element) { 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 afccf671fba..57d16bf6edc 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 @@ class ElementReferencesComputer { 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 5dc00b9a0dc..7064baad784 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 @@ class TypeHierarchyComputer { 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 8581f4ffcca..536ba29fe00 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 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor { if (element.isOperator) { return; } - if (element.enclosingElement is! CompilationUnitElement) { + if (element.enclosingElement2 is! CompilationUnitElement) { return; } var returnType = element.returnType; @@ -115,7 +115,7 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor { @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 3eb06e26cbf..c6be58068a0 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 @@ class _LocalVisitor extends LocalDeclarationVisitor { .thisOrAncestorOfType(); 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 @@ class _LocalVisitor extends LocalDeclarationVisitor { var enclosingClass = request.target.containingNode .thisOrAncestorOfType(); 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 71845bb913f..e35e2914f29 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 @@ class SuggestionBuilder { // 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 @@ class SuggestionBuilder { } 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 @@ class SuggestionBuilder { /// 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 @@ class SuggestionBuilder { inheritanceDistance: inheritanceDistance, ); - var enclosingElement = method.enclosingElement; + var enclosingElement = method.enclosingElement2; if (method.name == 'setState' && enclosingElement is ClassElement && flutter.isExactState(enclosingElement)) { @@ -777,10 +777,10 @@ class SuggestionBuilder { // 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 @@ class SuggestionBuilder { 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 @@ class SuggestionBuilder { /// 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 @@ class SuggestionBuilder { withNullability: _isNonNullableByDefault, ); - var enclosingElement = element.enclosingElement; + var enclosingElement = element.enclosingElement2; String? declaringType; if (enclosingElement is ClassElement) { @@ -1353,7 +1353,7 @@ class SuggestionBuilder { /// 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 35d0f87d15e..48f22d770a4 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 @@ class AddLate extends CorrectionProducer { 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 1582f94d577..65d41183286 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 @@ class ChangeToStaticAccess extends CorrectionProducer { } 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 51b500c387f..e7749461be6 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 @@ class _BaseVisitor extends RecursiveAstVisitor { var constructorElement = node.constructorName.staticElement; return constructorElement != null && !constructorElement.isFactory && - constructorElement.enclosingElement == classElement; + constructorElement.enclosingElement2 == classElement; } } @@ -571,7 +571,7 @@ class _EnumDescription { 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 d530aefa26d..2ba17f82754 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 @@ class _SuperclassReferenceFinder extends RecursiveAstVisitor { 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 26e9f45954e..2bafd703d7f 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 @@ class ConvertIntoFinalField extends CorrectionProducer { 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 cc2ed4d093e..bc4aefd0e4d 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 @@ class ConvertIntoIsNotEmpty extends CorrectionProducer { 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 68c1434f47d..85057d81e1c 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 @@ class ConvertMapFromIterableToForLiteral extends CorrectionProducer { 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 769ed53b430..30627768ee3 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 @@ class CreateConstructor extends CorrectionProducer { } // 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 c646e6f9a39..15517dc0e6d 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 @@ class _ReplacementEditBuilder extends RecursiveAstVisitor { } 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 c061f383eaf..dcbc524a1d9 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 @@ class _ReplacementEditBuilder extends RecursiveAstVisitor { } 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 @@ class _StatelessVerifier extends RecursiveAstVisitor { 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 e667453caaa..71b2377ba95 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 @@ class MakeFieldNotFinal extends CorrectionProducer { } // 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 07e51bb1185..8b178efd5d8 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 @@ class QualifyReference extends CorrectionProducer { 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 9d880a9355b..f18ab8cebc4 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 @@ class ShadowField extends CorrectionProducer { 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 e88e5cc0e92..b606c9fc0c1 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 @@ class _MatcherBuilder { ); } } 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 @@ class _MatcherBuilder { } } 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 7522efed20b..24930491af5 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 @@ extension on MethodDeclaration { 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 051e3fdf4d8..5f85fc8c0f9 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 @@ LibraryImportElement? _getImportElement( String prefix, Element element, Map> 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 2edef198ced..bd14c30a138 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 getElementKindName(Element element) { 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 @@ class CorrectionUtils { /// 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 416aaeb575b..4f3d7631ffc 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 @@ class _EdgeInsetsProperty { 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 77da5dda78c..0a1c2239a0b 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 @@ class _WidgetDescriptionComputer { constructorElement ??= classDescription?.constructor; if (constructorElement == null) return; - var classElement = constructorElement.enclosingElement; + var classElement = constructorElement.enclosingElement2; if (!classesBeingProcessed.add(classElement)) return; var existingNamed = {}; @@ -520,7 +520,7 @@ class _WidgetDescriptionComputer { } 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 @@ class _WidgetDescriptionComputer { 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 e64fb09464f..f1483f5bc1a 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 @@ const int _notFound = -1; /// name of the constructor, unless the constructor is a named constructor in /// which '.' 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 @@ class KytheDartVisitor extends GeneralizingAstVisitor with OutputUtils { // 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 @@ class SignatureElementVisitor extends GeneralizingElementVisitor { @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 @@ class SignatureElementVisitor extends GeneralizingElementVisitor { // 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 e226e3e5dd3..dcbe33c81e0 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 @@ class ConvertGetterToMethodRefactoringImpl extends RefactoringImpl Future 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 dd6724cf2d0..4a1812cd2f1 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 @@ class ConvertMethodToGetterRefactoringImpl extends RefactoringImpl 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 5a7c1e9d972..4dfd72a8230 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 @@ Element? _getLocalElement(SimpleIdentifier node) { 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 d807a1d6983..c85b15db5c6 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 @@ class _ParametersCollector extends RecursiveAstVisitor { 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 00cd08f01ec..235172d2e6d 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 @@ class InlineMethodRefactoringImpl extends RefactoringImpl @override String? get className { - var classElement = _methodElement?.enclosingElement; + var classElement = _methodElement?.enclosingElement2; if (classElement is ClassElement) { return classElement.displayName; } @@ -805,13 +805,13 @@ class _VariablesVisitor extends GeneralizingAstVisitor { } 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 c542a1c6cde..b85a9ff847b 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 @@ abstract class RenameRefactoring implements Refactoring { 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 ce85fb81f1c..d7bd902976a 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 @@ class _BaseClassMemberValidator { 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 @@ class _RenameClassMemberValidator extends _BaseClassMemberValidator { 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 5e7e7bc59a8..01ce273a8a7 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 @@ class RenameConstructorRefactoringImpl extends RenameRefactoringImpl { } 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 @@ class RenameConstructorRefactoringImpl extends RenameRefactoringImpl { } Future _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 06144976b2c..eb53d127331 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 @@ class _BaseUnitMemberValidator { 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 eda9ad46d24..0776411dbff 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 @@ Future> getHierarchyMembers( SearchEngine searchEngine, ClassMemberElement member) async { Set result = HashSet(); // 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> getHierarchyMembers( Future> getHierarchyNamedParameters( SearchEngine searchEngine, ParameterElement element) async { if (element.isNamed) { - var method = element.enclosingElement; + var method = element.enclosingElement2; if (method is MethodElement) { var hierarchyParameters = []; 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 bfe5606eeca..28512ddf556 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 @@ extension ElementExtension on Element { 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 @@ extension ElementExtension on Element { var current = this; while (true) { yield current; - var enclosing = current.enclosingElement; + var enclosing = current.enclosingElement2; if (enclosing == null) { break; } @@ -69,7 +69,7 @@ extension MethodElementExtensions on MethodElement { if (name != 'cast') { return false; } - var definingClass = enclosingElement; + var definingClass = enclosingElement2; if (definingClass is! ClassElement) { return false; } @@ -85,7 +85,7 @@ extension MethodElementExtensions on MethodElement { 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 f4231524cdc..c4253911655 100644 --- a/pkg/analysis_server/lib/src/utilities/flutter.dart +++ b/pkg/analysis_server/lib/src/utilities/flutter.dart @@ -192,7 +192,7 @@ class Flutter { /// 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 @@ class Flutter { /// 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 cccd6c9e4c4..a0e22e1440a 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 @@ enum E2 { three, four }'''); 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 3cd822f5b14..2bc9c5102d0 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 @@ class CompletionResult { 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 edab7018d7e..6bba8400e46 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 @@ class FlutterDataCollector extends RecursiveAstVisitor { 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 c13b51aee2b..8683e816e83 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 @@ class RelevanceDataCollector extends RecursiveAstVisitor { 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 @@ class RelevanceDataCollector extends RecursiveAstVisitor { Element? currentElement = element; while (currentElement != enclosingLibrary) { depth++; - currentElement = currentElement?.enclosingElement; + currentElement = currentElement?.enclosingElement2; } return depth; } @@ -1688,7 +1688,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor { 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 c84f8ed6617..1b1265e456b 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 f71d02c52d0..b14447a2d50 100644 --- a/pkg/analyzer/lib/dart/element/element.dart +++ b/pkg/analyzer/lib/dart/element/element.dart @@ -57,9 +57,13 @@ import 'package:pub_semver/pub_semver.dart'; /// 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 @@ abstract class ClassElement @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 get fields; @@ -392,9 +400,13 @@ abstract class ClassMemberElement implements Element { // 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 @@ abstract class CompilationUnitElement implements UriReferencedElement { /// unit. List 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 @@ abstract class ConstructorElement @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 @@ abstract class Element implements AnalysisTarget { /// 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 @@ abstract class ExecutableElement implements FunctionTypedElement { @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 @@ abstract class ExtensionElement implements TypeParameterizedElement { /// declared in this extension. List 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,9 +1439,13 @@ abstract class ImportElementPrefix { /// /// 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 @@ abstract class PartElement implements _ExistingElement { /// /// 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 @@ abstract class PropertyAccessorElement implements ExecutableElement { @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,9 +2033,13 @@ abstract class TypeAliasElement /// a [FunctionType]. DartType get aliasedType; + @Deprecated('Use enclosingElement2 instead') @override CompilationUnitElement get enclosingElement; + @override + CompilationUnitElement get enclosingElement2; + @override String get name; diff --git a/pkg/analyzer/lib/src/dart/analysis/index.dart b/pkg/analyzer/lib/src/dart/analysis/index.dart index 5660f03b1f6..7ea2d0cc07a 100644 --- a/pkg/analyzer/lib/src/dart/analysis/index.dart +++ b/pkg/analyzer/lib/src/dart/analysis/index.dart @@ -18,7 +18,7 @@ Element? declaredParameterElement( SimpleIdentifier node, Element? element, ) { - if (element == null || element.enclosingElement != null) { + if (element == null || element.enclosingElement2 != null) { return element; } @@ -63,7 +63,7 @@ Element? declaredParameterElement( /// 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 @@ class ElementNameComponents { 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 @@ class IndexElementInfo { } 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 @@ class IndexElementInfo { } 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 @@ class IndexElementInfo { 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 @@ class _IndexContributor extends GeneralizingAstVisitor { 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 @@ class _IndexContributor extends GeneralizingAstVisitor { // 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 @@ class _IndexContributor extends GeneralizingAstVisitor { ConstructorElement? constructor) { var seenConstructors = {}; while (constructor is ConstructorElementImpl && constructor.isSynthetic) { - var enclosing = constructor.enclosingElement; + var enclosing = constructor.enclosingElement2; if (enclosing.isMixinApplication) { var superInvocation = constructor.constantInitializers .whereType() diff --git a/pkg/analyzer/lib/src/dart/analysis/results.dart b/pkg/analyzer/lib/src/dart/analysis/results.dart index 223e40d5d53..124c052f971 100644 --- a/pkg/analyzer/lib/src/dart/analysis/results.dart +++ b/pkg/analyzer/lib/src/dart/analysis/results.dart @@ -178,7 +178,7 @@ class ResolvedForCompletionResultImpl { 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 d78196ba59d..3eb1e3861c1 100644 --- a/pkg/analyzer/lib/src/dart/analysis/search.dart +++ b/pkg/analyzer/lib/src/dart/analysis/search.dart @@ -257,7 +257,7 @@ class Search { } 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 @@ class Search { // 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 @@ class Search { )); 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 @@ class _FindDeclarations { 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 d51f9d97e57..2095651f5f2 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 @@ class ConstantVerifier extends RecursiveAstVisitor { // 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 5b205c48003..344949693df 100644 --- a/pkg/analyzer/lib/src/dart/constant/evaluation.dart +++ b/pkg/analyzer/lib/src/dart/constant/evaluation.dart @@ -198,7 +198,7 @@ class ConstantEvaluationEngine { 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 @@ class ConstantEvaluationEngine { } } } - 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 @@ class ConstantEvaluationEngine { 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 @@ class ConstantEvaluationEngine { 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 @@ class ConstantVisitor extends UnifyingAstVisitor { if (element.name == "identical") { NodeList 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 @@ class ConstantVisitor extends UnifyingAstVisitor { return false; } return identifier.name == 'length' && - identifier.staticElement?.enclosingElement is! ExtensionElement; + identifier.staticElement?.enclosingElement2 is! ExtensionElement; } void _reportNotPotentialConstants(AstNode node) { @@ -2129,7 +2129,7 @@ class _InstanceCreationEvaluator { List 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 @@ class _InstanceCreationEvaluator { } 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 @@ class _InstanceCreationEvaluator { } 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 6c13da9a3c0..284072fb677 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 @@ class _Collector { } if (element is ParameterElement) { - var enclosing = element.enclosingElement; + var enclosing = element.enclosingElement2; if (enclosing is ConstructorElement && isConstConstructorElement(enclosing)) { if (node.thisOrAncestorOfType() != null) { diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart index 63cdbaafae0..471c9977065 100644 --- a/pkg/analyzer/lib/src/dart/element/element.dart +++ b/pkg/analyzer/lib/src/dart/element/element.dart @@ -103,11 +103,17 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl @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 fields) { assert(!isMixinApplication); @@ -314,7 +320,7 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl !getter.isAbstract && !getter.isStatic && getter.isAccessibleIn2(library) && - getter.enclosingElement != this)); + getter.enclosingElement2 != this)); ExecutableElement? lookUpInheritedConcreteMember( String name, LibraryElement library) { @@ -334,7 +340,7 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl !method.isAbstract && !method.isStatic && method.isAccessibleIn2(library) && - method.enclosingElement != this)); + method.enclosingElement2 != this)); @override PropertyAccessorElement? lookUpInheritedConcreteSetter( @@ -344,7 +350,7 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl !setter.isAbstract && !setter.isStatic && setter.isAccessibleIn2(library) && - setter.enclosingElement != this)); + setter.enclosingElement2 != this)); @override MethodElement? lookUpInheritedMethod( @@ -353,7 +359,7 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl (MethodElement method) => !method.isStatic && method.isAccessibleIn2(library) && - method.enclosingElement != this)); + method.enclosingElement2 != this)); @override MethodElement? lookUpMethod(String methodName, LibraryElement library) => @@ -539,9 +545,15 @@ class AugmentationImportElementImpl extends _ExistingElementImpl 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 @@ class ClassElementImpl extends AbstractClassElementImpl { 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 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl _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 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl } @override - AnalysisSession get session => enclosingElement.session; + AnalysisSession get session => enclosingElement2.session; @override List get topLevelVariables { @@ -1366,7 +1379,7 @@ class ConstructorElementImpl extends ExecutableElementImpl @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 @@ class ConstructorElementImpl extends ExecutableElementImpl } } + @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 @@ class ConstructorElementImpl extends ExecutableElementImpl @override Element get nonSynthetic { - return isSynthetic ? enclosingElement : this; + return isSynthetic ? enclosingElement2 : this; } @override @@ -1439,7 +1457,7 @@ class ConstructorElementImpl extends ExecutableElementImpl @override InterfaceType get returnTypeInternal { - return (_returnType ??= enclosingElement.thisType) as InterfaceType; + return (_returnType ??= enclosingElement2.thisType) as InterfaceType; } ConstructorElement? get superConstructor { @@ -1568,7 +1586,7 @@ mixin ConstVariableElement implements ElementImpl, ConstantEvaluationTarget { if (library == null) { throw StateError( '[library: null][this: ($runtimeType) $this]' - '[enclosingElement: $enclosingElement]' + '[enclosingElement2: $enclosingElement2]' '[reference: $reference]', ); } @@ -1936,7 +1954,7 @@ class ElementAnnotationImpl implements ElementAnnotation { 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 @@ class ElementAnnotationImpl implements ElementAnnotation { }) { final element = this.element; return element is ConstructorElement && - element.enclosingElement.name == className && + element.enclosingElement2.name == className && element.library.name == libraryName; } @@ -2177,6 +2195,7 @@ abstract class ElementImpl implements Element { _docComment = doc; } + @Deprecated('Use enclosingElement2 instead') @override Element? get enclosingElement => _enclosingElement; @@ -2185,6 +2204,9 @@ abstract class ElementImpl implements Element { _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 @@ abstract class ElementImpl implements Element { @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 @@ abstract class ElementImpl implements Element { ) { Element? element = this; while (element != null && !predicate(element)) { - element = element.enclosingElement; + element = element.enclosingElement2; } return element as E?; } @@ -2646,7 +2668,7 @@ abstract class ElementImpl implements Element { if (element is CompilationUnitElement) { element = element.enclosingElement2; } else { - element = element.enclosingElement; + element = element.enclosingElement2; } } return element as E?; @@ -2725,12 +2747,7 @@ class ElementLocationImpl implements ElementLocation { 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 @@ abstract class ExecutableElementImpl extends _ExistingElementImpl /// [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,11 +3268,17 @@ class ExtensionElementImpl extends _ExistingElementImpl @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 @@ class FieldElementImpl extends PropertyInducingElementImpl /// /// 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 @@ class FunctionElementImpl extends ExecutableElementImpl @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 @@ class LabelElementImpl extends ElementImpl implements LabelElement { @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 @@ class MethodElementImpl extends ExecutableElementImpl implements MethodElement { @override Element get nonSynthetic { - if (isSynthetic && enclosingElement is EnumElementImpl) { - return enclosingElement; + if (isSynthetic && enclosingElement2 is EnumElementImpl) { + return enclosingElement2; } return this; } @@ -4976,6 +5008,9 @@ class MultiplyDefinedElementImpl implements MultiplyDefinedElement { @override Element? get enclosingElement => null; + @override + Element? get enclosingElement2 => null; + @override bool get hasAlwaysThrows => false; @@ -5201,8 +5236,12 @@ abstract class NonParameterVariableElementImpl extends VariableElementImpl /// [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 @@ class PartElementImpl extends _ExistingElementImpl implements PartElement { @override CompilationUnitElementImpl get enclosingUnit { - var enclosingLibrary = enclosingElement as LibraryElementImpl; + var enclosingLibrary = enclosingElement2 as LibraryElementImpl; return enclosingLibrary._definingCompilationUnit; } @@ -5506,11 +5545,11 @@ class PrefixElementImpl extends _ExistingElementImpl implements PrefixElement { @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 @@ class PropertyAccessorElementImpl_ImplicitGetter 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 @@ class PropertyAccessorElementImpl_ImplicitGetter if (!variable.isSynthetic) { return variable; } - assert(enclosingElement is EnumElementImpl); - return enclosingElement; + assert(enclosingElement2 is EnumElementImpl); + return enclosingElement2; } @override @@ -5732,8 +5775,12 @@ class PropertyAccessorElementImpl_ImplicitSetter 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 @@ abstract class PropertyInducingElementImpl @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 @@ class SuperFormalParameterElementImpl extends ParameterElementImpl @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 @@ class TypeAliasElementImpl extends _ExistingElementImpl @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 @@ class TypeParameterElementImpl extends ElementImpl 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 @@ mixin WrapperElementImpl implements ElementImpl { 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 @@ mixin _HasLibraryMixin on ElementImpl { 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 f5c453db180..6b256a02bfd 100644 --- a/pkg/analyzer/lib/src/dart/element/extensions.dart +++ b/pkg/analyzer/lib/src/dart/element/extensions.dart @@ -25,7 +25,7 @@ extension ElementAnnotationExtensions on ElementAnnotation { } } } else if (element is ConstructorElement) { - classElement = element.enclosingElement; + classElement = element.enclosingElement2; } if (classElement == null) { return const {}; @@ -68,17 +68,17 @@ extension ElementExtension on Element { 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 @@ extension ElementExtension on Element { /// [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 ElementExtension on Element { 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 49737aeeb19..9768db4bb6d 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 @@ class InheritanceManager3 { continue; } - var class_ = executable.enclosingElement; + var class_ = executable.enclosingElement2; if (class_ is ClassElement && class_.isDartCoreObject) { continue; } @@ -518,7 +518,7 @@ class InheritanceManager3 { } var current = currentList.single; - if (candidate.enclosingElement == mixinElement) { + if (candidate.enclosingElement2 == mixinElement) { namedCandidates[name] = [ isNonNullableByDefault ? candidate @@ -714,7 +714,7 @@ class InheritanceManager3 { Name name, ExecutableElement executable, ) { - if (executable.enclosingElement == class_) { + if (executable.enclosingElement2 == class_) { return executable; } @@ -902,7 +902,7 @@ class InheritanceManager3 { } 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 24555281168..cbe9d700794 100644 --- a/pkg/analyzer/lib/src/dart/element/member.dart +++ b/pkg/analyzer/lib/src/dart/element/member.dart @@ -37,8 +37,12 @@ class ConstructorMember extends ExecutableMember @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 @@ class FieldMember extends VariableMember implements FieldElement { @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 @@ class FunctionMember extends ExecutableMember implements FunctionElement { 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 @@ abstract class Member implements Element { @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 @@ class MethodMember extends ExecutableMember implements MethodElement { @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 @@ class ParameterMember extends VariableMember @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 @@ class PropertyAccessorMember extends ExecutableMember 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 9fc03c6a76d..3faa7fb99f4 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 @@ class TypeSystemImpl implements TypeSystem { // 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 @@ class TypeSystemImpl implements TypeSystem { // 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 52b1ab6a846..c5113f7fefb 100644 --- a/pkg/analyzer/lib/src/dart/micro/utils.dart +++ b/pkg/analyzer/lib/src/dart/micro/utils.dart @@ -43,7 +43,7 @@ ConstructorElement? _getActualConstructorElement( ConstructorElement? constructor) { var seenConstructors = {}; while (constructor is ConstructorElementImpl && constructor.isSynthetic) { - var enclosing = constructor.enclosingElement; + var enclosing = constructor.enclosingElement2; if (enclosing.isMixinApplication) { var superInvocation = constructor.constantInitializers .whereType() @@ -73,7 +73,7 @@ LibraryImportElement? _getImportElement( String prefix, Element element, Map> importElementsMap) { - if (element.enclosingElement is! CompilationUnitElement) { + if (element.enclosingElement2 is! CompilationUnitElement) { return null; } var usedLibrary = element.library; @@ -310,7 +310,7 @@ class ReferencesCollector extends GeneralizingAstVisitor { 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 db7e1df184d..339f8dfd132 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 @@ class ConstructorReferenceResolver { 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 e8801b08b0e..dba662ffa9e 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 @@ class FunctionReferenceResolver { 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 13368ab5af4..ac880210d04 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 @@ class MethodInvocationResolver with ScopeHelpers { 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 63e41ad80ba..cc95cedcb4b 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 @@ class _ErrorHelper { 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 6ddcf05c858..fd96f2e19b3 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 @@ class PropertyElementResolver with ScopeHelpers { 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 6681a49d05c..9726e9ff330 100644 --- a/pkg/analyzer/lib/src/diagnostic/diagnostic_factory.dart +++ b/pkg/analyzer/lib/src/diagnostic/diagnostic_factory.dart @@ -79,14 +79,14 @@ class DiagnosticFactory { 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 97cbefd2ca7..4e7b0295c9c 100644 --- a/pkg/analyzer/lib/src/error/assignment_verifier.dart +++ b/pkg/analyzer/lib/src/error/assignment_verifier.dart @@ -91,7 +91,7 @@ class AssignmentVerifier { _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 c5f4ab8695a..5ec9188afce 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 @@ class BestPracticesVerifier extends RecursiveAstVisitor { } } } 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 @@ class BestPracticesVerifier extends RecursiveAstVisitor { 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 @@ class BestPracticesVerifier extends RecursiveAstVisitor { 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 @@ class BestPracticesVerifier extends RecursiveAstVisitor { _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 @@ class BestPracticesVerifier extends RecursiveAstVisitor { 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 @@ class BestPracticesVerifier extends RecursiveAstVisitor { _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 @@ class BestPracticesVerifier extends RecursiveAstVisitor { 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 @@ class _InvalidAccessVerifier { 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 @@ class _InvalidAccessVerifier { node = identifier; } - var definingClass = element.enclosingElement; + var definingClass = element.enclosingElement2; if (hasProtected) { _errorReporter.reportErrorForNode( HintCode.INVALID_USE_OF_PROTECTED_MEMBER, @@ -2038,12 +2038,12 @@ class _InvalidAccessVerifier { 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 2169256ef70..609bc464a11 100644 --- a/pkg/analyzer/lib/src/error/correct_override.dart +++ b/pkg/analyzer/lib/src/error/correct_override.dart @@ -123,16 +123,16 @@ class CovariantParametersVerifier { 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 @@ class CovariantParametersVerifier { 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 @@ class _SuperParameter { _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 82de45d4c64..240e4406517 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 @@ class DeprecatedMemberUseVerifier { // 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 @@ class DeprecatedMemberUseVerifier { /// 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 a44e2975abd..9687d8c9c65 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 @@ class DuplicateDefinitionVerifier { [ enumElement.displayName, baseName, - inherited.enclosingElement.displayName, + inherited.enclosingElement2.displayName, ], ); } @@ -168,7 +168,7 @@ class DuplicateDefinitionVerifier { [ 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 f8354146a33..469f0f557ee 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 @@ class GetterSetterTypesVerifier { 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 4c990ff5c98..66afde05595 100644 --- a/pkg/analyzer/lib/src/error/imports_verifier.dart +++ b/pkg/analyzer/lib/src/error/imports_verifier.dart @@ -94,7 +94,7 @@ class GatherUsedImportedElementsVisitor extends RecursiveAstVisitor { 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 @@ class GatherUsedImportedElementsVisitor extends RecursiveAstVisitor { 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 e0deb860e0d..bd719715cd5 100644 --- a/pkg/analyzer/lib/src/error/inheritance_override.dart +++ b/pkg/analyzer/lib/src/error/inheritance_override.dart @@ -529,7 +529,7 @@ class _ClassVerifier { .INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED, derivedOptionalNodes[i], [ - baseExecutable.enclosingElement.displayName, + baseExecutable.enclosingElement2.displayName, baseExecutable.displayName, name ], @@ -558,7 +558,7 @@ class _ClassVerifier { .INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL, derivedOptionalNodes[i], [ - baseExecutable.enclosingElement.displayName, + baseExecutable.enclosingElement2.displayName, baseExecutable.displayName ], ); @@ -675,7 +675,7 @@ class _ClassVerifier { ) { 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 @@ class _ClassVerifier { reporter.reportErrorForNode( CompileTimeErrorCode.ILLEGAL_ENUM_VALUES_INHERITANCE, classNameNode, - [inherited.enclosingElement.name!], + [inherited.enclosingElement2.name!], ); } } @@ -792,20 +792,20 @@ class _ClassVerifier { 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 @@ class _ClassVerifier { } 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 e66ab216999..3ce9a09d86e 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 @@ class MustCallSuperVerifier { 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 @@ class MustCallSuperVerifier { 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 @@ class MustCallSuperVerifier { 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 @@ class MustCallSuperVerifier { /// 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 aadad6e2bb2..c2c2f5160c3 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 @@ class TypeArgumentsVerifier { 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 216f128bd18..aab0059e46c 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 @@ class GatherUsedLocalElementsVisitor extends RecursiveAstVisitor { 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 @@ class UnusedLocalElementsVerifier extends RecursiveAstVisitor { if (element.isPrivate) { return false; } - var enclosingElement = element.enclosingElement; + var enclosingElement = element.enclosingElement2; if (enclosingElement is ClassElement) { if (enclosingElement.isEnum) { @@ -544,7 +544,7 @@ class UnusedLocalElementsVerifier extends RecursiveAstVisitor { 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 @@ class UnusedLocalElementsVerifier extends RecursiveAstVisitor { 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 @@ class UnusedLocalElementsVerifier extends RecursiveAstVisitor { 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 @@ class UnusedLocalElementsVerifier extends RecursiveAstVisitor { } Iterable _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 @@ class UnusedLocalElementsVerifier extends RecursiveAstVisitor { // 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 6656aefe2b2..8cb650a9486 100644 --- a/pkg/analyzer/lib/src/generated/element_resolver.dart +++ b/pkg/analyzer/lib/src/generated/element_resolver.dart @@ -357,7 +357,7 @@ class ElementResolver { } 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 2df59bb8c48..9bce0358ce4 100644 --- a/pkg/analyzer/lib/src/generated/error_verifier.dart +++ b/pkg/analyzer/lib/src/generated/error_verifier.dart @@ -117,7 +117,7 @@ class EnclosingExecutableContext { } static bool _inFactoryConstructor(Element? element) { - var enclosing = element?.enclosingElement; + var enclosing = element?.enclosingElement2; if (enclosing == null) { return false; } @@ -128,7 +128,7 @@ class EnclosingExecutableContext { } static bool _inStaticMethod(Element? element) { - var enclosing = element?.enclosingElement; + var enclosing = element?.enclosingElement2; if (enclosing == null) { return false; } @@ -746,7 +746,7 @@ class ErrorVerifier extends RecursiveAstVisitor @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 @@ class ErrorVerifier extends RecursiveAstVisitor 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 @@ class ErrorVerifier extends RecursiveAstVisitor 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 @@ class ErrorVerifier extends RecursiveAstVisitor 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 @@ class ErrorVerifier extends RecursiveAstVisitor 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 @@ class ErrorVerifier extends RecursiveAstVisitor errorReporter.reportErrorForNode( CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, initializer, - [element.enclosingElement.displayName]); + [element.enclosingElement2.displayName]); return true; } } @@ -2155,7 +2155,7 @@ class ErrorVerifier extends RecursiveAstVisitor return; } // check if there is non-final field - ClassElement classElement = constructorElement.enclosingElement; + ClassElement classElement = constructorElement.enclosingElement2; if (!classElement.hasNonFinalField) { return; } @@ -2921,7 +2921,7 @@ class ErrorVerifier extends RecursiveAstVisitor // 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 @@ class ErrorVerifier extends RecursiveAstVisitor 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 @@ class ErrorVerifier extends RecursiveAstVisitor 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 @@ class ErrorVerifier extends RecursiveAstVisitor 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 @@ class ErrorVerifier extends RecursiveAstVisitor ); 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 @@ class ErrorVerifier extends RecursiveAstVisitor redirectedElement, redirectedConstructor, ); - var redirectedClass = redirectedElement?.enclosingElement; + var redirectedClass = redirectedElement?.enclosingElement2; if (redirectedClass is ClassElement && redirectedClass.isAbstract && redirectedElement != null && @@ -4323,7 +4323,7 @@ class ErrorVerifier extends RecursiveAstVisitor 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 @@ class ErrorVerifier extends RecursiveAstVisitor 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 575826438f7..43b4217c827 100644 --- a/pkg/analyzer/lib/src/generated/ffi_verifier.dart +++ b/pkg/analyzer/lib/src/generated/ffi_verifier.dart @@ -202,7 +202,7 @@ class FfiVerifier extends RecursiveAstVisitor { 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 @@ class FfiVerifier extends RecursiveAstVisitor { 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 @@ class FfiVerifier extends RecursiveAstVisitor { @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 @@ class FfiVerifier extends RecursiveAstVisitor { 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 @@ class FfiVerifier extends RecursiveAstVisitor { } } } 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 @@ class FfiVerifier extends RecursiveAstVisitor { 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 @@ class FfiVerifier extends RecursiveAstVisitor { 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 @@ class FfiVerifier extends RecursiveAstVisitor { // 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 @@ class FfiVerifier extends RecursiveAstVisitor { _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 @@ class FfiVerifier extends RecursiveAstVisitor { List 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 @@ extension on Annotation { final element = this.element; return element is ConstructorElement && element.ffiClass != null && - element.enclosingElement.name == + element.enclosingElement2.name == FfiVerifier._abiSpecificIntegerMappingClassName; } @@ -1251,21 +1251,21 @@ extension on Annotation { 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 @@ extension on ElementAnnotation { 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 @@ extension on ElementAnnotation { 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 @@ extension on Element? { 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 d11f10fbbe9..f4793daf42a 100644 --- a/pkg/analyzer/lib/src/generated/resolver.dart +++ b/pkg/analyzer/lib/src/generated/resolver.dart @@ -3605,7 +3605,7 @@ class ScopeResolverVisitor extends UnifyingAstVisitor { 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 275cde402ed..15411699a3e 100644 --- a/pkg/analyzer/lib/src/lint/linter.dart +++ b/pkg/analyzer/lib/src/lint/linter.dart @@ -338,7 +338,7 @@ class LinterContextImpl implements LinterContext { 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 a19950d3519..946751487f5 100644 --- a/pkg/analyzer/lib/src/summary2/bundle_reader.dart +++ b/pkg/analyzer/lib/src/summary2/bundle_reader.dart @@ -200,7 +200,7 @@ abstract class ElementLinkedData { 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 @@ class EnumElementLinkedData extends ElementLinkedData { @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 @@ class ExtensionElementLinkedData @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 @@ class MixinElementLinkedData extends ElementLinkedData { @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 @@ class ResolutionReader { // 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 e3364eb0f75..004008b98bb 100644 --- a/pkg/analyzer/lib/src/summary2/bundle_writer.dart +++ b/pkg/analyzer/lib/src/summary2/bundle_writer.dart @@ -847,7 +847,7 @@ class ResolutionSink extends _SummaryDataWriter { return const []; } - var enclosing = declaration.enclosingElement; + var enclosing = declaration.enclosingElement2; if (enclosing is TypeParameterizedElement) { if (enclosing is! ClassElement && enclosing is! ExtensionElement) { return const []; diff --git a/pkg/analyzer/lib/src/summary2/macro_declarations.dart b/pkg/analyzer/lib/src/summary2/macro_declarations.dart index bfe0b624ec4..8a7f6e6f3f0 100644 --- a/pkg/analyzer/lib/src/summary2/macro_declarations.dart +++ b/pkg/analyzer/lib/src/summary2/macro_declarations.dart @@ -110,7 +110,7 @@ class DeclarationBuilderFromElement { 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 d9e2f98a08b..dd7cae3c203 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 @@ class _ConstructorInferenceNode extends _InferenceNode { } } - var classElement = _constructor.enclosingElement; + var classElement = _constructor.enclosingElement2; if (classElement.isMixinApplication) { var superType = classElement.supertype; if (superType != null) { @@ -285,7 +285,7 @@ class _InferenceDependenciesCollector extends RecursiveAstVisitor { _set.add(element); - if (element.enclosingElement.typeParameters.isNotEmpty) { + if (element.enclosingElement2.typeParameters.isNotEmpty) { node.argumentList.accept(this); } } @@ -526,7 +526,7 @@ class _VariableInferenceNode extends _InferenceNode { } 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 bd67df2002c..038c16760b6 100644 --- a/pkg/analyzer/lib/src/task/strong_mode.dart +++ b/pkg/analyzer/lib/src/task/strong_mode.dart @@ -424,7 +424,7 @@ class InstanceMemberInferrer { 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 @@ class InstanceMemberInferrer { 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 18dec745d0f..6574c92b265 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/ast/visitor.dart'; 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 d34a268a8c4..ae995c2524e 100644 --- a/pkg/analyzer/test/generated/element_resolver_test.dart +++ b/pkg/analyzer/test/generated/element_resolver_test.dart @@ -35,7 +35,7 @@ class A { 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 @@ class A { 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 @@ class A { 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 @@ class A { 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 @@ class A { 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 @@ class A { 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 @@ const V = 0; 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 @@ const V = 0; 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 66ec3029c37..21ddaafa47e 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 @@ test(C c) => c.method(arg: true); '''); 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 @@ bool test(C c) => c.method(arg: true); '''); 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 1ccc8bb63c7..86cbe1c2164 100644 --- a/pkg/analyzer/test/generated/resolver_test.dart +++ b/pkg/analyzer/test/generated/resolver_test.dart @@ -74,7 +74,7 @@ class C { 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 8e08527eb39..8dc008fcf2e 100644 --- a/pkg/analyzer/test/id_tests/inheritance_test.dart +++ b/pkg/analyzer/test/id_tests/inheritance_test.dart @@ -102,7 +102,7 @@ class _InheritanceDataExtractor extends AstDataExtractor { 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 f1e82776b86..3a0d6d5de1b 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 @@ main() { 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 @@ main() { 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 @@ void foo(List Function() createList) {} assertType(closure, 'List Function()'); var closureElement = closure.declaredElement as FunctionElementImpl; - expect(closureElement.enclosingElement, findElement.function('main')); + expect(closureElement.enclosingElement2, findElement.function('main')); assertType(closureElement.returnType, 'List'); expect(closureElement.parameters, isEmpty); @@ -1708,7 +1708,7 @@ main(MyEnum e) { 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 4840c6933d0..eb4f3fb5aca 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 @@ class _InheritanceManager3Base extends PubPackageResolutionTest { 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 @@ class _InheritanceManager3Base extends PubPackageResolutionTest { 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 @@ class _InheritanceManager3Base extends PubPackageResolutionTest { 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 7ff22974fd0..0872e4cefac 100644 --- a/pkg/analyzer/test/src/dart/resolution/resolution.dart +++ b/pkg/analyzer/test/src/dart/resolution/resolution.dart @@ -214,7 +214,7 @@ mixin ResolutionTest implements ResourceProviderMixin { } void assertEnclosingElement(Element element, Element expectedEnclosing) { - expect(element.enclosingElement, expectedEnclosing); + expect(element.enclosingElement2, expectedEnclosing); } Future assertErrorsInCode( @@ -500,7 +500,7 @@ mixin ResolutionTest implements ResourceProviderMixin { ) { 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 df511ab6cd9..87e173bece2 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 @@ example(List list) { 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 @@ test(List list) { 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 @@ test(List list) { 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 @@ test() { 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 314b7e626d6..523f45b882f 100644 --- a/pkg/analyzer/test/src/summary/element_text.dart +++ b/pkg/analyzer/test/src/summary/element_text.dart @@ -194,8 +194,8 @@ class _ElementWriter { 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 @@ class _ElementWriter { 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 @@ class _ElementWriter { var superConstructor = e.superConstructor; if (superConstructor != null) { - if (!superConstructor.enclosingElement.isDartCoreObject) { + if (!superConstructor.enclosingElement2.isDartCoreObject) { _writeElementReference('superConstructor', superConstructor); } } @@ -428,7 +428,7 @@ class _ElementWriter { 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 @@ class _ElementWriter { _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 @@ class _ElementWriter { 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 6742fe33e92..c80647b41bf 100644 --- a/pkg/analyzer/test/src/summary/elements_test.dart +++ b/pkg/analyzer/test/src/summary/elements_test.dart @@ -21975,14 +21975,14 @@ typedef void F(int a); 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 @@ typedef F = void Function(int a); 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 @@ library 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 52d0d2666be..7dae51521fe 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 @@ class ResolvedAstPrinter extends ThrowingAstVisitor { } 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 73f745470de..edba42aee57 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 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder { @override void writeReference(Element element) { - if (element.enclosingElement is CompilationUnitElement) { + if (element.enclosingElement2 is CompilationUnitElement) { _writeLibraryReference(element); } write(element.displayName); @@ -1111,10 +1111,10 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder { 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 127cb49094a..e0a02d423c5 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 @@ mixin ElementSuggestionBuilder { // 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 e452d3dd005..f3446c689ae 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 @@ class SuggestionBuilderImpl implements SuggestionBuilder { 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 eb3d90521ae..8d281e65111 100644 --- a/pkg/analyzer_plugin/lib/utilities/analyzer_converter.dart +++ b/pkg/analyzer_plugin/lib/utilities/analyzer_converter.dart @@ -225,7 +225,7 @@ class AnalyzerConverter { // 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 @@ class AnalyzerConverter { 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 de32a210703..c58c3e21f83 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 @@ class _DartNavigationComputerVisitor extends RecursiveAstVisitor { 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 @@ class _DartNavigationComputerVisitor extends RecursiveAstVisitor { 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 @@ class _DartNavigationComputerVisitor extends RecursiveAstVisitor { 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 c48664f102f..3613ca663b1 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 @@ class _Base extends AbstractContextTest { } 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 87403befd3f..612c6640116 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 @@ enum E2 { three, four }'''); 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 4326006b618..62ecd1f46dd 100644 --- a/pkg/nnbd_migration/lib/instrumentation.dart +++ b/pkg/nnbd_migration/lib/instrumentation.dart @@ -37,7 +37,7 @@ class CodeReference { factory CodeReference.fromElement(Element element) { var unitElement = element.thisOrAncestorOfType(); if (unitElement == null) { - var enclosingElement = element.enclosingElement; + var enclosingElement = element.enclosingElement2; if (enclosingElement is LibraryElement) { unitElement = enclosingElement.definingCompilationUnit; } else { @@ -76,7 +76,7 @@ class CodeReference { 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 3139e2ad8cc..33556b2e86d 100644 --- a/pkg/nnbd_migration/lib/src/decorated_type.dart +++ b/pkg/nnbd_migration/lib/src/decorated_type.dart @@ -184,8 +184,8 @@ class DecoratedType implements DecoratedTypeInfo { // 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 @@ class DecoratedType implements DecoratedTypeInfo { Map.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 @@ class DecoratedTypeParameterBounds { final _parentedBounds = {}; DecoratedType? get(TypeParameterElement element) { - if (element.enclosingElement == null) { + if (element.enclosingElement2 == null) { return _orphanBounds[element]; } else { return _parentedBounds[element]; @@ -550,7 +550,7 @@ class DecoratedTypeParameterBounds { } 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 a77e967d0da..d992ce57e98 100644 --- a/pkg/nnbd_migration/lib/src/edge_builder.dart +++ b/pkg/nnbd_migration/lib/src/edge_builder.dart @@ -279,7 +279,7 @@ class EdgeBuilder extends GeneralizingAstVisitor Map? 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 @@ class EdgeBuilder extends GeneralizingAstVisitor 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 @@ class EdgeBuilder extends GeneralizingAstVisitor // 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 @@ class EdgeBuilder extends GeneralizingAstVisitor DecoratedType visitInstanceCreationExpression( InstanceCreationExpression node) { var callee = node.constructorName.staticElement!; - var typeParameters = callee.enclosingElement.typeParameters; + var typeParameters = callee.enclosingElement2.typeParameters; Iterable typeArgumentTypes; List decoratedTypeArguments; var typeArguments = node.constructorName.type.typeArguments; @@ -1387,7 +1387,7 @@ class EdgeBuilder extends GeneralizingAstVisitor } 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 @@ class EdgeBuilder extends GeneralizingAstVisitor } 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 @@ class EdgeBuilder extends GeneralizingAstVisitor } 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 @@ class EdgeBuilder extends GeneralizingAstVisitor var nullabilityNode = NullabilityNode.forInferredType(target); var class_ = node.thisOrAncestorOfType()!; var decoratedSupertype = _decoratedClassHierarchy!.getDecoratedSupertype( - class_.declaredElement!, callee.enclosingElement); + class_.declaredElement!, callee.enclosingElement2); var typeArguments = decoratedSupertype.typeArguments; Iterable typeArgumentTypes; typeArgumentTypes = typeArguments.map((t) => t!.type); @@ -1890,7 +1890,7 @@ class EdgeBuilder extends GeneralizingAstVisitor 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 @@ class EdgeBuilder extends GeneralizingAstVisitor } } 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 @@ class EdgeBuilder extends GeneralizingAstVisitor 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 @@ class EdgeBuilder extends GeneralizingAstVisitor 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 @@ class EdgeBuilder extends GeneralizingAstVisitor _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 @@ class EdgeBuilder extends GeneralizingAstVisitor _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 @@ class EdgeBuilder extends GeneralizingAstVisitor 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 @@ class EdgeBuilder extends GeneralizingAstVisitor 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 @@ class EdgeBuilder extends GeneralizingAstVisitor Map getterSubstitution = const {}; Map 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 @@ class EdgeBuilder extends GeneralizingAstVisitor 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 0f2f6ac2baa..b4c14e7bf05 100644 --- a/pkg/nnbd_migration/lib/src/fix_builder.dart +++ b/pkg/nnbd_migration/lib/src/fix_builder.dart @@ -467,7 +467,7 @@ class MigrationResolutionHooksImpl 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 @@ class MigrationResolutionHooksImpl /// 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 @@ class _FixBuilderPreVisitor extends GeneralizingAstVisitor 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 @@ class _FixBuilderPreVisitor extends GeneralizingAstVisitor // 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 e9b8d091ed2..7ac2f62a29d 100644 --- a/pkg/nnbd_migration/lib/src/node_builder.dart +++ b/pkg/nnbd_migration/lib/src/node_builder.dart @@ -707,7 +707,7 @@ class NodeBuilder extends GeneralizingAstVisitor 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 @@ class NodeBuilder extends GeneralizingAstVisitor // 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 @@ class NodeBuilder extends GeneralizingAstVisitor 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 38833b971d8..8f6eb6ebd56 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 @@ String _computeElementName(Element? element) { } 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 c4ed06fd419..85a14aae21e 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 @@ class BuiltValueTransformer { 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 cc270312619..997bf4658a5 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 @@ class WhereNotNullTransformer { 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 d276ad5bf56..edf402791fe 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 @@ class WhereOrNullTransformer { 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 7aa07647ebf..4258fad391a 100644 --- a/pkg/nnbd_migration/lib/src/variables.dart +++ b/pkg/nnbd_migration/lib/src/variables.dart @@ -125,7 +125,7 @@ class Variables { /// 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 @@ class Variables { 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 22ea76ba80f..07fe1b9e65c 100644 --- a/pkg/nnbd_migration/test/node_builder_test.dart +++ b/pkg/nnbd_migration/test/node_builder_test.dart @@ -1033,7 +1033,7 @@ void f() { } '''); 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 @@ void f() { } '''); var functionExpressionElement = - findNode.simpleParameter('int i').declaredElement!.enclosingElement!; + findNode.simpleParameter('int i').declaredElement!.enclosingElement2!; var decoratedType = variables!.decoratedElementType(functionExpressionElement); expect(