Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: pkg/analysis_server/test/services/refactoring/extract_method_test.dart

Issue 1655353002: Issue 25616. Support for extracting methods with function-typed parameters. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analysis_server/lib/src/services/refactoring/extract_method.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.services.refactoring.extract_method; 5 library test.services.refactoring.extract_method;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; 9 import 'package:analysis_server/plugin/protocol/protocol.dart';
10 import 'package:analysis_server/src/services/correction/status.dart'; 10 import 'package:analysis_server/src/services/correction/status.dart';
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 168 }
169 '''); 169 ''');
170 _createRefactoringForString('super()'); 170 _createRefactoringForString('super()');
171 return _assertConditionsFatal( 171 return _assertConditionsFatal(
172 'Cannot extract a constructor initializer. Select expression part of ini tializer.'); 172 'Cannot extract a constructor initializer. Select expression part of ini tializer.');
173 } 173 }
174 174
175 test_bad_doWhile_body() { 175 test_bad_doWhile_body() {
176 indexTestUnit(''' 176 indexTestUnit('''
177 main() { 177 main() {
178 do 178 do
179 // start 179 // start
180 { 180 {
181 } 181 }
182 // end 182 // end
183 while (true); 183 while (true);
184 } 184 }
185 '''); 185 ''');
186 _createRefactoringForStartEndComments(); 186 _createRefactoringForStartEndComments();
187 return _assertConditionsFatal( 187 return _assertConditionsFatal(
188 "Operation not applicable to a 'do' statement's body and expression."); 188 "Operation not applicable to a 'do' statement's body and expression.");
189 } 189 }
190 190
191 test_bad_emptySelection() { 191 test_bad_emptySelection() {
192 indexTestUnit(''' 192 indexTestUnit('''
193 main() { 193 main() {
194 // start 194 // start
195 // end 195 // end
196 print(0); 196 print(0);
197 } 197 }
198 '''); 198 ''');
199 _createRefactoringForStartEndComments(); 199 _createRefactoringForStartEndComments();
200 return _assertConditionsFatal( 200 return _assertConditionsFatal(
201 "Can only extract a single expression or a set of statements."); 201 "Can only extract a single expression or a set of statements.");
202 } 202 }
203 203
204 test_bad_forLoop_conditionAndUpdaters() { 204 test_bad_forLoop_conditionAndUpdaters() {
205 indexTestUnit(''' 205 indexTestUnit('''
206 main() { 206 main() {
207 for ( 207 for (
208 int i = 0; 208 int i = 0;
209 // start 209 // start
210 i < 10; 210 i < 10;
211 i++ 211 i++
212 // end 212 // end
213 ) {} 213 ) {}
214 } 214 }
215 '''); 215 ''');
216 _createRefactoringForStartEndComments(); 216 _createRefactoringForStartEndComments();
217 return _assertConditionsFatal( 217 return _assertConditionsFatal(
218 "Operation not applicable to a 'for' statement's condition and updaters. "); 218 "Operation not applicable to a 'for' statement's condition and updaters. ");
219 } 219 }
220 220
221 test_bad_forLoop_init() { 221 test_bad_forLoop_init() {
222 indexTestUnit(''' 222 indexTestUnit('''
223 main() { 223 main() {
224 for ( 224 for (
225 // start 225 // start
226 int i = 0 226 int i = 0
227 // end 227 // end
228 ; i < 10; 228 ; i < 10;
229 i++ 229 i++
230 ) {} 230 ) {}
231 } 231 }
232 '''); 232 ''');
233 _createRefactoringForStartEndComments(); 233 _createRefactoringForStartEndComments();
234 return _assertConditionsFatal( 234 return _assertConditionsFatal(
235 "Cannot extract initialization part of a 'for' statement."); 235 "Cannot extract initialization part of a 'for' statement.");
236 } 236 }
237 237
238 test_bad_forLoop_initAndCondition() { 238 test_bad_forLoop_initAndCondition() {
239 indexTestUnit(''' 239 indexTestUnit('''
240 main() { 240 main() {
241 for ( 241 for (
242 // start 242 // start
243 int i = 0; 243 int i = 0;
244 i < 10; 244 i < 10;
245 // end 245 // end
246 i++ 246 i++
247 ) {} 247 ) {}
248 } 248 }
249 '''); 249 ''');
250 _createRefactoringForStartEndComments(); 250 _createRefactoringForStartEndComments();
251 return _assertConditionsFatal( 251 return _assertConditionsFatal(
252 "Operation not applicable to a 'for' statement's initializer and conditi on."); 252 "Operation not applicable to a 'for' statement's initializer and conditi on.");
253 } 253 }
254 254
255 test_bad_forLoop_updaters() { 255 test_bad_forLoop_updaters() {
256 indexTestUnit(''' 256 indexTestUnit('''
257 main() { 257 main() {
258 for ( 258 for (
259 int i = 0; 259 int i = 0;
260 i < 10; 260 i < 10;
261 // start 261 // start
262 i++ 262 i++
263 // end 263 // end
264 ) {} 264 ) {}
265 } 265 }
266 '''); 266 ''');
267 _createRefactoringForStartEndComments(); 267 _createRefactoringForStartEndComments();
268 return _assertConditionsFatal( 268 return _assertConditionsFatal(
269 "Cannot extract increment part of a 'for' statement."); 269 "Cannot extract increment part of a 'for' statement.");
270 } 270 }
271 271
272 test_bad_forLoop_updatersAndBody() { 272 test_bad_forLoop_updatersAndBody() {
273 indexTestUnit(''' 273 indexTestUnit('''
274 main() { 274 main() {
275 for ( 275 for (
276 int i = 0; 276 int i = 0;
277 i < 10; 277 i < 10;
278 // start 278 // start
279 i++ 279 i++
280 ) {} 280 ) {}
281 // end 281 // end
282 } 282 }
283 '''); 283 ''');
284 _createRefactoringForStartEndComments(); 284 _createRefactoringForStartEndComments();
285 return _assertConditionsFatal( 285 return _assertConditionsFatal(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 '''); 342 ''');
343 _createRefactoringForStartEndComments(); 343 _createRefactoringForStartEndComments();
344 refactoring.name = 'bad-name'; 344 refactoring.name = 'bad-name';
345 // check conditions 345 // check conditions
346 return _assertConditionsFatal("Method name must not contain '-'."); 346 return _assertConditionsFatal("Method name must not contain '-'.");
347 } 347 }
348 348
349 test_bad_notSameParent() { 349 test_bad_notSameParent() {
350 indexTestUnit(''' 350 indexTestUnit('''
351 main() { 351 main() {
352 while (false) 352 while (false)
353 // start 353 // start
354 { 354 {
355 } 355 }
356 print(0); 356 print(0);
357 // end 357 // end
358 } 358 }
359 '''); 359 ''');
360 _createRefactoringForStartEndComments(); 360 _createRefactoringForStartEndComments();
361 return _assertConditionsFatal( 361 return _assertConditionsFatal(
362 'Not all selected statements are enclosed by the same parent statement.' ); 362 'Not all selected statements are enclosed by the same parent statement.' );
363 } 363 }
364 364
365 test_bad_parameterName_duplicate() async { 365 test_bad_parameterName_duplicate() async {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 '''); 500 ''');
501 _createRefactoringForStartEndComments(); 501 _createRefactoringForStartEndComments();
502 return _assertConditionsFatal( 502 return _assertConditionsFatal(
503 "Ambiguous return value: Selected block contains assignment(s) to " 503 "Ambiguous return value: Selected block contains assignment(s) to "
504 "local variables and return statement."); 504 "local variables and return statement.");
505 } 505 }
506 506
507 test_bad_switchCase() { 507 test_bad_switchCase() {
508 indexTestUnit(''' 508 indexTestUnit('''
509 main() { 509 main() {
510 switch (1) { 510 switch (1) {
511 // start 511 // start
512 case 0: break; 512 case 0: break;
513 // end 513 // end
514 } 514 }
515 } 515 }
516 '''); 516 ''');
517 _createRefactoringForStartEndComments(); 517 _createRefactoringForStartEndComments();
518 return _assertConditionsFatal( 518 return _assertConditionsFatal(
519 "Selection must either cover whole switch statement " 519 "Selection must either cover whole switch statement "
520 "or parts of a single case block."); 520 "or parts of a single case block.");
(...skipping 24 matching lines...) Expand all
545 '''); 545 ''');
546 _createRefactoringForStartEndString('); // marker', '// end'); 546 _createRefactoringForStartEndString('); // marker', '// end');
547 return _assertConditionsFatal( 547 return _assertConditionsFatal(
548 "The beginning of the selection contains characters that do not belong t o a statement."); 548 "The beginning of the selection contains characters that do not belong t o a statement.");
549 } 549 }
550 550
551 test_bad_try_catchBlock_block() { 551 test_bad_try_catchBlock_block() {
552 indexTestUnit(''' 552 indexTestUnit('''
553 main() { 553 main() {
554 try 554 try
555 {} 555 {}
556 catch (e) 556 catch (e)
557 // start 557 // start
558 {} 558 {}
559 // end 559 // end
560 } 560 }
561 '''); 561 ''');
562 _createRefactoringForStartEndComments(); 562 _createRefactoringForStartEndComments();
563 return _assertConditionsFatal( 563 return _assertConditionsFatal(
564 "Selection must either cover whole try statement or " 564 "Selection must either cover whole try statement or "
565 "parts of try, catch, or finally block."); 565 "parts of try, catch, or finally block.");
566 } 566 }
567 567
568 test_bad_try_catchBlock_complete() { 568 test_bad_try_catchBlock_complete() {
569 indexTestUnit(''' 569 indexTestUnit('''
570 main() { 570 main() {
571 try 571 try
572 {} 572 {}
573 // start 573 // start
574 catch (e) 574 catch (e)
575 {} 575 {}
576 // end 576 // end
577 } 577 }
578 '''); 578 ''');
579 _createRefactoringForStartEndComments(); 579 _createRefactoringForStartEndComments();
580 return _assertConditionsFatal( 580 return _assertConditionsFatal(
581 "Selection must either cover whole try statement or " 581 "Selection must either cover whole try statement or "
582 "parts of try, catch, or finally block."); 582 "parts of try, catch, or finally block.");
583 } 583 }
584 584
585 test_bad_try_catchBlock_exception() { 585 test_bad_try_catchBlock_exception() {
586 indexTestUnit(''' 586 indexTestUnit('''
587 main() { 587 main() {
588 try { 588 try {
589 } catch ( 589 } catch (
590 // start 590 // start
591 e 591 e
592 // end 592 // end
593 ) { 593 ) {
594 } 594 }
595 } 595 }
596 '''); 596 ''');
597 _createRefactoringForStartEndComments(); 597 _createRefactoringForStartEndComments();
598 return _assertConditionsFatal( 598 return _assertConditionsFatal(
599 'Cannot extract the name part of a declaration.'); 599 'Cannot extract the name part of a declaration.');
600 } 600 }
601 601
602 test_bad_try_finallyBlock() { 602 test_bad_try_finallyBlock() {
603 indexTestUnit(''' 603 indexTestUnit('''
604 main() { 604 main() {
605 try 605 try
606 {} 606 {}
607 finally 607 finally
608 // start 608 // start
609 {} 609 {}
610 // end 610 // end
611 } 611 }
612 '''); 612 ''');
613 _createRefactoringForStartEndComments(); 613 _createRefactoringForStartEndComments();
614 return _assertConditionsFatal( 614 return _assertConditionsFatal(
615 "Selection must either cover whole try statement or " 615 "Selection must either cover whole try statement or "
616 "parts of try, catch, or finally block."); 616 "parts of try, catch, or finally block.");
617 } 617 }
618 618
619 test_bad_try_tryBlock() { 619 test_bad_try_tryBlock() {
620 indexTestUnit(''' 620 indexTestUnit('''
621 main() { 621 main() {
622 try 622 try
623 // start 623 // start
624 {} 624 {}
625 // end 625 // end
626 finally 626 finally
627 {} 627 {}
628 } 628 }
629 '''); 629 ''');
630 _createRefactoringForStartEndComments(); 630 _createRefactoringForStartEndComments();
631 return _assertConditionsFatal( 631 return _assertConditionsFatal(
632 "Selection must either cover whole try statement or " 632 "Selection must either cover whole try statement or "
633 "parts of try, catch, or finally block."); 633 "parts of try, catch, or finally block.");
634 } 634 }
635 635
636 test_bad_typeReference() { 636 test_bad_typeReference() {
637 indexTestUnit(''' 637 indexTestUnit('''
638 main() { 638 main() {
639 int a = 0; 639 int a = 0;
640 } 640 }
641 '''); 641 ''');
642 _createRefactoringForString("int"); 642 _createRefactoringForString("int");
643 return _assertConditionsFatal("Cannot extract a single type reference."); 643 return _assertConditionsFatal("Cannot extract a single type reference.");
644 } 644 }
645 645
646 test_bad_variableDeclarationFragment() { 646 test_bad_variableDeclarationFragment() {
647 indexTestUnit(''' 647 indexTestUnit('''
648 main() { 648 main() {
649 int 649 int
650 // start 650 // start
651 a = 1 651 a = 1
652 // end 652 // end
653 ,b = 2; 653 ,b = 2;
654 } 654 }
655 '''); 655 ''');
656 _createRefactoringForStartEndComments(); 656 _createRefactoringForStartEndComments();
657 return _assertConditionsFatal( 657 return _assertConditionsFatal(
658 "Cannot extract a variable declaration fragment. Select whole declaratio n statement."); 658 "Cannot extract a variable declaration fragment. Select whole declaratio n statement.");
659 } 659 }
660 660
661 test_bad_while_conditionAndBody() { 661 test_bad_while_conditionAndBody() {
662 indexTestUnit(''' 662 indexTestUnit('''
663 main() { 663 main() {
664 while 664 while
665 // start 665 // start
666 (false) 666 (false)
667 { 667 {
668 } 668 }
669 // end 669 // end
670 } 670 }
671 '''); 671 ''');
672 _createRefactoringForStartEndComments(); 672 _createRefactoringForStartEndComments();
673 return _assertConditionsFatal( 673 return _assertConditionsFatal(
674 "Operation not applicable to a while statement's expression and body."); 674 "Operation not applicable to a while statement's expression and body.");
675 } 675 }
676 676
677 test_canExtractGetter_false_closure() async { 677 test_canExtractGetter_false_closure() async {
678 indexTestUnit(''' 678 indexTestUnit('''
(...skipping 1781 matching lines...) Expand 10 before | Expand all | Expand 10 after
2460 res(v); 2460 res(v);
2461 // end 2461 // end
2462 } 2462 }
2463 2463
2464 void res(Future<int> v) { 2464 void res(Future<int> v) {
2465 print(v); 2465 print(v);
2466 } 2466 }
2467 '''); 2467 ''');
2468 } 2468 }
2469 2469
2470 test_statements_parameters_localFunction() {
2471 _addLibraryReturningAsync();
2472 indexTestUnit('''
2473 class C {
2474 int f(int a) {
2475 int callback(int x, int y) => x + a;
2476 int b = a + 1;
2477 // start
2478 int c = callback(b, 2);
2479 // end
2480 int d = c + 1;
2481 return d;
2482 }
2483 }''');
2484 _createRefactoringForStartEndComments();
2485 // apply refactoring
2486 return _assertSuccessfulRefactoring('''
2487 class C {
2488 int f(int a) {
2489 int callback(int x, int y) => x + a;
2490 int b = a + 1;
2491 // start
2492 int c = res(callback, b);
2493 // end
2494 int d = c + 1;
2495 return d;
2496 }
2497
2498 int res(int callback(int x, int y), int b) {
2499 int c = callback(b, 2);
2500 return c;
2501 }
2502 }''');
2503 }
2504
2470 test_statements_parameters_noLocalVariableConflict() async { 2505 test_statements_parameters_noLocalVariableConflict() async {
2471 indexTestUnit(''' 2506 indexTestUnit('''
2472 int f(int x) { 2507 int f(int x) {
2473 int y = x + 1; 2508 int y = x + 1;
2474 // start 2509 // start
2475 if (y % 2 == 0) { 2510 if (y % 2 == 0) {
2476 int y = x + 2; 2511 int y = x + 2;
2477 return y; 2512 return y;
2478 } else { 2513 } else {
2479 return y; 2514 return y;
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
2800 * Returns a deep copy of [refactoring] parameters. 2835 * Returns a deep copy of [refactoring] parameters.
2801 * There was a bug masked by updating parameter instances shared between the 2836 * There was a bug masked by updating parameter instances shared between the
2802 * refactoring and the test. 2837 * refactoring and the test.
2803 */ 2838 */
2804 List<RefactoringMethodParameter> _getParametersCopy() { 2839 List<RefactoringMethodParameter> _getParametersCopy() {
2805 return refactoring.parameters.map((p) { 2840 return refactoring.parameters.map((p) {
2806 return new RefactoringMethodParameter(p.kind, p.type, p.name, id: p.id); 2841 return new RefactoringMethodParameter(p.kind, p.type, p.name, id: p.id);
2807 }).toList(); 2842 }).toList();
2808 } 2843 }
2809 } 2844 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/refactoring/extract_method.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698