| 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.completion.dart.keyword; | 5 library test.services.completion.dart.keyword; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/protocol.dart'; | 7 import 'package:analysis_server/src/protocol.dart'; |
| 8 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 8 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| 9 import 'package:analysis_server/src/services/completion/keyword_contributor.dart
'; | 9 import 'package:analysis_server/src/services/completion/keyword_contributor.dart
'; |
| 10 import 'package:analyzer/src/generated/scanner.dart'; | 10 import 'package:analyzer/src/generated/scanner.dart'; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 Keyword.EXPORT, | 67 Keyword.EXPORT, |
| 68 Keyword.FINAL, | 68 Keyword.FINAL, |
| 69 Keyword.IMPORT, | 69 Keyword.IMPORT, |
| 70 Keyword.LIBRARY, | 70 Keyword.LIBRARY, |
| 71 Keyword.PART, | 71 Keyword.PART, |
| 72 Keyword.TYPEDEF, | 72 Keyword.TYPEDEF, |
| 73 Keyword.VAR, | 73 Keyword.VAR, |
| 74 Keyword.VOID | 74 Keyword.VOID |
| 75 ]; | 75 ]; |
| 76 | 76 |
| 77 static const List<Keyword> IN_BLOCK_IN_CLASS = const [ | 77 static const List<Keyword> STMT_START_IN_CLASS = const [ |
| 78 Keyword.ASSERT, | 78 Keyword.ASSERT, |
| 79 Keyword.CASE, | 79 Keyword.CASE, |
| 80 Keyword.CONTINUE, | 80 Keyword.CONTINUE, |
| 81 Keyword.DO, | 81 Keyword.DO, |
| 82 Keyword.FINAL, | 82 Keyword.FINAL, |
| 83 Keyword.FOR, | 83 Keyword.FOR, |
| 84 Keyword.IF, | 84 Keyword.IF, |
| 85 Keyword.NEW, | 85 Keyword.NEW, |
| 86 Keyword.RETHROW, | 86 Keyword.RETHROW, |
| 87 Keyword.RETURN, | 87 Keyword.RETURN, |
| 88 Keyword.SUPER, | 88 Keyword.SUPER, |
| 89 Keyword.SWITCH, | 89 Keyword.SWITCH, |
| 90 Keyword.THIS, | 90 Keyword.THIS, |
| 91 Keyword.THROW, | 91 Keyword.THROW, |
| 92 Keyword.TRY, | 92 Keyword.TRY, |
| 93 Keyword.VAR, | 93 Keyword.VAR, |
| 94 Keyword.VOID, | 94 Keyword.VOID, |
| 95 Keyword.WHILE | 95 Keyword.WHILE |
| 96 ]; | 96 ]; |
| 97 | 97 |
| 98 static const List<Keyword> IN_BLOCK_NOT_IN_CLASS = const [ | 98 static const List<Keyword> STMT_START_OUTSIDE_CLASS = const [ |
| 99 Keyword.ASSERT, | 99 Keyword.ASSERT, |
| 100 Keyword.CASE, | 100 Keyword.CASE, |
| 101 Keyword.CONTINUE, | 101 Keyword.CONTINUE, |
| 102 Keyword.DO, | 102 Keyword.DO, |
| 103 Keyword.FINAL, | 103 Keyword.FINAL, |
| 104 Keyword.FOR, | 104 Keyword.FOR, |
| 105 Keyword.IF, | 105 Keyword.IF, |
| 106 Keyword.NEW, | 106 Keyword.NEW, |
| 107 Keyword.RETHROW, | 107 Keyword.RETHROW, |
| 108 Keyword.RETURN, | 108 Keyword.RETURN, |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 | 346 |
| 347 test_function_body_inClass_constructorInitializer() { | 347 test_function_body_inClass_constructorInitializer() { |
| 348 addTestSource(r''' | 348 addTestSource(r''' |
| 349 foo(p) {} | 349 foo(p) {} |
| 350 class A { | 350 class A { |
| 351 final f; | 351 final f; |
| 352 A() : f = foo(() {^}); | 352 A() : f = foo(() {^}); |
| 353 } | 353 } |
| 354 '''); | 354 '''); |
| 355 expect(computeFast(), isTrue); | 355 expect(computeFast(), isTrue); |
| 356 assertSuggestKeywords(IN_BLOCK_NOT_IN_CLASS); | 356 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS); |
| 357 } | 357 } |
| 358 | 358 |
| 359 test_function_body_inClass_field() { | 359 test_function_body_inClass_field() { |
| 360 addTestSource(r''' | 360 addTestSource(r''' |
| 361 class A { | 361 class A { |
| 362 var f = () {^}; | 362 var f = () {^}; |
| 363 } | 363 } |
| 364 '''); | 364 '''); |
| 365 expect(computeFast(), isTrue); | 365 expect(computeFast(), isTrue); |
| 366 assertSuggestKeywords(IN_BLOCK_NOT_IN_CLASS); | 366 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS); |
| 367 } | 367 } |
| 368 | 368 |
| 369 test_function_body_inClass_methodBody() { | 369 test_function_body_inClass_methodBody() { |
| 370 addTestSource(r''' | 370 addTestSource(r''' |
| 371 class A { | 371 class A { |
| 372 m() { | 372 m() { |
| 373 f() {^}; | 373 f() {^}; |
| 374 } | 374 } |
| 375 } | 375 } |
| 376 '''); | 376 '''); |
| 377 expect(computeFast(), isTrue); | 377 expect(computeFast(), isTrue); |
| 378 assertSuggestKeywords(IN_BLOCK_IN_CLASS); | 378 assertSuggestKeywords(STMT_START_IN_CLASS); |
| 379 } | 379 } |
| 380 | 380 |
| 381 test_function_body_inClass_methodBody_inFunction() { | 381 test_function_body_inClass_methodBody_inFunction() { |
| 382 addTestSource(r''' | 382 addTestSource(r''' |
| 383 class A { | 383 class A { |
| 384 m() { | 384 m() { |
| 385 f() { | 385 f() { |
| 386 f2() {^}; | 386 f2() {^}; |
| 387 }; | 387 }; |
| 388 } | 388 } |
| 389 } | 389 } |
| 390 '''); | 390 '''); |
| 391 expect(computeFast(), isTrue); | 391 expect(computeFast(), isTrue); |
| 392 assertSuggestKeywords(IN_BLOCK_IN_CLASS); | 392 assertSuggestKeywords(STMT_START_IN_CLASS); |
| 393 } | 393 } |
| 394 | 394 |
| 395 test_function_body_inUnit() { | 395 test_function_body_inUnit() { |
| 396 addTestSource('main() {^}'); | 396 addTestSource('main() {^}'); |
| 397 expect(computeFast(), isTrue); | 397 expect(computeFast(), isTrue); |
| 398 assertSuggestKeywords(IN_BLOCK_NOT_IN_CLASS); | 398 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS); |
| 399 } | 399 } |
| 400 | 400 |
| 401 test_function_body_inUnit_afterBlock() { | 401 test_function_body_inUnit_afterBlock() { |
| 402 addTestSource('main() {{}^}'); | 402 addTestSource('main() {{}^}'); |
| 403 expect(computeFast(), isTrue); | 403 expect(computeFast(), isTrue); |
| 404 assertSuggestKeywords(IN_BLOCK_NOT_IN_CLASS); | 404 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS); |
| 405 } |
| 406 |
| 407 test_if_in_class() { |
| 408 addTestSource('class A {foo() {if (true) ^}}'); |
| 409 expect(computeFast(), isTrue); |
| 410 assertSuggestKeywords(STMT_START_IN_CLASS, DART_RELEVANCE_KEYWORD); |
| 411 } |
| 412 |
| 413 test_if_in_class2() { |
| 414 addTestSource('class A {foo() {if (true) ^;}}'); |
| 415 expect(computeFast(), isTrue); |
| 416 assertSuggestKeywords(STMT_START_IN_CLASS, DART_RELEVANCE_KEYWORD); |
| 417 } |
| 418 |
| 419 test_if_in_class3() { |
| 420 addTestSource('class A {foo() {if (true) r^;}}'); |
| 421 expect(computeFast(), isTrue); |
| 422 assertSuggestKeywords(STMT_START_IN_CLASS, DART_RELEVANCE_KEYWORD); |
| 423 } |
| 424 |
| 425 test_if_in_class4() { |
| 426 addTestSource('class A {foo() {if (true) ^ go();}}'); |
| 427 expect(computeFast(), isTrue); |
| 428 assertSuggestKeywords(STMT_START_IN_CLASS, DART_RELEVANCE_KEYWORD); |
| 429 } |
| 430 |
| 431 test_if_outside_class() { |
| 432 addTestSource('foo() {if (true) ^}'); |
| 433 expect(computeFast(), isTrue); |
| 434 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS, DART_RELEVANCE_KEYWORD); |
| 435 } |
| 436 |
| 437 test_if_outside_class2() { |
| 438 addTestSource('foo() {if (true) ^;}'); |
| 439 expect(computeFast(), isTrue); |
| 440 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS, DART_RELEVANCE_KEYWORD); |
| 441 } |
| 442 |
| 443 test_if_outside_class3() { |
| 444 addTestSource('foo() {if (true) r^;}'); |
| 445 expect(computeFast(), isTrue); |
| 446 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS, DART_RELEVANCE_KEYWORD); |
| 447 } |
| 448 |
| 449 test_if_outside_class4() { |
| 450 addTestSource('foo() {if (true) ^ go();}'); |
| 451 expect(computeFast(), isTrue); |
| 452 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS, DART_RELEVANCE_KEYWORD); |
| 405 } | 453 } |
| 406 | 454 |
| 407 test_import() { | 455 test_import() { |
| 408 addTestSource('import "foo" deferred as foo ^;'); | 456 addTestSource('import "foo" deferred as foo ^;'); |
| 409 expect(computeFast(), isTrue); | 457 expect(computeFast(), isTrue); |
| 410 assertSuggestKeywords([], DART_RELEVANCE_HIGH); | 458 assertSuggestKeywords([], DART_RELEVANCE_HIGH); |
| 411 } | 459 } |
| 412 | 460 |
| 413 test_import_as() { | 461 test_import_as() { |
| 414 addTestSource('import "foo" deferred ^;'); | 462 addTestSource('import "foo" deferred ^;'); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 expect(computeFast(), isTrue); | 505 expect(computeFast(), isTrue); |
| 458 assertSuggestKeywords([Keyword.AS, Keyword.DEFERRED], DART_RELEVANCE_HIGH); | 506 assertSuggestKeywords([Keyword.AS, Keyword.DEFERRED], DART_RELEVANCE_HIGH); |
| 459 } | 507 } |
| 460 | 508 |
| 461 test_import_deferred6() { | 509 test_import_deferred6() { |
| 462 addTestSource('import "foo" d^ import'); | 510 addTestSource('import "foo" d^ import'); |
| 463 expect(computeFast(), isTrue); | 511 expect(computeFast(), isTrue); |
| 464 assertSuggestKeywords([Keyword.AS, Keyword.DEFERRED], DART_RELEVANCE_HIGH); | 512 assertSuggestKeywords([Keyword.AS, Keyword.DEFERRED], DART_RELEVANCE_HIGH); |
| 465 } | 513 } |
| 466 | 514 |
| 467 test_import_deferred_not() { | |
| 468 addTestSource('import "foo" as foo ^;'); | |
| 469 expect(computeFast(), isTrue); | |
| 470 assertSuggestKeywords([], DART_RELEVANCE_HIGH); | |
| 471 } | |
| 472 | |
| 473 test_import_deferred_as() { | 515 test_import_deferred_as() { |
| 474 addTestSource('import "foo" ^;'); | 516 addTestSource('import "foo" ^;'); |
| 475 expect(computeFast(), isTrue); | 517 expect(computeFast(), isTrue); |
| 476 assertSuggestKeywords([Keyword.AS, Keyword.DEFERRED], DART_RELEVANCE_HIGH); | 518 assertSuggestKeywords([Keyword.AS, Keyword.DEFERRED], DART_RELEVANCE_HIGH); |
| 477 } | 519 } |
| 478 | 520 |
| 479 test_import_deferred_as2() { | 521 test_import_deferred_as2() { |
| 480 addTestSource('import "foo" d^;'); | 522 addTestSource('import "foo" d^;'); |
| 481 expect(computeFast(), isTrue); | 523 expect(computeFast(), isTrue); |
| 482 assertSuggestKeywords([Keyword.AS, Keyword.DEFERRED], DART_RELEVANCE_HIGH); | 524 assertSuggestKeywords([Keyword.AS, Keyword.DEFERRED], DART_RELEVANCE_HIGH); |
| 483 } | 525 } |
| 484 | 526 |
| 485 test_import_deferred_as3() { | 527 test_import_deferred_as3() { |
| 486 addTestSource('import "foo" ^'); | 528 addTestSource('import "foo" ^'); |
| 487 expect(computeFast(), isTrue); | 529 expect(computeFast(), isTrue); |
| 488 assertSuggestKeywords([Keyword.AS, Keyword.DEFERRED], DART_RELEVANCE_HIGH); | 530 assertSuggestKeywords([Keyword.AS, Keyword.DEFERRED], DART_RELEVANCE_HIGH); |
| 489 } | 531 } |
| 490 | 532 |
| 491 test_import_deferred_as4() { | 533 test_import_deferred_as4() { |
| 492 addTestSource('import "foo" d^'); | 534 addTestSource('import "foo" d^'); |
| 493 expect(computeFast(), isTrue); | 535 expect(computeFast(), isTrue); |
| 494 assertSuggestKeywords([Keyword.AS, Keyword.DEFERRED], DART_RELEVANCE_HIGH); | 536 assertSuggestKeywords([Keyword.AS, Keyword.DEFERRED], DART_RELEVANCE_HIGH); |
| 495 } | 537 } |
| 496 | 538 |
| 539 test_import_deferred_not() { |
| 540 addTestSource('import "foo" as foo ^;'); |
| 541 expect(computeFast(), isTrue); |
| 542 assertSuggestKeywords([], DART_RELEVANCE_HIGH); |
| 543 } |
| 544 |
| 497 test_library() { | 545 test_library() { |
| 498 addTestSource('library foo;^'); | 546 addTestSource('library foo;^'); |
| 499 expect(computeFast(), isTrue); | 547 expect(computeFast(), isTrue); |
| 500 assertSuggestKeywords( | 548 assertSuggestKeywords( |
| 501 DIRECTIVE_AND_DECLARATION_KEYWORDS, DART_RELEVANCE_HIGH); | 549 DIRECTIVE_AND_DECLARATION_KEYWORDS, DART_RELEVANCE_HIGH); |
| 502 } | 550 } |
| 503 | 551 |
| 504 test_library_name() { | 552 test_library_name() { |
| 505 addTestSource('library ^'); | 553 addTestSource('library ^'); |
| 506 expect(computeFast(), isTrue); | 554 expect(computeFast(), isTrue); |
| 507 assertSuggestKeywords([]); | 555 assertSuggestKeywords([]); |
| 508 } | 556 } |
| 509 | 557 |
| 510 test_method_body() { | 558 test_method_body() { |
| 511 addTestSource('class A { foo() {^}}'); | 559 addTestSource('class A { foo() {^}}'); |
| 512 expect(computeFast(), isTrue); | 560 expect(computeFast(), isTrue); |
| 513 assertSuggestKeywords(IN_BLOCK_IN_CLASS); | 561 assertSuggestKeywords(STMT_START_IN_CLASS); |
| 514 } | 562 } |
| 515 | 563 |
| 516 test_named_constructor_invocation() { | 564 test_named_constructor_invocation() { |
| 517 addTestSource('void main() {new Future.^}'); | 565 addTestSource('void main() {new Future.^}'); |
| 518 expect(computeFast(), isTrue); | 566 expect(computeFast(), isTrue); |
| 519 assertSuggestKeywords([]); | 567 assertSuggestKeywords([]); |
| 520 } | 568 } |
| 521 | 569 |
| 522 test_part_of() { | 570 test_part_of() { |
| 523 addTestSource('part of foo;^'); | 571 addTestSource('part of foo;^'); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 546 sorted.forEach((k) => msg.writeln(' Keyword.${k.name},')); | 594 sorted.forEach((k) => msg.writeln(' Keyword.${k.name},')); |
| 547 } | 595 } |
| 548 | 596 |
| 549 bool _equalSets(Iterable<Keyword> iter1, Iterable<Keyword> iter2) { | 597 bool _equalSets(Iterable<Keyword> iter1, Iterable<Keyword> iter2) { |
| 550 if (iter1.length != iter2.length) return false; | 598 if (iter1.length != iter2.length) return false; |
| 551 if (iter1.any((k) => !iter2.contains(k))) return false; | 599 if (iter1.any((k) => !iter2.contains(k))) return false; |
| 552 if (iter2.any((k) => !iter1.contains(k))) return false; | 600 if (iter2.any((k) => !iter1.contains(k))) return false; |
| 553 return true; | 601 return true; |
| 554 } | 602 } |
| 555 } | 603 } |
| OLD | NEW |