Skip to content

Commit

Permalink
[analyzer] Remove Element2.location
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
DanTup authored and scheglov committed Dec 22, 2024
1 parent 354c64f commit 3557eb4
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uri> requiredImports;
final String? colorHex;

Expand Down Expand Up @@ -39,7 +37,6 @@ class DartCompletionSuggestion extends CompletionSuggestion {
super.parameterType,
super.libraryUri,
super.isNotImported,
required this.elementLocation,
this.requiredImports = const [],
this.colorHex,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ class SuggestionBuilder {
false,
false,
displayText: displayText,
elementLocation: null, // type.element is Null for FunctionType.
),
);
}
Expand Down Expand Up @@ -728,7 +727,6 @@ class SuggestionBuilder {
parameterType: type,
replacementLength: replacementLength,
element: convertElement2(parameter),
elementLocation: parameter.location,
);

if (parameter is FieldFormalParameterElement2) {
Expand Down Expand Up @@ -850,7 +848,6 @@ class SuggestionBuilder {
element.metadata2.hasDeprecated,
false,
displayText: displayText,
elementLocation: element.location,
requiredImports: overrideImports.toList(),
);
suggestion.element = protocol.convertElement2(element);
Expand Down Expand Up @@ -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',
);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
);
Expand Down
6 changes: 0 additions & 6 deletions pkg/analyzer/lib/dart/element/element2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 0 additions & 11 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -5576,9 +5571,6 @@ abstract class InstanceElementImpl2 extends ElementImpl2
@override
LibraryElement2 get library2 => firstFragment.library2!;

@override
ElementLocation? get location => firstFragment.location;

@override
List<ElementAnnotation> get metadata => firstFragment.metadata;

Expand Down Expand Up @@ -8700,9 +8692,6 @@ class MultiplyDefinedElementImpl2 extends ElementImpl2
@override
LibraryElement2 get library2 => libraryFragment.element;

@override
ElementLocation? get location => null;

@override
Element2 get nonSynthetic2 => this;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class _DartNavigationCollector {
if (fragment.element == DynamicElementImpl.instance) {
return;
}
if (fragment.element.location == null) {
if (fragment.element is MultiplyDefinedElement2) {
return;
}

Expand Down

0 comments on commit 3557eb4

Please sign in to comment.