| 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 analyzer.test.dart.ast.ast_test; | 5 library analyzer.test.dart.ast.ast_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
| 9 import 'package:analyzer/src/dart/ast/token.dart'; | 9 import 'package:analyzer/src/dart/ast/token.dart'; |
| 10 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 10 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 list[1] = node; | 566 list[1] = node; |
| 567 fail("Expected IndexOutOfBoundsException"); | 567 fail("Expected IndexOutOfBoundsException"); |
| 568 } on RangeError { | 568 } on RangeError { |
| 569 // Expected | 569 // Expected |
| 570 } | 570 } |
| 571 } | 571 } |
| 572 } | 572 } |
| 573 | 573 |
| 574 @reflectiveTest | 574 @reflectiveTest |
| 575 class SimpleIdentifierTest extends ParserTestCase { | 575 class SimpleIdentifierTest extends ParserTestCase { |
| 576 void test_inDeclarationContext_catch_exception() { | |
| 577 SimpleIdentifier identifier = | |
| 578 AstFactory.catchClause("e").exceptionParameter; | |
| 579 expect(identifier.inDeclarationContext(), isTrue); | |
| 580 } | |
| 581 | |
| 582 void test_inDeclarationContext_catch_stack() { | |
| 583 SimpleIdentifier identifier = | |
| 584 AstFactory.catchClause2("e", "s").stackTraceParameter; | |
| 585 expect(identifier.inDeclarationContext(), isTrue); | |
| 586 } | |
| 587 | |
| 588 void test_inDeclarationContext_classDeclaration() { | |
| 589 SimpleIdentifier identifier = | |
| 590 AstFactory.classDeclaration(null, "C", null, null, null, null).name; | |
| 591 expect(identifier.inDeclarationContext(), isTrue); | |
| 592 } | |
| 593 | |
| 594 void test_inDeclarationContext_classTypeAlias() { | |
| 595 SimpleIdentifier identifier = | |
| 596 AstFactory.classTypeAlias("C", null, null, null, null, null).name; | |
| 597 expect(identifier.inDeclarationContext(), isTrue); | |
| 598 } | |
| 599 | |
| 600 void test_inDeclarationContext_constructorDeclaration() { | |
| 601 SimpleIdentifier identifier = AstFactory | |
| 602 .constructorDeclaration(AstFactory.identifier3("C"), "c", null, null) | |
| 603 .name; | |
| 604 expect(identifier.inDeclarationContext(), isTrue); | |
| 605 } | |
| 606 | |
| 607 void test_inDeclarationContext_declaredIdentifier() { | |
| 608 DeclaredIdentifier declaredIdentifier = AstFactory.declaredIdentifier3("v"); | |
| 609 SimpleIdentifier identifier = declaredIdentifier.identifier; | |
| 610 expect(identifier.inDeclarationContext(), isTrue); | |
| 611 } | |
| 612 | |
| 613 void test_inDeclarationContext_enumConstantDeclaration() { | |
| 614 EnumDeclaration enumDeclaration = | |
| 615 AstFactory.enumDeclaration2('MyEnum', ['CONST']); | |
| 616 SimpleIdentifier identifier = enumDeclaration.constants[0].name; | |
| 617 expect(identifier.inDeclarationContext(), isTrue); | |
| 618 } | |
| 619 | |
| 620 void test_inDeclarationContext_enumDeclaration() { | |
| 621 EnumDeclaration enumDeclaration = | |
| 622 AstFactory.enumDeclaration2('MyEnum', ['A', 'B', 'C']); | |
| 623 SimpleIdentifier identifier = enumDeclaration.name; | |
| 624 expect(identifier.inDeclarationContext(), isTrue); | |
| 625 } | |
| 626 | |
| 627 void test_inDeclarationContext_fieldFormalParameter() { | |
| 628 SimpleIdentifier identifier = | |
| 629 AstFactory.fieldFormalParameter2("p").identifier; | |
| 630 expect(identifier.inDeclarationContext(), isFalse); | |
| 631 } | |
| 632 | |
| 633 void test_inDeclarationContext_functionDeclaration() { | |
| 634 SimpleIdentifier identifier = | |
| 635 AstFactory.functionDeclaration(null, null, "f", null).name; | |
| 636 expect(identifier.inDeclarationContext(), isTrue); | |
| 637 } | |
| 638 | |
| 639 void test_inDeclarationContext_functionTypeAlias() { | |
| 640 SimpleIdentifier identifier = | |
| 641 AstFactory.typeAlias(null, "F", null, null).name; | |
| 642 expect(identifier.inDeclarationContext(), isTrue); | |
| 643 } | |
| 644 | |
| 645 void test_inDeclarationContext_label_false() { | |
| 646 SimpleIdentifier identifier = | |
| 647 AstFactory.namedExpression2("l", AstFactory.integer(0)).name.label; | |
| 648 expect(identifier.inDeclarationContext(), isFalse); | |
| 649 } | |
| 650 | |
| 651 void test_inDeclarationContext_label_true() { | |
| 652 Label label = AstFactory.label2("l"); | |
| 653 SimpleIdentifier identifier = label.label; | |
| 654 AstFactory.labeledStatement([label], AstFactory.emptyStatement()); | |
| 655 expect(identifier.inDeclarationContext(), isTrue); | |
| 656 } | |
| 657 | |
| 658 void test_inDeclarationContext_methodDeclaration() { | |
| 659 SimpleIdentifier identifier = AstFactory.identifier3("m"); | |
| 660 AstFactory.methodDeclaration2( | |
| 661 null, null, null, null, identifier, null, null); | |
| 662 expect(identifier.inDeclarationContext(), isTrue); | |
| 663 } | |
| 664 | |
| 665 void test_inDeclarationContext_prefix() { | |
| 666 SimpleIdentifier identifier = | |
| 667 AstFactory.importDirective3("uri", "pref").prefix; | |
| 668 expect(identifier.inDeclarationContext(), isTrue); | |
| 669 } | |
| 670 | |
| 671 void test_inDeclarationContext_simpleFormalParameter() { | |
| 672 SimpleIdentifier identifier = | |
| 673 AstFactory.simpleFormalParameter3("p").identifier; | |
| 674 expect(identifier.inDeclarationContext(), isTrue); | |
| 675 } | |
| 676 | |
| 677 void test_inDeclarationContext_typeParameter_bound() { | |
| 678 TypeName bound = AstFactory.typeName4("A"); | |
| 679 SimpleIdentifier identifier = bound.name as SimpleIdentifier; | |
| 680 AstFactory.typeParameter2("E", bound); | |
| 681 expect(identifier.inDeclarationContext(), isFalse); | |
| 682 } | |
| 683 | |
| 684 void test_inDeclarationContext_typeParameter_name() { | |
| 685 SimpleIdentifier identifier = AstFactory.typeParameter("E").name; | |
| 686 expect(identifier.inDeclarationContext(), isTrue); | |
| 687 } | |
| 688 | |
| 689 void test_inDeclarationContext_variableDeclaration() { | |
| 690 SimpleIdentifier identifier = AstFactory.variableDeclaration("v").name; | |
| 691 expect(identifier.inDeclarationContext(), isTrue); | |
| 692 } | |
| 693 | |
| 694 void test_inGetterContext() { | 576 void test_inGetterContext() { |
| 695 for (_WrapperKind wrapper in _WrapperKind.values) { | 577 for (_WrapperKind wrapper in _WrapperKind.values) { |
| 696 for (_AssignmentKind assignment in _AssignmentKind.values) { | 578 for (_AssignmentKind assignment in _AssignmentKind.values) { |
| 697 SimpleIdentifier identifier = _createIdentifier(wrapper, assignment); | 579 SimpleIdentifier identifier = _createIdentifier(wrapper, assignment); |
| 698 if (assignment == _AssignmentKind.SIMPLE_LEFT && | 580 if (assignment == _AssignmentKind.SIMPLE_LEFT && |
| 699 wrapper != _WrapperKind.PREFIXED_LEFT && | 581 wrapper != _WrapperKind.PREFIXED_LEFT && |
| 700 wrapper != _WrapperKind.PROPERTY_LEFT) { | 582 wrapper != _WrapperKind.PROPERTY_LEFT) { |
| 701 if (identifier.inGetterContext()) { | 583 if (identifier.inGetterContext()) { |
| 702 fail("Expected ${_topMostNode(identifier).toSource()} to be false"); | 584 fail("Expected ${_topMostNode(identifier).toSource()} to be false"); |
| 703 } | 585 } |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 final int ordinal; | 1220 final int ordinal; |
| 1339 | 1221 |
| 1340 const _WrapperKind(this.name, this.ordinal); | 1222 const _WrapperKind(this.name, this.ordinal); |
| 1341 | 1223 |
| 1342 int get hashCode => ordinal; | 1224 int get hashCode => ordinal; |
| 1343 | 1225 |
| 1344 int compareTo(_WrapperKind other) => ordinal - other.ordinal; | 1226 int compareTo(_WrapperKind other) => ordinal - other.ordinal; |
| 1345 | 1227 |
| 1346 String toString() => name; | 1228 String toString() => name; |
| 1347 } | 1229 } |
| OLD | NEW |