From a1f5ee9861c73486ab3f9bdc8090c0d0342d5397 Mon Sep 17 00:00:00 2001 From: pq Date: Tue, 7 Jan 2025 14:23:57 -0800 Subject: [PATCH] [element model] migrate `abstract_single_unit` Change-Id: I6d717985cb6d8ddafb0f7d8b9e1428f1c5f1fa21 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403484 Commit-Queue: Phil Quitslund Reviewed-by: Konstantin Shcheglov --- pkg/analysis_server/analyzer_use_new_elements.txt | 1 - pkg/analysis_server/test/abstract_single_unit.dart | 10 +++------- .../refactoring/legacy/extract_method_test.dart | 2 +- .../refactoring/legacy/rename_library_test.dart | 2 +- .../test/services/search/element_visitors_test.dart | 3 +++ 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/pkg/analysis_server/analyzer_use_new_elements.txt b/pkg/analysis_server/analyzer_use_new_elements.txt index 0402a8a429cd..13cef931a044 100644 --- a/pkg/analysis_server/analyzer_use_new_elements.txt +++ b/pkg/analysis_server/analyzer_use_new_elements.txt @@ -12,6 +12,5 @@ lib/src/services/refactoring/legacy/refactoring_manager.dart lib/src/services/refactoring/legacy/rename.dart lib/src/services/refactoring/legacy/rename_import.dart lib/src/services/search/element_visitors.dart -test/abstract_single_unit.dart test/services/refactoring/legacy/abstract_rename.dart test/services/search/element_visitors_test.dart diff --git a/pkg/analysis_server/test/abstract_single_unit.dart b/pkg/analysis_server/test/abstract_single_unit.dart index 7ded6ccf6c4c..360e23dbffef 100644 --- a/pkg/analysis_server/test/abstract_single_unit.dart +++ b/pkg/analysis_server/test/abstract_single_unit.dart @@ -4,7 +4,6 @@ import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/ast/ast.dart'; -import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/error/error.dart'; import 'package:analyzer/file_system/file_system.dart'; @@ -13,7 +12,6 @@ import 'package:analyzer/src/test_utilities/find_element.dart'; import 'package:analyzer/src/test_utilities/find_element2.dart'; import 'package:analyzer/src/test_utilities/find_node.dart'; import 'package:analyzer/src/utilities/extensions/analysis_session.dart'; -import 'package:analyzer/src/utilities/extensions/element.dart'; import 'package:test/test.dart'; import 'abstract_context.dart'; @@ -26,13 +24,11 @@ class AbstractSingleUnitTest extends AbstractContextTest { late ResolvedLibraryResult? testLibraryResult; late ResolvedUnitResult testAnalysisResult; late CompilationUnit testUnit; - late CompilationUnitElement testUnitElement; - late LibraryElement testLibraryElement; late FindNode findNode; late FindElement findElement; late FindElement2 findElement2; - LibraryElement2 get testLibraryElement2 => testLibraryElement.asElement2; + late LibraryElement2 testLibraryElement; void addTestSource(String code) { testCode = code; @@ -84,8 +80,8 @@ class AbstractSingleUnitTest extends AbstractContextTest { isEmpty, ); } - testUnitElement = testUnit.declaredElement!; - testLibraryElement = testUnitElement.library; + + testLibraryElement = testUnit.declaredFragment!.element; findNode = FindNode(testCode, testUnit); findElement = FindElement(testUnit); findElement2 = FindElement2(testUnit); diff --git a/pkg/analysis_server/test/services/refactoring/legacy/extract_method_test.dart b/pkg/analysis_server/test/services/refactoring/legacy/extract_method_test.dart index 95ee7323b85c..954122e87efc 100644 --- a/pkg/analysis_server/test/services/refactoring/legacy/extract_method_test.dart +++ b/pkg/analysis_server/test/services/refactoring/legacy/extract_method_test.dart @@ -332,7 +332,7 @@ import 'package:ddd/ddd.dart'; await addLibraryImports( testAnalysisResult.session, change, - testLibraryElement2, + testLibraryElement, newLibraries.toSet(), ); var testEdit = change.getFileEdit(testFile.path); diff --git a/pkg/analysis_server/test/services/refactoring/legacy/rename_library_test.dart b/pkg/analysis_server/test/services/refactoring/legacy/rename_library_test.dart index d8c440bbc7a0..76e80ff3439b 100644 --- a/pkg/analysis_server/test/services/refactoring/legacy/rename_library_test.dart +++ b/pkg/analysis_server/test/services/refactoring/legacy/rename_library_test.dart @@ -93,6 +93,6 @@ part of the.new.name; } void _createRenameRefactoring() { - createRenameRefactoringForElement2(testLibraryElement2); + createRenameRefactoringForElement2(testLibraryElement); } } diff --git a/pkg/analysis_server/test/services/search/element_visitors_test.dart b/pkg/analysis_server/test/services/search/element_visitors_test.dart index 372dac631ff6..c1a2a9814434 100644 --- a/pkg/analysis_server/test/services/search/element_visitors_test.dart +++ b/pkg/analysis_server/test/services/search/element_visitors_test.dart @@ -4,6 +4,7 @@ import 'package:analysis_server/src/services/search/element_visitors.dart'; import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/src/utilities/extensions/element.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; @@ -17,6 +18,8 @@ void main() { @reflectiveTest class FindElementByNameOffsetTest extends AbstractSingleUnitTest { + Element get testUnitElement => testLibraryElement.asElement; + Future test_class() async { await resolveTestCode(r''' class AAA {}