From 745d0ff64aead2475313845e28f1c61d66bdfeda Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Mon, 26 Sep 2022 23:58:14 +0000 Subject: [PATCH] Deprecate 'Element.enclosingElement3', use 'enclosingElement'. Change-Id: I6f4fd7e8c0f071bde10cb5e57ed6195ae517e575 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261221 Reviewed-by: Brian Wilkerson Commit-Queue: Konstantin Shcheglov --- pkg/analysis_server/lib/src/cider/rename.dart | 10 +- .../src/computer/computer_call_hierarchy.dart | 2 +- .../lib/src/computer/computer_color.dart | 2 +- .../lib/src/computer/computer_highlights.dart | 4 +- .../lib/src/computer/computer_hover.dart | 8 +- .../lib/src/computer/computer_outline.dart | 2 +- .../lib/src/computer/computer_overrides.dart | 4 +- .../computer/imported_elements_computer.dart | 2 +- .../lib/src/protocol_server.dart | 6 +- .../lib/src/search/element_references.dart | 2 +- .../lib/src/search/type_hierarchy.dart | 4 +- .../dart/local_library_contributor.dart | 4 +- .../dart/local_reference_contributor.dart | 4 +- .../dart/redirecting_contributor.dart | 4 +- .../completion/dart/suggestion_builder.dart | 24 +-- .../services/correction/dart/add_late.dart | 2 +- .../dart/change_to_static_access.dart | 2 +- .../dart/convert_class_to_enum.dart | 4 +- .../dart/convert_class_to_mixin.dart | 2 +- .../dart/convert_into_final_field.dart | 2 +- .../dart/convert_into_is_not_empty.dart | 2 +- ...vert_map_from_iterable_to_for_literal.dart | 2 +- .../correction/dart/create_constructor.dart | 2 +- .../flutter_convert_to_stateful_widget.dart | 2 +- .../flutter_convert_to_stateless_widget.dart | 4 +- .../correction/dart/make_field_not_final.dart | 2 +- .../correction/dart/qualify_reference.dart | 2 +- .../correction/dart/shadow_field.dart | 2 +- .../fix/data_driven/element_matcher.dart | 4 +- .../fix/data_driven/rename_parameter.dart | 2 +- .../src/services/correction/namespace.dart | 2 +- .../lib/src/services/correction/util.dart | 4 +- .../lib/src/services/flutter/property.dart | 2 +- .../services/flutter/widget_descriptions.dart | 6 +- .../src/services/kythe/kythe_visitors.dart | 8 +- .../legacy/convert_getter_to_method.dart | 6 +- .../legacy/convert_method_to_getter.dart | 2 +- .../refactoring/legacy/extract_method.dart | 2 +- .../refactoring/legacy/extract_widget.dart | 2 +- .../refactoring/legacy/inline_method.dart | 6 +- .../refactoring/legacy/refactoring.dart | 2 +- .../legacy/rename_class_member.dart | 6 +- .../legacy/rename_constructor.dart | 4 +- .../legacy/rename_unit_member.dart | 2 +- .../lib/src/services/search/hierarchy.dart | 4 +- .../lib/src/utilities/extensions/element.dart | 14 +- .../lib/src/utilities/flutter.dart | 4 +- .../code_completion/completion_metrics.dart | 2 +- .../tool/code_completion/flutter_metrics.dart | 2 +- .../code_completion/relevance_metrics.dart | 8 +- pkg/analyzer/CHANGELOG.md | 3 + pkg/analyzer/lib/dart/element/element.dart | 52 ++++++ pkg/analyzer/lib/src/dart/analysis/index.dart | 30 ++-- .../lib/src/dart/analysis/search.dart | 8 +- .../src/dart/constant/constant_verifier.dart | 2 +- .../lib/src/dart/constant/evaluation.dart | 18 +- .../dart/constant/potentially_constant.dart | 2 +- .../lib/src/dart/element/element.dart | 166 ++++++++++++------ .../lib/src/dart/element/extensions.dart | 14 +- .../dart/element/inheritance_manager3.dart | 8 +- pkg/analyzer/lib/src/dart/element/member.dart | 42 ++++- .../lib/src/dart/element/type_system.dart | 4 +- pkg/analyzer/lib/src/dart/micro/utils.dart | 6 +- .../constructor_reference_resolver.dart | 2 +- .../resolver/function_reference_resolver.dart | 2 +- .../resolver/method_invocation_resolver.dart | 2 +- .../dart/resolver/named_type_resolver.dart | 2 +- .../resolver/property_element_resolver.dart | 2 +- .../src/diagnostic/diagnostic_factory.dart | 4 +- .../lib/src/error/assignment_verifier.dart | 2 +- .../src/error/best_practices_verifier.dart | 27 ++- .../lib/src/error/correct_override.dart | 9 +- .../error/deprecated_member_use_verifier.dart | 4 +- .../error/duplicate_definition_verifier.dart | 4 +- .../error/getter_setter_types_verifier.dart | 12 +- .../lib/src/error/imports_verifier.dart | 4 +- .../lib/src/error/inheritance_override.dart | 16 +- .../src/error/must_call_super_verifier.dart | 14 +- .../src/error/type_arguments_verifier.dart | 2 +- .../error/unused_local_elements_verifier.dart | 14 +- .../lib/src/generated/element_resolver.dart | 2 +- .../lib/src/generated/error_verifier.dart | 40 ++--- .../lib/src/generated/ffi_verifier.dart | 34 ++-- pkg/analyzer/lib/src/generated/resolver.dart | 2 +- pkg/analyzer/lib/src/lint/linter.dart | 2 +- .../lib/src/summary2/bundle_reader.dart | 10 +- .../lib/src/summary2/bundle_writer.dart | 2 +- .../lib/src/summary2/informative_data.dart | 2 +- .../lib/src/summary2/macro_declarations.dart | 2 +- .../lib/src/summary2/top_level_inference.dart | 10 +- pkg/analyzer/lib/src/task/strong_mode.dart | 4 +- .../lib/src/util/ast_data_extractor.dart | 2 +- pkg/analyzer/pubspec.yaml | 2 +- .../test/generated/element_resolver_test.dart | 16 +- .../generated/non_error_resolver_test.dart | 4 +- .../test/generated/resolver_test.dart | 2 +- .../test/id_tests/inheritance_test.dart | 2 +- .../dart/analysis/driver_resolution_test.dart | 8 +- .../element/inheritance_manager3_test.dart | 6 +- .../test/src/dart/resolution/resolution.dart | 4 +- .../inference_update_1_test.dart | 10 +- .../test/src/summary/element_text.dart | 16 +- .../test/src/summary/elements_test.dart | 16 +- .../src/summary/resolved_ast_printer.dart | 2 +- .../change_builder/change_builder_dart.dart | 6 +- .../element_suggestion_builder.dart | 2 +- .../completion/suggestion_builder.dart | 2 +- .../lib/utilities/analyzer_converter.dart | 8 +- .../utilities/navigation/navigation_dart.dart | 6 +- .../completion/completion_target_test.dart | 2 +- pkg/nnbd_migration/lib/instrumentation.dart | 4 +- .../lib/src/decorated_type.dart | 10 +- pkg/nnbd_migration/lib/src/edge_builder.dart | 46 ++--- pkg/nnbd_migration/lib/src/fix_builder.dart | 10 +- pkg/nnbd_migration/lib/src/node_builder.dart | 6 +- .../lib/src/nullability_node_target.dart | 2 +- .../utilities/built_value_transformer.dart | 2 +- .../utilities/where_not_null_transformer.dart | 2 +- .../utilities/where_or_null_transformer.dart | 2 +- pkg/nnbd_migration/lib/src/variables.dart | 4 +- .../test/node_builder_test.dart | 4 +- 121 files changed, 571 insertions(+), 430 deletions(-) diff --git a/pkg/analysis_server/lib/src/cider/rename.dart b/pkg/analysis_server/lib/src/cider/rename.dart index 6d417a50ffe..ebb81cfac0a 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.enclosingElement3; + var parentClass = element.enclosingElement; // 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.enclosingElement3.lineInfo - .getLocation(stateClass.nameOffset); + var location = + stateClass.enclosingElement.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 interfaceElement = element.enclosingElement3; + var interfaceElement = element.enclosingElement; var fileResolver = canRename._fileResolver; var libraryPath = interfaceElement!.library!.source.fullName; @@ -382,7 +382,7 @@ class CiderRenameComputer { } bool _canRenameElement(Element element) { - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; 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 e857a2c4ef7..730a7e0dcec 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.enclosingElement3; + final enclosingElement = element.enclosingElement; 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 66493561c6f..1026b0a941a 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?.enclosingElement3; + final classElement = staticElement?.enclosingElement; 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 770fa97e298..e54d3997eea 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.enclosingElement3 is CompilationUnitElement; + var isTopLevel = element.enclosingElement 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.enclosingElement3 is CompilationUnitElement; + var isTopLevel = element.enclosingElement 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 d60ad4f2958..c2c341e211f 100644 --- a/pkg/analysis_server/lib/src/computer/computer_hover.dart +++ b/pkg/analysis_server/lib/src/computer/computer_hover.dart @@ -95,7 +95,7 @@ class DartUnitHoverComputer { hover.elementKind = element.kind.displayName; hover.isDeprecated = element.hasDeprecated; // not local element - if (element.enclosingElement3 is! ExecutableElement) { + if (element.enclosingElement is! ExecutableElement) { // containing class var containingClass = element.thisOrAncestorOfType(); @@ -184,7 +184,7 @@ class DartUnitHoverComputer { element = element.field; } if (element is ParameterElement) { - element = element.enclosingElement3; + element = element.enclosingElement; } if (element == null) { // This can happen when the code is invalid, such as having a field formal @@ -229,9 +229,9 @@ class DartUnitHoverComputer { var result = dartdocInfo.processDartdoc(rawDoc, includeSummary: includeSummary); - var documentedElementClass = documentedElement.enclosingElement3; + var documentedElementClass = documentedElement.enclosingElement; if (documentedElementClass != null && - documentedElementClass != element.enclosingElement3) { + documentedElementClass != element.enclosingElement) { 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 b4c1c4f3683..95b8fa034ff 100644 --- a/pkg/analysis_server/lib/src/computer/computer_outline.dart +++ b/pkg/analysis_server/lib/src/computer/computer_outline.dart @@ -528,7 +528,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.enclosingElement3; + var parent = element.enclosingElement; 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 852b00d6ae4..ed92d77dd5e 100644 --- a/pkg/analysis_server/lib/src/computer/computer_overrides.dart +++ b/pkg/analysis_server/lib/src/computer/computer_overrides.dart @@ -11,7 +11,7 @@ import 'package:analyzer/dart/element/element.dart'; /// Return the elements that the given [element] overrides. OverriddenElements findOverriddenElements(Element element) { - if (element.enclosingElement3 is InterfaceElement) { + if (element.enclosingElement is InterfaceElement) { return _OverriddenElementsFinder(element).find(); } return OverriddenElements(element, [], []); @@ -111,7 +111,7 @@ class _OverriddenElementsFinder { final Set _visited = {}; factory _OverriddenElementsFinder(Element seed) { - var class_ = seed.enclosingElement3 as InterfaceElement; + var class_ = seed.enclosingElement as InterfaceElement; 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 e500165fd02..85352f07c0e 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.enclosingElement3 is CompilationUnitElement) { + nodeElement.enclosingElement 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 b7393d512dd..ad1fa21d686 100644 --- a/pkg/analysis_server/lib/src/protocol_server.dart +++ b/pkg/analysis_server/lib/src/protocol_server.dart @@ -225,7 +225,7 @@ Location newLocation_fromUnit( OverriddenMember newOverriddenMember_fromEngine(engine.Element member, {required bool withNullability}) { var element = convertElement(member, withNullability: withNullability); - var className = member.enclosingElement3!.displayName; + var className = member.enclosingElement!.displayName; return OverriddenMember(element, className); } @@ -272,7 +272,7 @@ List _computePath(engine.Element element) { var path = []; if (element is engine.PrefixElement) { - element = element.enclosingElement3.definingCompilationUnit; + element = element.enclosingElement.definingCompilationUnit; } var withNullability = element.library?.isNonNullableByDefault ?? false; @@ -287,7 +287,7 @@ engine.CompilationUnitElement _getUnitElement(engine.Element element) { return element; } - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; 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 ae1d4fbd964..23c5bc9bd83 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.enclosingElement3 is InterfaceElement; + return element.enclosingElement is InterfaceElement; } } diff --git a/pkg/analysis_server/lib/src/search/type_hierarchy.dart b/pkg/analysis_server/lib/src/search/type_hierarchy.dart index 990c53b60fd..f5441d34b4c 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.enclosingElement3; + element = _pivotElement.enclosingElement; } if (_pivotElement is ExecutableElement) { - element = _pivotElement.enclosingElement3; + element = _pivotElement.enclosingElement; } if (element is InterfaceElement) { _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 95db08be1db..681944233cf 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 @@ -77,7 +77,7 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor { if (element.isOperator) { return; } - if (element.enclosingElement3 is! CompilationUnitElement) { + if (element.enclosingElement is! CompilationUnitElement) { return; } var returnType = element.returnType; @@ -108,7 +108,7 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor { void visitPropertyAccessorElement(PropertyAccessorElement element) { if (opType.includeReturnValueSuggestions || (opType.includeAnnotationSuggestions && element.variable.isConst)) { - var parent = element.enclosingElement3; + var parent = element.enclosingElement; if (parent is InterfaceElement || 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 b09c4711b82..4b1d4173bec 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 @@ -263,7 +263,7 @@ class _LocalVisitor extends LocalDeclarationVisitor { .thisOrAncestorOfType(); var enclosingElement = enclosingClass?.declaredElement; if (enclosingElement != null) { - var enclosingElement = field.enclosingElement3; + var enclosingElement = field.enclosingElement; if (enclosingElement is InterfaceElement) { inheritanceDistance = request.featureComputer .inheritanceDistanceFeature(enclosingElement, enclosingElement); @@ -342,7 +342,7 @@ class _LocalVisitor extends LocalDeclarationVisitor { var enclosingClass = request.target.containingNode .thisOrAncestorOfType(); if (enclosingClass != null) { - var enclosingElement = element?.enclosingElement3; + var enclosingElement = element?.enclosingElement; if (enclosingElement is InterfaceElement) { inheritanceDistance = request.featureComputer .inheritanceDistanceFeature( diff --git a/pkg/analysis_server/lib/src/services/completion/dart/redirecting_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/redirecting_contributor.dart index 9cceb5ca984..10561f1f55b 100644 --- a/pkg/analysis_server/lib/src/services/completion/dart/redirecting_contributor.dart +++ b/pkg/analysis_server/lib/src/services/completion/dart/redirecting_contributor.dart @@ -24,7 +24,7 @@ class RedirectingContributor extends DartCompletionContributor { var containingConstructor = parent.thisOrAncestorOfType(); var constructorElement = containingConstructor?.declaredElement; - var classElement = constructorElement?.enclosingElement3; + var classElement = constructorElement?.enclosingElement; if (classElement != null) { for (var constructor in classElement.constructors) { if (constructor != constructorElement) { @@ -52,7 +52,7 @@ class RedirectingContributor extends DartCompletionContributor { var containingConstructor = parent.thisOrAncestorOfType(); var constructorElement = containingConstructor?.declaredElement; - var classElement = constructorElement?.enclosingElement3; + var classElement = constructorElement?.enclosingElement; var libraryElement = request.libraryElement; if (classElement == null) { return; 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 8571456f172..d14953e3348 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 @@ -394,7 +394,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.enclosingElement3; + var enclosingClass = constructor.enclosingElement; var className = enclosingClass.name; if (className.isEmpty) { return; @@ -442,10 +442,10 @@ class SuggestionBuilder { } else if (element is ExtensionElement) { suggestExtension(element, kind: kind); } else if (element is FunctionElement && - element.enclosingElement3 is CompilationUnitElement) { + element.enclosingElement is CompilationUnitElement) { suggestTopLevelFunction(element, kind: kind); } else if (element is PropertyAccessorElement && - element.enclosingElement3 is CompilationUnitElement) { + element.enclosingElement is CompilationUnitElement) { suggestTopLevelPropertyAccessor(element); } else if (element is TypeAliasElement) { suggestTypeAlias(element); @@ -458,7 +458,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.enclosingElement3; + var enumElement = constant.enclosingElement; var enumName = enumElement.name; var completion = '$enumName.$constantName'; var relevance = @@ -706,7 +706,7 @@ class SuggestionBuilder { inheritanceDistance: inheritanceDistance, ); - var enclosingElement = method.enclosingElement3; + var enclosingElement = method.enclosingElement; if (method.name == 'setState' && enclosingElement is ClassElement && flutter.isExactState(enclosingElement)) { @@ -778,10 +778,10 @@ class SuggestionBuilder { // Optionally add Flutter child widget details. // todo (pq): revisit this special casing; likely it can be generalized away - var element = parameter.enclosingElement3; + var element = parameter.enclosingElement; // If appendColon is false, default values should never be appended. if (element is ConstructorElement && appendColon) { - if (Flutter.instance.isWidget(element.enclosingElement3)) { + if (Flutter.instance.isWidget(element.enclosingElement)) { var codeStyleOptions = request .analysisSession.analysisContext.analysisOptions.codeStyleOptions; // Don't bother with nullability. It won't affect default list values. @@ -1082,9 +1082,9 @@ class SuggestionBuilder { void suggestTopLevelPropertyAccessor(PropertyAccessorElement accessor, {String? prefix}) { assert( - accessor.enclosingElement3 is CompilationUnitElement, + accessor.enclosingElement is CompilationUnitElement, 'Enclosing element of ${accessor.runtimeType} is ' - '${accessor.enclosingElement3.runtimeType}.'); + '${accessor.enclosingElement.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 @@ -1134,7 +1134,7 @@ class SuggestionBuilder { /// referenced using a prefix, then the [prefix] should be provided. void suggestTopLevelVariable(TopLevelVariableElement variable, {String? prefix}) { - assert(variable.enclosingElement3 is CompilationUnitElement); + assert(variable.enclosingElement is CompilationUnitElement); var relevance = _computeTopLevelRelevance(variable, elementType: variable.type); _addBuilder( @@ -1367,7 +1367,7 @@ class SuggestionBuilder { withNullability: _isNonNullableByDefault, ); - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; String? declaringType; if (enclosingElement is InterfaceElement) { @@ -1426,7 +1426,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.enclosingElement3; + var enclosing = element.enclosingElement; if (enclosing is InterfaceElement) { return enclosing.name; } else if (enclosing is ExtensionElement) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_late.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_late.dart index 4c310159cab..b6dc2ecd234 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 @@ -60,7 +60,7 @@ class AddLate extends CorrectionProducer { getter.isSynthetic && !getter.variable.isSynthetic && getter.variable.setter == null && - getter.enclosingElement3 is InterfaceElement) { + getter.enclosingElement is InterfaceElement) { 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 d37eab0f96a..05ca6a5fd2c 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.enclosingElement3; + var declaringElement = invokedElement.enclosingElement; if (declaringElement is InterfaceElement) { _className = declaringElement.name; diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_class_to_enum.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_class_to_enum.dart index f25096cfb4e..b050fd1849a 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 @@ -76,7 +76,7 @@ class _BaseVisitor extends RecursiveAstVisitor { var constructorElement = node.constructorName.staticElement; return constructorElement != null && !constructorElement.isFactory && - constructorElement.enclosingElement3 == classElement; + constructorElement.enclosingElement == classElement; } } @@ -567,7 +567,7 @@ class _EnumDescription { initializer.constructorName.staticElement; if (constructorElement != null && !constructorElement.isFactory && - constructorElement.enclosingElement3 == classElement) { + constructorElement.enclosingElement == 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 34bc5523917..f31dc29bebb 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.enclosingElement3; + var enclosingElement = element.enclosingElement; 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 d5e46f0c44d..2870da687ca 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.enclosingElement3; + var enclosing = element.enclosingElement; if (enclosing is InterfaceElement) { if (enclosing.getSetter(element.name) != null) { return; diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_into_is_not_empty.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_into_is_not_empty.dart index 2a1ab485bbe..cc2ed4d093e 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.enclosingElement3; + var propertyTarget = propertyElement.enclosingElement; 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 bb1adf8d20c..df050b268ed 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/convert_map_from_iterable_to_for_literal.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_map_from_iterable_to_for_literal.dart @@ -42,7 +42,7 @@ class ConvertMapFromIterableToForLiteral extends CorrectionProducer { var element = creation.constructorName.staticElement; if (element == null || element.name != 'fromIterable' || - element.enclosingElement3 != typeProvider.mapElement) { + element.enclosingElement != 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 c19dd622e93..f18ea389693 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 @@ -164,7 +164,7 @@ class CreateConstructor extends CorrectionProducer { } // prepare target ClassDeclaration - var targetElement = constructorElement.enclosingElement3; + var targetElement = constructorElement.enclosingElement; 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 3a2077cc3dc..a4013bfda1c 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 @@ -313,7 +313,7 @@ class _ReplacementEditBuilder extends RecursiveAstVisitor { } var element = node.staticElement; if (element is ExecutableElement && - element.enclosingElement3 == widgetClassElement && + element.enclosingElement == 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 da2a6983247..f6350442506 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 @@ -316,7 +316,7 @@ class _ReplacementEditBuilder extends RecursiveAstVisitor { } var element = node.staticElement; if (element is ExecutableElement && - element.enclosingElement3 == widgetClassElement && + element.enclosingElement == widgetClassElement && !elementsToMove.contains(element)) { var parent = node.parent; if (parent is PrefixedIdentifier) { @@ -359,7 +359,7 @@ class _StatelessVerifier extends RecursiveAstVisitor { void visitMethodInvocation(MethodInvocation node) { var methodElement = node.methodName.staticElement?.declaration; if (methodElement is ClassMemberElement) { - var classElement = methodElement.enclosingElement3; + var classElement = methodElement.enclosingElement; 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 3a9a404fed9..e667453caaa 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.enclosingElement3 is! ClassElement) { + if (getter.enclosingElement 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 21b7a43b6ae..07e51bb1185 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.enclosingElement3; + var enclosingElement = memberElement.enclosingElement; 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 1dd813cdfe9..ace51ce5021 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.enclosingElement3 is! InterfaceElement) { + if (!accessor.isGetter || accessor.enclosingElement is! InterfaceElement) { // TODO(brianwilkerson) Should we also require that the getter be synthetic? return; } diff --git a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_matcher.dart b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_matcher.dart index 0f2db8bbd1c..d4a64a483f4 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 @@ -208,7 +208,7 @@ class _MatcherBuilder { ); } } else if (parent is SuperConstructorInvocation) { - var superclassName = parent.staticElement?.enclosingElement3.name; + var superclassName = parent.staticElement?.enclosingElement.name; if (superclassName != null) { _addMatcher( components: [parent.constructorName?.name ?? '', superclassName], @@ -509,7 +509,7 @@ class _MatcherBuilder { } } if (element != null) { - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement is InterfaceElement) { return [identifier.name, enclosingElement.name]; } else if (enclosingElement is ExtensionElement) { diff --git a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/rename_parameter.dart b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/rename_parameter.dart index 2461903ab08..7be444461b1 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.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement is InterfaceElement) { var name = Name(enclosingElement.library.source.uri, element.name); return InheritanceManager3().getInherited2(enclosingElement, name); diff --git a/pkg/analysis_server/lib/src/services/correction/namespace.dart b/pkg/analysis_server/lib/src/services/correction/namespace.dart index a2abded6445..051e3fdf4d8 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.enclosingElement3 is! CompilationUnitElement) { + if (element.enclosingElement 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 97abd970be6..afceabc0bdf 100644 --- a/pkg/analysis_server/lib/src/services/correction/util.dart +++ b/pkg/analysis_server/lib/src/services/correction/util.dart @@ -226,7 +226,7 @@ String getElementKindName(Element element) { String getElementQualifiedName(Element element) { var kind = element.kind; if (kind == ElementKind.FIELD || kind == ElementKind.METHOD) { - return '${element.enclosingElement3!.displayName}.${element.displayName}'; + return '${element.enclosingElement!.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!; @@ -1434,7 +1434,7 @@ class CorrectionUtils { /// Checks if [element] is visible in [targetExecutableElement] or /// [targetClassElement]. bool _isTypeParameterVisible(TypeParameterElement element) { - var enclosing = element.enclosingElement3; + var enclosing = element.enclosingElement; 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 6e2f3b8a51c..65fc5a6b480 100644 --- a/pkg/analysis_server/lib/src/services/flutter/property.dart +++ b/pkg/analysis_server/lib/src/services/flutter/property.dart @@ -467,7 +467,7 @@ class _EdgeInsetsProperty { var constructor = propertyExpression.constructorName.staticElement; if (flutter != null && constructor != null && - constructor.enclosingElement3 == classEdgeInsets) { + constructor.enclosingElement == 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 416118f03d6..40b7cba3575 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.enclosingElement3; + var classElement = constructorElement.enclosingElement; if (!elementsBeingProcessed.add(classElement)) return; var existingNamed = {}; @@ -520,7 +520,7 @@ class _WidgetDescriptionComputer { } protocol.FlutterWidgetPropertyValueEnumItem _toEnumItem(FieldElement field) { - var interfaceElement = field.enclosingElement3 as InterfaceElement; + var interfaceElement = field.enclosingElement as InterfaceElement; var libraryUriStr = '${interfaceElement.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.enclosingElement3 as InterfaceElement; + var enclosingClass = field.enclosingElement as InterfaceElement; 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 847e8616ac0..162347e0354 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.enclosingElement3.name; + var name = element.enclosingElement.name; var constructorName = element.name; if (constructorName.isNotEmpty) { name = '$name.$constructorName'; @@ -725,7 +725,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor with OutputUtils { // We can't call _handleRefEdge as the anchor node has already been // written out. var enclosingEltVName = _vNameFromElement( - constructorElement.enclosingElement3, schema.RECORD_KIND); + constructorElement.enclosingElement, schema.RECORD_KIND); var anchorVName = _vNameAnchor(constructorName.offset, constructorName.end); addEdge(anchorVName, schema.REF_EDGE, enclosingEltVName); @@ -1416,7 +1416,7 @@ class SignatureElementVisitor extends GeneralizingElementVisitor { @override StringBuffer visitElement(Element element) { assert(element is! MultiplyInheritedExecutableElement); - var enclosingElt = element.enclosingElement3!; + var enclosingElt = element.enclosingElement!; var buffer = enclosingElt.accept(this)!; if (buffer.isNotEmpty) { buffer.write('#'); @@ -1448,7 +1448,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.enclosingElement3!.accept(this)! + return element.enclosingElement!.accept(this)! ..write('.') ..write(element.name); } diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_getter_to_method.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_getter_to_method.dart index a84650858bc..f2d4cd815fe 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_getter_to_method.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_getter_to_method.dart @@ -46,15 +46,15 @@ class ConvertGetterToMethodRefactoringImpl extends RefactoringImpl Future createChange() async { change = SourceChange(refactoringName); // function - if (element.enclosingElement3 is CompilationUnitElement) { + if (element.enclosingElement is CompilationUnitElement) { await _updateElementDeclaration(element); await _updateElementReferences(element); } // method var field = element.variable; if (field is FieldElement && - (field.enclosingElement3 is InterfaceElement || - field.enclosingElement3 is ExtensionElement)) { + (field.enclosingElement is InterfaceElement || + field.enclosingElement 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/legacy/convert_method_to_getter.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_method_to_getter.dart index 069baef65cf..38ed56c8e98 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_method_to_getter.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_method_to_getter.dart @@ -72,7 +72,7 @@ class ConvertMethodToGetterRefactoringImpl extends RefactoringImpl RefactoringStatus _checkElement() { // check Element type if (element is FunctionElement) { - if (element.enclosingElement3 is! CompilationUnitElement) { + if (element.enclosingElement is! CompilationUnitElement) { return RefactoringStatus.fatal( 'Only top-level functions can be converted to getters.'); } diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart index ff1ece3c256..ef6bd79ac61 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart @@ -38,7 +38,7 @@ bool isLocalElement(Element? element) { return element is LocalVariableElement || element is ParameterElement || element is FunctionElement && - element.enclosingElement3 is! CompilationUnitElement; + element.enclosingElement is! CompilationUnitElement; } Element? _getLocalElement(SimpleIdentifier node) { diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_widget.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_widget.dart index 5c6aed4bf39..f1c57588887 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_widget.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_widget.dart @@ -669,7 +669,7 @@ class _ParametersCollector extends RecursiveAstVisitor { enclosingClass, ...enclosingClass.allSupertypes.map((t) => t.element2) ]; - return enclosingClasses.contains(element.enclosingElement3); + return enclosingClasses.contains(element.enclosingElement); } return false; } diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/inline_method.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/inline_method.dart index b25f05e610e..2674cb8ba26 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/inline_method.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/inline_method.dart @@ -213,7 +213,7 @@ class InlineMethodRefactoringImpl extends RefactoringImpl @override String? get className { - var interfaceElement = _methodElement?.enclosingElement3; + var interfaceElement = _methodElement?.enclosingElement; if (interfaceElement is InterfaceElement) { return interfaceElement.displayName; } @@ -835,13 +835,13 @@ class _VariablesVisitor extends GeneralizingAstVisitor { } else { return; } - if (element.enclosingElement3 is! InterfaceElement) { + if (element.enclosingElement is! InterfaceElement) { return; } // record the implicit static or instance reference var offset = node.offset; if (element.isStatic) { - var className = element.enclosingElement3.displayName; + var className = element.enclosingElement.displayName; result.addImplicitClassNameOffset(className, offset); } else { result.addImplicitThisOffset(offset); diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart index dac82ded338..3d19013227a 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart @@ -417,7 +417,7 @@ abstract class RenameRefactoring implements Refactoring { if (element is PropertyAccessorElement) { element = element.variable; } - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement is CompilationUnitElement) { return RenameUnitMemberRefactoringImpl( workspace, sessionHelper, resolvedUnit, element); diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_class_member.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_class_member.dart index cbaa739d9c3..e43571d1919 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_class_member.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_class_member.dart @@ -96,7 +96,7 @@ class RenameClassMemberRefactoringImpl extends RenameRefactoringImpl { } else { processor.addDeclarationEdit(renameElement); if (!newName.startsWith('_')) { - var interfaceElement = renameElement.enclosingElement3; + var interfaceElement = renameElement.enclosingElement; if (interfaceElement is InterfaceElement) { for (var constructor in interfaceElement.constructors) { for (var parameter in constructor.parameters) { @@ -230,7 +230,7 @@ class _BaseClassMemberValidator { var declarations = await searchEngine.searchMemberDeclarations(name); for (var declaration in declarations) { var nameElement = getSyntheticAccessorVariable(declaration.element); - var nameClass = nameElement.enclosingElement3; + var nameClass = nameElement.enclosingElement; // the renamed Element shadows a member of a superclass if (superClasses.contains(nameClass)) { result.addError( @@ -366,7 +366,7 @@ class _RenameClassMemberValidator extends _BaseClassMemberValidator { var subClasses = await searchEngine.searchAllSubtypes(interfaceElement); // check shadowing of class names for (var element in elements) { - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement is InterfaceElement && enclosingElement.name == name) { result.addError( diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_constructor.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_constructor.dart index dab16f287e8..034d985703a 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_constructor.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_constructor.dart @@ -77,7 +77,7 @@ class RenameConstructorRefactoringImpl extends RenameRefactoringImpl { } void _analyzePossibleConflicts(RefactoringStatus result) { - var parentClass = element.enclosingElement3; + var parentClass = element.enclosingElement; // 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 ' @@ -102,7 +102,7 @@ class RenameConstructorRefactoringImpl extends RenameRefactoringImpl { } Future _replaceSynthetic() async { - var classElement = element.enclosingElement3; + var classElement = element.enclosingElement; var result = await sessionHelper.getElementDeclaration(classElement); if (result == null) { diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_unit_member.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_unit_member.dart index cf575bf28e2..f2e22b47c16 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_unit_member.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_unit_member.dart @@ -216,7 +216,7 @@ class _BaseUnitMemberValidator { var declarations = await searchEngine.searchMemberDeclarations(name); for (var declaration in declarations) { var member = declaration.element; - var declaringClass = member.enclosingElement3 as InterfaceElement; + var declaringClass = member.enclosingElement as InterfaceElement; var memberReferences = await searchEngine.searchReferences(member); for (var memberReference in memberReferences) { var refElement = memberReference.element; diff --git a/pkg/analysis_server/lib/src/services/search/hierarchy.dart b/pkg/analysis_server/lib/src/services/search/hierarchy.dart index 4125c091dc9..d99b8732566 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.enclosingElement3; + var enclosingElement = member.enclosingElement; 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.enclosingElement3; + var method = element.enclosingElement; 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 906f3b4b984..43f190d7f06 100644 --- a/pkg/analysis_server/lib/src/utilities/extensions/element.dart +++ b/pkg/analysis_server/lib/src/utilities/extensions/element.dart @@ -30,15 +30,15 @@ extension ElementExtension on Element { if (hasDeprecated) { return true; } - var ancestor = enclosingElement3; + var ancestor = enclosingElement; if (ancestor is InterfaceElement) { if (ancestor.hasDeprecated) { return true; } - ancestor = ancestor.enclosingElement3; + ancestor = ancestor.enclosingElement; } return ancestor is CompilationUnitElement && - ancestor.enclosingElement3.hasDeprecated; + ancestor.enclosingElement.hasDeprecated; } /// Return this element and all its enclosing elements. @@ -46,7 +46,7 @@ extension ElementExtension on Element { var current = this; while (true) { yield current; - var enclosing = current.enclosingElement3; + var enclosing = current.enclosingElement; if (enclosing == null) { break; } @@ -69,7 +69,7 @@ extension MethodElementExtensions on MethodElement { if (name != 'cast') { return false; } - var definingClass = enclosingElement3; + var definingClass = enclosingElement; if (definingClass is! ClassElement) { return false; } @@ -85,7 +85,7 @@ extension MethodElementExtensions on MethodElement { if (name != 'toList') { return false; } - var definingClass = enclosingElement3; + var definingClass = enclosingElement; if (definingClass is! ClassElement) { return false; } @@ -98,7 +98,7 @@ extension MethodElementExtensions on MethodElement { if (name != 'toSet') { return false; } - var definingClass = enclosingElement3; + var definingClass = enclosingElement; 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 afc37f7de46..625d6c86d26 100644 --- a/pkg/analysis_server/lib/src/utilities/flutter.dart +++ b/pkg/analysis_server/lib/src/utilities/flutter.dart @@ -203,7 +203,7 @@ class Flutter { /// Return the presentation for the given Flutter `Widget` creation [node]. String? getWidgetPresentationText(InstanceCreationExpression node) { - var element = node.constructorName.staticElement?.enclosingElement3; + var element = node.constructorName.staticElement?.enclosingElement; if (!isWidget(element)) { return null; } @@ -521,7 +521,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?.enclosingElement3; + var element = expr?.constructorName.staticElement?.enclosingElement; return isWidget(element); } diff --git a/pkg/analysis_server/tool/code_completion/completion_metrics.dart b/pkg/analysis_server/tool/code_completion/completion_metrics.dart index 6c514210506..312562352b9 100644 --- a/pkg/analysis_server/tool/code_completion/completion_metrics.dart +++ b/pkg/analysis_server/tool/code_completion/completion_metrics.dart @@ -1701,7 +1701,7 @@ class CompletionResult { var entity = expectedCompletion.syntacticEntity; var element = _getElement(entity); if (element != null) { - var parent = element.enclosingElement3; + var parent = element.enclosingElement; if (parent is InterfaceElement || parent is ExtensionElement) { if (_isStatic(element)) { return CompletionGroup.staticMember; diff --git a/pkg/analysis_server/tool/code_completion/flutter_metrics.dart b/pkg/analysis_server/tool/code_completion/flutter_metrics.dart index fdd758e5879..edab7018d7e 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.enclosingElement3.name; + var childWidget = element.enclosingElement.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 555bf480486..71dc018b1de 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.enclosingElement3 is InterfaceElement) { + if (!element.isStatic && element.enclosingElement is InterfaceElement) { var overriddenMembers = inheritanceManager.getOverridden2( - element.enclosingElement3 as InterfaceElement, + element.enclosingElement as InterfaceElement, Name(element.librarySource.uri, element.name)); if (overriddenMembers != null) { // Consider limiting this to the most immediate override. If the @@ -1406,7 +1406,7 @@ class RelevanceDataCollector extends RecursiveAstVisitor { Element? currentElement = element; while (currentElement != enclosingLibrary) { depth++; - currentElement = currentElement?.enclosingElement3; + currentElement = currentElement?.enclosingElement; } 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.enclosingElement3!; + var definingElement = element.enclosingElement!; 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 1056ce9c835..d57ecffd1dc 100644 --- a/pkg/analyzer/CHANGELOG.md +++ b/pkg/analyzer/CHANGELOG.md @@ -1,3 +1,6 @@ +## 5.2.0-dev +* Deprecated `Element.enclosingElement3`, use `enclosingElement` instead. + ## 5.1.0 * Deprecated `AstNode.name2`, use `name` instead. * Deprecated `AstNode.declaredElement2`, use `declaredElement` instead. diff --git a/pkg/analyzer/lib/dart/element/element.dart b/pkg/analyzer/lib/dart/element/element.dart index d5580e9c3e1..084446d6bb6 100644 --- a/pkg/analyzer/lib/dart/element/element.dart +++ b/pkg/analyzer/lib/dart/element/element.dart @@ -57,6 +57,10 @@ import 'package:pub_semver/pub_semver.dart'; /// Clients may not extend, implement or mix-in this class. @experimental abstract class AugmentationImportElement implements _ExistingElement { + @override + LibraryOrAugmentationElement get enclosingElement; + + @Deprecated('Use enclosingElement instead') @override LibraryOrAugmentationElement get enclosingElement3; @@ -236,6 +240,10 @@ abstract class ClassMemberElement implements Element { // TODO(brianwilkerson) Either remove this class or rename it to something // more correct. + @override + Element get enclosingElement; + + @Deprecated('Use enclosingElement instead') @override Element get enclosingElement3; @@ -271,6 +279,11 @@ abstract class CompilationUnitElement implements UriReferencedElement { /// Return the library, or library augmentation that encloses this unit. @override + LibraryOrAugmentationElement get enclosingElement; + + /// Return the library, or library augmentation that encloses this unit. + @Deprecated('Use enclosingElement instead') + @override LibraryOrAugmentationElement get enclosingElement3; /// Return a list containing all of the enums contained in this compilation @@ -344,6 +357,10 @@ abstract class ConstructorElement @override String get displayName; + @override + InterfaceElement get enclosingElement; + + @Deprecated('Use enclosingElement instead') @override InterfaceElement get enclosingElement3; @@ -490,6 +507,12 @@ 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. + 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. + @Deprecated('Use enclosingElement instead') Element? get enclosingElement3; /// Return `true` if this element has an annotation of the form @@ -1078,6 +1101,10 @@ abstract class ExecutableElement implements FunctionTypedElement { @override String get displayName; + @override + Element get enclosingElement; + + @Deprecated('Use enclosingElement instead') @override Element get enclosingElement3; @@ -1128,6 +1155,10 @@ abstract class ExtensionElement implements TypeParameterizedElement { /// declared in this extension. List get accessors; + @override + CompilationUnitElement get enclosingElement; + + @Deprecated('Use enclosingElement instead') @override CompilationUnitElement get enclosingElement3; @@ -1522,6 +1553,10 @@ abstract class InterfaceOrAugmentationElement /// class, as is the case when this element represents an enum or a mixin. List get constructors; + @override + CompilationUnitElement get enclosingElement; + + @Deprecated('Use enclosingElement instead') @override CompilationUnitElement get enclosingElement3; @@ -1563,6 +1598,10 @@ abstract class InterfaceOrAugmentationElement /// /// Clients may not extend, implement or mix-in this class. abstract class LabelElement implements Element { + @override + ExecutableElement get enclosingElement; + + @Deprecated('Use enclosingElement instead') @override ExecutableElement get enclosingElement3; @@ -2002,6 +2041,11 @@ abstract class PartElement implements _ExistingElement { abstract class PrefixElement implements _ExistingElement { /// Return the library, or library augmentation that encloses this element. @override + LibraryOrAugmentationElement get enclosingElement; + + /// Return the library, or library augmentation that encloses this element. + @Deprecated('Use enclosingElement instead') + @override LibraryOrAugmentationElement get enclosingElement3; /// Return the imports that share this prefix. @@ -2073,6 +2117,10 @@ abstract class PropertyAccessorElement implements ExecutableElement { @override PropertyAccessorElement get declaration; + @override + Element get enclosingElement; + + @Deprecated('Use enclosingElement instead') @override Element get enclosingElement3; @@ -2192,6 +2240,10 @@ abstract class TypeAliasElement /// a [FunctionType]. DartType get aliasedType; + @override + CompilationUnitElement get enclosingElement; + + @Deprecated('Use enclosingElement instead') @override CompilationUnitElement get enclosingElement3; diff --git a/pkg/analyzer/lib/src/dart/analysis/index.dart b/pkg/analyzer/lib/src/dart/analysis/index.dart index 2152fb67c60..9ccf01c538b 100644 --- a/pkg/analyzer/lib/src/dart/analysis/index.dart +++ b/pkg/analyzer/lib/src/dart/analysis/index.dart @@ -19,7 +19,7 @@ Element? declaredParameterElement( SimpleIdentifier node, Element? element, ) { - if (element == null || element.enclosingElement3 != null) { + if (element == null || element.enclosingElement != null) { return element; } @@ -64,7 +64,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.enclosingElement3) { + for (Element? e = element; e != null; e = e.enclosingElement) { if (e is CompilationUnitElement) { return e; } @@ -89,21 +89,21 @@ class ElementNameComponents { String? parameterName; if (element is ParameterElement) { parameterName = element.name; - element = element.enclosingElement3!; + element = element.enclosingElement!; } String? classMemberName; - if (element.enclosingElement3 is InterfaceElement || - element.enclosingElement3 is ExtensionElement) { + if (element.enclosingElement is InterfaceElement || + element.enclosingElement is ExtensionElement) { classMemberName = element.name; - element = element.enclosingElement3!; + element = element.enclosingElement!; } String? unitMemberName; - if (element.enclosingElement3 is CompilationUnitElement) { + if (element.enclosingElement is CompilationUnitElement) { unitMemberName = element.name; if (element is ExtensionElement && unitMemberName == null) { - var enclosingUnit = element.enclosingElement3; + var enclosingUnit = element.enclosingElement; var indexOf = enclosingUnit.extensions.indexOf(element); unitMemberName = 'extension-$indexOf'; } @@ -140,7 +140,7 @@ class IndexElementInfo { } else if (element.isSynthetic) { if (elementKind == ElementKind.CONSTRUCTOR) { kind = IndexSyntheticElementKind.constructor; - element = element.enclosingElement3!; + element = element.enclosingElement!; } else if (element is FunctionElement && element.name == FunctionElement.LOAD_LIBRARY_NAME) { kind = IndexSyntheticElementKind.loadLibrary; @@ -152,7 +152,7 @@ class IndexElementInfo { } else if (elementKind == ElementKind.GETTER || elementKind == ElementKind.SETTER) { var accessor = element as PropertyAccessorElement; - Element enclosing = element.enclosingElement3; + Element enclosing = element.enclosingElement; bool isEnumGetter = enclosing is EnumElement; if (isEnumGetter && accessor.name == 'index') { kind = IndexSyntheticElementKind.enumIndex; @@ -167,7 +167,7 @@ class IndexElementInfo { element = accessor.variable; } } else if (element is MethodElement) { - Element enclosing = element.enclosingElement3; + Element enclosing = element.enclosingElement; bool isEnumMethod = enclosing is EnumElement; if (isEnumMethod && element.name == 'toString') { kind = IndexSyntheticElementKind.enumToString; @@ -492,14 +492,14 @@ class _IndexContributor extends GeneralizingAstVisitor { elementKind == ElementKind.TYPE_PARAMETER || elementKind == ElementKind.FUNCTION && element is FunctionElement && - element.enclosingElement3 is ExecutableElement || + element.enclosingElement 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.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement == null || enclosingElement.isSynthetic) { return; } @@ -509,7 +509,7 @@ class _IndexContributor extends GeneralizingAstVisitor { // named parameters. Ignore them. if (elementKind == ElementKind.PARAMETER && element is ParameterElement && - element.enclosingElement3 is GenericFunctionTypeElement) { + element.enclosingElement is GenericFunctionTypeElement) { return; } // Add the relation. @@ -989,7 +989,7 @@ class _IndexContributor extends GeneralizingAstVisitor { ConstructorElement? constructor) { var seenConstructors = {}; while (constructor is ConstructorElementImpl && constructor.isSynthetic) { - var enclosing = constructor.enclosingElement3; + var enclosing = constructor.enclosingElement; if (enclosing is ClassElement && enclosing.isMixinApplication) { var superInvocation = constructor.constantInitializers .whereType() diff --git a/pkg/analyzer/lib/src/dart/analysis/search.dart b/pkg/analyzer/lib/src/dart/analysis/search.dart index a2df00ebda8..cdbf4140761 100644 --- a/pkg/analyzer/lib/src/dart/analysis/search.dart +++ b/pkg/analyzer/lib/src/dart/analysis/search.dart @@ -286,7 +286,7 @@ class Search { } else if (element is PropertyInducingElement) { return _searchReferences_Field(element, searchedFiles); } else if (kind == ElementKind.FUNCTION || kind == ElementKind.METHOD) { - if (element.enclosingElement3 is ExecutableElement) { + if (element.enclosingElement is ExecutableElement) { return _searchReferences_Local( element, (n) => n is Block, searchedFiles); } @@ -434,7 +434,7 @@ class Search { // Prepare the element name. String name = element.displayName; if (element is ConstructorElement) { - name = element.enclosingElement3.displayName; + name = element.enclosingElement.displayName; } // Prepare the list of files that reference the element name. @@ -683,7 +683,7 @@ class Search { )); if (parameter.isNamed || parameter.isOptionalPositional || - parameter.enclosingElement3 is ConstructorElement) { + parameter.enclosingElement is ConstructorElement) { results.addAll(await _searchReferences(parameter, searchedFiles)); } return results; @@ -939,7 +939,7 @@ class _FindCompilationUnitDeclarations { return; } - var enclosing = element.enclosingElement3; + var enclosing = element.enclosingElement; 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 92f31c3809f..ad6d426a582 100644 --- a/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart +++ b/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart @@ -374,7 +374,7 @@ class ConstantVerifier extends RecursiveAstVisitor { // lookup for == var method = element.lookUpConcreteMethod("==", _currentLibrary); if (method == null || - (method.enclosingElement3 as ClassElement).isDartCoreObject) { + (method.enclosingElement 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 7234ee82b5b..2d4094845b0 100644 --- a/pkg/analyzer/lib/src/dart/constant/evaluation.dart +++ b/pkg/analyzer/lib/src/dart/constant/evaluation.dart @@ -215,7 +215,7 @@ class ConstantEvaluationEngine { void computeDependencies( ConstantEvaluationTarget constant, ReferenceFinderCallback callback) { if (constant is ConstFieldElementImpl && constant.isEnumConstant) { - var enclosing = constant.enclosingElement3; + var enclosing = constant.enclosingElement; if (enclosing is EnumElementImpl) { if (enclosing.name == 'values') { return; @@ -275,7 +275,7 @@ class ConstantEvaluationEngine { } } } - for (FieldElement field in constant.enclosingElement3.fields) { + for (FieldElement field in constant.enclosingElement.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) && @@ -389,7 +389,7 @@ class ConstantEvaluationEngine { return null; } var typeProvider = constructor.library.typeProvider; - if (constructor.enclosingElement3 == typeProvider.symbolElement) { + if (constructor.enclosingElement == 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. @@ -413,7 +413,7 @@ class ConstantEvaluationEngine { static _EnumConstant? _enumConstant(VariableElementImpl element) { if (element is ConstFieldElementImpl && element.isEnumConstant) { - var enum_ = element.enclosingElement3; + var enum_ = element.enclosingElement; if (enum_ is EnumElementImpl) { var index = enum_.constants.indexOf(element); assert(index >= 0); @@ -890,7 +890,7 @@ class ConstantVisitor extends UnifyingAstVisitor { if (element.name == "identical") { NodeList arguments = node.argumentList.arguments; if (arguments.length == 2) { - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement is CompilationUnitElement) { LibraryElement library = enclosingElement.library; if (library.isDartCore) { @@ -1474,7 +1474,7 @@ class ConstantVisitor extends UnifyingAstVisitor { return false; } return identifier.name == 'length' && - identifier.staticElement?.enclosingElement3 is! ExtensionElement; + identifier.staticElement?.enclosingElement is! ExtensionElement; } void _reportNotPotentialConstants(AstNode node) { @@ -2175,7 +2175,7 @@ class _InstanceCreationEvaluator { List arguments, { required bool isNullSafe, }) { - final definingClass = _constructor.enclosingElement3; + final definingClass = _constructor.enclosingElement; var argumentCount = arguments.length; if (_constructor.name == "fromEnvironment") { if (!_checkFromEnvironmentArguments(arguments, definingType)) { @@ -2286,7 +2286,7 @@ class _InstanceCreationEvaluator { } void _checkFields() { - var fields = _constructor.enclosingElement3.fields; + var fields = _constructor.enclosingElement.fields; for (var field in fields) { if ((field.isFinal || field.isConst) && !field.isStatic && @@ -2575,7 +2575,7 @@ class _InstanceCreationEvaluator { } void _checkTypeParameters() { - var typeParameters = _constructor.enclosingElement3.typeParameters; + var typeParameters = _constructor.enclosingElement.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 c01cd99fec8..c988dc593a1 100644 --- a/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart +++ b/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart @@ -231,7 +231,7 @@ class _Collector { } if (element is ParameterElement) { - var enclosing = element.enclosingElement3; + var enclosing = element.enclosingElement; 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 7e8f8c02285..7f25506f269 100644 --- a/pkg/analyzer/lib/src/dart/element/element.dart +++ b/pkg/analyzer/lib/src/dart/element/element.dart @@ -104,10 +104,14 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl String get displayName => name; @override - CompilationUnitElementImpl get enclosingElement3 { + CompilationUnitElementImpl get enclosingElement { return _enclosingElement as CompilationUnitElementImpl; } + @Deprecated('Use enclosingElement instead') + @override + CompilationUnitElementImpl get enclosingElement3 => enclosingElement; + /// Set the fields contained in this class to the given [fields]. set fields(List fields) { for (FieldElement field in fields) { @@ -293,7 +297,7 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl !getter.isAbstract && !getter.isStatic && getter.isAccessibleIn2(library) && - getter.enclosingElement3 != this)); + getter.enclosingElement != this)); ExecutableElement? lookUpInheritedConcreteMember( String name, LibraryElement library) { @@ -313,7 +317,7 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl !method.isAbstract && !method.isStatic && method.isAccessibleIn2(library) && - method.enclosingElement3 != this)); + method.enclosingElement != this)); @override PropertyAccessorElement? lookUpInheritedConcreteSetter( @@ -323,7 +327,7 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl !setter.isAbstract && !setter.isStatic && setter.isAccessibleIn2(library) && - setter.enclosingElement3 != this)); + setter.enclosingElement != this)); @override MethodElement? lookUpInheritedMethod( @@ -332,7 +336,7 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl (MethodElement method) => !method.isStatic && method.isAccessibleIn2(library) && - method.enclosingElement3 != this)); + method.enclosingElement != this)); @override MethodElement? lookUpMethod(String methodName, LibraryElement library) => @@ -518,9 +522,15 @@ class AugmentationImportElementImpl extends _ExistingElementImpl required this.uri, }) : super(null, importKeywordOffset); + @override + LibraryOrAugmentationElementImpl get enclosingElement { + return super.enclosingElement as LibraryOrAugmentationElementImpl; + } + + @Deprecated('Use enclosingElement instead') @override LibraryOrAugmentationElementImpl get enclosingElement3 { - return super.enclosingElement3 as LibraryOrAugmentationElementImpl; + return enclosingElement; } @override @@ -642,7 +652,7 @@ class ClassElementImpl extends ClassOrMixinElementImpl implements ClassElement { bool get hasNoSuchMethod { MethodElement? method = lookUpConcreteMethod( FunctionElement.NO_SUCH_METHOD_METHOD_NAME, library); - var definingClass = method?.enclosingElement3 as ClassElement?; + var definingClass = method?.enclosingElement as ClassElement?; return definingClass != null && !definingClass.isDartCoreObject; } @@ -1132,8 +1142,12 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl } @override - LibraryOrAugmentationElement get enclosingElement3 => - super.enclosingElement3 as LibraryOrAugmentationElement; + LibraryOrAugmentationElement get enclosingElement => + super.enclosingElement as LibraryOrAugmentationElement; + + @Deprecated('Use enclosingElement instead') + @override + LibraryOrAugmentationElement get enclosingElement3 => enclosingElement; @override CompilationUnitElementImpl get enclosingUnit { @@ -1210,7 +1224,7 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl } @override - AnalysisSession get session => enclosingElement3.session; + AnalysisSession get session => enclosingElement.session; @override List get topLevelVariables { @@ -1384,7 +1398,7 @@ class ConstructorElementImpl extends ExecutableElementImpl @override String get displayName { - var className = enclosingElement3.name; + var className = enclosingElement.name; var name = this.name; if (name.isNotEmpty) { return '$className.$name'; @@ -1394,8 +1408,12 @@ class ConstructorElementImpl extends ExecutableElementImpl } @override - InterfaceElement get enclosingElement3 => - super.enclosingElement3 as AbstractClassElementImpl; + InterfaceElement get enclosingElement => + super.enclosingElement as AbstractClassElementImpl; + + @Deprecated('Use enclosingElement instead') + @override + InterfaceElement get enclosingElement3 => enclosingElement; @override bool get isConst { @@ -1432,7 +1450,7 @@ class ConstructorElementImpl extends ExecutableElementImpl @override Element get nonSynthetic { - return isSynthetic ? enclosingElement3 : this; + return isSynthetic ? enclosingElement : this; } @override @@ -1457,7 +1475,7 @@ class ConstructorElementImpl extends ExecutableElementImpl @override InterfaceType get returnTypeInternal { - return (_returnType ??= enclosingElement3.thisType) as InterfaceType; + return (_returnType ??= enclosingElement.thisType) as InterfaceType; } ConstructorElement? get superConstructor { @@ -1591,7 +1609,7 @@ mixin ConstVariableElement implements ElementImpl, ConstantEvaluationTarget { if (library == null) { throw StateError( '[library: null][this: ($runtimeType) $this]' - '[enclosingElement: $enclosingElement3]' + '[enclosingElement: $enclosingElement]' '[reference: $reference]', ); } @@ -1966,7 +1984,7 @@ class ElementAnnotationImpl implements ElementAnnotation { final element = this.element; if (element is ConstructorElement) { return element.library.isDartCore && - element.enclosingElement3.name == _deprecatedClassName; + element.enclosingElement.name == _deprecatedClassName; } else if (element is PropertyAccessorElement) { return element.library.isDartCore && element.name == _deprecatedVariableName; @@ -2098,7 +2116,7 @@ class ElementAnnotationImpl implements ElementAnnotation { }) { final element = this.element; return element is ConstructorElement && - element.enclosingElement3.name == className && + element.enclosingElement.name == className && element.library.name == libraryName; } @@ -2208,13 +2226,17 @@ abstract class ElementImpl implements Element { _docComment = doc; } + @override + Element? get enclosingElement => _enclosingElement; + /// Set the enclosing element of this element to the given [element]. set enclosingElement(Element? element) { _enclosingElement = element as ElementImpl?; } + @Deprecated('Use enclosingElement instead') @override - Element? get enclosingElement3 => _enclosingElement; + Element? get enclosingElement3 => 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. @@ -2564,12 +2586,12 @@ abstract class ElementImpl implements Element { @override AnalysisSession? get session { - return enclosingElement3?.session; + return enclosingElement?.session; } @override Source? get source { - return enclosingElement3?.source; + return enclosingElement?.source; } /// Return the context to resolve type parameters in, or `null` if neither @@ -2674,7 +2696,7 @@ abstract class ElementImpl implements Element { ) { Element? element = this; while (element != null && !predicate(element)) { - element = element.enclosingElement3; + element = element.enclosingElement; } return element as E?; } @@ -2684,9 +2706,9 @@ abstract class ElementImpl implements Element { Element? element = this; while (element != null && element is! E) { if (element is CompilationUnitElement) { - element = element.enclosingElement3; + element = element.enclosingElement; } else { - element = element.enclosingElement3; + element = element.enclosingElement; } } return element as E?; @@ -2756,7 +2778,7 @@ class ElementLocationImpl implements ElementLocation { Element? ancestor = element; while (ancestor != null) { components.insert(0, (ancestor as ElementImpl).identifier); - ancestor = ancestor.enclosingElement3; + ancestor = ancestor.enclosingElement; } _components = components; } @@ -3000,7 +3022,11 @@ abstract class ExecutableElementImpl extends _ExistingElementImpl ExecutableElementImpl(String super.name, super.offset, {super.reference}); @override - Element get enclosingElement3 => super.enclosingElement3!; + Element get enclosingElement => super.enclosingElement!; + + @Deprecated('Use enclosingElement instead') + @override + Element get enclosingElement3 => enclosingElement; @override bool get hasImplicitReturnType { @@ -3216,9 +3242,15 @@ class ExtensionElementImpl extends _ExistingElementImpl @override String get displayName => name ?? ''; + @override + CompilationUnitElementImpl get enclosingElement { + return super.enclosingElement as CompilationUnitElementImpl; + } + + @Deprecated('Use enclosingElement instead') @override CompilationUnitElementImpl get enclosingElement3 { - return super.enclosingElement3 as CompilationUnitElementImpl; + return enclosingElement; } @override @@ -3419,7 +3451,7 @@ class FieldElementImpl extends PropertyInducingElementImpl /// /// Such fields are `index`, `_name`, and `values`. bool get isSyntheticEnumField { - return enclosingElement3 is EnumElementImpl && + return enclosingElement is EnumElementImpl && isSynthetic && getter?.isSynthetic == true && setter == null; @@ -3487,7 +3519,7 @@ class FunctionElementImpl extends ExecutableElementImpl @override String get identifier { String identifier = super.identifier; - Element? enclosing = enclosingElement3; + Element? enclosing = enclosingElement; if (enclosing is ExecutableElement || enclosing is VariableElement) { identifier += "@$nameOffset"; } @@ -3687,8 +3719,12 @@ class LabelElementImpl extends ElementImpl implements LabelElement { String get displayName => name; @override - ExecutableElement get enclosingElement3 => - super.enclosingElement3 as ExecutableElement; + ExecutableElement get enclosingElement => + super.enclosingElement as ExecutableElement; + + @Deprecated('Use enclosingElement instead') + @override + ExecutableElement get enclosingElement3 => enclosingElement; /// Return `true` if this label is associated with a `switch` member (`case /// ` or`default`). @@ -4606,8 +4642,8 @@ class MethodElementImpl extends ExecutableElementImpl implements MethodElement { @override Element get nonSynthetic { - if (isSynthetic && enclosingElement3 is EnumElementImpl) { - return enclosingElement3; + if (isSynthetic && enclosingElement is EnumElementImpl) { + return enclosingElement; } return this; } @@ -4859,6 +4895,10 @@ class MultiplyDefinedElementImpl implements MultiplyDefinedElement { @override String? get documentationComment => null; + @override + Element? get enclosingElement => null; + + @Deprecated('Use enclosingElement instead') @override Element? get enclosingElement3 => null; @@ -5080,7 +5120,11 @@ abstract class NonParameterVariableElementImpl extends VariableElementImpl NonParameterVariableElementImpl(String super.name, super.offset); @override - Element get enclosingElement3 => super.enclosingElement3!; + Element get enclosingElement => super.enclosingElement!; + + @Deprecated('Use enclosingElement instead') + @override + Element get enclosingElement3 => enclosingElement; bool get hasInitializer { return hasModifier(Modifier.HAS_INITIALIZER); @@ -5346,7 +5390,7 @@ class PartElementImpl extends _ExistingElementImpl implements PartElement { @override CompilationUnitElementImpl get enclosingUnit { - var enclosingLibrary = enclosingElement3 as LibraryElementImpl; + var enclosingLibrary = enclosingElement as LibraryElementImpl; return enclosingLibrary._definingCompilationUnit; } @@ -5378,12 +5422,16 @@ class PrefixElementImpl extends _ExistingElementImpl implements PrefixElement { String get displayName => name; @override - LibraryOrAugmentationElementImpl get enclosingElement3 => - super.enclosingElement3 as LibraryOrAugmentationElementImpl; + LibraryOrAugmentationElementImpl get enclosingElement => + super.enclosingElement as LibraryOrAugmentationElementImpl; + + @Deprecated('Use enclosingElement instead') + @override + LibraryOrAugmentationElementImpl get enclosingElement3 => enclosingElement; @override List get imports2 { - return enclosingElement3.libraryImports + return enclosingElement.libraryImports .where((import) => import.prefix?.element == this) .toList(); } @@ -5397,7 +5445,7 @@ class PrefixElementImpl extends _ExistingElementImpl implements PrefixElement { } @override - Scope get scope => _scope ??= PrefixScope(enclosingElement3, this); + Scope get scope => _scope ??= PrefixScope(enclosingElement, this); @override T? accept(ElementVisitor visitor) => visitor.visitPrefixElement(this); @@ -5539,7 +5587,11 @@ class PropertyAccessorElementImpl_ImplicitGetter } @override - Element get enclosingElement3 => variable.enclosingElement3!; + Element get enclosingElement => variable.enclosingElement!; + + @Deprecated('Use enclosingElement instead') + @override + Element get enclosingElement3 => enclosingElement; @override bool get hasImplicitReturnType => variable.hasImplicitType; @@ -5553,8 +5605,8 @@ class PropertyAccessorElementImpl_ImplicitGetter if (!variable.isSynthetic) { return variable; } - assert(enclosingElement3 is EnumElementImpl); - return enclosingElement3; + assert(enclosingElement is EnumElementImpl); + return enclosingElement; } @override @@ -5600,7 +5652,11 @@ class PropertyAccessorElementImpl_ImplicitSetter } @override - Element get enclosingElement3 => variable.enclosingElement3!; + Element get enclosingElement => variable.enclosingElement!; + + @Deprecated('Use enclosingElement instead') + @override + Element get enclosingElement3 => enclosingElement; @override bool get isSetter => true; @@ -5698,10 +5754,10 @@ abstract class PropertyInducingElementImpl @override Element get nonSynthetic { if (isSynthetic) { - if (enclosingElement3 is EnumElementImpl) { + if (enclosingElement is EnumElementImpl) { // TODO(scheglov) remove 'index'? if (name == 'index' || name == 'values') { - return enclosingElement3; + return enclosingElement; } } return (getter ?? setter)!; @@ -5842,16 +5898,16 @@ class SuperFormalParameterElementImpl extends ParameterElementImpl @override ParameterElement? get superConstructorParameter { - final enclosingElement3 = this.enclosingElement3; - if (enclosingElement3 is ConstructorElementImpl) { - var superConstructor = enclosingElement3.superConstructor; + final enclosingElement = this.enclosingElement; + if (enclosingElement is ConstructorElementImpl) { + var superConstructor = enclosingElement.superConstructor; if (superConstructor != null) { var superParameters = superConstructor.parameters; if (isNamed) { return superParameters .firstWhereOrNull((e) => e.isNamed && e.name == name); } else { - var index = indexIn(enclosingElement3); + var index = indexIn(enclosingElement); var positionalSuperParameters = superParameters.where((e) => e.isPositional).toList(); if (index >= 0 && index < positionalSuperParameters.length) { @@ -5953,8 +6009,12 @@ class TypeAliasElementImpl extends _ExistingElementImpl String get displayName => name; @override - CompilationUnitElement get enclosingElement3 => - super.enclosingElement3 as CompilationUnitElement; + CompilationUnitElement get enclosingElement => + super.enclosingElement as CompilationUnitElement; + + @Deprecated('Use enclosingElement instead') + @override + CompilationUnitElement get enclosingElement3 => enclosingElement; /// Returns whether this alias is a "proper rename" of [aliasedClass], as /// defined in the constructor-tearoffs specification. @@ -6206,7 +6266,7 @@ class TypeParameterElementImpl extends ElementImpl return true; } if (other is TypeParameterElement) { - if (other.enclosingElement3 == null || enclosingElement3 == null) { + if (other.enclosingElement == null || enclosingElement == null) { return identical(other, this); } return other.location == location; @@ -6431,7 +6491,7 @@ mixin _HasLibraryMixin on ElementImpl { Source get librarySource => library.source; @override - Source get source => enclosingElement3!.source!; + Source get source => enclosingElement!.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 e155c0d04e9..5122ae1f244 100644 --- a/pkg/analyzer/lib/src/dart/element/extensions.dart +++ b/pkg/analyzer/lib/src/dart/element/extensions.dart @@ -26,7 +26,7 @@ extension ElementAnnotationExtensions on ElementAnnotation { } } } else if (element is ConstructorElement) { - interfaceElement = element.enclosingElement3; + interfaceElement = element.enclosingElement; } if (interfaceElement == null) { return const {}; @@ -69,21 +69,21 @@ extension ElementExtension on Element { return true; } - var ancestor = enclosingElement3; + var ancestor = enclosingElement; if (ancestor is InterfaceElement) { if (ancestor.hasDoNotStore) { return true; } - ancestor = ancestor.enclosingElement3; + ancestor = ancestor.enclosingElement; } else if (ancestor is ExtensionElement) { if (ancestor.hasDoNotStore) { return true; } - ancestor = ancestor.enclosingElement3; + ancestor = ancestor.enclosingElement; } return ancestor is CompilationUnitElement && - ancestor.enclosingElement3.hasDoNotStore; + ancestor.enclosingElement.hasDoNotStore; } /// Return `true` if this element is an instance member of a class or mixin. @@ -95,7 +95,7 @@ extension ElementExtension on Element { /// [PropertyAccessorElement]s. bool get isInstanceMember { var this_ = this; - var enclosing = this_.enclosingElement3; + var enclosing = this_.enclosingElement; if (enclosing is InterfaceElement) { return this_ is MethodElement && !this_.isStatic || this_ is PropertyAccessorElement && !this_.isStatic; @@ -106,7 +106,7 @@ extension ElementExtension on Element { extension ExecutableElementExtension on ExecutableElement { bool get isEnumConstructor { - return this is ConstructorElement && enclosingElement3 is EnumElementImpl; + return this is ConstructorElement && enclosingElement 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 27811a7a073..12f7996f83f 100644 --- a/pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart +++ b/pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart @@ -367,7 +367,7 @@ class InheritanceManager3 { continue; } - var class_ = executable.enclosingElement3; + var class_ = executable.enclosingElement; if (class_ is ClassElement && class_.isDartCoreObject) { continue; } @@ -520,7 +520,7 @@ class InheritanceManager3 { } var current = currentList.single; - if (candidate.enclosingElement3 == mixinElement) { + if (candidate.enclosingElement == mixinElement) { namedCandidates[name] = [ isNonNullableByDefault ? candidate @@ -716,7 +716,7 @@ class InheritanceManager3 { Name name, ExecutableElement executable, ) { - if (executable.enclosingElement3 == class_) { + if (executable.enclosingElement == class_) { return executable; } @@ -906,7 +906,7 @@ class InheritanceManager3 { } static bool _isDeclaredInObject(ExecutableElement element) { - var enclosing = element.enclosingElement3; + var enclosing = element.enclosingElement; // TODO(scheglov) `is! MixinElement` after the separation. return enclosing is InterfaceElement && enclosing.supertype == null && diff --git a/pkg/analyzer/lib/src/dart/element/member.dart b/pkg/analyzer/lib/src/dart/element/member.dart index d29f06e19a2..2ba5a6d3390 100644 --- a/pkg/analyzer/lib/src/dart/element/member.dart +++ b/pkg/analyzer/lib/src/dart/element/member.dart @@ -44,7 +44,11 @@ class ConstructorMember extends ExecutableMember String get displayName => declaration.displayName; @override - InterfaceElement get enclosingElement3 => declaration.enclosingElement3; + InterfaceElement get enclosingElement => declaration.enclosingElement; + + @Deprecated('Use enclosingElement instead') + @override + InterfaceElement get enclosingElement3 => enclosingElement; @override bool get isConst => declaration.isConst; @@ -345,7 +349,11 @@ class FieldMember extends VariableMember implements FieldElement { String get displayName => declaration.displayName; @override - Element get enclosingElement3 => declaration.enclosingElement3; + Element get enclosingElement => declaration.enclosingElement; + + @Deprecated('Use enclosingElement instead') + @override + Element get enclosingElement3 => enclosingElement; @override PropertyAccessorElement? get getter { @@ -435,7 +443,11 @@ class FunctionMember extends ExecutableMember implements FunctionElement { FunctionElement get declaration => super.declaration as FunctionElement; @override - Element get enclosingElement3 => declaration.enclosingElement3; + Element get enclosingElement => declaration.enclosingElement; + + @Deprecated('Use enclosingElement instead') + @override + Element get enclosingElement3 => enclosingElement; @override bool get isDartCoreIdentical => declaration.isDartCoreIdentical; @@ -494,7 +506,11 @@ abstract class Member implements Element { String? get documentationComment => _declaration.documentationComment; @override - Element? get enclosingElement3 => _declaration.enclosingElement3; + Element? get enclosingElement => _declaration.enclosingElement; + + @Deprecated('Use enclosingElement instead') + @override + Element? get enclosingElement3 => enclosingElement; @override bool get hasAlwaysThrows => _declaration.hasAlwaysThrows; @@ -779,7 +795,11 @@ class MethodMember extends ExecutableMember implements MethodElement { MethodElement get declaration => super.declaration as MethodElement; @override - Element get enclosingElement3 => declaration.enclosingElement3; + Element get enclosingElement => declaration.enclosingElement; + + @Deprecated('Use enclosingElement instead') + @override + Element get enclosingElement3 => enclosingElement; @override String get name => declaration.name; @@ -863,7 +883,11 @@ class ParameterMember extends VariableMember String? get defaultValueCode => declaration.defaultValueCode; @override - Element? get enclosingElement3 => declaration.enclosingElement3; + Element? get enclosingElement => declaration.enclosingElement; + + @Deprecated('Use enclosingElement instead') + @override + Element? get enclosingElement3 => enclosingElement; @override bool get hasDefaultValue => declaration.hasDefaultValue; @@ -1004,7 +1028,11 @@ class PropertyAccessorMember extends ExecutableMember super.declaration as PropertyAccessorElement; @override - Element get enclosingElement3 => declaration.enclosingElement3; + Element get enclosingElement => declaration.enclosingElement; + + @Deprecated('Use enclosingElement instead') + @override + Element get enclosingElement3 => enclosingElement; @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 2a00d90d221..fd978003585 100644 --- a/pkg/analyzer/lib/src/dart/element/type_system.dart +++ b/pkg/analyzer/lib/src/dart/element/type_system.dart @@ -1717,7 +1717,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.enclosingElement3 is ExtensionElement) { + if (methodElement.enclosingElement is ExtensionElement) { return currentType; } @@ -1821,7 +1821,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.enclosingElement3 is ExtensionElement) { + if (methodElement.enclosingElement 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 4df8021ebbc..708959f3656 100644 --- a/pkg/analyzer/lib/src/dart/micro/utils.dart +++ b/pkg/analyzer/lib/src/dart/micro/utils.dart @@ -47,7 +47,7 @@ ConstructorElement? _getActualConstructorElement( ConstructorElement? constructor) { var seenConstructors = {}; while (constructor is ConstructorElementImpl && constructor.isSynthetic) { - var enclosing = constructor.enclosingElement3; + var enclosing = constructor.enclosingElement; if (enclosing is ClassElement && enclosing.isMixinApplication) { var superInvocation = constructor.constantInitializers .whereType() @@ -77,7 +77,7 @@ LibraryImportElement? _getImportElement( String prefix, Element element, Map> importElementsMap) { - if (element.enclosingElement3 is! CompilationUnitElement) { + if (element.enclosingElement is! CompilationUnitElement) { return null; } var usedLibrary = element.library; @@ -314,7 +314,7 @@ class ReferencesCollector extends GeneralizingAstVisitor { length = 0; } references.add(MatchInfo(offset, length, kind)); - } else if (e != null && e.enclosingElement3 == element) { + } else if (e != null && e.enclosingElement == 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 62d8b23f395..f6380a716e5 100644 --- a/pkg/analyzer/lib/src/dart/resolver/constructor_reference_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/constructor_reference_resolver.dart @@ -30,7 +30,7 @@ class ConstructorReferenceResolver { node.constructorName.accept(_resolver); var element = node.constructorName.staticElement; if (element != null && !element.isFactory) { - final enclosingElement = element.enclosingElement3; + final enclosingElement = element.enclosingElement; if (enclosingElement is ClassElement && enclosingElement.isAbstract) { _resolver.errorReporter.reportErrorForNode( CompileTimeErrorCode 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 435fc82588f..416c3ce996e 100644 --- a/pkg/analyzer/lib/src/dart/resolver/function_reference_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/function_reference_resolver.dart @@ -174,7 +174,7 @@ class FunctionReferenceResolver { ExecutableElement element, { required bool implicitReceiver, }) { - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; 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 1bb8b59bcdb..ee8890ef56e 100644 --- a/pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart @@ -212,7 +212,7 @@ class MethodInvocationResolver with ScopeHelpers { ExecutableElement element, bool nullReceiver, ) { - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; 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 420f3b7ffb4..0465c7299a9 100644 --- a/pkg/analyzer/lib/src/dart/resolver/named_type_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/named_type_resolver.dart @@ -569,7 +569,7 @@ class _ErrorHelper { if (element is LocalVariableElement || (element is FunctionElement && - element.enclosingElement3 is ExecutableElement)) { + element.enclosingElement 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 f7e53ac8325..e113b09b13d 100644 --- a/pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart @@ -315,7 +315,7 @@ class PropertyElementResolver with ScopeHelpers { propertyName, ); } else { - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; 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 2e1fa8ca8e8..c96b8406296 100644 --- a/pkg/analyzer/lib/src/diagnostic/diagnostic_factory.dart +++ b/pkg/analyzer/lib/src/diagnostic/diagnostic_factory.dart @@ -180,9 +180,9 @@ class DiagnosticFactory { return AnalysisError( source, errorNode.offset, errorNode.length, errorCode, [ member.name, - member.enclosingElement3.name!, + member.enclosingElement.name!, member.type, - superMember.enclosingElement3.name!, + superMember.enclosingElement.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 4a2a15a8ab8..db6259fe255 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.enclosingElement3.displayName], + [variable.name, variable.enclosingElement.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 c4f77013ef7..0154c4e5762 100644 --- a/pkg/analyzer/lib/src/error/best_practices_verifier.dart +++ b/pkg/analyzer/lib/src/error/best_practices_verifier.dart @@ -173,7 +173,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor { } } } else if (parent is ConstructorDeclaration) { - var class_ = parent.declaredElement!.enclosingElement3; + var class_ = parent.declaredElement!.enclosingElement; if (class_.isPrivate || (parentElement?.isPrivate ?? false)) { _errorReporter.reportErrorForNode( HintCode.INVALID_INTERNAL_ANNOTATION, node, []); @@ -325,7 +325,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor { var invokedElement = element.element!; var name = invokedElement.name; if (invokedElement is ConstructorElement) { - var className = invokedElement.enclosingElement3.name; + var className = invokedElement.enclosingElement.name; if (name!.isEmpty) { name = className; } else { @@ -481,7 +481,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.enclosingElement3!; + Element enclosingElement = element.enclosingElement!; if (enclosingElement is InterfaceElement) { var overridden = _inheritanceManager .getMember2(enclosingElement, name, forSuper: true); @@ -507,7 +507,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor { _errorReporter.reportErrorForToken( HintCode.INVALID_OVERRIDE_OF_NON_VIRTUAL_MEMBER, field.name, [ field.name.lexeme, - overriddenElement.enclosingElement3.displayName + overriddenElement.enclosingElement.displayName ]); } if (!_invalidAccessVerifier._inTestDirectory) { @@ -650,7 +650,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor { void visitMethodDeclaration(MethodDeclaration node) { bool wasInDoNotStoreMember = _inDoNotStoreMember; var element = node.declaredElement!; - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; Name name = Name(_currentLibrary.source.uri, element.name); @@ -700,10 +700,9 @@ class BestPracticesVerifier extends RecursiveAstVisitor { // always named, so we can safely assume // `overriddenElement.enclosingElement3.name` is non-`null`. _errorReporter.reportErrorForToken( - HintCode.INVALID_OVERRIDE_OF_NON_VIRTUAL_MEMBER, node.name, [ - node.name.lexeme, - overriddenElement.enclosingElement3.displayName - ]); + HintCode.INVALID_OVERRIDE_OF_NON_VIRTUAL_MEMBER, + node.name, + [node.name.lexeme, overriddenElement.enclosingElement.displayName]); } super.visitMethodDeclaration(node); @@ -1481,7 +1480,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?.enclosingElement3; + var classElement = methodElement?.enclosingElement; return methodElement is MethodElement && classElement is ClassElement && !classElement.isDartCoreObject; @@ -1984,7 +1983,7 @@ class _InvalidAccessVerifier { SimpleIdentifier identifier, Element element) { bool hasProtected = _hasProtected(element); if (hasProtected) { - var definingClass = element.enclosingElement3 as InterfaceElement; + var definingClass = element.enclosingElement as InterfaceElement; if (_hasTypeOrSuperType(_enclosingClass, definingClass)) { return; } @@ -2023,7 +2022,7 @@ class _InvalidAccessVerifier { node = identifier; } - var definingClass = element.enclosingElement3; + var definingClass = element.enclosingElement; if (hasProtected) { _errorReporter.reportErrorForNode( HintCode.INVALID_USE_OF_PROTECTED_MEMBER, @@ -2079,12 +2078,12 @@ class _InvalidAccessVerifier { bool _hasProtected(Element element) { if (element is PropertyAccessorElement && - element.enclosingElement3 is InterfaceElement && + element.enclosingElement is InterfaceElement && (element.hasProtected || element.variable.hasProtected)) { return true; } if (element is MethodElement && - element.enclosingElement3 is InterfaceElement && + element.enclosingElement is InterfaceElement && 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 b0d7fe4755a..cd2c3177c89 100644 --- a/pkg/analyzer/lib/src/error/correct_override.dart +++ b/pkg/analyzer/lib/src/error/correct_override.dart @@ -131,9 +131,9 @@ class CovariantParametersVerifier { errorNode.length, [ _thisMember.name, - _thisMember.enclosingElement3.name!, + _thisMember.enclosingElement.name!, _thisMember.type, - superMember.enclosingElement3.name!, + superMember.enclosingElement.name!, superMember.type, ], ); @@ -144,7 +144,7 @@ class CovariantParametersVerifier { List<_SuperMember> _superMembers() { var classHierarchy = _session.classHierarchy; - var classElement = _thisMember.enclosingElement3 as InterfaceElement; + var classElement = _thisMember.enclosingElement as InterfaceElement; var interfaces = classHierarchy.implementedInterfaces(classElement); var superMembers = <_SuperMember>[]; @@ -272,6 +272,5 @@ class _SuperParameter { _SuperParameter(this.element, this.type); - ExecutableElement get member => - element.enclosingElement3 as ExecutableElement; + ExecutableElement get member => element.enclosingElement 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 c3dd1bf54b2..e5182766e9e 100644 --- a/pkg/analyzer/lib/src/error/deprecated_member_use_verifier.dart +++ b/pkg/analyzer/lib/src/error/deprecated_member_use_verifier.dart @@ -167,7 +167,7 @@ abstract class BaseDeprecatedMemberUseVerifier { // TODO(jwren) We should modify ConstructorElement.getDisplayName(), // or have the logic centralized elsewhere, instead of doing this logic // here. - displayName = element.enclosingElement3.displayName; + displayName = element.enclosingElement.displayName; if (element.displayName.isNotEmpty) { displayName = "$displayName.${element.displayName}"; } @@ -240,7 +240,7 @@ abstract class BaseDeprecatedMemberUseVerifier { /// Return `true` if [element] is a [ParameterElement] declared in [node]. static bool _isLocalParameter(Element? element, AstNode? node) { if (element is ParameterElement) { - var definingFunction = element.enclosingElement3 as ExecutableElement; + var definingFunction = element.enclosingElement 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 e904e8cdaac..dd5b5deb9a4 100644 --- a/pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart +++ b/pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart @@ -150,7 +150,7 @@ class DuplicateDefinitionVerifier { [ enumElement.displayName, baseName, - inherited.enclosingElement3.displayName, + inherited.enclosingElement.displayName, ], ); } @@ -177,7 +177,7 @@ class DuplicateDefinitionVerifier { [ enumElement.displayName, baseName, - inherited.enclosingElement3.displayName, + inherited.enclosingElement.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 cb76e1b83c4..0f51c27d883 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.enclosingElement3 == element) { + if (getter.enclosingElement == element) { errorElement = getter; - } else if (setter.enclosingElement3 == element) { + } else if (setter.enclosingElement == element) { errorElement = setter; } else { errorElement = element; } var getterName = getter.displayName; - if (getter.enclosingElement3 != element) { - var getterClassName = getter.enclosingElement3.displayName; + if (getter.enclosingElement != element) { + var getterClassName = getter.enclosingElement.displayName; getterName = '$getterClassName.$getterName'; } var setterName = setter.displayName; - if (setter.enclosingElement3 != element) { - var setterClassName = setter.enclosingElement3.displayName; + if (setter.enclosingElement != element) { + var setterClassName = setter.enclosingElement.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 757440830a5..c45bf624047 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.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement is ExtensionElement) { _recordUsedExtension(enclosingElement); } @@ -165,7 +165,7 @@ class GatherUsedImportedElementsVisitor extends RecursiveAstVisitor { if (_recordPrefixMap(identifier, element)) { return; } - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; 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 484508eae50..6e1b65c24a5 100644 --- a/pkg/analyzer/lib/src/error/inheritance_override.dart +++ b/pkg/analyzer/lib/src/error/inheritance_override.dart @@ -557,7 +557,7 @@ class _ClassVerifier { .INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED, derivedOptionalNodes[i], [ - baseExecutable.enclosingElement3.displayName, + baseExecutable.enclosingElement.displayName, baseExecutable.displayName, name ], @@ -586,7 +586,7 @@ class _ClassVerifier { .INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL, derivedOptionalNodes[i], [ - baseExecutable.enclosingElement3.displayName, + baseExecutable.enclosingElement.displayName, baseExecutable.displayName ], ); @@ -711,7 +711,7 @@ class _ClassVerifier { ) { var member = concreteMap[Name(libraryUri, memberName)]; if (member != null) { - var enclosingClass = member.enclosingElement3 as InterfaceElement; + var enclosingClass = member.enclosingElement as InterfaceElement; if (enclosingClass is! ClassElement || filter(enclosingClass)) { reporter.reportErrorForToken( CompileTimeErrorCode.ILLEGAL_CONCRETE_ENUM_MEMBER_INHERITANCE, @@ -752,7 +752,7 @@ class _ClassVerifier { reporter.reportErrorForToken( CompileTimeErrorCode.ILLEGAL_ENUM_VALUES_INHERITANCE, classNameToken, - [inherited.enclosingElement3.name!], + [inherited.enclosingElement.name!], ); } } @@ -837,13 +837,13 @@ class _ClassVerifier { token, [ name.name, - conflict.getter.enclosingElement3.name!, - conflict.method.enclosingElement3.name! + conflict.getter.enclosingElement.name!, + conflict.method.enclosingElement.name! ], ); } else if (conflict is CandidatesConflict) { var candidatesStr = conflict.candidates.map((candidate) { - var className = candidate.enclosingElement3.name; + var className = candidate.enclosingElement.name; var typeStr = candidate.type.getDisplayString( withNullability: _isNonNullableByDefault, ); @@ -879,7 +879,7 @@ class _ClassVerifier { } var elementName = element.displayName; - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; 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 6b42b3b6238..7bbe7f8a868 100644 --- a/pkg/analyzer/lib/src/error/must_call_super_verifier.dart +++ b/pkg/analyzer/lib/src/error/must_call_super_verifier.dart @@ -28,11 +28,11 @@ class MustCallSuperVerifier { if (element is MethodElement && _hasConcreteSuperMethod(element)) { _verifySuperIsCalled( - node, overridden.name, overridden.enclosingElement3.name); + node, overridden.name, overridden.enclosingElement.name); return; } - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement is! ClassElement) { return; } @@ -42,7 +42,7 @@ class MustCallSuperVerifier { .lookUpInheritedConcreteGetter(element.name, element.library); if (inheritedConcreteGetter != null) { _verifySuperIsCalled( - node, overridden.name, overridden.enclosingElement3.name); + node, overridden.name, overridden.enclosingElement.name); } return; } @@ -57,7 +57,7 @@ class MustCallSuperVerifier { if (name.endsWith('=')) { name = name.substring(0, name.length - 1); } - _verifySuperIsCalled(node, name, overridden.enclosingElement3.name); + _verifySuperIsCalled(node, name, overridden.enclosingElement.name); } } } @@ -73,10 +73,10 @@ class MustCallSuperVerifier { ExecutableElement? _findOverriddenMemberWithMustCallSuper( ExecutableElement element) { //Element member = node.declaredElement; - if (element.enclosingElement3 is! InterfaceElement) { + if (element.enclosingElement is! InterfaceElement) { return null; } - var classElement = element.enclosingElement3 as InterfaceElement; + var classElement = element.enclosingElement as InterfaceElement; String name = element.name; // Walk up the type hierarchy from [classElement], ignoring direct @@ -118,7 +118,7 @@ class MustCallSuperVerifier { /// Returns whether [node] overrides a concrete method. bool _hasConcreteSuperMethod(ExecutableElement element) { - var classElement = element.enclosingElement3 as InterfaceElement; + var classElement = element.enclosingElement as InterfaceElement; String name = element.name; if (classElement.supertype.isConcrete(name)) { diff --git a/pkg/analyzer/lib/src/error/type_arguments_verifier.dart b/pkg/analyzer/lib/src/error/type_arguments_verifier.dart index 012f253cc2a..56b58eda564 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.enclosingElement3; + var enumElement = constructorElement.enclosingElement; 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 71a26cd4db1..fcbbb327147 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?.enclosingElement3; + var enclosingElement = element?.enclosingElement; if (element == null) { if (isIdentifierRead) { usedElements.unresolvedReadMembers.add(node.name); @@ -652,7 +652,7 @@ class UnusedLocalElementsVerifier extends RecursiveAstVisitor { if (element.isPrivate) { return false; } - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement is EnumElement) { if (element is ConstructorElement && element.isGenerative) { @@ -680,7 +680,7 @@ class UnusedLocalElementsVerifier extends RecursiveAstVisitor { bool elementIsStaticVariable = element is VariableElement && element.isStatic; if (element.isPublic) { - if (_isPrivateClassOrExtension(element.enclosingElement3!) && + if (_isPrivateClassOrExtension(element.enclosingElement!) && elementIsStaticVariable) { // Public static fields of private classes, mixins, and extensions are // inaccessible from outside the library in which they are declared. @@ -717,7 +717,7 @@ class UnusedLocalElementsVerifier extends RecursiveAstVisitor { element is FunctionElement && !element.isStatic) { // local variable or function } else if (element is ParameterElement) { - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; // Only report unused parameters of constructors, methods, and functions. if (enclosingElement is! ConstructorElement && enclosingElement is! FunctionElement && @@ -729,7 +729,7 @@ class UnusedLocalElementsVerifier extends RecursiveAstVisitor { return true; } if (enclosingElement is ConstructorElement && - enclosingElement.enclosingElement3.typeParameters.isNotEmpty) { + enclosingElement.enclosingElement.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 @@ -783,7 +783,7 @@ class UnusedLocalElementsVerifier extends RecursiveAstVisitor { } Iterable _overriddenElements(Element element) { - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement is InterfaceElement) { Name name = Name(_libraryUri, element.name!); var overridden = @@ -865,7 +865,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.enclosingElement3.constructors.length > 1 && + if (element.enclosingElement.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 c628ab5254b..ce43c70de7d 100644 --- a/pkg/analyzer/lib/src/generated/element_resolver.dart +++ b/pkg/analyzer/lib/src/generated/element_resolver.dart @@ -377,7 +377,7 @@ class ElementResolver { } else { if (element.isFactory && // Check if we've reported [NO_GENERATIVE_CONSTRUCTORS_IN_SUPERCLASS]. - !element.enclosingElement3.constructors + !element.enclosingElement.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 9274345c303..a7397ce6674 100644 --- a/pkg/analyzer/lib/src/generated/error_verifier.dart +++ b/pkg/analyzer/lib/src/generated/error_verifier.dart @@ -116,7 +116,7 @@ class EnclosingExecutableContext { } static bool _inFactoryConstructor(Element? element) { - var enclosing = element?.enclosingElement3; + var enclosing = element?.enclosingElement; if (enclosing == null) { return false; } @@ -127,7 +127,7 @@ class EnclosingExecutableContext { } static bool _inStaticMethod(Element? element) { - var enclosing = element?.enclosingElement3; + var enclosing = element?.enclosingElement; if (enclosing == null) { return false; } @@ -754,7 +754,7 @@ class ErrorVerifier extends RecursiveAstVisitor @override void visitFunctionDeclaration(FunctionDeclaration node) { ExecutableElement functionElement = node.declaredElement!; - if (functionElement.enclosingElement3 is! CompilationUnitElement) { + if (functionElement.enclosingElement is! CompilationUnitElement) { _hiddenElements!.declare(functionElement); } @@ -1636,7 +1636,7 @@ class ErrorVerifier extends RecursiveAstVisitor errorReporter.reportErrorForNode( CompileTimeErrorCode.ASSIGNMENT_TO_FINAL_NO_SETTER, highlightedNode, - [variable.name, variable.enclosingElement3.displayName], + [variable.name, variable.enclosingElement.displayName], ); } else { errorReporter.reportErrorForNode( @@ -1806,14 +1806,14 @@ class ErrorVerifier extends RecursiveAstVisitor CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, method, [ _enclosingClass!.displayName, name, - inherited.enclosingElement3.displayName, + inherited.enclosingElement.displayName, ]); } else if (inherited is PropertyAccessorElement) { errorReporter.reportErrorForElement( CompileTimeErrorCode.CONFLICTING_METHOD_AND_FIELD, method, [ _enclosingClass!.displayName, name, - inherited.enclosingElement3.displayName + inherited.enclosingElement.displayName ]); } } @@ -1833,14 +1833,14 @@ class ErrorVerifier extends RecursiveAstVisitor CompileTimeErrorCode.CONFLICTING_STATIC_AND_INSTANCE, accessor, [ _enclosingClass!.displayName, name, - inherited.enclosingElement3.displayName, + inherited.enclosingElement.displayName, ]); } else if (inherited is MethodElement) { errorReporter.reportErrorForElement( CompileTimeErrorCode.CONFLICTING_FIELD_AND_METHOD, accessor, [ _enclosingClass!.displayName, name, - inherited.enclosingElement3.displayName + inherited.enclosingElement.displayName ]); } } @@ -2098,11 +2098,11 @@ class ErrorVerifier extends RecursiveAstVisitor errorReporter.reportErrorForNode( CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN_WITH_FIELD, constructor.returnType, - ["'${field.enclosingElement3.name}.${field.name}'"]); + ["'${field.enclosingElement.name}.${field.name}'"]); return true; } else if (instanceFields.length > 1) { var fieldNames = instanceFields - .map((field) => "'${field.enclosingElement3.name}.${field.name}'") + .map((field) => "'${field.enclosingElement.name}.${field.name}'") .join(', '); errorReporter.reportErrorForNode( CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN_WITH_FIELDS, @@ -2126,7 +2126,7 @@ class ErrorVerifier extends RecursiveAstVisitor errorReporter.reportErrorForNode( CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, initializer, - [element.enclosingElement3.displayName]); + [element.enclosingElement.displayName]); return true; } } @@ -2164,7 +2164,7 @@ class ErrorVerifier extends RecursiveAstVisitor return; } // check if there is non-final field - final classElement = constructorElement.enclosingElement3; + final classElement = constructorElement.enclosingElement; if (classElement is! ClassElement || !classElement.hasNonFinalField) { return; } @@ -2935,7 +2935,7 @@ class ErrorVerifier extends RecursiveAstVisitor // OK, instance member return; } - Element enclosingElement = element.enclosingElement3; + Element enclosingElement = element.enclosingElement; if (enclosingElement is ExtensionElement) { if (target is ExtensionOverride) { // OK, target is an extension override @@ -3017,7 +3017,7 @@ class ErrorVerifier extends RecursiveAstVisitor var constructorElement = node.staticElement; if (constructorElement != null && constructorElement.isGenerative && - constructorElement.enclosingElement3 is EnumElement) { + constructorElement.enclosingElement is EnumElement) { if (_currentLibrary.featureSet.isEnabled(Feature.enhanced_enums)) { errorReporter.reportErrorForNode( CompileTimeErrorCode.INVALID_REFERENCE_TO_GENERATIVE_ENUM_CONSTRUCTOR, @@ -3060,7 +3060,7 @@ class ErrorVerifier extends RecursiveAstVisitor return; } // not a class member - Element enclosingElement = element.enclosingElement3; + Element enclosingElement = element.enclosingElement; if (enclosingElement is! InterfaceElement && enclosingElement is! ExtensionElement) { return; @@ -3194,7 +3194,7 @@ class ErrorVerifier extends RecursiveAstVisitor } // We should only check exported declarations, i.e. top-level. - if (declaredElement.enclosingElement3 is! CompilationUnitElement) { + if (declaredElement.enclosingElement is! CompilationUnitElement) { return; } @@ -3534,7 +3534,7 @@ class ErrorVerifier extends RecursiveAstVisitor namedType, [ name, namedType.name.name, - inheritedMember.enclosingElement3.name! + inheritedMember.enclosingElement.name! ]); return true; } @@ -4062,7 +4062,7 @@ class ErrorVerifier extends RecursiveAstVisitor redirectedElement, redirectedConstructor, ); - var redirectedClass = redirectedElement?.enclosingElement3; + var redirectedClass = redirectedElement?.enclosingElement; if (redirectedClass is ClassElement && redirectedClass.isAbstract && redirectedElement != null && @@ -4330,7 +4330,7 @@ class ErrorVerifier extends RecursiveAstVisitor if (_enclosingExecutable.inStaticMethod || _isInStaticVariableDeclaration) { var element = identifier.staticElement; if (element is TypeParameterElement && - element.enclosingElement3 is InterfaceElement) { + element.enclosingElement is InterfaceElement) { // 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). @@ -4572,7 +4572,7 @@ class ErrorVerifier extends RecursiveAstVisitor if (element == null || element is TypeParameterElement) { return; } - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; 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 0694f657ca3..bec8451416f 100644 --- a/pkg/analyzer/lib/src/generated/ffi_verifier.dart +++ b/pkg/analyzer/lib/src/generated/ffi_verifier.dart @@ -204,7 +204,7 @@ class FfiVerifier extends RecursiveAstVisitor { void visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { var element = node.staticElement; if (element is MethodElement) { - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement.isAllocatorExtension && element.name == _allocateExtensionMethodName) { _validateAllocate(node); @@ -217,7 +217,7 @@ class FfiVerifier extends RecursiveAstVisitor { void visitIndexExpression(IndexExpression node) { var element = node.staticElement; if (element is MethodElement) { - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement.isNativeStructPointerExtension || enclosingElement.isNativeStructArrayExtension) { if (element.name == '[]') { @@ -230,7 +230,7 @@ class FfiVerifier extends RecursiveAstVisitor { @override void visitInstanceCreationExpression(InstanceCreationExpression node) { var constructor = node.constructorName.staticElement; - var class_ = constructor?.enclosingElement3; + var class_ = constructor?.enclosingElement; if (class_.isStructSubclass || class_.isUnionSubclass) { _errorReporter.reportErrorForNode( FfiCode.CREATION_OF_STRUCT_OR_UNION, @@ -255,7 +255,7 @@ class FfiVerifier extends RecursiveAstVisitor { void visitMethodInvocation(MethodInvocation node) { var element = node.methodName.staticElement; if (element is MethodElement) { - Element enclosingElement = element.enclosingElement3; + Element enclosingElement = element.enclosingElement; if (enclosingElement.isPointer) { if (element.name == 'fromFunction') { _validateFromFunction(node, element); @@ -272,7 +272,7 @@ class FfiVerifier extends RecursiveAstVisitor { } } } else if (element is FunctionElement) { - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement is CompilationUnitElement) { if (element.library.name == 'dart.ffi') { if (element.name == 'sizeOf') { @@ -288,7 +288,7 @@ class FfiVerifier extends RecursiveAstVisitor { void visitPrefixedIdentifier(PrefixedIdentifier node) { var element = node.staticElement; if (element != null) { - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement.isNativeStructPointerExtension) { if (element.name == 'ref') { _validateRefPrefixedIdentifier(node); @@ -302,7 +302,7 @@ class FfiVerifier extends RecursiveAstVisitor { void visitPropertyAccess(PropertyAccess node) { var element = node.propertyName.staticElement; if (element != null) { - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement.isNativeStructPointerExtension) { if (element.name == 'ref') { _validateRefPropertyAccess(node); @@ -361,7 +361,7 @@ class FfiVerifier extends RecursiveAstVisitor { // Receiver can only be Pointer if the class extends // NativeFieldWrapperClass1. if (ffiSignature.normalParameterTypes[0].isPointer) { - final cls = declarationElement.enclosingElement3 as InterfaceElement; + final cls = declarationElement.enclosingElement as InterfaceElement; if (!_extendsNativeFieldWrapperClass1(cls.thisType)) { _errorReporter.reportErrorForNode( FfiCode @@ -613,7 +613,7 @@ class FfiVerifier extends RecursiveAstVisitor { _PrimitiveDartType _typeForAnnotation(Annotation annotation) { var element = annotation.element; if (element is ConstructorElement) { - String name = element.enclosingElement3.name; + String name = element.enclosingElement.name; if (_primitiveIntegerNativeTypes.contains(name)) { return _PrimitiveDartType.int; } else if (_primitiveDoubleNativeTypes.contains(name)) { @@ -732,7 +732,7 @@ class FfiVerifier extends RecursiveAstVisitor { List extraAnnotations = []; for (Annotation annotation in annotations) { if (annotation.element.ffiClass != null || - annotation.element?.enclosingElement3.isAbiSpecificIntegerSubclass == + annotation.element?.enclosingElement.isAbiSpecificIntegerSubclass == true) { if (requiredFound) { extraAnnotations.add(annotation); @@ -1307,7 +1307,7 @@ extension on Annotation { final element = this.element; return element is ConstructorElement && element.ffiClass != null && - element.enclosingElement3.name == + element.enclosingElement.name == FfiVerifier._abiSpecificIntegerMappingClassName; } @@ -1315,21 +1315,21 @@ extension on Annotation { final element = this.element; return element is ConstructorElement && element.ffiClass != null && - element.enclosingElement3.name == 'Array'; + element.enclosingElement.name == 'Array'; } bool get isFfiNative { final element = this.element; return element is ConstructorElement && element.ffiClass != null && - element.enclosingElement3.name == 'FfiNative'; + element.enclosingElement.name == 'FfiNative'; } bool get isPacked { final element = this.element; return element is ConstructorElement && element.ffiClass != null && - element.enclosingElement3.name == 'Packed'; + element.enclosingElement.name == 'Packed'; } } @@ -1373,7 +1373,7 @@ extension on ElementAnnotation { final element = this.element; return element is ConstructorElement && element.ffiClass != null && - element.enclosingElement3.name == 'Array'; + element.enclosingElement.name == 'Array'; // Note: this is 'Array' instead of '_ArraySize' because it finds the // forwarding factory instead of the forwarded constructor. } @@ -1382,7 +1382,7 @@ extension on ElementAnnotation { final element = this.element; return element is ConstructorElement && element.ffiClass != null && - element.enclosingElement3.name == 'Packed'; + element.enclosingElement.name == 'Packed'; } int? get packedMemberAlignment { @@ -1397,7 +1397,7 @@ extension on Element? { ClassElement? get ffiClass { var element = this; if (element is ConstructorElement) { - element = element.enclosingElement3; + element = element.enclosingElement; } 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 860e2b65f69..648da600c40 100644 --- a/pkg/analyzer/lib/src/generated/resolver.dart +++ b/pkg/analyzer/lib/src/generated/resolver.dart @@ -3924,7 +3924,7 @@ class ScopeResolverVisitor extends UnifyingAstVisitor { if (node.inSetterContext()) { _localVariableInfo.potentiallyMutatedInScope.add(element); if (_enclosingClosure != null && - element.enclosingElement3 != _enclosingClosure) { + element.enclosingElement != _enclosingClosure) { _localVariableInfo.potentiallyMutatedInClosure.add(element); } } diff --git a/pkg/analyzer/lib/src/lint/linter.dart b/pkg/analyzer/lib/src/lint/linter.dart index 5af26ba9f4d..04a56bdc579 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!; - final classElement = element.enclosingElement3; + final classElement = element.enclosingElement; if (classElement is ClassElement && classElement.hasNonFinalField) { return false; } diff --git a/pkg/analyzer/lib/src/summary2/bundle_reader.dart b/pkg/analyzer/lib/src/summary2/bundle_reader.dart index 88368c2cd5a..da908c422a0 100644 --- a/pkg/analyzer/lib/src/summary2/bundle_reader.dart +++ b/pkg/analyzer/lib/src/summary2/bundle_reader.dart @@ -201,7 +201,7 @@ abstract class ElementLinkedData { ResolutionReader reader, ElementImpl element, ) { - var enclosing = element.enclosingElement3; + var enclosing = element.enclosingElement; if (enclosing is InterfaceElement) { reader._addTypeParameters(enclosing.typeParameters); } else if (enclosing is CompilationUnitElement) { @@ -273,7 +273,7 @@ class EnumElementLinkedData extends ElementLinkedData { @override void _read(element, reader) { element.metadata = reader._readAnnotationList( - unitElement: element.enclosingElement3, + unitElement: element.enclosingElement, ); _readTypeParameters(reader, element.typeParameters); element.supertype = reader._readOptionalInterfaceType(); @@ -297,7 +297,7 @@ class ExtensionElementLinkedData @override void _read(element, reader) { element.metadata = reader._readAnnotationList( - unitElement: element.enclosingElement3, + unitElement: element.enclosingElement, ); _readTypeParameters(reader, element.typeParameters); element.extendedType = reader.readRequiredType(); @@ -1558,7 +1558,7 @@ class MixinElementLinkedData extends ElementLinkedData { @override void _read(element, reader) { element.metadata = reader._readAnnotationList( - unitElement: element.enclosingElement3, + unitElement: element.enclosingElement, ); _readTypeParameters(reader, element.typeParameters); element.superclassConstraints = reader._readInterfaceTypeList(); @@ -1642,7 +1642,7 @@ class ResolutionReader { // TODO(scheglov) why to check for empty? If we have this flags. if (arguments.isNotEmpty) { var typeParameters = - (element.enclosingElement3 as TypeParameterizedElement) + (element.enclosingElement 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 182d3ca72b3..93ea875c18b 100644 --- a/pkg/analyzer/lib/src/summary2/bundle_writer.dart +++ b/pkg/analyzer/lib/src/summary2/bundle_writer.dart @@ -866,7 +866,7 @@ class ResolutionSink extends _SummaryDataWriter { return const []; } - var enclosing = declaration.enclosingElement3; + var enclosing = declaration.enclosingElement; if (enclosing is TypeParameterizedElement) { if (enclosing is! InterfaceElement && enclosing is! ExtensionElement) { return const []; diff --git a/pkg/analyzer/lib/src/summary2/informative_data.dart b/pkg/analyzer/lib/src/summary2/informative_data.dart index fc0b1e5224d..2b927788dc9 100644 --- a/pkg/analyzer/lib/src/summary2/informative_data.dart +++ b/pkg/analyzer/lib/src/summary2/informative_data.dart @@ -78,7 +78,7 @@ class InformativeDataApplier { var unitReader = SummaryDataReader(unitInfoBytes); var unitInfo = _InfoUnit(unitReader); - final enclosing = unitElement.enclosingElement3; + final enclosing = unitElement.enclosingElement; if (enclosing is LibraryElementImpl) { if (identical(enclosing.definingCompilationUnit, unitElement)) { _applyToLibrary(enclosing, unitInfo); diff --git a/pkg/analyzer/lib/src/summary2/macro_declarations.dart b/pkg/analyzer/lib/src/summary2/macro_declarations.dart index 0ed1491f31a..a8c9cd8b739 100644 --- a/pkg/analyzer/lib/src/summary2/macro_declarations.dart +++ b/pkg/analyzer/lib/src/summary2/macro_declarations.dart @@ -116,7 +116,7 @@ class DeclarationBuilderFromElement { FieldDeclarationImpl _fieldElement(FieldElement element) { assert(!_fieldMap.containsKey(element)); - final enclosingClass = element.enclosingElement3 as ClassElement; + final enclosingClass = element.enclosingElement 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 d54134bbc33..f40a23cc743 100644 --- a/pkg/analyzer/lib/src/summary2/top_level_inference.dart +++ b/pkg/analyzer/lib/src/summary2/top_level_inference.dart @@ -47,7 +47,7 @@ class ConstantInitializersResolver { unit.extensions.forEach(_resolveExtensionFields); unit.mixins2.forEach(_resolveInterfaceFields); - _scope = unit.enclosingElement3.scope; + _scope = unit.enclosingElement.scope; unit.topLevelVariables.forEach(_resolveVariable); } } @@ -174,7 +174,7 @@ class _ConstructorInferenceNode extends _InferenceNode { } } - var classElement = _constructor.enclosingElement3; + var classElement = _constructor.enclosingElement; if (classElement is ClassElement && classElement.isMixinApplication) { var superType = classElement.supertype; if (superType != null) { @@ -285,7 +285,7 @@ class _InferenceDependenciesCollector extends RecursiveAstVisitor { _set.add(element); - if (element.enclosingElement3.typeParameters.isNotEmpty) { + if (element.enclosingElement.typeParameters.isNotEmpty) { node.argumentList.accept(this); } } @@ -356,7 +356,7 @@ class _InitializerInference { unit.extensions.forEach(_addExtensionElementFields); unit.mixins2.forEach(_addClassElementFields); - _scope = unit.enclosingElement3.scope; + _scope = unit.enclosingElement.scope; for (var element in unit.topLevelVariables) { _addVariableNode(element); } @@ -526,7 +526,7 @@ class _VariableInferenceNode extends _InferenceNode { } void _resolveInitializer({required bool forDependencies}) { - var enclosingElement = _element.enclosingElement3; + var enclosingElement = _element.enclosingElement; var enclosingClassElement = enclosingElement is InterfaceElement ? 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 57d70fb0064..93f68d96f6e 100644 --- a/pkg/analyzer/lib/src/task/strong_mode.dart +++ b/pkg/analyzer/lib/src/task/strong_mode.dart @@ -421,7 +421,7 @@ class InstanceMemberInferrer { var conflict = conflicts.single; if (conflict is CandidatesConflict) { conflictExplanation = conflict.candidates.map((candidate) { - var className = candidate.enclosingElement3.name; + var className = candidate.enclosingElement.name; var typeStr = candidate.type.getDisplayString( withNullability: typeSystem.isNonNullableByDefault, ); @@ -537,7 +537,7 @@ class InstanceMemberInferrer { overridden = overridden.declaration; // Skip Object itself. - var enclosingElement = overridden.enclosingElement3; + var enclosingElement = overridden.enclosingElement; 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 8b0a2bdee8e..ff0650ac5c5 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.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement is CompilationUnitElement) { var memberName = element.name!; if (element is PropertyAccessorElement && element.isSetter) { diff --git a/pkg/analyzer/pubspec.yaml b/pkg/analyzer/pubspec.yaml index 29ad061032d..9add5b30c9a 100644 --- a/pkg/analyzer/pubspec.yaml +++ b/pkg/analyzer/pubspec.yaml @@ -1,5 +1,5 @@ name: analyzer -version: 5.1.0 +version: 5.2.0-dev description: This package provides a library that performs static analysis of Dart code. repository: https://github.com/dart-lang/sdk/tree/main/pkg/analyzer diff --git a/pkg/analyzer/test/generated/element_resolver_test.dart b/pkg/analyzer/test/generated/element_resolver_test.dart index 0642108fba9..d34a268a8c4 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.enclosingElement3, name1.staticElement); + expect(annotationElement.enclosingElement, 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.enclosingElement3, name2.staticElement); + expect(annotationElement.enclosingElement, 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.enclosingElement3, name2.staticElement); + expect(annotationElement.enclosingElement, 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.enclosingElement3, name2.staticElement); + expect(annotationElement.enclosingElement, 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.enclosingElement3, name1.staticElement); + expect(annotationElement.enclosingElement, 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.enclosingElement3, name1.staticElement); + expect(annotationElement.enclosingElement, 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.enclosingElement3, isCompilationUnitElement); + expect(annotationElement.enclosingElement, 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.enclosingElement3, isCompilationUnitElement); + expect(annotationElement.enclosingElement, 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 2496ae6e7e2..8503da82df8 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.enclosingElement3, isNotNull); + expect(y.enclosingElement, 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.enclosingElement3, isNotNull); + expect(y.enclosingElement, 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 08289bab86c..d556d49a56a 100644 --- a/pkg/analyzer/test/generated/resolver_test.dart +++ b/pkg/analyzer/test/generated/resolver_test.dart @@ -71,7 +71,7 @@ class C { var constructor = findElement.unnamedConstructor('C'); var x = findElement.localFunction('x'); - expect(x.enclosingElement3, constructor); + expect(x.enclosingElement, constructor); } } diff --git a/pkg/analyzer/test/id_tests/inheritance_test.dart b/pkg/analyzer/test/id_tests/inheritance_test.dart index 3b2a770dde5..6abbf999a66 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.enclosingElement3 as InterfaceElement; + var enclosingClass = executable.enclosingElement as InterfaceElement; if (enclosingClass is ClassElement && enclosingClass.isDartCoreObject) { continue; } 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 14b9c10d8d4..e9b5f0439fa 100644 --- a/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart +++ b/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart @@ -972,7 +972,7 @@ main() { forInvocation.argumentList.arguments[0] as FunctionExpression; var closureElement = closure.declaredElement as FunctionElementImpl; - expect(closureElement.enclosingElement3, same(mainElement)); + expect(closureElement.enclosingElement, same(mainElement)); ParameterElement itemElement = closureElement.parameters[0]; itemElement1 = itemElement; @@ -1013,7 +1013,7 @@ main() { forInvocation.argumentList.arguments[0] as FunctionExpression; var closureElement = closure.declaredElement as FunctionElementImpl; - expect(closureElement.enclosingElement3, same(mainElement)); + expect(closureElement.enclosingElement, same(mainElement)); ParameterElement itemElement = closureElement.parameters[0]; expect(itemElement, isNot(same(itemElement1))); @@ -1056,7 +1056,7 @@ void foo(List Function() createList) {} assertType(closure, 'List Function()'); var closureElement = closure.declaredElement as FunctionElementImpl; - expect(closureElement.enclosingElement3, findElement.function('main')); + expect(closureElement.enclosingElement, findElement.function('main')); assertType(closureElement.returnType, 'List'); expect(closureElement.parameters, isEmpty); @@ -1702,7 +1702,7 @@ main(MyEnum e) { var methodElement = invocation.methodName.staticElement as MethodElement; expect(methodElement.name, 'toString'); - expect(methodElement.enclosingElement3, same(objectElement)); + expect(methodElement.enclosingElement, 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 89a3ffbfc0b..f731879e3d2 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.enclosingElement3; + var enclosingElement = element.enclosingElement; 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.enclosingElement3, same(element.enclosingElement3)); + expect(variable.enclosingElement, same(element.enclosingElement)); 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.enclosingElement3; + var enclosingElement = element.enclosingElement; 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 f283466419f..c9d68c1a2e0 100644 --- a/pkg/analyzer/test/src/dart/resolution/resolution.dart +++ b/pkg/analyzer/test/src/dart/resolution/resolution.dart @@ -223,7 +223,7 @@ mixin ResolutionTest implements ResourceProviderMixin { } void assertEnclosingElement(Element element, Element expectedEnclosing) { - expect(element.enclosingElement3, expectedEnclosing); + expect(element.enclosingElement, expectedEnclosing); } Future assertErrorsInCode( @@ -500,7 +500,7 @@ mixin ResolutionTest implements ResourceProviderMixin { ) { var actualMapString = Map.fromEntries( substitution.map.entries.where((entry) { - return entry.key.enclosingElement3 is! ExecutableElement; + return entry.key.enclosingElement 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 299ab7ce371..df511ab6cd9 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!.enclosingElement3.name, - 'num'); + expect( + findNode.binary('x + y').staticElement!.enclosingElement.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?.enclosingElement3.name, + expect(findNode.binary('+ y').staticElement?.enclosingElement.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!.enclosingElement3.name, 'num'); + expect(findNode.binary('+ y').staticElement!.enclosingElement.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!.enclosingElement3.name, 'num'); + expect(findNode.binary('+ y').staticElement!.enclosingElement.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 be639119308..e72b0fbf45a 100644 --- a/pkg/analyzer/test/src/summary/element_text.dart +++ b/pkg/analyzer/test/src/summary/element_text.dart @@ -199,8 +199,8 @@ class _ElementWriter { expect(accessor.variable, same(property)); - var propertyEnclosing = property.enclosingElement3; - expect(accessor.enclosingElement3, same(propertyEnclosing)); + var propertyEnclosing = property.enclosingElement; + expect(accessor.enclosingElement, same(propertyEnclosing)); if (propertyEnclosing is CompilationUnitElement) { expect(propertyEnclosing.accessors, contains(accessor)); @@ -383,7 +383,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.enclosingElement3)) { + if (identical(classReference.element, e.enclosingElement)) { expect(reference.element, same(e)); } } @@ -420,7 +420,7 @@ class _ElementWriter { var superConstructor = e.superConstructor; if (superConstructor != null) { - final enclosingElement = superConstructor.enclosingElement3; + final enclosingElement = superConstructor.enclosingElement; if (enclosingElement is ClassElement && !enclosingElement.isDartCoreObject) { _writeElementReference('superConstructor', superConstructor); @@ -440,7 +440,7 @@ class _ElementWriter { if (e.isSynthetic) { expect(e.nameOffset, -1); - expect(e.nonSynthetic, same(e.enclosingElement3)); + expect(e.nonSynthetic, same(e.enclosingElement)); } else { if (!e.isTempAugmentation) { expect(e.nameOffset, isPositive); @@ -690,9 +690,9 @@ class _ElementWriter { _writeNonSyntheticElement(e); }); - if (e.isSynthetic && e.enclosingElement3 is EnumElementImpl) { + if (e.isSynthetic && e.enclosingElement is EnumElementImpl) { expect(e.name, 'toString'); - expect(e.nonSynthetic, same(e.enclosingElement3)); + expect(e.nonSynthetic, same(e.enclosingElement)); } else { _assertNonSyntheticElementSelf(e); } @@ -797,7 +797,7 @@ class _ElementWriter { PropertyInducingElement variable = e.variable; expect(variable, isNotNull); - var variableEnclosing = variable.enclosingElement3; + var variableEnclosing = variable.enclosingElement; if (variableEnclosing is CompilationUnitElement) { expect(variableEnclosing.topLevelVariables, contains(variable)); } else if (variableEnclosing is InterfaceElement) { diff --git a/pkg/analyzer/test/src/summary/elements_test.dart b/pkg/analyzer/test/src/summary/elements_test.dart index fb1d4b0cd7a..dc16003eceb 100644 --- a/pkg/analyzer/test/src/summary/elements_test.dart +++ b/pkg/analyzer/test/src/summary/elements_test.dart @@ -22663,14 +22663,14 @@ typedef void F(int a); var T = F.typeParameters[0]; expect(T.name, 'T'); - expect(T.enclosingElement3, same(F)); + expect(T.enclosingElement, same(F)); var function = F.aliasedElement as GenericFunctionTypeElement; - expect(function.enclosingElement3, same(F)); + expect(function.enclosingElement, same(F)); var a = function.parameters[0]; expect(a.name, 'a'); - expect(a.enclosingElement3, same(function)); + expect(a.enclosingElement, same(function)); } test_functionTypeAlias_type_element() async { @@ -23817,18 +23817,18 @@ typedef F = void Function(int a); var T = F.typeParameters[0]; expect(T.name, 'T'); - expect(T.enclosingElement3, same(F)); + expect(T.enclosingElement, same(F)); var function = F.aliasedElement as GenericFunctionTypeElement; - expect(function.enclosingElement3, same(F)); + expect(function.enclosingElement, same(F)); var U = function.typeParameters[0]; expect(U.name, 'U'); - expect(U.enclosingElement3, same(function)); + expect(U.enclosingElement, same(function)); var a = function.parameters[0]; expect(a.name, 'a'); - expect(a.enclosingElement3, same(function)); + expect(a.enclosingElement, same(function)); } test_genericTypeAlias_recursive() async { @@ -26993,7 +26993,7 @@ library final import_0 = library.augmentationImports[0]; final augmentation = import_0.importedAugmentation!; - expect(augmentation.enclosingElement3, same(library)); + expect(augmentation.enclosingElement, 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 403da7abd61..1fe65d37e6a 100644 --- a/pkg/analyzer/test/src/summary/resolved_ast_printer.dart +++ b/pkg/analyzer/test/src/summary/resolved_ast_printer.dart @@ -1355,7 +1355,7 @@ class ResolvedAstPrinter extends ThrowingAstVisitor { } String _elementToReferenceString(Element element) { - final enclosingElement = element.enclosingElement3; + final enclosingElement = element.enclosingElement; 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 2d12f6c23be..38fbffcfe05 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 @@ -693,7 +693,7 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder { @override void writeReference(Element element) { - if (element.enclosingElement3 is CompilationUnitElement) { + if (element.enclosingElement is CompilationUnitElement) { _writeLibraryReference(element); } write(element.displayName); @@ -1118,10 +1118,10 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder { if (type is TypeParameterType) { _initializeEnclosingElements(); var element = type.element2; - var enclosing = element.enclosingElement3; + var enclosing = element.enclosingElement; while (enclosing is GenericFunctionTypeElement || enclosing is ParameterElement) { - enclosing = enclosing!.enclosingElement3; + enclosing = enclosing!.enclosingElement; } 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 7d683d3dfc1..127cb49094a 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.enclosingElement3 is ClassElement + var elemKind = element.enclosingElement 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 7e7bbe205c9..e452d3dd005 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.enclosingElement3; + var enclosingElement = element.enclosingElement; 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 25457391867..658e533ef04 100644 --- a/pkg/analyzer_plugin/lib/utilities/analyzer_converter.dart +++ b/pkg/analyzer_plugin/lib/utilities/analyzer_converter.dart @@ -226,7 +226,7 @@ class AnalyzerConverter { // in either or both of these cases? ) { final type = element.type; - if (type is InterfaceType && type.element2 == element.enclosingElement3) { + if (type is InterfaceType && type.element2 == element.enclosingElement) { return plugin.ElementKind.ENUM_CONSTANT; } } @@ -326,15 +326,15 @@ class AnalyzerConverter { if (currentElement is analyzer.CompilationUnitElement) { return currentElement; } - if (currentElement.enclosingElement3 is analyzer.LibraryElement) { - currentElement = currentElement.enclosingElement3; + if (currentElement.enclosingElement is analyzer.LibraryElement) { + currentElement = currentElement.enclosingElement; } if (currentElement is analyzer.LibraryElement) { return currentElement.definingCompilationUnit; } for (; currentElement != null; - currentElement = currentElement.enclosingElement3) { + currentElement = currentElement.enclosingElement) { 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 00dfe67aaf9..a2e17588be0 100644 --- a/pkg/analyzer_plugin/lib/utilities/navigation/navigation_dart.dart +++ b/pkg/analyzer_plugin/lib/utilities/navigation/navigation_dart.dart @@ -148,7 +148,7 @@ class _DartNavigationComputerVisitor extends RecursiveAstVisitor { void visitAnnotation(Annotation node) { var element = node.element; if (element is ConstructorElement && element.isSynthetic) { - element = element.enclosingElement3; + element = element.enclosingElement; } var name = node.name; if (name is PrefixedIdentifier) { @@ -454,7 +454,7 @@ class _DartNavigationComputerVisitor extends RecursiveAstVisitor { RedirectingConstructorInvocation node) { Element? element = node.staticElement; if (element != null && element.isSynthetic) { - element = element.enclosingElement3; + element = element.enclosingElement; } // add region computer._addRegionForToken(node.thisKeyword, element); @@ -483,7 +483,7 @@ class _DartNavigationComputerVisitor extends RecursiveAstVisitor { void visitSuperConstructorInvocation(SuperConstructorInvocation node) { Element? element = node.staticElement; if (element != null && element.isSynthetic) { - element = element.enclosingElement3; + element = element.enclosingElement; } // 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 ab696eb8c74..c48664f102f 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.enclosingElement3; + var executableEnclosing = executable.enclosingElement; if (executableEnclosing is CompilationUnitElement) { return executable.name; } else if (executable is ConstructorElement) { diff --git a/pkg/nnbd_migration/lib/instrumentation.dart b/pkg/nnbd_migration/lib/instrumentation.dart index 844b6a6a9a5..270028e7397 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.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement is LibraryElement) { unitElement = enclosingElement.definingCompilationUnit; } else { @@ -76,7 +76,7 @@ class CodeReference { if (elementName != null) { parts.add(elementName); } - element = element.enclosingElement3; + element = element.enclosingElement; } 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 0f0a28d0a07..a4c032a5a1a 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.enclosingElement3 == null, - '$parameter should not have parent ${parameter.enclosingElement3}'); + assert(parameter.enclosingElement == null, + '$parameter should not have parent ${parameter.enclosingElement}'); } /// If `this` represents an interface type, returns the substitution necessary @@ -414,7 +414,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].enclosingElement3 == null) { + if (undecoratedResult.typeFormals[i].enclosingElement == null) { substitution[typeFormals[i]] = DecoratedType._forTypeParameterSubstitution( undecoratedResult.typeFormals[i]); @@ -541,7 +541,7 @@ class DecoratedTypeParameterBounds { final _parentedBounds = {}; DecoratedType? get(TypeParameterElement element) { - if (element.enclosingElement3 == null) { + if (element.enclosingElement == null) { return _orphanBounds[element]; } else { return _parentedBounds[element]; @@ -549,7 +549,7 @@ class DecoratedTypeParameterBounds { } void put(TypeParameterElement element, DecoratedType? bounds) { - if (element.enclosingElement3 == null) { + if (element.enclosingElement == 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 75dbe2854a8..31fe0473851 100644 --- a/pkg/nnbd_migration/lib/src/edge_builder.dart +++ b/pkg/nnbd_migration/lib/src/edge_builder.dart @@ -285,7 +285,7 @@ class EdgeBuilder extends GeneralizingAstVisitor Map? substitution; Element? baseElement = element.declaration; if (targetType != null) { - var enclosingElement = baseElement!.enclosingElement3; + var enclosingElement = baseElement!.enclosingElement; if (enclosingElement is InterfaceElement) { if (targetType.type.explicitBound is InterfaceType && enclosingElement.typeParameters.isNotEmpty) { @@ -479,8 +479,8 @@ class EdgeBuilder extends GeneralizingAstVisitor var assignee = getWriteOrReadElement(node.leftHandSide as SimpleIdentifier)!; var enclosingElementOfCurrentFunction = - _currentFunctionExpression!.declaredElement!.enclosingElement3; - if (enclosingElementOfCurrentFunction == assignee.enclosingElement3) { + _currentFunctionExpression!.declaredElement!.enclosingElement; + if (enclosingElementOfCurrentFunction == assignee.enclosingElement) { // [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 @@ -854,7 +854,7 @@ class EdgeBuilder extends GeneralizingAstVisitor // Nothing to do; assume the implicit default value of `null` will never // be reached. } else { - var enclosingElement = declaredElement.enclosingElement3; + var enclosingElement = declaredElement.enclosingElement; if (enclosingElement is ConstructorElement && enclosingElement.isFactory && enclosingElement.redirectedConstructor != null) { @@ -1223,7 +1223,7 @@ class EdgeBuilder extends GeneralizingAstVisitor DecoratedType visitInstanceCreationExpression( InstanceCreationExpression node) { var callee = node.constructorName.staticElement!; - var typeParameters = callee.enclosingElement3.typeParameters; + var typeParameters = callee.enclosingElement.typeParameters; Iterable typeArgumentTypes; List decoratedTypeArguments; var typeArguments = node.constructorName.type.typeArguments; @@ -1404,7 +1404,7 @@ class EdgeBuilder extends GeneralizingAstVisitor } else { targetType = _handleTarget(target, node.methodName.name, callee); } - } else if (target == null && callee!.enclosingElement3 is ClassElement) { + } else if (target == null && callee!.enclosingElement is ClassElement) { targetType = _thisOrSuper(node); _checkThisNotNull(targetType, node); } @@ -1811,13 +1811,13 @@ class EdgeBuilder extends GeneralizingAstVisitor } else if (staticElement is FunctionElement || staticElement is MethodElement || staticElement is ConstructorElement) { - if (staticElement!.enclosingElement3 is ClassElement) { + if (staticElement!.enclosingElement is ClassElement) { targetType = _thisOrSuper(node); } result = getOrComputeElementType(node, staticElement, targetType: targetType); } else if (staticElement is PropertyAccessorElement) { - if (staticElement.enclosingElement3 is ClassElement) { + if (staticElement.enclosingElement is ClassElement) { targetType = _thisOrSuper(node); } var elementType = @@ -1832,8 +1832,8 @@ class EdgeBuilder extends GeneralizingAstVisitor } else if (staticElement == null) { assert(node.toString() == 'void', "${node.toString()} != 'void'"); result = _makeNullableVoidType(node); - } else if (staticElement.enclosingElement3 is ClassElement && - staticElement.enclosingElement3 is EnumElement) { + } else if (staticElement.enclosingElement is ClassElement && + staticElement.enclosingElement is EnumElement) { result = getOrComputeElementType(node, staticElement); } else { // TODO(paulberry) @@ -1899,7 +1899,7 @@ class EdgeBuilder extends GeneralizingAstVisitor var nullabilityNode = NullabilityNode.forInferredType(target); var class_ = node.thisOrAncestorOfType()!; var decoratedSupertype = _decoratedClassHierarchy!.getDecoratedSupertype( - class_.declaredElement!, callee.enclosingElement3); + class_.declaredElement!, callee.enclosingElement); var typeArguments = decoratedSupertype.typeArguments; Iterable typeArgumentTypes; typeArgumentTypes = typeArguments.map((t) => t!.type); @@ -1907,7 +1907,7 @@ class EdgeBuilder extends GeneralizingAstVisitor typeArguments: typeArguments); var calleeType = getOrComputeElementType(node, callee, targetType: createdType); - var constructorTypeParameters = callee.enclosingElement3.typeParameters; + var constructorTypeParameters = callee.enclosingElement.typeParameters; _handleInvocationArguments( node, @@ -2019,7 +2019,7 @@ class EdgeBuilder extends GeneralizingAstVisitor } } var type = _variables.decoratedElementType(declaredElement); - var enclosingElement = declaredElement.enclosingElement3; + var enclosingElement = declaredElement.enclosingElement; if (!declaredElement.isStatic && enclosingElement is ClassElement) { var overriddenElements = _inheritanceManager.getOverridden2( enclosingElement, @@ -2583,7 +2583,7 @@ class EdgeBuilder extends GeneralizingAstVisitor void _handleConstructorRedirection( FormalParameterList parameters, ConstructorName redirectedConstructor) { var callee = redirectedConstructor.staticElement!.declaration; - var redirectedClass = callee.enclosingElement3; + var redirectedClass = callee.enclosingElement; var calleeType = _variables.decoratedElementType(callee); var typeArguments = redirectedConstructor.type.typeArguments; var typeArgumentTypes = @@ -2602,7 +2602,7 @@ class EdgeBuilder extends GeneralizingAstVisitor if (node.argumentList.arguments.isNotEmpty && callee is ExecutableElement && callee.isStatic) { - var enclosingElement = callee.enclosingElement3; + var enclosingElement = callee.enclosingElement; if (enclosingElement is ClassElement) { if (callee.name == 'checkNotNull' && enclosingElement.name == 'ArgumentError' && @@ -2647,7 +2647,7 @@ class EdgeBuilder extends GeneralizingAstVisitor _addParametersToFlowAnalysis(parameters); // Push a scope of post-dominated declarations on the stack. _postDominatedLocals.pushScope(elements: declaredElement.parameters); - if (declaredElement.enclosingElement3 is ExtensionElement) { + if (declaredElement.enclosingElement is ExtensionElement) { _postDominatedLocals.add(_extensionThis); } try { @@ -2662,7 +2662,7 @@ class EdgeBuilder extends GeneralizingAstVisitor _handleConstructorRedirection(parameters!, redirectedConstructor); } if (declaredElement is! ConstructorElement) { - var enclosingElement = declaredElement.enclosingElement3; + var enclosingElement = declaredElement.enclosingElement; if (enclosingElement is ClassElement) { var overriddenElements = _inheritanceManager.getOverridden2( enclosingElement, @@ -2749,7 +2749,7 @@ class EdgeBuilder extends GeneralizingAstVisitor ClassElement classElement, Element overriddenElement) { overriddenElement = overriddenElement.declaration!; - var overriddenClass = overriddenElement.enclosingElement3 as ClassElement; + var overriddenClass = overriddenElement.enclosingElement as ClassElement; var decoratedSupertype = _decoratedClassHierarchy! .getDecoratedSupertype(classElement, overriddenClass); var substitution = decoratedSupertype.asSubstitution; @@ -2851,7 +2851,7 @@ class EdgeBuilder extends GeneralizingAstVisitor Element overriddenElement) { overriddenElement = overriddenElement.declaration!; var overriddenClass = - overriddenElement.enclosingElement3 as InterfaceElement; + overriddenElement.enclosingElement as InterfaceElement; var decoratedSupertype = _decoratedClassHierarchy! .getDecoratedSupertype(classElement, overriddenClass); var substitution = decoratedSupertype.asSubstitution; @@ -2982,13 +2982,13 @@ class EdgeBuilder extends GeneralizingAstVisitor Map getterSubstitution = const {}; Map setterSubstitution = const {}; if (class_ != null) { - var getterClass = getter.enclosingElement3 as ClassElement; + var getterClass = getter.enclosingElement as ClassElement; if (!identical(class_, getterClass)) { getterSubstitution = _decoratedClassHierarchy! .getDecoratedSupertype(class_, getterClass) .asSubstitution; } - var setterClass = setter.enclosingElement3 as ClassElement; + var setterClass = setter.enclosingElement as ClassElement; if (!identical(class_, setterClass)) { setterSubstitution = _decoratedClassHierarchy! .getDecoratedSupertype(class_, setterClass) @@ -3124,7 +3124,7 @@ class EdgeBuilder extends GeneralizingAstVisitor if (target is SimpleIdentifier) { var targetElement = target.staticElement; if (targetElement is ParameterElement && - targetElement.enclosingElement3 == _currentExecutable && + targetElement.enclosingElement == _currentExecutable && !_currentExecutable!.name.startsWith('_')) { _graph.makeNullable( _variables.decoratedElementType(targetElement).node!, @@ -3258,7 +3258,7 @@ class EdgeBuilder extends GeneralizingAstVisitor if (isDeclaredOnObject(name)) { return _dispatch(target); } else if ((callee is MethodElement || callee is PropertyAccessorElement) && - callee!.enclosingElement3 is ExtensionElement) { + callee!.enclosingElement 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 155c15a25f5..0cfe32cc00f 100644 --- a/pkg/nnbd_migration/lib/src/fix_builder.dart +++ b/pkg/nnbd_migration/lib/src/fix_builder.dart @@ -492,7 +492,7 @@ class MigrationResolutionHooksImpl return variable.typeInternal; } if (variable is ParameterElement) { - var enclosingElement = variable.enclosingElement3; + var enclosingElement = variable.enclosingElement; if (enclosingElement is PropertyAccessorElement && enclosingElement.isSynthetic) { // This is the parameter of a synthetic getter, so it has the same @@ -527,7 +527,7 @@ class MigrationResolutionHooksImpl /// on a nullable type without introducing a null check). bool isNullableExtensionMember(Element? element) { if (element != null) { - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement is ExtensionElement) { return _fixBuilder._typeSystem .isPotentiallyNullable(enclosingElement.extendedType); @@ -1278,7 +1278,7 @@ class _FixBuilderPreVisitor extends GeneralizingAstVisitor var nullabilityNode = _fixBuilder._variables!.decoratedElementType(element!).node!; if (!nullabilityNode.isNullable) { - var enclosingElement = element.enclosingElement3; + var enclosingElement = element.enclosingElement; if (enclosingElement is ConstructorElement && enclosingElement.isFactory && enclosingElement.redirectedConstructor != null && @@ -1391,8 +1391,8 @@ class _FixBuilderPreVisitor extends GeneralizingAstVisitor // Change an existing `@required` annotation into a `required` keyword if // possible. final element = parameter.declaredElement!; - final method = element.enclosingElement3!; - final cls = method.enclosingElement3!; + final method = element.enclosingElement!; + final cls = method.enclosingElement!; 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 f774316f318..48550f611cd 100644 --- a/pkg/nnbd_migration/lib/src/node_builder.dart +++ b/pkg/nnbd_migration/lib/src/node_builder.dart @@ -703,7 +703,7 @@ class NodeBuilder extends GeneralizingAstVisitor for (var annotation in metadata) { var element = annotation.element; if (element is ConstructorElement) { - var name = element.enclosingElement3.name; + var name = element.enclosingElement.name; if (_isAngularUri(element.librarySource.uri)) { if (name == 'ViewChild' || name == 'ContentChild') { return _AngularAnnotation.child; @@ -745,7 +745,7 @@ class NodeBuilder extends GeneralizingAstVisitor // Constructors have no explicit return type annotation, so use the // implicit return type. decoratedReturnType = _createDecoratedTypeForClass( - declaredElement.enclosingElement3, parameters!.parent); + declaredElement.enclosingElement, parameters!.parent); instrumentation?.implicitReturnType(source, node, decoratedReturnType); } else { // Inferred return type. @@ -846,7 +846,7 @@ class NodeBuilder extends GeneralizingAstVisitor for (var annotation in node.metadata) { var element = annotation.element; if (element is ConstructorElement && - element.enclosingElement3.name == 'Optional' && + element.enclosingElement.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 4566ca26085..83199366ef3 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.enclosingElement3; + element = element.enclosingElement; } 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 892c0b5b7e9..c4ed06fd419 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.enclosingElement3 is CompilationUnitElement) { + if (element.enclosingElement 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 35d35882f79..17e75265596 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.enclosingElement3; + var enclosingElement = element.declaration.enclosingElement; 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 162d5447662..d276ad5bf56 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.enclosingElement3; + var enclosingElement = element.declaration.enclosingElement; 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 969b0d5fc52..573ce93ef7d 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.enclosingElement3; + var enclosingElement = typeParameter.enclosingElement; 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.enclosingElement3 is LibraryElement && + element.enclosingElement 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 bbe00c24ee2..341a6541a66 100644 --- a/pkg/nnbd_migration/test/node_builder_test.dart +++ b/pkg/nnbd_migration/test/node_builder_test.dart @@ -1029,7 +1029,7 @@ void f() { } '''); var functionExpressionElement = - findNode.simpleParameter('int i').declaredElement!.enclosingElement3!; + findNode.simpleParameter('int i').declaredElement!.enclosingElement!; var decoratedType = variables.decoratedElementType(functionExpressionElement); expect(decoratedType.positionalParameters![0], @@ -1046,7 +1046,7 @@ void f() { } '''); var functionExpressionElement = - findNode.simpleParameter('int i').declaredElement!.enclosingElement3!; + findNode.simpleParameter('int i').declaredElement!.enclosingElement!; var decoratedType = variables.decoratedElementType(functionExpressionElement); expect(