Skip to content

Commit dd72ef9

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Support extension types in "Move top level to file" refactor
Fixes #60296 Change-Id: I1cac91c280987758ae320621395a79f93b35cf4e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414764 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent 550eb48 commit dd72ef9

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

pkg/analysis_server/lib/src/services/refactoring/move_top_level_to_file.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ class MoveTopLevelToFile extends RefactoringProducer {
274274
name = node.name.lexeme;
275275
} else if (node is ExtensionDeclaration && validSelection(node.name)) {
276276
name = node.name?.lexeme;
277+
} else if (node is ExtensionTypeDeclaration &&
278+
validSelection(node.name)) {
279+
name = node.name.lexeme;
277280
} else if (node is FunctionDeclaration &&
278281
node.parent is CompilationUnit &&
279282
validSelection(node.name)) {

pkg/analysis_server/test/src/services/refactoring/move_top_level_to_file_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,31 @@ extension ExtensionToMove on int { }
16271627
>>>>>>>>>> lib/main.dart
16281628
class A {}
16291629
1630+
class B {}
1631+
''';
1632+
await _singleDeclaration(
1633+
originalSource: originalSource,
1634+
expected: expected,
1635+
declarationName: declarationName,
1636+
);
1637+
}
1638+
1639+
Future<void> test_single_extensionType() async {
1640+
var originalSource = '''
1641+
class A {}
1642+
1643+
extension type ExtensionTypeToMo^ve(String _) {}
1644+
1645+
class B {}
1646+
''';
1647+
var declarationName = 'ExtensionTypeToMove';
1648+
1649+
var expected = '''
1650+
>>>>>>>>>> lib/extension_type_to_move.dart created
1651+
extension type ExtensionTypeToMove(String _) {}
1652+
>>>>>>>>>> lib/main.dart
1653+
class A {}
1654+
16301655
class B {}
16311656
''';
16321657
await _singleDeclaration(

0 commit comments

Comments
 (0)