| OLD | NEW |
| 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.correction.fix; | 5 library test.services.correction.fix; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/protocol.dart' hide AnalysisError; | 7 import 'package:analysis_server/src/protocol.dart' hide AnalysisError; |
| 8 import 'package:analysis_server/src/services/correction/fix.dart'; | 8 import 'package:analysis_server/src/services/correction/fix.dart'; |
| 9 import 'package:analysis_server/src/services/index/index.dart'; | 9 import 'package:analysis_server/src/services/index/index.dart'; |
| 10 import 'package:analysis_server/src/services/index/local_memory_index.dart'; | 10 import 'package:analysis_server/src/services/index/local_memory_index.dart'; |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 } | 388 } |
| 389 | 389 |
| 390 method() {} | 390 method() {} |
| 391 } | 391 } |
| 392 main() { | 392 main() { |
| 393 new A.named(1, 2.0); | 393 new A.named(1, 2.0); |
| 394 } | 394 } |
| 395 '''); | 395 '''); |
| 396 } | 396 } |
| 397 | 397 |
| 398 void test_createField_qualified_instance_hasField() { | 398 void test_createField_getter_multiLevel() { |
| 399 _indexTestUnit(''' |
| 400 class A { |
| 401 } |
| 402 class B { |
| 403 A a; |
| 404 } |
| 405 class C { |
| 406 B b; |
| 407 } |
| 408 main(C c) { |
| 409 int v = c.b.a.test; |
| 410 } |
| 411 '''); |
| 412 assertHasFix(FixKind.CREATE_FIELD, ''' |
| 413 class A { |
| 414 int test; |
| 415 } |
| 416 class B { |
| 417 A a; |
| 418 } |
| 419 class C { |
| 420 B b; |
| 421 } |
| 422 main(C c) { |
| 423 int v = c.b.a.test; |
| 424 } |
| 425 '''); |
| 426 } |
| 427 |
| 428 void test_createField_getter_qualified_instance() { |
| 429 _indexTestUnit(''' |
| 430 class A { |
| 431 } |
| 432 main(A a) { |
| 433 int v = a.test; |
| 434 } |
| 435 '''); |
| 436 assertHasFix(FixKind.CREATE_FIELD, ''' |
| 437 class A { |
| 438 int test; |
| 439 } |
| 440 main(A a) { |
| 441 int v = a.test; |
| 442 } |
| 443 '''); |
| 444 } |
| 445 |
| 446 void test_createField_getter_unqualified_instance_asInvocationArgument() { |
| 447 _indexTestUnit(''' |
| 448 class A { |
| 449 main() { |
| 450 f(test); |
| 451 } |
| 452 } |
| 453 f(String s) {} |
| 454 '''); |
| 455 assertHasFix(FixKind.CREATE_FIELD, ''' |
| 456 class A { |
| 457 String test; |
| 458 |
| 459 main() { |
| 460 f(test); |
| 461 } |
| 462 } |
| 463 f(String s) {} |
| 464 '''); |
| 465 } |
| 466 |
| 467 void test_createField_getter_unqualified_instance_asStatement() { |
| 468 _indexTestUnit(''' |
| 469 class A { |
| 470 main() { |
| 471 test; |
| 472 } |
| 473 } |
| 474 '''); |
| 475 assertHasFix(FixKind.CREATE_FIELD, ''' |
| 476 class A { |
| 477 var test; |
| 478 |
| 479 main() { |
| 480 test; |
| 481 } |
| 482 } |
| 483 '''); |
| 484 } |
| 485 |
| 486 void test_createField_getter_unqualified_instance_assignmentLhs() { |
| 487 _indexTestUnit(''' |
| 488 class A { |
| 489 main() { |
| 490 int v = test; |
| 491 } |
| 492 } |
| 493 '''); |
| 494 assertHasFix(FixKind.CREATE_FIELD, ''' |
| 495 class A { |
| 496 int test; |
| 497 |
| 498 main() { |
| 499 int v = test; |
| 500 } |
| 501 } |
| 502 '''); |
| 503 } |
| 504 |
| 505 void test_createField_setter_qualified_instance_hasField() { |
| 399 _indexTestUnit(''' | 506 _indexTestUnit(''' |
| 400 class A { | 507 class A { |
| 401 int aaa; | 508 int aaa; |
| 402 int zzz; | 509 int zzz; |
| 403 | 510 |
| 404 existingMethod() {} | 511 existingMethod() {} |
| 405 } | 512 } |
| 406 main(A a) { | 513 main(A a) { |
| 407 a.test = 5; | 514 a.test = 5; |
| 408 } | 515 } |
| 409 '''); | 516 '''); |
| 410 assertHasFix(FixKind.CREATE_FIELD, ''' | 517 assertHasFix(FixKind.CREATE_FIELD, ''' |
| 411 class A { | 518 class A { |
| 412 int aaa; | 519 int aaa; |
| 413 int zzz; | 520 int zzz; |
| 414 | 521 |
| 415 int test; | 522 int test; |
| 416 | 523 |
| 417 existingMethod() {} | 524 existingMethod() {} |
| 418 } | 525 } |
| 419 main(A a) { | 526 main(A a) { |
| 420 a.test = 5; | 527 a.test = 5; |
| 421 } | 528 } |
| 422 '''); | 529 '''); |
| 423 } | 530 } |
| 424 | 531 |
| 425 void test_createField_qualified_instance_hasMethod() { | 532 void test_createField_setter_qualified_instance_hasMethod() { |
| 426 _indexTestUnit(''' | 533 _indexTestUnit(''' |
| 427 class A { | 534 class A { |
| 428 existingMethod() {} | 535 existingMethod() {} |
| 429 } | 536 } |
| 430 main(A a) { | 537 main(A a) { |
| 431 a.test = 5; | 538 a.test = 5; |
| 432 } | 539 } |
| 433 '''); | 540 '''); |
| 434 assertHasFix(FixKind.CREATE_FIELD, ''' | 541 assertHasFix(FixKind.CREATE_FIELD, ''' |
| 435 class A { | 542 class A { |
| 436 int test; | 543 int test; |
| 437 | 544 |
| 438 existingMethod() {} | 545 existingMethod() {} |
| 439 } | 546 } |
| 440 main(A a) { | 547 main(A a) { |
| 441 a.test = 5; | 548 a.test = 5; |
| 442 } | 549 } |
| 443 '''); | 550 '''); |
| 444 } | 551 } |
| 445 | 552 |
| 446 void test_createField_qualified_static() { | 553 void test_createField_setter_qualified_static() { |
| 447 _indexTestUnit(''' | 554 _indexTestUnit(''' |
| 448 class A { | 555 class A { |
| 449 } | 556 } |
| 450 main() { | 557 main() { |
| 451 A.test = 5; | 558 A.test = 5; |
| 452 } | 559 } |
| 453 '''); | 560 '''); |
| 454 assertHasFix(FixKind.CREATE_FIELD, ''' | 561 assertHasFix(FixKind.CREATE_FIELD, ''' |
| 455 class A { | 562 class A { |
| 456 static int test; | 563 static int test; |
| 457 } | 564 } |
| 458 main() { | 565 main() { |
| 459 A.test = 5; | 566 A.test = 5; |
| 460 } | 567 } |
| 461 '''); | 568 '''); |
| 462 } | 569 } |
| 463 | 570 |
| 464 void test_createField_unqualified_instance() { | 571 void test_createField_setter_unqualified_instance() { |
| 465 _indexTestUnit(''' | 572 _indexTestUnit(''' |
| 466 class A { | 573 class A { |
| 467 main() { | 574 main() { |
| 468 test = 5; | 575 test = 5; |
| 469 } | 576 } |
| 470 } | 577 } |
| 471 '''); | 578 '''); |
| 472 assertHasFix(FixKind.CREATE_FIELD, ''' | 579 assertHasFix(FixKind.CREATE_FIELD, ''' |
| 473 class A { | 580 class A { |
| 474 int test; | 581 int test; |
| 475 | 582 |
| 476 main() { | 583 main() { |
| 477 test = 5; | 584 test = 5; |
| 478 } | 585 } |
| 479 } | 586 } |
| 480 '''); | 587 '''); |
| 481 } | 588 } |
| 482 | 589 |
| 483 void test_createField_unqualified_static() { | 590 void test_createField_setter_unqualified_static() { |
| 484 _indexTestUnit(''' | 591 _indexTestUnit(''' |
| 485 class A { | 592 class A { |
| 486 static main() { | 593 static main() { |
| 487 test = 5; | 594 test = 5; |
| 488 } | 595 } |
| 489 } | 596 } |
| 490 '''); | 597 '''); |
| 491 assertHasFix(FixKind.CREATE_FIELD, ''' | 598 assertHasFix(FixKind.CREATE_FIELD, ''' |
| 492 class A { | 599 class A { |
| 493 static int test; | 600 static int test; |
| (...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2112 positions.add(new Position(testFile, offset)); | 2219 positions.add(new Position(testFile, offset)); |
| 2113 } | 2220 } |
| 2114 return positions; | 2221 return positions; |
| 2115 } | 2222 } |
| 2116 | 2223 |
| 2117 void _indexTestUnit(String code) { | 2224 void _indexTestUnit(String code) { |
| 2118 resolveTestUnit(code); | 2225 resolveTestUnit(code); |
| 2119 index.indexUnit(context, testUnit); | 2226 index.indexUnit(context, testUnit); |
| 2120 } | 2227 } |
| 2121 } | 2228 } |
| OLD | NEW |