From 34d945cb7c9335f959b38ff5082a7f4904768067 Mon Sep 17 00:00:00 2001 From: Brian Wilkerson Date: Fri, 15 Nov 2024 21:57:47 +0000 Subject: [PATCH] Migrate more server tests Change-Id: Iee3e6b6db9c58e9fcf790e2874f73c8eac6e660d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395404 Reviewed-by: Konstantin Shcheglov Commit-Queue: Brian Wilkerson --- .../analyzer_use_new_elements.txt | 4 -- .../edit_get_available_refactorings.dart | 3 +- .../src/lsp/handlers/code_actions/dart.dart | 9 ++-- .../handlers/commands/abstract_refactor.dart | 43 +++++++++---------- .../refactoring/legacy/extract_method.dart | 11 +++-- .../refactoring/legacy/refactoring.dart | 16 +++++-- .../legacy/refactoring_manager.dart | 35 +++++++-------- .../test/abstract_single_unit.dart | 5 +++ .../test/lsp/code_actions_abstract.dart | 11 ++++- .../correction/name_suggestion_test.dart | 8 ++-- .../legacy/convert_getter_to_method_test.dart | 20 ++++----- .../legacy/convert_method_to_getter_test.dart | 26 +++++------ .../legacy/extract_method_test.dart | 4 +- .../lib/src/utilities/extensions/element.dart | 5 +++ 14 files changed, 112 insertions(+), 88 deletions(-) diff --git a/pkg/analysis_server/analyzer_use_new_elements.txt b/pkg/analysis_server/analyzer_use_new_elements.txt index 7bf3769c45ac..5f4c060501a3 100644 --- a/pkg/analysis_server/analyzer_use_new_elements.txt +++ b/pkg/analysis_server/analyzer_use_new_elements.txt @@ -93,12 +93,8 @@ lib/src/utilities/extensions/completion_request.dart lib/src/utilities/extensions/element.dart test/abstract_single_unit.dart test/plugin/protocol_dart_test.dart -test/services/correction/name_suggestion_test.dart test/services/correction/status_test.dart test/services/refactoring/legacy/abstract_rename.dart -test/services/refactoring/legacy/convert_getter_to_method_test.dart -test/services/refactoring/legacy/convert_method_to_getter_test.dart -test/services/refactoring/legacy/extract_method_test.dart test/services/refactoring/legacy/rename_class_member_test.dart test/services/refactoring/legacy/rename_constructor_test.dart test/services/refactoring/legacy/rename_import_test.dart diff --git a/pkg/analysis_server/lib/src/handler/legacy/edit_get_available_refactorings.dart b/pkg/analysis_server/lib/src/handler/legacy/edit_get_available_refactorings.dart index 2d70facc2cc8..3a782aa0a100 100644 --- a/pkg/analysis_server/lib/src/handler/legacy/edit_get_available_refactorings.dart +++ b/pkg/analysis_server/lib/src/handler/legacy/edit_get_available_refactorings.dart @@ -10,6 +10,7 @@ import 'package:analysis_server/src/services/refactoring/legacy/refactoring.dart import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/src/dart/ast/utilities.dart'; import 'package:analyzer/src/util/file_paths.dart'; +import 'package:analyzer/src/utilities/extensions/element.dart'; import 'package:analyzer_plugin/protocol/protocol_common.dart'; /// The handler for the `edit.getAvailableRefactorings` request. @@ -88,7 +89,7 @@ class EditGetAvailableRefactoringsHandler extends LegacyHandler { if (ConvertMethodToGetterRefactoring( refactoringWorkspace, resolvedUnit.session, - element, + element.asElement2, ).isAvailable()) { kinds.add(RefactoringKind.CONVERT_METHOD_TO_GETTER); } diff --git a/pkg/analysis_server/lib/src/lsp/handlers/code_actions/dart.dart b/pkg/analysis_server/lib/src/lsp/handlers/code_actions/dart.dart index 5c7ce3d04d26..3ed20f977570 100644 --- a/pkg/analysis_server/lib/src/lsp/handlers/code_actions/dart.dart +++ b/pkg/analysis_server/lib/src/lsp/handlers/code_actions/dart.dart @@ -21,8 +21,9 @@ import 'package:analysis_server_plugin/src/correction/fix_processor.dart'; import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/analysis/session.dart' show InconsistentAnalysisException; -import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/src/dart/ast/utilities.dart'; +import 'package:analyzer/src/utilities/extensions/element.dart'; /// Produces [CodeAction]s from Dart source commands, fixes, assists and /// refactors from the server. @@ -320,10 +321,10 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer { // Converts/Rewrites if (shouldIncludeKind(CodeActionKind.RefactorRewrite)) { var node = NodeLocator(offset).searchWithin(unit.unit); - var element = server.getElementOfNode(node); + var element = server.getElementOfNode(node).asElement2; // Getter to Method - if (element is PropertyAccessorElement && + if (element is GetterElement && ConvertGetterToMethodRefactoring( server.refactoringWorkspace, unit.session, @@ -339,7 +340,7 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer { } // Method to Getter - if (element is ExecutableElement && + if (element is ExecutableElement2 && ConvertMethodToGetterRefactoring( server.refactoringWorkspace, unit.session, diff --git a/pkg/analysis_server/lib/src/lsp/handlers/commands/abstract_refactor.dart b/pkg/analysis_server/lib/src/lsp/handlers/commands/abstract_refactor.dart index 34ec52bdb6cb..1f88d33bbf96 100644 --- a/pkg/analysis_server/lib/src/lsp/handlers/commands/abstract_refactor.dart +++ b/pkg/analysis_server/lib/src/lsp/handlers/commands/abstract_refactor.dart @@ -14,8 +14,9 @@ import 'package:analysis_server/src/lsp/progress.dart'; import 'package:analysis_server/src/protocol_server.dart'; import 'package:analysis_server/src/services/refactoring/legacy/refactoring.dart'; import 'package:analyzer/dart/analysis/results.dart'; -import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/src/dart/ast/utilities.dart'; +import 'package:analyzer/src/utilities/extensions/element.dart'; final _manager = LspRefactorManager._(); @@ -126,38 +127,34 @@ abstract class AbstractRefactorCommandHandler extends SimpleEditCommandHandler case RefactoringKind.CONVERT_GETTER_TO_METHOD: var node = NodeLocator(offset).searchWithin(result.unit); - var element = server.getElementOfNode(node); - if (element != null) { - if (element is PropertyAccessorElement) { - var refactor = ConvertGetterToMethodRefactoring( - server.refactoringWorkspace, - result.session, - element, - ); - return success(refactor); - } + var element = server.getElementOfNode(node).asElement2; + if (element is GetterElement) { + var refactor = ConvertGetterToMethodRefactoring( + server.refactoringWorkspace, + result.session, + element, + ); + return success(refactor); } return error( ServerErrorCodes.InvalidCommandArguments, - 'Location supplied to $commandName $kind is not longer valid', + 'Location supplied to $commandName $kind is no longer valid', ); case RefactoringKind.CONVERT_METHOD_TO_GETTER: var node = NodeLocator(offset).searchWithin(result.unit); - var element = server.getElementOfNode(node); - if (element != null) { - if (element is ExecutableElement) { - var refactor = ConvertMethodToGetterRefactoring( - server.refactoringWorkspace, - result.session, - element, - ); - return success(refactor); - } + var element = server.getElementOfNode(node).asElement2; + if (element is ExecutableElement2) { + var refactor = ConvertMethodToGetterRefactoring( + server.refactoringWorkspace, + result.session, + element, + ); + return success(refactor); } return error( ServerErrorCodes.InvalidCommandArguments, - 'Location supplied to $commandName $kind is not longer valid', + 'Location supplied to $commandName $kind is no longer valid', ); default: diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart index 8bfc4c0163aa..1b5ca5cebea9 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart @@ -23,6 +23,7 @@ import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/ast/token.dart'; import 'package:analyzer/dart/ast/visitor.dart'; import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/element2.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/dart/element/type_system.dart'; @@ -35,6 +36,7 @@ import 'package:analyzer/src/dart/ast/utilities.dart'; import 'package:analyzer/src/dart/resolver/exit_detector.dart'; import 'package:analyzer/src/generated/java_core.dart'; import 'package:analyzer/src/utilities/extensions/ast.dart'; +import 'package:analyzer/src/utilities/extensions/element.dart'; import 'package:analyzer/src/utilities/extensions/string.dart'; import 'package:analyzer_plugin/utilities/range_factory.dart'; import 'package:meta/meta.dart'; @@ -47,16 +49,19 @@ const String _tokenSeparator = '\uFFFF'; Future addLibraryImports( AnalysisSession session, SourceChange change, - LibraryElement targetLibrary, + LibraryElement2 targetLibrary2, Set libraries, ) async { - var libraryPath = targetLibrary.source.fullName; + var libraryPath = targetLibrary2.firstFragment.source.fullName; var resolveResult = await session.getResolvedUnit(libraryPath); if (resolveResult is! ResolvedUnitResult) { return; } + // TODO(brianwilkerson): Use `targetLibrary2` everywhere below and rename it + // to `targetLibrary`. + var targetLibrary = targetLibrary2.asElement as LibraryElement; var libUtils = CorrectionUtils(resolveResult); var eol = libUtils.endOfLine; // Prepare information about existing imports. @@ -582,7 +587,7 @@ final class ExtractMethodRefactoringImpl extends RefactoringImpl await addLibraryImports( _resolveResult.session, change, - _resolveResult.libraryElement, + _resolveResult.libraryElement2, _librariesToImport, ); return change; diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart index b628451bb24e..6996ddf46b2d 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart @@ -44,9 +44,13 @@ abstract class ConvertGetterToMethodRefactoring implements Refactoring { factory ConvertGetterToMethodRefactoring( RefactoringWorkspace workspace, AnalysisSession session, - PropertyAccessorElement element, + GetterElement element, ) { - return ConvertGetterToMethodRefactoringImpl(workspace, session, element); + return ConvertGetterToMethodRefactoringImpl( + workspace, + session, + element.asElement as PropertyAccessorElement, + ); } /// Return `true` if refactoring is available, possibly without checking all @@ -67,9 +71,13 @@ abstract class ConvertMethodToGetterRefactoring implements Refactoring { factory ConvertMethodToGetterRefactoring( RefactoringWorkspace workspace, AnalysisSession session, - ExecutableElement element, + ExecutableElement2 element, ) { - return ConvertMethodToGetterRefactoringImpl(workspace, session, element); + return ConvertMethodToGetterRefactoringImpl( + workspace, + session, + element.asElement, + ); } /// Return `true` if refactoring is available, possibly without checking all diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring_manager.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring_manager.dart index 28b68c151c21..1bdaffdbb920 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring_manager.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring_manager.dart @@ -13,9 +13,10 @@ import 'package:analysis_server/src/services/refactoring/legacy/refactoring.dart import 'package:analysis_server/src/services/search/search_engine.dart'; import 'package:analyzer/dart/analysis/session.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/src/dart/ast/utilities.dart'; import 'package:analyzer/src/utilities/cancellation.dart'; +import 'package:analyzer/src/utilities/extensions/element.dart'; int test_resetCount = 0; @@ -219,30 +220,26 @@ class RefactoringManager { var resolvedUnit = await server.getResolvedUnit(file); if (resolvedUnit != null) { var node = NodeLocator(offset).searchWithin(resolvedUnit.unit); - var element = server.getElementOfNode(node); - if (element != null) { - if (element is PropertyAccessorElement) { - refactoring = ConvertGetterToMethodRefactoring( - refactoringWorkspace, - resolvedUnit.session, - element, - ); - } + var element = server.getElementOfNode(node).asElement2; + if (element is GetterElement) { + refactoring = ConvertGetterToMethodRefactoring( + refactoringWorkspace, + resolvedUnit.session, + element, + ); } } } else if (kind == RefactoringKind.CONVERT_METHOD_TO_GETTER) { var resolvedUnit = await server.getResolvedUnit(file); if (resolvedUnit != null) { var node = NodeLocator(offset).searchWithin(resolvedUnit.unit); - var element = server.getElementOfNode(node); - if (element != null) { - if (element is ExecutableElement) { - refactoring = ConvertMethodToGetterRefactoring( - refactoringWorkspace, - resolvedUnit.session, - element, - ); - } + var element = server.getElementOfNode(node).asElement2; + if (element is ExecutableElement2) { + refactoring = ConvertMethodToGetterRefactoring( + refactoringWorkspace, + resolvedUnit.session, + element, + ); } } } else if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { diff --git a/pkg/analysis_server/test/abstract_single_unit.dart b/pkg/analysis_server/test/abstract_single_unit.dart index 9c6ec3be21a4..7299977228e8 100644 --- a/pkg/analysis_server/test/abstract_single_unit.dart +++ b/pkg/analysis_server/test/abstract_single_unit.dart @@ -5,12 +5,14 @@ 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'; import 'package:analyzer/src/error/codes.g.dart'; 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/element.dart'; import 'package:test/test.dart'; import 'abstract_context.dart'; @@ -28,6 +30,9 @@ class AbstractSingleUnitTest extends AbstractContextTest { late FindElement findElement; late FindElement2 findElement2; + LibraryElement2 get testLibraryElement2 => + testLibraryElement.asElement2 as LibraryElement2; + void addTestSource(String code) { testCode = code; newFile(testFile.path, code); diff --git a/pkg/analysis_server/test/lsp/code_actions_abstract.dart b/pkg/analysis_server/test/lsp/code_actions_abstract.dart index a213007696e6..2755f8695f69 100644 --- a/pkg/analysis_server/test/lsp/code_actions_abstract.dart +++ b/pkg/analysis_server/test/lsp/code_actions_abstract.dart @@ -42,7 +42,16 @@ abstract class AbstractCodeActionsTest extends AbstractLspAnalysisServerTest { triggerKind: triggerKind, ); - return findAction(codeActions, kind: kind, command: command, title: title)!; + var action = findAction( + codeActions, + kind: kind, + command: command, + title: title, + ); + if (action == null) { + fail('Failed to find a code action titled "$title".'); + } + return action; } /// Expects that command [commandName] was logged to the analytics manager. diff --git a/pkg/analysis_server/test/services/correction/name_suggestion_test.dart b/pkg/analysis_server/test/services/correction/name_suggestion_test.dart index 67a32693ef72..15a7fddb0e3e 100644 --- a/pkg/analysis_server/test/services/correction/name_suggestion_test.dart +++ b/pkg/analysis_server/test/services/correction/name_suggestion_test.dart @@ -38,7 +38,7 @@ void f() { } '''); var excluded = {}; - var expectedType = findElement.localVar('node').type; + var expectedType = findElement2.localVar('node').type; var assignedExpression = findNode.nullLiteral('null;'); var suggestions = getVariableNameSuggestionsForExpression( expectedType, @@ -54,7 +54,7 @@ void f() { double res = 0.0; } '''); - var expectedType = findElement.localVar('res').type; + var expectedType = findElement2.localVar('res').type; var assignedExpression = findNode.doubleLiteral('0.0;'); // first choice for "double" is "d" expect( @@ -82,7 +82,7 @@ void f() { int res = 0; } '''); - var expectedType = findElement.localVar('res').type; + var expectedType = findElement2.localVar('res').type; var assignedExpression = findNode.integerLiteral('0;'); // first choice for "int" is "i" expect( @@ -110,7 +110,7 @@ void f() { String res = 'abc'; } '''); - var expectedType = findElement.localVar('res').type; + var expectedType = findElement2.localVar('res').type; var assignedExpression = findNode.stringLiteral("'abc';"); // first choice for "String" is "s" expect( diff --git a/pkg/analysis_server/test/services/refactoring/legacy/convert_getter_to_method_test.dart b/pkg/analysis_server/test/services/refactoring/legacy/convert_getter_to_method_test.dart index 74cc81c948d0..5671b5fffadb 100644 --- a/pkg/analysis_server/test/services/refactoring/legacy/convert_getter_to_method_test.dart +++ b/pkg/analysis_server/test/services/refactoring/legacy/convert_getter_to_method_test.dart @@ -3,8 +3,8 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analysis_server/src/services/refactoring/legacy/refactoring.dart'; -import 'package:analyzer/dart/element/element.dart'; -import 'package:analyzer/src/test_utilities/find_element.dart'; +import 'package:analyzer/dart/element/element2.dart'; +import 'package:analyzer/src/test_utilities/find_element2.dart'; import 'package:analyzer_plugin/protocol/protocol_common.dart' hide ElementKind; import 'package:analyzer_plugin/protocol/protocol_common.dart'; import 'package:matcher/expect.dart'; @@ -32,7 +32,7 @@ void f(String a) { var va = a.test; } '''); - var element = findElement.getter('test', of: 'A'); + var element = findElement2.getter('test', of: 'A'); _createRefactoringForElement(element); // apply refactoring return _assertSuccessfulRefactoring(''' @@ -53,7 +53,7 @@ void f() { var b = test; } '''); - var element = findElement.topGet('test'); + var element = findElement2.topGet('test'); _createRefactoringForElement(element); // apply refactoring return _assertSuccessfulRefactoring(''' @@ -86,7 +86,7 @@ void f(A a, B b, C c, D d) { var vd = d.test; } '''); - var element = findElement.getter('test', of: 'B'); + var element = findElement2.getter('test', of: 'B'); _createRefactoringForElement(element); // apply refactoring return _assertSuccessfulRefactoring(''' @@ -123,7 +123,7 @@ class A { } '''); - var element = findElement.getter('x', of: 'A'); + var element = findElement2.getter('x', of: 'A'); _createRefactoringForElement(element); await assertRefactoringConditionsOK(); var refactoringChange = await refactoring.createChange(); @@ -151,7 +151,7 @@ void f(A a, B b) { b.test; } '''); - var element = findElement.getter('test', of: 'B'); + var element = findElement2.getter('test', of: 'B'); _createRefactoringForElement(element); // apply refactoring return _assertSuccessfulRefactoring(''' @@ -175,7 +175,7 @@ String get foo => ''; await indexTestUnit(''); // Initialize project. - var element = FindElement(externalUnit.unit).topVar('foo').getter!; + var element = FindElement2(externalUnit.unit).topVar('foo').getter2!; _createRefactoringForElement(element); // check conditions @@ -190,7 +190,7 @@ int test = 42; void f() { } '''); - var element = findElement.topGet('test'); + var element = findElement2.topGet('test'); _createRefactoringForElement(element); // check conditions await _assertInitialConditions_fatal( @@ -216,7 +216,7 @@ void f() { assertTestChangeResult(expectedCode); } - void _createRefactoringForElement(PropertyAccessorElement element) { + void _createRefactoringForElement(GetterElement element) { refactoring = ConvertGetterToMethodRefactoring( refactoringWorkspace, testAnalysisResult.session, diff --git a/pkg/analysis_server/test/services/refactoring/legacy/convert_method_to_getter_test.dart b/pkg/analysis_server/test/services/refactoring/legacy/convert_method_to_getter_test.dart index dfe13b5d23c2..82b9c8b62d2c 100644 --- a/pkg/analysis_server/test/services/refactoring/legacy/convert_method_to_getter_test.dart +++ b/pkg/analysis_server/test/services/refactoring/legacy/convert_method_to_getter_test.dart @@ -3,8 +3,8 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analysis_server/src/services/refactoring/legacy/refactoring.dart'; -import 'package:analyzer/dart/element/element.dart'; -import 'package:analyzer/src/test_utilities/find_element.dart'; +import 'package:analyzer/dart/element/element2.dart'; +import 'package:analyzer/src/test_utilities/find_element2.dart'; import 'package:analyzer_plugin/protocol/protocol_common.dart' show RefactoringProblemSeverity; import 'package:matcher/expect.dart'; @@ -31,7 +31,7 @@ void f() { var b = test(); } '''); - var element = findElement.topFunction('test'); + var element = findElement2.topFunction('test'); _createRefactoringForElement(element); // apply refactoring return _assertSuccessfulRefactoring(''' @@ -64,7 +64,7 @@ void f(A a, B b, C c, D d) { var vd = d.test(); } '''); - var element = findElement.method('test', of: 'B'); + var element = findElement2.method('test', of: 'B'); _createRefactoringForElement(element); // apply refactoring return _assertSuccessfulRefactoring(''' @@ -101,7 +101,7 @@ class A { } '''); - var element = findElement.method('x', of: 'A'); + var element = findElement2.method('x', of: 'A'); _createRefactoringForElement(element); await assertRefactoringConditionsOK(); var refactoringChange = await refactoring.createChange(); @@ -129,7 +129,7 @@ void f(A a, B b) { b.test(); } '''); - var element = findElement.method('test', of: 'B'); + var element = findElement2.method('test', of: 'B'); _createRefactoringForElement(element); // apply refactoring return _assertSuccessfulRefactoring(''' @@ -152,7 +152,7 @@ void f() { var b = test; } '''); - var element = findElement.topGet('test'); + var element = findElement2.topGet('test'); _createRefactoringForElement(element); // check conditions await _assertInitialConditions_fatal( @@ -167,7 +167,7 @@ void f() { var v = test(1); } '''); - var element = findElement.topFunction('test'); + var element = findElement2.topFunction('test'); _createRefactoringForElement(element); // check conditions await _assertInitialConditions_fatal( @@ -182,7 +182,7 @@ void f() { var v = test(); } '''); - var element = findElement.localFunction('test'); + var element = findElement2.localFunction('test'); _createRefactoringForElement(element); // check conditions await _assertInitialConditions_fatal( @@ -196,7 +196,7 @@ class A { A.test(); } '''); - var element = findElement.constructor('test'); + var element = findElement2.constructor('test'); _createRefactoringForElement(element); // check conditions await _assertInitialConditions_fatal( @@ -213,7 +213,7 @@ String foo() => ''; await indexTestUnit(''); // Initialize project. - var element = FindElement(externalUnit.unit).topFunction('foo'); + var element = FindElement2(externalUnit.unit).topFunction('foo'); _createRefactoringForElement(element); // check conditions @@ -226,7 +226,7 @@ String foo() => ''; await indexTestUnit(''' void test() {} '''); - var element = findElement.topFunction('test'); + var element = findElement2.topFunction('test'); _createRefactoringForElement(element); // check conditions await _assertInitialConditions_fatal( @@ -252,7 +252,7 @@ void test() {} assertTestChangeResult(expectedCode); } - void _createRefactoringForElement(ExecutableElement element) { + void _createRefactoringForElement(ExecutableElement2 element) { refactoring = ConvertMethodToGetterRefactoring( refactoringWorkspace, testAnalysisResult.session, 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 2dda459343f9..cfa809a5ca4d 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, - testLibraryElement, + testLibraryElement2, newLibraries.toSet(), ); var testEdit = change.getFileEdit(testFile.path); @@ -2119,7 +2119,7 @@ class A { await indexTestUnit(''' import 'macros.dart'; - + void f() { print('!'); } diff --git a/pkg/analyzer/lib/src/utilities/extensions/element.dart b/pkg/analyzer/lib/src/utilities/extensions/element.dart index 9d66a308b7fb..ecfad05b60cb 100644 --- a/pkg/analyzer/lib/src/utilities/extensions/element.dart +++ b/pkg/analyzer/lib/src/utilities/extensions/element.dart @@ -189,6 +189,11 @@ extension ElementOrNullExtension on Element? { return self; } else if (self is PrefixElementImpl) { return self.element2; + } else if (self is LibraryImportElementImpl || + self is LibraryExportElementImpl || + self is PartElementImpl) { + // There is no equivalent in the new element model. + return null; } else { return (self as Fragment?)?.element; }