| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.src.summary.summary_common; | 5 library analyzer.test.src.summary.summary_common; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 // summarize_elements.dart isn't yet able to record the prefix of | 498 // summarize_elements.dart isn't yet able to record the prefix of |
| 499 // unresolved references. TODO(paulberry): fix this. | 499 // unresolved references. TODO(paulberry): fix this. |
| 500 expect(reference.prefixReference, 0); | 500 expect(reference.prefixReference, 0); |
| 501 } else if (expectedPrefix != null) { | 501 } else if (expectedPrefix != null) { |
| 502 checkPrefix(reference.prefixReference, expectedPrefix); | 502 checkPrefix(reference.prefixReference, expectedPrefix); |
| 503 } else if (prefixExpectations != null) { | 503 } else if (prefixExpectations != null) { |
| 504 for (_PrefixExpectation expectation in prefixExpectations) { | 504 for (_PrefixExpectation expectation in prefixExpectations) { |
| 505 expect(reference.prefixReference, isNot(0)); | 505 expect(reference.prefixReference, isNot(0)); |
| 506 reference = checkTypeRefCommonElements( | 506 reference = checkTypeRefCommonElements( |
| 507 reference.prefixReference, | 507 reference.prefixReference, |
| 508 expectation.inLibraryDefiningUnit ? null : absoluteUri, | 508 expectation.inLibraryDefiningUnit |
| 509 expectation.inLibraryDefiningUnit ? null : relativeUri, | 509 ? null |
| 510 : expectation.absoluteUri ?? absoluteUri, |
| 511 expectation.inLibraryDefiningUnit |
| 512 ? null |
| 513 : expectation.relativeUri ?? relativeUri, |
| 510 expectation.name, | 514 expectation.name, |
| 511 expectation.kind, | 515 expectation.kind, |
| 512 expectedTargetUnit, | 516 expectedTargetUnit, |
| 513 linkedSourceUnit, | 517 linkedSourceUnit, |
| 514 unlinkedSourceUnit, | 518 unlinkedSourceUnit, |
| 515 expectation.numTypeParameters); | 519 expectation.numTypeParameters); |
| 516 } | 520 } |
| 517 expect(reference.prefixReference, 0); | 521 expect(reference.prefixReference, 0); |
| 518 } else { | 522 } else { |
| 519 expect(reference.prefixReference, 0); | 523 expect(reference.prefixReference, 0); |
| (...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1717 ], referenceValidators: [ | 1721 ], referenceValidators: [ |
| 1718 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'C', | 1722 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'C', |
| 1719 expectedKind: ReferenceKind.classOrEnum, | 1723 expectedKind: ReferenceKind.classOrEnum, |
| 1720 prefixExpectations: [ | 1724 prefixExpectations: [ |
| 1721 new _PrefixExpectation(ReferenceKind.prefix, 'p', | 1725 new _PrefixExpectation(ReferenceKind.prefix, 'p', |
| 1722 inLibraryDefiningUnit: true) | 1726 inLibraryDefiningUnit: true) |
| 1723 ]) | 1727 ]) |
| 1724 ]); | 1728 ]); |
| 1725 } | 1729 } |
| 1726 | 1730 |
| 1727 test_constExpr_length() { | 1731 test_constExpr_length_classConstField() { |
| 1732 UnlinkedVariable variable = serializeVariableText(''' |
| 1733 class C { |
| 1734 static const int length = 0; |
| 1735 } |
| 1736 const int v = C.length; |
| 1737 '''); |
| 1738 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 1739 UnlinkedConstOperation.pushReference |
| 1740 ], referenceValidators: [ |
| 1741 (EntityRef r) => checkTypeRef(r, null, null, 'length', |
| 1742 expectedKind: ReferenceKind.constField, |
| 1743 prefixExpectations: [ |
| 1744 new _PrefixExpectation(ReferenceKind.classOrEnum, 'C') |
| 1745 ]) |
| 1746 ]); |
| 1747 } |
| 1748 |
| 1749 test_constExpr_length_classConstField_imported_withPrefix() { |
| 1750 addNamedSource( |
| 1751 '/a.dart', |
| 1752 ''' |
| 1753 class C { |
| 1754 static const int length = 0; |
| 1755 } |
| 1756 '''); |
| 1757 UnlinkedVariable variable = serializeVariableText(''' |
| 1758 import 'a.dart' as p; |
| 1759 const int v = p.C.length; |
| 1760 '''); |
| 1761 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 1762 UnlinkedConstOperation.pushReference |
| 1763 ], referenceValidators: [ |
| 1764 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'length', |
| 1765 expectedKind: ReferenceKind.constField, |
| 1766 prefixExpectations: [ |
| 1767 new _PrefixExpectation(ReferenceKind.classOrEnum, 'C', |
| 1768 absoluteUri: absUri('/a.dart'), relativeUri: 'a.dart'), |
| 1769 new _PrefixExpectation(ReferenceKind.prefix, 'p', |
| 1770 inLibraryDefiningUnit: true) |
| 1771 ]) |
| 1772 ]); |
| 1773 } |
| 1774 |
| 1775 test_constExpr_length_identifierTarget() { |
| 1776 UnlinkedVariable variable = serializeVariableText(''' |
| 1777 const String a = 'aaa'; |
| 1778 const int v = a.length; |
| 1779 '''); |
| 1780 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 1781 UnlinkedConstOperation.pushReference |
| 1782 ], referenceValidators: [ |
| 1783 (EntityRef r) => checkTypeRef(r, null, null, 'length', |
| 1784 expectedKind: ReferenceKind.length, |
| 1785 prefixExpectations: [ |
| 1786 new _PrefixExpectation( |
| 1787 ReferenceKind.topLevelPropertyAccessor, 'a') |
| 1788 ]) |
| 1789 ]); |
| 1790 } |
| 1791 |
| 1792 test_constExpr_length_identifierTarget_classConstField() { |
| 1793 UnlinkedVariable variable = serializeVariableText(''' |
| 1794 class C { |
| 1795 static const String F = ''; |
| 1796 } |
| 1797 const int v = C.F.length; |
| 1798 '''); |
| 1799 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 1800 UnlinkedConstOperation.pushReference |
| 1801 ], referenceValidators: [ |
| 1802 (EntityRef r) => checkTypeRef(r, null, null, 'length', |
| 1803 expectedKind: ReferenceKind.length, |
| 1804 prefixExpectations: [ |
| 1805 new _PrefixExpectation(ReferenceKind.constField, 'F'), |
| 1806 new _PrefixExpectation(ReferenceKind.classOrEnum, 'C'), |
| 1807 ]) |
| 1808 ]); |
| 1809 } |
| 1810 |
| 1811 test_constExpr_length_identifierTarget_imported() { |
| 1812 addNamedSource( |
| 1813 '/a.dart', |
| 1814 ''' |
| 1815 const String a = 'aaa'; |
| 1816 '''); |
| 1817 UnlinkedVariable variable = serializeVariableText(''' |
| 1818 import 'a.dart'; |
| 1819 const int v = a.length; |
| 1820 '''); |
| 1821 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 1822 UnlinkedConstOperation.pushReference |
| 1823 ], referenceValidators: [ |
| 1824 (EntityRef r) => checkTypeRef(r, null, null, 'length', |
| 1825 expectedKind: ReferenceKind.length, |
| 1826 prefixExpectations: [ |
| 1827 new _PrefixExpectation( |
| 1828 ReferenceKind.topLevelPropertyAccessor, 'a', |
| 1829 absoluteUri: absUri('/a.dart'), relativeUri: 'a.dart') |
| 1830 ]) |
| 1831 ]); |
| 1832 } |
| 1833 |
| 1834 test_constExpr_length_identifierTarget_imported_withPrefix() { |
| 1835 addNamedSource( |
| 1836 '/a.dart', |
| 1837 ''' |
| 1838 const String a = 'aaa'; |
| 1839 '''); |
| 1840 UnlinkedVariable variable = serializeVariableText(''' |
| 1841 import 'a.dart' as p; |
| 1842 const int v = p.a.length; |
| 1843 '''); |
| 1844 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 1845 UnlinkedConstOperation.pushReference |
| 1846 ], referenceValidators: [ |
| 1847 (EntityRef r) => checkTypeRef(r, null, null, 'length', |
| 1848 expectedKind: ReferenceKind.length, |
| 1849 prefixExpectations: [ |
| 1850 new _PrefixExpectation( |
| 1851 ReferenceKind.topLevelPropertyAccessor, 'a', |
| 1852 absoluteUri: absUri('/a.dart'), relativeUri: 'a.dart'), |
| 1853 new _PrefixExpectation(ReferenceKind.prefix, 'p', |
| 1854 inLibraryDefiningUnit: true) |
| 1855 ]) |
| 1856 ]); |
| 1857 } |
| 1858 |
| 1859 test_constExpr_length_parenthesizedBinaryTarget() { |
| 1860 UnlinkedVariable variable = |
| 1861 serializeVariableText('const v = ("abc" + "edf").length;'); |
| 1862 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 1863 UnlinkedConstOperation.pushString, |
| 1864 UnlinkedConstOperation.pushString, |
| 1865 UnlinkedConstOperation.add, |
| 1866 UnlinkedConstOperation.length |
| 1867 ], strings: [ |
| 1868 'abc', |
| 1869 'edf' |
| 1870 ]); |
| 1871 } |
| 1872 |
| 1873 test_constExpr_length_parenthesizedStringTarget() { |
| 1874 UnlinkedVariable variable = |
| 1875 serializeVariableText('const v = ("abc").length;'); |
| 1876 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 1877 UnlinkedConstOperation.pushString, |
| 1878 UnlinkedConstOperation.length |
| 1879 ], strings: [ |
| 1880 'abc' |
| 1881 ]); |
| 1882 } |
| 1883 |
| 1884 test_constExpr_length_stringLiteralTarget() { |
| 1728 UnlinkedVariable variable = | 1885 UnlinkedVariable variable = |
| 1729 serializeVariableText('const v = "abc".length;'); | 1886 serializeVariableText('const v = "abc".length;'); |
| 1730 _assertUnlinkedConst(variable.constExpr, operators: [ | 1887 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 1731 UnlinkedConstOperation.pushString, | 1888 UnlinkedConstOperation.pushString, |
| 1732 UnlinkedConstOperation.length | 1889 UnlinkedConstOperation.length |
| 1733 ], strings: [ | 1890 ], strings: [ |
| 1734 'abc' | 1891 'abc' |
| 1735 ]); | 1892 ]); |
| 1736 } | 1893 } |
| 1737 | 1894 |
| (...skipping 3022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4760 } | 4917 } |
| 4761 } | 4918 } |
| 4762 | 4919 |
| 4763 /** | 4920 /** |
| 4764 * Description of expectations for a prelinked prefix reference. | 4921 * Description of expectations for a prelinked prefix reference. |
| 4765 */ | 4922 */ |
| 4766 class _PrefixExpectation { | 4923 class _PrefixExpectation { |
| 4767 final ReferenceKind kind; | 4924 final ReferenceKind kind; |
| 4768 final String name; | 4925 final String name; |
| 4769 final bool inLibraryDefiningUnit; | 4926 final bool inLibraryDefiningUnit; |
| 4927 final String absoluteUri; |
| 4928 final String relativeUri; |
| 4770 final int numTypeParameters; | 4929 final int numTypeParameters; |
| 4771 | 4930 |
| 4772 _PrefixExpectation(this.kind, this.name, | 4931 _PrefixExpectation(this.kind, this.name, |
| 4773 {this.inLibraryDefiningUnit: false, this.numTypeParameters: 0}); | 4932 {this.inLibraryDefiningUnit: false, |
| 4933 this.absoluteUri, |
| 4934 this.relativeUri, |
| 4935 this.numTypeParameters: 0}); |
| 4774 } | 4936 } |
| OLD | NEW |