Skip to content

Commit 2c960d5

Browse files
bwilkersonCommit Queue
authored andcommitted
Add access to FindElement2 in the test framework
Change-Id: I8a0def9df469a8e629e67e5c8cbd343bd076f74e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390925 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 505e236 commit 2c960d5

File tree

7 files changed

+28
-2
lines changed

7 files changed

+28
-2
lines changed

pkg/analysis_server/test/abstract_single_unit.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:analyzer/error/error.dart';
99
import 'package:analyzer/file_system/file_system.dart';
1010
import 'package:analyzer/src/error/codes.g.dart';
1111
import 'package:analyzer/src/test_utilities/find_element.dart';
12+
import 'package:analyzer/src/test_utilities/find_element_2.dart';
1213
import 'package:analyzer/src/test_utilities/find_node.dart';
1314
import 'package:test/test.dart';
1415

@@ -25,6 +26,7 @@ class AbstractSingleUnitTest extends AbstractContextTest {
2526
late LibraryElement testLibraryElement;
2627
late FindNode findNode;
2728
late FindElement findElement;
29+
late FindElement2 findElement2;
2830

2931
void addTestSource(String code) {
3032
testCode = code;
@@ -49,6 +51,7 @@ class AbstractSingleUnitTest extends AbstractContextTest {
4951
testUnit = result.unit;
5052
findNode = FindNode(testCode, testUnit);
5153
findElement = FindElement(testUnit);
54+
findElement2 = FindElement2(testUnit);
5255
return result;
5356
}
5457

@@ -73,6 +76,7 @@ class AbstractSingleUnitTest extends AbstractContextTest {
7376
testLibraryElement = testUnitElement.library;
7477
findNode = FindNode(testCode, testUnit);
7578
findElement = FindElement(testUnit);
79+
findElement2 = FindElement2(testUnit);
7680
return result;
7781
}
7882

pkg/analysis_server/test/services/search/search_engine_test.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:analyzer/dart/analysis/results.dart';
88
import 'package:analyzer/dart/element/element.dart';
99
import 'package:analyzer/file_system/file_system.dart';
1010
import 'package:analyzer/src/test_utilities/find_element.dart';
11+
import 'package:analyzer/src/test_utilities/find_element_2.dart';
1112
import 'package:analyzer/src/test_utilities/find_node.dart';
1213
import 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
1314
import 'package:analyzer/src/util/file_paths.dart';
@@ -30,6 +31,7 @@ class PubPackageResolutionTest extends AbstractContextTest {
3031
late ResolvedUnitResult result;
3132
late FindNode findNode;
3233
late FindElement findElement;
34+
late FindElement2 findElement2;
3335

3436
void addTestFile(String content) {
3537
newFile(testFile.path, content);
@@ -41,6 +43,7 @@ class PubPackageResolutionTest extends AbstractContextTest {
4143

4244
findNode = FindNode(result.content, result.unit);
4345
findElement = FindElement(result.unit);
46+
findElement2 = FindElement2(result.unit);
4447
}
4548

4649
/// Put the [code] into the test file, and resolve it.
@@ -580,7 +583,7 @@ class B extends A {
580583
Future<void> test_searchReferences_parameter_topLevelShadow_wildcard() async {
581584
var code = '''
582585
int _ = 0;
583-
int f(int _) => _;
586+
int f(int _) => _;
584587
''';
585588
await resolveTestCode(code);
586589

@@ -606,7 +609,7 @@ int f(int _) => _;
606609

607610
Future<void> test_searchReferences_parameter_wildcard() async {
608611
var code = '''
609-
f(int _) {}
612+
f(int _) {}
610613
''';
611614
await resolveTestCode(code);
612615

pkg/analyzer/test/src/dart/micro/file_resolution.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:analyzer/src/dart/analysis/unlinked_unit_store.dart';
1414
import 'package:analyzer/src/dart/micro/resolve_file.dart';
1515
import 'package:analyzer/src/dart/sdk/sdk.dart';
1616
import 'package:analyzer/src/test_utilities/find_element.dart';
17+
import 'package:analyzer/src/test_utilities/find_element_2.dart';
1718
import 'package:analyzer/src/test_utilities/find_node.dart';
1819
import 'package:analyzer/src/test_utilities/mock_sdk.dart';
1920
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
@@ -137,6 +138,7 @@ class FileResolutionTest with ResourceProviderMixin, ResolutionTest {
137138
result = await resolveFile(testFile);
138139
findNode = FindNode(result.content, result.unit);
139140
findElement = FindElement(result.unit);
141+
findElement2 = FindElement2(result.unit);
140142
}
141143

142144
void setUp() {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import 'package:analyzer/src/dart/element/type_algebra.dart';
1919
import 'package:analyzer/src/dart/element/type_system.dart';
2020
import 'package:analyzer/src/generated/engine.dart';
2121
import 'package:analyzer/src/test_utilities/find_element.dart';
22+
import 'package:analyzer/src/test_utilities/find_element_2.dart';
2223
import 'package:analyzer/src/test_utilities/find_node.dart';
2324
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
2425
import 'package:analyzer_utilities/testing/tree_string_sink.dart';
@@ -46,6 +47,7 @@ mixin ResolutionTest implements ResourceProviderMixin {
4647
late ResolvedUnitResult result;
4748
late FindNode findNode;
4849
late FindElement findElement;
50+
late FindElement2 findElement2;
4951

5052
final DartObjectPrinterConfiguration dartObjectPrinterConfiguration =
5153
DartObjectPrinterConfiguration();
@@ -474,6 +476,7 @@ mixin ResolutionTest implements ResourceProviderMixin {
474476

475477
findNode = FindNode(result.content, result.unit);
476478
findElement = FindElement(result.unit);
479+
findElement2 = FindElement2(result.unit);
477480
}
478481

479482
/// Create a new file with the [path] and [content], resolve it into [result].
@@ -587,6 +590,10 @@ extension ResolvedUnitResultExtension on ResolvedUnitResult {
587590
return FindElement(unit);
588591
}
589592

593+
FindElement2 get findElement2 {
594+
return FindElement2(unit);
595+
}
596+
590597
FindNode get findNode {
591598
return FindNode(content, unit);
592599
}

pkg/analyzer_plugin/test/src/utilities/completion/completion_target_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/element/element.dart';
77
import 'package:analyzer/src/test_utilities/find_element.dart';
8+
import 'package:analyzer/src/test_utilities/find_element_2.dart';
89
import 'package:analyzer_plugin/src/utilities/completion/completion_target.dart';
910
import 'package:test/test.dart';
1011
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -888,6 +889,7 @@ class _Base extends AbstractContextTest {
888889
int? offset;
889890
late CompletionTarget target;
890891
late FindElement findElement;
892+
late FindElement2 findElement2;
891893

892894
void assertTarget(
893895
String entityText,
@@ -955,6 +957,7 @@ class _Base extends AbstractContextTest {
955957

956958
var result = await resolveFile(path);
957959
findElement = FindElement(result.unit);
960+
findElement2 = FindElement2(result.unit);
958961

959962
target = CompletionTarget.forOffset(result.unit, offset!);
960963
}

pkg/analyzer_plugin/test/support/abstract_single_unit.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:analyzer/src/dart/ast/element_locator.dart';
1010
import 'package:analyzer/src/dart/ast/utilities.dart';
1111
import 'package:analyzer/src/error/codes.dart';
1212
import 'package:analyzer/src/test_utilities/find_element.dart';
13+
import 'package:analyzer/src/test_utilities/find_element_2.dart';
1314
import 'package:analyzer/src/test_utilities/find_node.dart';
1415
import 'package:test/test.dart';
1516

@@ -24,6 +25,7 @@ class AbstractSingleUnitTest extends AbstractContextTest {
2425
late CompilationUnit testUnit;
2526
late FindNode findNode;
2627
late FindElement findElement;
28+
late FindElement2 findElement2;
2729

2830
void addTestSource(String code) {
2931
testCode = code;
@@ -119,6 +121,7 @@ class AbstractSingleUnitTest extends AbstractContextTest {
119121
}
120122
findNode = FindNode(testCode, testUnit);
121123
findElement = FindElement(testUnit);
124+
findElement2 = FindElement2(testUnit);
122125
}
123126

124127
@override

pkg/linter/test/rule_test_support.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import 'package:analyzer/src/lint/pub.dart';
1717
import 'package:analyzer/src/lint/registry.dart';
1818
import 'package:analyzer/src/lint/util.dart';
1919
import 'package:analyzer/src/test_utilities/find_element.dart';
20+
import 'package:analyzer/src/test_utilities/find_element_2.dart';
2021
import 'package:analyzer/src/test_utilities/find_node.dart';
2122
import 'package:analyzer/src/test_utilities/mock_sdk.dart';
2223
import 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
@@ -510,6 +511,8 @@ abstract class _ContextResolutionTest
510511

511512
late FindElement findElement;
512513

514+
late FindElement2 findElement2;
515+
513516
late FindNode findNode;
514517

515518
late ResolvedUnitResult result;
@@ -555,6 +558,7 @@ abstract class _ContextResolutionTest
555558
var result = await session.getResolvedUnit(path) as ResolvedUnitResult;
556559

557560
findElement = FindElement(result.unit);
561+
findElement2 = FindElement2(result.unit);
558562
findNode = FindNode(result.content, result.unit);
559563
return result;
560564
}

0 commit comments

Comments
 (0)