| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:convert'; | 5 import 'dart:convert'; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/src/summary/format.dart'; | 9 import 'package:analyzer/src/summary/format.dart'; |
| 10 import 'package:analyzer/src/summary/idl.dart'; | 10 import 'package:analyzer/src/summary/idl.dart'; |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 class A {} | 623 class A {} |
| 624 A myVariable = null; | 624 A myVariable = null; |
| 625 '''); | 625 '''); |
| 626 Element element = findElement('A'); | 626 Element element = findElement('A'); |
| 627 assertThat(element).isReferencedAt('A myVariable'); | 627 assertThat(element).isReferencedAt('A myVariable'); |
| 628 } | 628 } |
| 629 | 629 |
| 630 void test_usedName_isInvokedBy() { | 630 void test_usedName_isInvokedBy() { |
| 631 verifyNoTestUnitErrors = false; | 631 verifyNoTestUnitErrors = false; |
| 632 _indexTestUnit(''' | 632 _indexTestUnit(''' |
| 633 class A { | 633 class C { |
| 634 Function x; | 634 x() {} |
| 635 | 635 } |
| 636 m() { | 636 main(C c) { |
| 637 x(); // 1 | 637 x(); // nq |
| 638 this.x(); // 2 | 638 c.x(); // q |
| 639 y(); // 3 | 639 y(); // nq |
| 640 this.y(); // 4 | 640 c.y(); // q |
| 641 } | |
| 642 } | 641 } |
| 643 '''); | 642 '''); |
| 644 assertThatName('x') | 643 assertThatName('x') |
| 645 ..isInvokedAt('x(); // 1', isQualified: false) | 644 ..isNotInvokedAt('x(); // nq') |
| 646 ..isInvokedAt('x(); // 2'); | 645 ..isNotInvokedAt('x(); // q'); |
| 647 assertThatName('y') | 646 assertThatName('y') |
| 648 ..isInvokedAt('y(); // 3', isQualified: false, isResolved: false) | 647 ..isNotInvokedAt('y(); // nq') |
| 649 ..isInvokedAt('y(); // 4', isResolved: false); | 648 ..isInvokedAt('y(); // q'); |
| 650 } | 649 } |
| 651 | 650 |
| 652 void test_usedName_isReferencedBy() { | 651 void test_usedName_isReferencedBy() { |
| 653 verifyNoTestUnitErrors = false; | 652 verifyNoTestUnitErrors = false; |
| 654 _indexTestUnit(''' | 653 _indexTestUnit(''' |
| 655 class A { | 654 class C { |
| 656 int x; | 655 int x; |
| 657 | 656 } |
| 658 m() { | 657 main(C c) { |
| 659 x; // 1 | 658 x; // nq |
| 660 this.x; // 2 | 659 c.x; // q |
| 661 y; // 3 | 660 y; // nq |
| 662 this.y; // 4 | 661 c.y; // q |
| 663 } | |
| 664 } | 662 } |
| 665 '''); | 663 '''); |
| 666 assertThatName('x') | 664 assertThatName('x') |
| 667 ..isReferencedAt('x; // 1', isQualified: false) | 665 ..isNotReferencedAt('x; // nq') |
| 668 ..isReferencedAt('x; // 2'); | 666 ..isNotReferencedAt('x; // q'); |
| 669 assertThatName('y') | 667 assertThatName('y') |
| 670 ..isReferencedAt('y; // 3', isQualified: false, isResolved: false) | 668 ..isNotReferencedAt('y; // nq') |
| 671 ..isReferencedAt('y; // 4', isResolved: false); | 669 ..isReferencedAt('y; // q'); |
| 672 } | 670 } |
| 673 | 671 |
| 674 void _assertDefinedName(String name, IndexNameKind kind, String search) { | 672 void _assertDefinedName(String name, IndexNameKind kind, String search) { |
| 675 int offset = findOffset(search); | 673 int offset = findOffset(search); |
| 676 int nameId = _getStringId(name); | 674 int nameId = _getStringId(name); |
| 677 for (int i = 0; i < unitIndex.definedNames.length; i++) { | 675 for (int i = 0; i < unitIndex.definedNames.length; i++) { |
| 678 if (unitIndex.definedNames[i] == nameId && | 676 if (unitIndex.definedNames[i] == nameId && |
| 679 unitIndex.definedNameKinds[i] == kind && | 677 unitIndex.definedNameKinds[i] == kind && |
| 680 unitIndex.definedNameOffsets[i] == offset) { | 678 unitIndex.definedNameOffsets[i] == offset) { |
| 681 return; | 679 return; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 707 } | 705 } |
| 708 if (matchIndex != null && | 706 if (matchIndex != null && |
| 709 unitIndex.usedElementKinds[matchIndex] == expectedRelationKind) { | 707 unitIndex.usedElementKinds[matchIndex] == expectedRelationKind) { |
| 710 // TODO(scheglov) verify 'qualified' and 'resolved' | 708 // TODO(scheglov) verify 'qualified' and 'resolved' |
| 711 return; | 709 return; |
| 712 } | 710 } |
| 713 _failWithIndexDump( | 711 _failWithIndexDump( |
| 714 'not found\n$element $expectedRelationKind at $expectedLocation'); | 712 'not found\n$element $expectedRelationKind at $expectedLocation'); |
| 715 } | 713 } |
| 716 | 714 |
| 717 void _assertUsedName( | 715 void _assertUsedName(String name, IndexRelationKind kind, |
| 718 String name, IndexRelationKind kind, ExpectedLocation expectedLocation) { | 716 ExpectedLocation expectedLocation, bool isNot) { |
| 719 int nameId = _getStringId(name); | 717 int nameId = _getStringId(name); |
| 720 for (int i = 0; i < unitIndex.usedNames.length; i++) { | 718 for (int i = 0; i < unitIndex.usedNames.length; i++) { |
| 721 if (unitIndex.usedNames[i] == nameId && | 719 if (unitIndex.usedNames[i] == nameId && |
| 722 unitIndex.usedNameKinds[i] == kind && | 720 unitIndex.usedNameKinds[i] == kind && |
| 723 unitIndex.usedNameOffsets[i] == expectedLocation.offset) { | 721 unitIndex.usedNameOffsets[i] == expectedLocation.offset) { |
| 722 if (isNot) { |
| 723 _failWithIndexDump('Unexpected $name $kind at $expectedLocation'); |
| 724 } |
| 724 // TODO(scheglov) verify 'qualified' and 'resolved' | 725 // TODO(scheglov) verify 'qualified' and 'resolved' |
| 725 return; | 726 return; |
| 726 } | 727 } |
| 727 } | 728 } |
| 729 if (isNot) { |
| 730 return; |
| 731 } |
| 728 _failWithIndexDump('Not found $name $kind at $expectedLocation'); | 732 _failWithIndexDump('Not found $name $kind at $expectedLocation'); |
| 729 } | 733 } |
| 730 | 734 |
| 731 ExpectedLocation _expectedLocation(String search, | 735 ExpectedLocation _expectedLocation(String search, |
| 732 {int length, bool isQualified: false, bool isResolved: true}) { | 736 {int length, bool isQualified: false, bool isResolved: true}) { |
| 733 int offset = findOffset(search); | 737 int offset = findOffset(search); |
| 734 if (length == null) { | 738 if (length == null) { |
| 735 length = getLeadingIdentifierLength(search); | 739 length = getLeadingIdentifierLength(search); |
| 736 } | 740 } |
| 737 return new ExpectedLocation( | 741 return new ExpectedLocation( |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 test._expectedLocation(search, length: length)); | 858 test._expectedLocation(search, length: length)); |
| 855 } | 859 } |
| 856 } | 860 } |
| 857 | 861 |
| 858 class _NameIndexAssert { | 862 class _NameIndexAssert { |
| 859 final PackageIndexAssemblerTest test; | 863 final PackageIndexAssemblerTest test; |
| 860 final String name; | 864 final String name; |
| 861 | 865 |
| 862 _NameIndexAssert(this.test, this.name); | 866 _NameIndexAssert(this.test, this.name); |
| 863 | 867 |
| 864 void isInvokedAt(String search, | 868 void isInvokedAt(String search, {int length}) { |
| 865 {int length, bool isQualified: true, bool isResolved: true}) { | 869 test._assertUsedName(name, IndexRelationKind.IS_INVOKED_BY, |
| 866 test._assertUsedName( | 870 test._expectedLocation(search, length: length), false); |
| 867 name, | |
| 868 IndexRelationKind.IS_INVOKED_BY, | |
| 869 test._expectedLocation(search, | |
| 870 length: length, isQualified: isQualified, isResolved: isResolved)); | |
| 871 } | 871 } |
| 872 | 872 |
| 873 void isReferencedAt(String search, | 873 void isNotInvokedAt(String search, {int length}) { |
| 874 {int length, bool isQualified: true, bool isResolved: true}) { | 874 test._assertUsedName(name, IndexRelationKind.IS_INVOKED_BY, |
| 875 test._assertUsedName( | 875 test._expectedLocation(search, length: length), true); |
| 876 name, | 876 } |
| 877 IndexRelationKind.IS_REFERENCED_BY, | 877 |
| 878 test._expectedLocation(search, | 878 void isNotReferencedAt(String search, {int length}) { |
| 879 length: length, isQualified: isQualified, isResolved: isResolved)); | 879 test._assertUsedName(name, IndexRelationKind.IS_REFERENCED_BY, |
| 880 test._expectedLocation(search, length: length), true); |
| 881 } |
| 882 |
| 883 void isReferencedAt(String search, {int length}) { |
| 884 test._assertUsedName(name, IndexRelationKind.IS_REFERENCED_BY, |
| 885 test._expectedLocation(search, length: length), false); |
| 880 } | 886 } |
| 881 } | 887 } |
| OLD | NEW |