File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed
lib/src/services/correction
test/services/refactoring/legacy Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -247,6 +247,7 @@ AstNode? getEnclosingClassOrUnitMember(AstNode input) {
247
247
case ClassDeclaration _:
248
248
case CompilationUnit _:
249
249
case EnumDeclaration _:
250
+ case ExtensionDeclaration _:
250
251
case ExtensionTypeDeclaration _:
251
252
case MixinDeclaration _:
252
253
return member;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import 'abstract_refactoring.dart';
12
12
void main () {
13
13
defineReflectiveSuite (() {
14
14
defineReflectiveTests (ExtractMethodTest_Enum );
15
+ defineReflectiveTests (ExtractMethodTest_Extension );
15
16
defineReflectiveTests (ExtractMethodTest_ExtensionType );
16
17
defineReflectiveTests (ExtractMethodTest_Mixin );
17
18
defineReflectiveTests (ExtractMethodTest );
@@ -3338,6 +3339,57 @@ enum E {
3338
3339
}
3339
3340
}
3340
3341
3342
+ @reflectiveTest
3343
+ class ExtractMethodTest_Extension extends _ExtractMethodTest {
3344
+ Future <void > test_singleExpression_method () async {
3345
+ await indexTestUnit ('''
3346
+ extension E on int {
3347
+ void foo() {
3348
+ int a = 1 + 2;
3349
+ }
3350
+ }
3351
+ ''' );
3352
+ _createRefactoringForString ('1 + 2' );
3353
+ // apply refactoring
3354
+ return _assertSuccessfulRefactoring ('''
3355
+ extension E on int {
3356
+ void foo() {
3357
+ int a = res();
3358
+ }
3359
+
3360
+ int res() => 1 + 2;
3361
+ }
3362
+ ''' );
3363
+ }
3364
+
3365
+ Future <void > test_statements_method () async {
3366
+ await indexTestUnit ('''
3367
+ extension E on int {
3368
+ void foo() {
3369
+ // start
3370
+ print(0);
3371
+ // end
3372
+ }
3373
+ }
3374
+ ''' );
3375
+ _createRefactoringForStartEndComments ();
3376
+ // apply refactoring
3377
+ return _assertSuccessfulRefactoring ('''
3378
+ extension E on int {
3379
+ void foo() {
3380
+ // start
3381
+ res();
3382
+ // end
3383
+ }
3384
+
3385
+ void res() {
3386
+ print(0);
3387
+ }
3388
+ }
3389
+ ''' );
3390
+ }
3391
+ }
3392
+
3341
3393
@reflectiveTest
3342
3394
class ExtractMethodTest_ExtensionType extends _ExtractMethodTest {
3343
3395
Future <void > test_bad_conflict_method_alreadyDeclaresMethod () async {
You can’t perform that action at this time.
0 commit comments