Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: pkg/analyzer/test/src/summary/summary_common.dart

Issue 1642483002: Improve 'length' instance property reference encoding. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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_stringLiteralTarget() {
1728 UnlinkedVariable variable = 1860 UnlinkedVariable variable =
1729 serializeVariableText('const v = "abc".length;'); 1861 serializeVariableText('const v = "abc".length;');
Paul Berry 2016/01/27 16:48:59 Also add tests for the cases I mentioned earlier:
1730 _assertUnlinkedConst(variable.constExpr, operators: [ 1862 _assertUnlinkedConst(variable.constExpr, operators: [
1731 UnlinkedConstOperation.pushString, 1863 UnlinkedConstOperation.pushString,
1732 UnlinkedConstOperation.length 1864 UnlinkedConstOperation.length
1733 ], strings: [ 1865 ], strings: [
1734 'abc' 1866 'abc'
1735 ]); 1867 ]);
1736 } 1868 }
1737 1869
1738 test_constExpr_makeSymbol() { 1870 test_constExpr_makeSymbol() {
1739 UnlinkedVariable variable = serializeVariableText('const v = #a.bb.ccc;'); 1871 UnlinkedVariable variable = serializeVariableText('const v = #a.bb.ccc;');
(...skipping 3004 matching lines...) Expand 10 before | Expand all | Expand 10 after
4744 } 4876 }
4745 } 4877 }
4746 4878
4747 /** 4879 /**
4748 * Description of expectations for a prelinked prefix reference. 4880 * Description of expectations for a prelinked prefix reference.
4749 */ 4881 */
4750 class _PrefixExpectation { 4882 class _PrefixExpectation {
4751 final ReferenceKind kind; 4883 final ReferenceKind kind;
4752 final String name; 4884 final String name;
4753 final bool inLibraryDefiningUnit; 4885 final bool inLibraryDefiningUnit;
4886 final String absoluteUri;
4887 final String relativeUri;
4754 final int numTypeParameters; 4888 final int numTypeParameters;
4755 4889
4756 _PrefixExpectation(this.kind, this.name, 4890 _PrefixExpectation(this.kind, this.name,
4757 {this.inLibraryDefiningUnit: false, this.numTypeParameters: 0}); 4891 {this.inLibraryDefiningUnit: false,
4892 this.absoluteUri,
4893 this.relativeUri,
4894 this.numTypeParameters: 0});
4758 } 4895 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698