Skip to content

Commit a564aef

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Remove ElementLocation.
Change-Id: I92b46c19878e4b0e27d2bf5e08b90bbb666df1e1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424580 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent 5828f83 commit a564aef

File tree

7 files changed

+2
-207
lines changed

7 files changed

+2
-207
lines changed

pkg/analysis_server/lib/src/computer/computer_lazy_type_hierarchy.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:analysis_server/src/services/search/search_engine.dart';
99
import 'package:analysis_server/src/utilities/element_location2.dart';
1010
import 'package:analyzer/dart/analysis/results.dart';
1111
import 'package:analyzer/dart/ast/ast.dart';
12-
import 'package:analyzer/dart/element/element2.dart' hide ElementLocation;
12+
import 'package:analyzer/dart/element/element2.dart';
1313
import 'package:analyzer/dart/element/type.dart';
1414
import 'package:analyzer/source/source_range.dart';
1515
import 'package:analyzer/src/dart/element/element.dart';

pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,12 +1443,6 @@ class SuggestionBuilder {
14431443
namedParameters,
14441444
);
14451445
}
1446-
// If element is a local variable or is a parameter of a local function,
1447-
// then the element location can be null.
1448-
ElementLocation? elementLocation;
1449-
if (element is! LocalVariableElement2 ||
1450-
(element is FormalParameterElement &&
1451-
element.enclosingElement2 != null)) {}
14521446

14531447
return _ElementCompletionData(
14541448
isDeprecated: element.hasOrInheritsDeprecated,
@@ -1461,7 +1455,6 @@ class SuggestionBuilder {
14611455
documentation: documentation,
14621456
defaultArgumentList: defaultArgumentList,
14631457
element: suggestedElement,
1464-
elementLocation: elementLocation,
14651458
colorHex: colorHex,
14661459
);
14671460
}
@@ -1735,7 +1728,6 @@ class _ElementCompletionData {
17351728
CompletionDefaultArgumentList? defaultArgumentList;
17361729
final _ElementDocumentation? documentation;
17371730
final protocol.Element element;
1738-
final ElementLocation? elementLocation;
17391731
final String? colorHex;
17401732

17411733
_ElementCompletionData({
@@ -1749,7 +1741,6 @@ class _ElementCompletionData {
17491741
required this.defaultArgumentList,
17501742
required this.documentation,
17511743
required this.element,
1752-
required this.elementLocation,
17531744
required this.colorHex,
17541745
});
17551746
}

pkg/analyzer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Remove deprecated `DartType.isStructurallyEqualTo`.
44
* Remove deprecated `RecordType.positionalTypes`.
55
* Remove deprecated `RecordType.sortedNamedTypes`.
6+
* Remove `ElementLocation` class, its values are not returned anymore.
67

78
## 7.4.1
89
* Restore `InstanceElement.augmented` getter.

pkg/analyzer/api.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,10 +3158,6 @@ package:analyzer/dart/element/element.dart:
31583158
ordinal (getter: int)
31593159
compareTo (method: int Function(ElementKind))
31603160
toString (method: String Function())
3161-
ElementLocation (class extends Object):
3162-
new (constructor: ElementLocation Function())
3163-
components (getter: List<String>)
3164-
encoding (getter: String)
31653161
ElementVisitor2 (class<R> extends Object):
31663162
new (constructor: ElementVisitor2<R> Function())
31673163
visitClassElement (method: R? Function(ClassElement2))
@@ -3840,7 +3836,6 @@ package:analyzer/dart/element/element2.dart:
38403836
ElementAnnotation (see above)
38413837
ElementDirective (see above)
38423838
ElementKind (see above)
3843-
ElementLocation (see above)
38443839
ElementVisitor2 (see above)
38453840
EnumElement2 (see above)
38463841
EnumFragment (see above)

pkg/analyzer/lib/dart/element/element.dart

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -937,20 +937,6 @@ class ElementKind implements Comparable<ElementKind> {
937937
String toString() => name;
938938
}
939939

940-
/// The location of an element within the element model.
941-
///
942-
/// Clients may not extend, implement or mix-in this class.
943-
abstract class ElementLocation {
944-
/// The path to the element whose location is represented by this object.
945-
///
946-
/// Clients must not modify the returned array.
947-
List<String> get components;
948-
949-
/// The encoded representation of this location that can be used to create a
950-
/// location that is equal to this location.
951-
String get encoding;
952-
}
953-
954940
/// An object that can be used to visit an element structure.
955941
///
956942
/// Clients may not extend, implement or mix-in this class. There are classes

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,118 +2844,6 @@ abstract class ElementImpl2 implements Element2 {
28442844
}
28452845
}
28462846

2847-
/// A concrete implementation of an [ElementLocation].
2848-
class ElementLocationImpl implements ElementLocation {
2849-
/// The character used to separate components in the encoded form.
2850-
static const int _separatorChar = 0x3B;
2851-
2852-
/// The path to the element whose location is represented by this object.
2853-
late final List<String> _components;
2854-
2855-
/// Initialize a newly created location to represent the given [element].
2856-
ElementLocationImpl.con1(ElementImpl element) {
2857-
List<String> components = <String>[];
2858-
ElementImpl? ancestor = element;
2859-
while (ancestor != null) {
2860-
components.insert(0, ancestor.identifier);
2861-
if (ancestor is CompilationUnitElementImpl) {
2862-
components.insert(0, ancestor.library.identifier);
2863-
break;
2864-
}
2865-
ancestor = ancestor.enclosingElement3;
2866-
}
2867-
_components = components.toFixedList();
2868-
}
2869-
2870-
/// Initialize a newly created location from the given [encoding].
2871-
ElementLocationImpl.con2(String encoding) {
2872-
_components = _decode(encoding);
2873-
}
2874-
2875-
@override
2876-
List<String> get components => _components;
2877-
2878-
@override
2879-
String get encoding {
2880-
StringBuffer buffer = StringBuffer();
2881-
int length = _components.length;
2882-
for (int i = 0; i < length; i++) {
2883-
if (i > 0) {
2884-
buffer.writeCharCode(_separatorChar);
2885-
}
2886-
_encode(buffer, _components[i]);
2887-
}
2888-
return buffer.toString();
2889-
}
2890-
2891-
@override
2892-
int get hashCode => Object.hashAll(_components);
2893-
2894-
@override
2895-
bool operator ==(Object other) {
2896-
if (identical(this, other)) {
2897-
return true;
2898-
}
2899-
if (other is ElementLocationImpl) {
2900-
List<String> otherComponents = other._components;
2901-
int length = _components.length;
2902-
if (otherComponents.length != length) {
2903-
return false;
2904-
}
2905-
for (int i = 0; i < length; i++) {
2906-
if (_components[i] != otherComponents[i]) {
2907-
return false;
2908-
}
2909-
}
2910-
return true;
2911-
}
2912-
return false;
2913-
}
2914-
2915-
@override
2916-
String toString() => encoding;
2917-
2918-
/// Decode the [encoding] of a location into a list of components and return
2919-
/// the components.
2920-
List<String> _decode(String encoding) {
2921-
List<String> components = <String>[];
2922-
StringBuffer buffer = StringBuffer();
2923-
int index = 0;
2924-
int length = encoding.length;
2925-
while (index < length) {
2926-
int currentChar = encoding.codeUnitAt(index);
2927-
if (currentChar == _separatorChar) {
2928-
if (index + 1 < length &&
2929-
encoding.codeUnitAt(index + 1) == _separatorChar) {
2930-
buffer.writeCharCode(_separatorChar);
2931-
index += 2;
2932-
} else {
2933-
components.add(buffer.toString());
2934-
buffer = StringBuffer();
2935-
index++;
2936-
}
2937-
} else {
2938-
buffer.writeCharCode(currentChar);
2939-
index++;
2940-
}
2941-
}
2942-
components.add(buffer.toString());
2943-
return components;
2944-
}
2945-
2946-
/// Append an encoded form of the given [component] to the given [buffer].
2947-
void _encode(StringBuffer buffer, String component) {
2948-
int length = component.length;
2949-
for (int i = 0; i < length; i++) {
2950-
int currentChar = component.codeUnitAt(i);
2951-
if (currentChar == _separatorChar) {
2952-
buffer.writeCharCode(_separatorChar);
2953-
}
2954-
buffer.writeCharCode(currentChar);
2955-
}
2956-
}
2957-
}
2958-
29592847
/// A shared internal interface of `Element` and [Member].
29602848
/// Used during migration to avoid referencing `Element`.
29612849
abstract class ElementOrMember {

pkg/analyzer/test/src/dart/element/element_test.dart

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'package:analyzer/dart/constant/value.dart';
66
import 'package:analyzer/dart/element/element2.dart';
77
import 'package:analyzer/dart/element/type.dart';
8-
import 'package:analyzer/src/dart/element/element.dart';
98
import 'package:analyzer/src/dart/element/type.dart';
109
import 'package:analyzer/src/utilities/extensions/element.dart';
1110
import 'package:test/test.dart';
@@ -18,7 +17,6 @@ import '../resolution/context_collection_resolution.dart';
1817
main() {
1918
defineReflectiveSuite(() {
2019
defineReflectiveTests(ElementAnnotationImplTest);
21-
defineReflectiveTests(ElementLocationImplTest);
2220
defineReflectiveTests(FieldElementImplTest);
2321
defineReflectiveTests(FunctionTypeImplTest);
2422
defineReflectiveTests(MaybeAugmentedInstanceElementMixinTest);
@@ -52,70 +50,6 @@ main() {
5250
}
5351
}
5452

55-
@reflectiveTest
56-
class ElementLocationImplTest {
57-
void test_create_encoding() {
58-
String encoding = "a;b;c";
59-
ElementLocationImpl location = ElementLocationImpl.con2(encoding);
60-
expect(location.encoding, encoding);
61-
}
62-
63-
/// For example unnamed constructor.
64-
void test_create_encoding_emptyLast() {
65-
String encoding = "a;b;c;";
66-
ElementLocationImpl location = ElementLocationImpl.con2(encoding);
67-
expect(location.encoding, encoding);
68-
}
69-
70-
void test_equals_equal() {
71-
String encoding = "a;b;c";
72-
ElementLocationImpl first = ElementLocationImpl.con2(encoding);
73-
ElementLocationImpl second = ElementLocationImpl.con2(encoding);
74-
expect(first == second, isTrue);
75-
}
76-
77-
void test_equals_notEqual_differentLengths() {
78-
ElementLocationImpl first = ElementLocationImpl.con2("a;b;c");
79-
ElementLocationImpl second = ElementLocationImpl.con2("a;b;c;d");
80-
expect(first == second, isFalse);
81-
}
82-
83-
void test_equals_notEqual_notLocation() {
84-
ElementLocationImpl first = ElementLocationImpl.con2("a;b;c");
85-
// ignore: unrelated_type_equality_checks
86-
expect(first == "a;b;d", isFalse);
87-
}
88-
89-
void test_equals_notEqual_sameLengths() {
90-
ElementLocationImpl first = ElementLocationImpl.con2("a;b;c");
91-
ElementLocationImpl second = ElementLocationImpl.con2("a;b;d");
92-
expect(first == second, isFalse);
93-
}
94-
95-
void test_getComponents() {
96-
String encoding = "a;b;c";
97-
ElementLocationImpl location = ElementLocationImpl.con2(encoding);
98-
List<String> components = location.components;
99-
expect(components, hasLength(3));
100-
expect(components[0], "a");
101-
expect(components[1], "b");
102-
expect(components[2], "c");
103-
}
104-
105-
void test_getEncoding() {
106-
String encoding = "a;b;c;;d";
107-
ElementLocationImpl location = ElementLocationImpl.con2(encoding);
108-
expect(location.encoding, encoding);
109-
}
110-
111-
void test_hashCode_equal() {
112-
String encoding = "a;b;c";
113-
ElementLocationImpl first = ElementLocationImpl.con2(encoding);
114-
ElementLocationImpl second = ElementLocationImpl.con2(encoding);
115-
expect(first.hashCode == second.hashCode, isTrue);
116-
}
117-
}
118-
11953
@reflectiveTest
12054
class FieldElementImplTest extends PubPackageResolutionTest {
12155
test_isEnumConstant() async {

0 commit comments

Comments
 (0)