Skip to content

Commit 6494efb

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Use identical() to compare ElementImpl(s).
Change-Id: Idbe935bc6ae333d9940d8ea53ad44011eff237ab Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401384 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent da70ebe commit 6494efb

File tree

16 files changed

+86
-17
lines changed

16 files changed

+86
-17
lines changed

pkg/analysis_server/test/abstract_context.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ class AbstractContextTest
188188
return result as ResolvedUnitResult;
189189
}
190190

191+
void makeFilePriority(File file) {
192+
driverFor(file).priorityFiles2 = [file];
193+
}
194+
191195
@override
192196
File newFile(String path, String content) {
193197
if (_analysisContextCollection != null && !path.endsWith('.dart')) {

pkg/analysis_server/test/analysis_server_base.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ abstract class ContextResolutionTest with ResourceProviderMixin {
152152
);
153153
}
154154

155+
Future<void> setPriorityFiles2(List<File> files) async {
156+
await handleSuccessfulRequest(
157+
AnalysisSetPriorityFilesParams(
158+
files.map((e) => e.path).toList(),
159+
).toRequest('0', clientUriConverter: server.uriConverter),
160+
);
161+
}
162+
155163
Future<void> setRoots({
156164
required List<String> included,
157165
required List<String> excluded,

pkg/analysis_server/test/edit/refactoring_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ void f() {
12321232
}
12331233
''');
12341234
// Start refactoring.
1235+
await setPriorityFiles2([testFile]);
12351236
var result = await getRefactoringResult(() {
12361237
return _sendInlineRequest('res =');
12371238
});
@@ -1241,6 +1242,7 @@ void f() {
12411242
}
12421243

12431244
Future<void> test_feedback() {
1245+
setPriorityFiles([testFile]);
12441246
addTestFile('''
12451247
void f() {
12461248
int test = 42;
@@ -1272,6 +1274,7 @@ void f() {
12721274
}
12731275

12741276
Future<void> test_OK() {
1277+
setPriorityFiles([testFile]);
12751278
addTestFile('''
12761279
void f() {
12771280
int test = 42;
@@ -2547,6 +2550,7 @@ void f() {
25472550
}
25482551

25492552
Future<void> test_feedback() {
2553+
setPriorityFiles([testFile]);
25502554
addTestFile('''
25512555
class Test {}
25522556
void f() {
@@ -2770,6 +2774,7 @@ part of my.new_name;
27702774
}
27712775

27722776
Future<void> test_localVariable() {
2777+
setPriorityFiles([testFile]);
27732778
addTestFile('''
27742779
void f() {
27752780
int test = 0;
@@ -2881,6 +2886,7 @@ void f(Object? x) {
28812886
}
28822887

28832888
Future<void> test_patternVariable_patternAssignment() {
2889+
setPriorityFiles([testFile]);
28842890
addTestFile('''
28852891
void f(Object? x) {
28862892
int test;

pkg/analysis_server/test/lsp/code_actions_abstract.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ abstract class AbstractCodeActionsTest extends AbstractLspAnalysisServerTest {
183183
String? command,
184184
String? title,
185185
ProgressToken? commandWorkDoneToken,
186+
bool openTargetFile = false,
186187
}) async {
187188
filePath ??= mainFilePath;
188189

@@ -200,6 +201,7 @@ $expected''';
200201
kind: kind,
201202
command: command,
202203
title: title,
204+
openTargetFile: openTargetFile,
203205
);
204206

205207
// Verify the edits either by executing the command we expected, or

pkg/analysis_server/test/lsp/code_actions_refactor_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@ class NewWidget extends StatelessWidget {
882882
expectedContent,
883883
command: Commands.performRefactor,
884884
title: extractWidgetTitle,
885+
openTargetFile: true,
885886
);
886887
}
887888

@@ -927,6 +928,7 @@ void f() {
927928
expectedContent,
928929
command: Commands.performRefactor,
929930
title: inlineVariableTitle,
931+
openTargetFile: true,
930932
);
931933
}
932934
}

pkg/analysis_server/test/search/element_references_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@ void f(A a, B b, C c) {
882882
}
883883

884884
Future<void> test_label() async {
885+
await setPriorityFiles2([testFile]);
885886
addTestFile('''
886887
void f() {
887888
myLabel:
@@ -901,6 +902,7 @@ myLabel:
901902
}
902903

903904
Future<void> test_localVariable() async {
905+
await setPriorityFiles2([testFile]);
904906
addTestFile('''
905907
void f() {
906908
var vvv = 1;
@@ -1300,6 +1302,7 @@ void f(({int foo}) x, num ^a) {
13001302
}
13011303

13021304
Future<void> test_pattern_relational_variable() async {
1305+
await setPriorityFiles2([testFile]);
13031306
await assertReferences(
13041307
kind: ElementKind.LOCAL_VARIABLE,
13051308
resultKinds: {0: SearchResultKind.READ},
@@ -1562,6 +1565,7 @@ class A<T> {
15621565
}
15631566

15641567
Future<void> test_variable_forEachElement_block() async {
1568+
await setPriorityFiles2([testFile]);
15651569
addTestFile('''
15661570
void f(List<int> values) {
15671571
{
@@ -1575,6 +1579,7 @@ void f(List<int> values) {
15751579
}
15761580

15771581
Future<void> test_variable_forEachElement_expressionBody() async {
1582+
await setPriorityFiles2([testFile]);
15781583
addTestFile('''
15791584
Object f() => [for (final value in []) value * 2];
15801585
''');
@@ -1584,6 +1589,7 @@ Object f() => [for (final value in []) value * 2];
15841589
}
15851590

15861591
Future<void> test_variable_forEachElement_functionBody() async {
1592+
await setPriorityFiles2([testFile]);
15871593
addTestFile('''
15881594
void f(List<int> values) {
15891595
[for (final value in values) value * 2];
@@ -1595,6 +1601,7 @@ void f(List<int> values) {
15951601
}
15961602

15971603
Future<void> test_variable_forEachElement_topLevelVariable() async {
1604+
await setPriorityFiles2([testFile]);
15981605
addTestFile('''
15991606
final a = [for (final value in []) value * 2];
16001607
''');

pkg/analysis_server/test/services/refactoring/legacy/abstract_refactoring.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ abstract class RefactoringTest extends AbstractSingleUnitTest {
145145
}
146146

147147
Future<void> indexTestUnit(String code) async {
148+
// Make it priority, so the resolved unit stays in memory.
149+
// So, when we get a local element, and search for it, we use this unit.
150+
// This is important when local elements equality is identity.
151+
makeFilePriority(testFile);
152+
148153
await resolveTestCode(code);
149154
}
150155

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3074,12 +3074,7 @@ abstract class ElementImpl implements Element, Element2 {
30743074

30753075
@override
30763076
bool operator ==(Object other) {
3077-
if (identical(this, other)) {
3078-
return true;
3079-
}
3080-
return other is ElementImpl &&
3081-
other.kind == kind &&
3082-
other.location == location;
3077+
return identical(this, other);
30833078
}
30843079

30853080
@override

pkg/analyzer/test/src/dart/analysis/search_test.dart

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,7 @@ main() {
14871487
}
14881488

14891489
test_searchReferences_FunctionElement_local() async {
1490+
makeFilePriority(testFile);
14901491
await resolveTestCode('''
14911492
main() {
14921493
test() {}
@@ -1602,6 +1603,7 @@ main() {
16021603
}
16031604

16041605
test_searchReferences_LabelElement() async {
1606+
makeFilePriority(testFile);
16051607
await resolveTestCode('''
16061608
main() {
16071609
label:
@@ -1693,6 +1695,7 @@ part 'unitB.dart';
16931695
}
16941696

16951697
test_searchReferences_LocalVariableElement() async {
1698+
makeFilePriority(testFile);
16961699
await resolveTestCode(r'''
16971700
main() {
16981701
var v;
@@ -1713,6 +1716,7 @@ main() {
17131716
}
17141717

17151718
test_searchReferences_LocalVariableElement_inForEachElement_expressionBody() async {
1719+
makeFilePriority(testFile);
17161720
await resolveTestCode('''
17171721
Object f() => [
17181722
for (var v in []) v,
@@ -1726,6 +1730,7 @@ Object f() => [
17261730
}
17271731

17281732
test_searchReferences_LocalVariableElement_inForEachElement_inBlock() async {
1733+
makeFilePriority(testFile);
17291734
await resolveTestCode('''
17301735
Object f() {
17311736
{
@@ -1743,6 +1748,7 @@ Object f() {
17431748
}
17441749

17451750
test_searchReferences_LocalVariableElement_inForEachElement_inFunctionBody() async {
1751+
makeFilePriority(testFile);
17461752
await resolveTestCode('''
17471753
Object f() {
17481754
return [
@@ -1758,6 +1764,7 @@ Object f() {
17581764
}
17591765

17601766
test_searchReferences_LocalVariableElement_inForEachElement_topLevel() async {
1767+
makeFilePriority(testFile);
17611768
await resolveTestCode('''
17621769
var x = [
17631770
for (var v in []) v,
@@ -1771,6 +1778,7 @@ var x = [
17711778
}
17721779

17731780
test_searchReferences_LocalVariableElement_inForEachLoop() async {
1781+
makeFilePriority(testFile);
17741782
await resolveTestCode('''
17751783
main() {
17761784
for (var v in []) {
@@ -1793,16 +1801,7 @@ main() {
17931801

17941802
test_searchReferences_LocalVariableElement_inPackage() async {
17951803
var aaaPackageRootPath = '$packagesRootPath/aaa';
1796-
var testPath = convertPath('$aaaPackageRootPath/lib/a.dart');
1797-
1798-
writeTestPackageConfig(
1799-
PackageConfigFileBuilder()
1800-
..add(name: 'aaa', rootPath: aaaPackageRootPath),
1801-
);
1802-
1803-
fileForContextSelection = testFile;
1804-
1805-
await resolveFileCode(testPath, '''
1804+
var a_file = newFile('$aaaPackageRootPath/lib/a.dart', '''
18061805
main() {
18071806
var v;
18081807
v = 1;
@@ -1811,6 +1810,17 @@ main() {
18111810
v();
18121811
}
18131812
''');
1813+
1814+
writeTestPackageConfig(
1815+
PackageConfigFileBuilder()
1816+
..add(name: 'aaa', rootPath: aaaPackageRootPath),
1817+
);
1818+
1819+
fileForContextSelection = testFile;
1820+
1821+
driverFor(testFile).priorityFiles2 = [a_file];
1822+
await resolveFile2(a_file);
1823+
18141824
var element = findElement2.localVar('v');
18151825
await assertElementReferencesText(element, r'''
18161826
package:aaa/a.dart::<fragment>::@function::main
@@ -2191,6 +2201,7 @@ main() {
21912201
}
21922202

21932203
test_searchReferences_ParameterElement_requiredPositional_ofLocalFunction() async {
2204+
makeFilePriority(testFile);
21942205
await resolveTestCode('''
21952206
main() {
21962207
foo(p) {
@@ -2753,6 +2764,7 @@ void f(Object? x) {
27532764
}
27542765

27552766
test_searchReferences_VariablePatternElement_patternAssignment() async {
2767+
makeFilePriority(testFile);
27562768
await resolveTestCode('''
27572769
void f() {
27582770
int v;

pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ abstract class ContextResolutionTest
310310
return libraryResult.element2;
311311
}
312312

313+
void makeFilePriority(File file) {
314+
driverFor(file).priorityFiles2 = [file];
315+
}
316+
313317
@override
314318
File newFile(String path, String content) {
315319
if (_analysisContextCollection != null && !path.endsWith('.dart')) {

0 commit comments

Comments
 (0)