From 3557eb4a268c77de76391e2b63d56f91b5bed006 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Sun, 22 Dec 2024 12:55:56 -0800 Subject: [PATCH] [analyzer] Remove Element2.location The completion code was no longer using this (we use `ElementLocation2` directly in the completion handler now), and the navigation check was just to ensure we didn't include MultiplyDefinedElements in navigation results. Change-Id: I8412ec60d3d56386a7ced3d78c3a7428313df5d3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402101 Reviewed-by: Konstantin Shcheglov Reviewed-by: Brian Wilkerson --- .../completion/dart/dart_completion_suggestion.dart | 3 --- .../services/completion/dart/suggestion_builder.dart | 9 +-------- pkg/analyzer/lib/dart/element/element2.dart | 6 ------ pkg/analyzer/lib/src/dart/element/element.dart | 11 ----------- .../lib/src/utilities/navigation/navigation_dart.dart | 2 +- 5 files changed, 2 insertions(+), 29 deletions(-) diff --git a/pkg/analysis_server/lib/src/services/completion/dart/dart_completion_suggestion.dart b/pkg/analysis_server/lib/src/services/completion/dart/dart_completion_suggestion.dart index 18988185b91c..3493493512fa 100644 --- a/pkg/analysis_server/lib/src/services/completion/dart/dart_completion_suggestion.dart +++ b/pkg/analysis_server/lib/src/services/completion/dart/dart_completion_suggestion.dart @@ -4,12 +4,10 @@ import 'package:analysis_server/src/protocol_server.dart' show CompletionSuggestion; -import 'package:analyzer/dart/element/element2.dart'; /// An extension of [CompletionSuggestion] that includes additional /// Dart-specific fields that are not part of the JSON protocol. class DartCompletionSuggestion extends CompletionSuggestion { - final ElementLocation? elementLocation; final List requiredImports; final String? colorHex; @@ -39,7 +37,6 @@ class DartCompletionSuggestion extends CompletionSuggestion { super.parameterType, super.libraryUri, super.isNotImported, - required this.elementLocation, this.requiredImports = const [], this.colorHex, }); 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 b83a87808d72..ce29aadfb39a 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 @@ -152,7 +152,6 @@ class SuggestionBuilder { false, false, displayText: displayText, - elementLocation: null, // type.element is Null for FunctionType. ), ); } @@ -728,7 +727,6 @@ class SuggestionBuilder { parameterType: type, replacementLength: replacementLength, element: convertElement2(parameter), - elementLocation: parameter.location, ); if (parameter is FieldFormalParameterElement2) { @@ -850,7 +848,6 @@ class SuggestionBuilder { element.metadata2.hasDeprecated, false, displayText: displayText, - elementLocation: element.location, requiredImports: overrideImports.toList(), ); suggestion.element = protocol.convertElement2(element); @@ -928,7 +925,6 @@ class SuggestionBuilder { false, // Let the user know that we are going to insert a complete statement. displayText: displayText, - elementLocation: method.location, ), textToMatchOverride: 'setState', ); @@ -1522,9 +1518,7 @@ class SuggestionBuilder { ElementLocation? elementLocation; if (element is! LocalVariableElement2 || (element is FormalParameterElement && - element.enclosingElement2 != null)) { - elementLocation = element.location; - } + element.enclosingElement2 != null)) {} return _ElementCompletionData( isDeprecated: element.hasOrInheritsDeprecated, @@ -1799,7 +1793,6 @@ class _CompletionSuggestionBuilderImpl implements CompletionSuggestionBuilder { defaultArgumentListTextRanges: element.defaultArgumentList?.ranges, libraryUri: libraryUriStr, isNotImported: isNotImported ? true : null, - elementLocation: element.elementLocation, requiredImports: requiredImports, colorHex: element.colorHex, ); diff --git a/pkg/analyzer/lib/dart/element/element2.dart b/pkg/analyzer/lib/dart/element/element2.dart index d80630e6cf3c..d56914ad6ad6 100644 --- a/pkg/analyzer/lib/dart/element/element2.dart +++ b/pkg/analyzer/lib/dart/element/element2.dart @@ -54,7 +54,6 @@ import 'package:analyzer/dart/element/element.dart' DirectiveUri, ElementAnnotation, ElementKind, - ElementLocation, LibraryLanguageVersion, NamespaceCombinator; import 'package:analyzer/dart/element/nullability_suffix.dart'; @@ -436,11 +435,6 @@ abstract class Element2 { /// in a single library. LibraryElement2? get library2; - /// The location of this element in the element model. - /// - /// The object can be used to locate this element at a later time. - ElementLocation? get location; - /// The name to use for lookup in maps. /// /// It is usually the same as [name3], with a few special cases. diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart index ab9a176d001b..5848c930fd34 100644 --- a/pkg/analyzer/lib/src/dart/element/element.dart +++ b/pkg/analyzer/lib/src/dart/element/element.dart @@ -3337,11 +3337,6 @@ abstract class ElementImpl2 implements Element2 { @override bool get isPublic => !isPrivate; - @override - ElementLocation? get location { - return ElementLocationImpl.fromElement(this); - } - @override String? get lookupName { return name3; @@ -5576,9 +5571,6 @@ abstract class InstanceElementImpl2 extends ElementImpl2 @override LibraryElement2 get library2 => firstFragment.library2!; - @override - ElementLocation? get location => firstFragment.location; - @override List get metadata => firstFragment.metadata; @@ -8700,9 +8692,6 @@ class MultiplyDefinedElementImpl2 extends ElementImpl2 @override LibraryElement2 get library2 => libraryFragment.element; - @override - ElementLocation? get location => null; - @override Element2 get nonSynthetic2 => this; diff --git a/pkg/analyzer_plugin/lib/src/utilities/navigation/navigation_dart.dart b/pkg/analyzer_plugin/lib/src/utilities/navigation/navigation_dart.dart index af62095d44a3..e7a9fa3bbabe 100644 --- a/pkg/analyzer_plugin/lib/src/utilities/navigation/navigation_dart.dart +++ b/pkg/analyzer_plugin/lib/src/utilities/navigation/navigation_dart.dart @@ -145,7 +145,7 @@ class _DartNavigationCollector { if (fragment.element == DynamicElementImpl.instance) { return; } - if (fragment.element.location == null) { + if (fragment.element is MultiplyDefinedElement2) { return; }