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

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

Issue 1468583002: Add a unit index to prelinked type references in summaries. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove an unnecessary TODO. Created 5 years, 1 month 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 test.src.serialization.elements_test; 5 library test.src.serialization.elements_test;
6 6
7 import 'dart:typed_data'; 7 import 'dart:typed_data';
8 8
9 import 'package:analyzer/src/generated/element.dart'; 9 import 'package:analyzer/src/generated/element.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 * in a file reachable via [absoluteUri] and [relativeUri], having name 203 * in a file reachable via [absoluteUri] and [relativeUri], having name
204 * [expectedName]. If [expectedPrefix] is supplied, verify that the type is 204 * [expectedName]. If [expectedPrefix] is supplied, verify that the type is
205 * reached via the given prefix. If [allowTypeParameters] is true, allow the 205 * reached via the given prefix. If [allowTypeParameters] is true, allow the
206 * type reference to supply type parameters. [expectedKind] is the kind of 206 * type reference to supply type parameters. [expectedKind] is the kind of
207 * object referenced. 207 * object referenced.
208 */ 208 */
209 void checkTypeRef(UnlinkedTypeRef typeRef, String absoluteUri, 209 void checkTypeRef(UnlinkedTypeRef typeRef, String absoluteUri,
210 String relativeUri, String expectedName, 210 String relativeUri, String expectedName,
211 {String expectedPrefix, 211 {String expectedPrefix,
212 bool allowTypeParameters: false, 212 bool allowTypeParameters: false,
213 PrelinkedReferenceKind expectedKind: 213 PrelinkedReferenceKind expectedKind: PrelinkedReferenceKind.classOrEnum,
214 PrelinkedReferenceKind.classOrEnum}) { 214 int expectedUnit: 0}) {
215 expect(typeRef, new isInstanceOf<UnlinkedTypeRef>()); 215 expect(typeRef, new isInstanceOf<UnlinkedTypeRef>());
216 expect(typeRef.paramReference, 0); 216 expect(typeRef.paramReference, 0);
217 int index = typeRef.reference; 217 int index = typeRef.reference;
218 UnlinkedReference reference = unlinked.references[index]; 218 UnlinkedReference reference = unlinked.references[index];
219 PrelinkedReference referenceResolution = lib.references[index]; 219 PrelinkedReference referenceResolution = lib.references[index];
220 if (absoluteUri == null) { 220 if (absoluteUri == null) {
221 expect(referenceResolution.dependency, 0); 221 expect(referenceResolution.dependency, 0);
222 } else { 222 } else {
223 checkDependency(referenceResolution.dependency, absoluteUri, relativeUri); 223 checkDependency(referenceResolution.dependency, absoluteUri, relativeUri);
224 } 224 }
225 if (!allowTypeParameters) { 225 if (!allowTypeParameters) {
226 expect(typeRef.typeArguments, isEmpty); 226 expect(typeRef.typeArguments, isEmpty);
227 } 227 }
228 if (expectedName == null) { 228 if (expectedName == null) {
229 expect(reference.name, isEmpty); 229 expect(reference.name, isEmpty);
230 } else { 230 } else {
231 expect(reference.name, expectedName); 231 expect(reference.name, expectedName);
232 } 232 }
233 if (checkAstDerivedData) { 233 if (checkAstDerivedData) {
234 if (expectedPrefix == null) { 234 if (expectedPrefix == null) {
235 expect(reference.prefix, 0); 235 expect(reference.prefix, 0);
236 expect(unlinked.prefixes[reference.prefix].name, isEmpty); 236 expect(unlinked.prefixes[reference.prefix].name, isEmpty);
237 } else { 237 } else {
238 expect(reference.prefix, isNot(0)); 238 expect(reference.prefix, isNot(0));
239 expect(unlinked.prefixes[reference.prefix].name, expectedPrefix); 239 expect(unlinked.prefixes[reference.prefix].name, expectedPrefix);
240 } 240 }
241 } 241 }
242 expect(referenceResolution.kind, expectedKind); 242 expect(referenceResolution.kind, expectedKind);
243 expect(referenceResolution.unit, expectedUnit);
243 } 244 }
244 245
245 /** 246 /**
246 * Verify that the given [typeRef] represents a reference to an unresolved 247 * Verify that the given [typeRef] represents a reference to an unresolved
247 * type. 248 * type.
248 */ 249 */
249 void checkUnresolvedTypeRef( 250 void checkUnresolvedTypeRef(
250 UnlinkedTypeRef typeRef, String expectedPrefix, String expectedName) { 251 UnlinkedTypeRef typeRef, String expectedPrefix, String expectedName) {
251 // When serializing from the element model, unresolved type refs lose their 252 // When serializing from the element model, unresolved type refs lose their
252 // name. 253 // name.
(...skipping 1399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 } 1653 }
1653 1654
1654 test_type_reference_to_imported_part() { 1655 test_type_reference_to_imported_part() {
1655 addNamedSource('/a.dart', 'library my.lib; part "b.dart";'); 1656 addNamedSource('/a.dart', 'library my.lib; part "b.dart";');
1656 addNamedSource('/b.dart', 'part of my.lib; class C {}'); 1657 addNamedSource('/b.dart', 'part of my.lib; class C {}');
1657 checkTypeRef( 1658 checkTypeRef(
1658 serializeTypeText('C', 1659 serializeTypeText('C',
1659 otherDeclarations: 'library my.lib; import "a.dart";'), 1660 otherDeclarations: 'library my.lib; import "a.dart";'),
1660 absUri('/a.dart'), 1661 absUri('/a.dart'),
1661 'a.dart', 1662 'a.dart',
1662 'C'); 1663 'C',
1664 expectedUnit: 1);
1663 } 1665 }
1664 1666
1665 test_type_reference_to_imported_part_with_prefix() { 1667 test_type_reference_to_imported_part_with_prefix() {
1666 addNamedSource('/a.dart', 'library my.lib; part "b.dart";'); 1668 addNamedSource('/a.dart', 'library my.lib; part "b.dart";');
1667 addNamedSource('/b.dart', 'part of my.lib; class C {}'); 1669 addNamedSource('/b.dart', 'part of my.lib; class C {}');
1668 checkTypeRef( 1670 checkTypeRef(
1669 serializeTypeText('p.C', 1671 serializeTypeText('p.C',
1670 otherDeclarations: 'library my.lib; import "a.dart" as p;'), 1672 otherDeclarations: 'library my.lib; import "a.dart" as p;'),
1671 absUri('/a.dart'), 1673 absUri('/a.dart'),
1672 'a.dart', 1674 'a.dart',
1673 'C', 1675 'C',
1674 expectedPrefix: 'p'); 1676 expectedPrefix: 'p',
1677 expectedUnit: 1);
1675 } 1678 }
1676 1679
1677 test_type_reference_to_internal_class() { 1680 test_type_reference_to_internal_class() {
1678 checkTypeRef(serializeTypeText('C', otherDeclarations: 'class C {}'), null, 1681 checkTypeRef(serializeTypeText('C', otherDeclarations: 'class C {}'), null,
1679 null, 'C'); 1682 null, 'C');
1680 } 1683 }
1681 1684
1682 test_type_reference_to_internal_class_alias() { 1685 test_type_reference_to_internal_class_alias() {
1683 checkTypeRef( 1686 checkTypeRef(
1684 serializeTypeText('C', 1687 serializeTypeText('C',
1685 otherDeclarations: 'class C = D with E; class D {} class E {}'), 1688 otherDeclarations: 'class C = D with E; class D {} class E {}'),
1686 null, 1689 null,
1687 null, 1690 null,
1688 'C'); 1691 'C');
1689 } 1692 }
1690 1693
1691 test_type_reference_to_internal_enum() { 1694 test_type_reference_to_internal_enum() {
1692 checkTypeRef(serializeTypeText('E', otherDeclarations: 'enum E { value }'), 1695 checkTypeRef(serializeTypeText('E', otherDeclarations: 'enum E { value }'),
1693 null, null, 'E'); 1696 null, null, 'E');
1694 } 1697 }
1695 1698
1696 test_type_reference_to_local_part() { 1699 test_type_reference_to_local_part() {
1697 addNamedSource('/a.dart', 'part of my.lib; class C {}'); 1700 addNamedSource('/a.dart', 'part of my.lib; class C {}');
1698 checkTypeRef( 1701 checkTypeRef(
1699 serializeTypeText('C', 1702 serializeTypeText('C',
1700 otherDeclarations: 'library my.lib; part "a.dart";'), 1703 otherDeclarations: 'library my.lib; part "a.dart";'),
1701 null, 1704 null,
1702 null, 1705 null,
1703 'C'); 1706 'C',
1707 expectedUnit: 1);
1704 } 1708 }
1705 1709
1706 test_type_reference_to_nonexistent_file_via_prefix() { 1710 test_type_reference_to_nonexistent_file_via_prefix() {
1707 UnlinkedTypeRef typeRef = serializeTypeText('p.C', 1711 UnlinkedTypeRef typeRef = serializeTypeText('p.C',
1708 otherDeclarations: 'import "foo.dart" as p;', allowErrors: true); 1712 otherDeclarations: 'import "foo.dart" as p;', allowErrors: true);
1709 checkUnresolvedTypeRef(typeRef, 'p', 'C'); 1713 checkUnresolvedTypeRef(typeRef, 'p', 'C');
1710 } 1714 }
1711 1715
1712 test_type_reference_to_typedef() { 1716 test_type_reference_to_typedef() {
1713 checkTypeRef(serializeTypeText('F', otherDeclarations: 'typedef void F();'), 1717 checkTypeRef(serializeTypeText('F', otherDeclarations: 'typedef void F();'),
1714 null, null, 'F', 1718 null, null, 'F',
1715 expectedKind: PrelinkedReferenceKind.typedef); 1719 expectedKind: PrelinkedReferenceKind.typedef);
1716 } 1720 }
1717 1721
1718 test_type_unit_counts_unreferenced_units() { 1722 test_type_unit_counts_unreferenced_units() {
1719 addNamedSource('/a.dart', 'library a; part "b.dart"; part "c.dart";'); 1723 addNamedSource('/a.dart', 'library a; part "b.dart"; part "c.dart";');
1720 addNamedSource('/b.dart', 'part of a;'); 1724 addNamedSource('/b.dart', 'part of a;');
1721 addNamedSource('/c.dart', 'part of a; class C {}'); 1725 addNamedSource('/c.dart', 'part of a; class C {}');
1722 UnlinkedTypeRef typeRef = 1726 UnlinkedTypeRef typeRef =
1723 serializeTypeText('C', otherDeclarations: 'import "a.dart";'); 1727 serializeTypeText('C', otherDeclarations: 'import "a.dart";');
1724 // The referenced unit should be 2, since unit 0 is a.dart and unit 1 is 1728 // The referenced unit should be 2, since unit 0 is a.dart and unit 1 is
1725 // b.dart. a.dart and b.dart are counted even though nothing is imported 1729 // b.dart. a.dart and b.dart are counted even though nothing is imported
1726 // from them. 1730 // from them.
1727 checkTypeRef(typeRef, absUri('/a.dart'), 'a.dart', 'C'); 1731 checkTypeRef(typeRef, absUri('/a.dart'), 'a.dart', 'C', expectedUnit: 2);
1728 } 1732 }
1729 1733
1730 test_type_unresolved() { 1734 test_type_unresolved() {
1731 UnlinkedTypeRef typeRef = serializeTypeText('Foo', allowErrors: true); 1735 UnlinkedTypeRef typeRef = serializeTypeText('Foo', allowErrors: true);
1732 checkUnresolvedTypeRef(typeRef, null, 'Foo'); 1736 checkUnresolvedTypeRef(typeRef, null, 'Foo');
1733 } 1737 }
1734 1738
1735 test_typedef_name() { 1739 test_typedef_name() {
1736 UnlinkedTypedef type = serializeTypedefText('typedef F();'); 1740 UnlinkedTypedef type = serializeTypedefText('typedef F();');
1737 expect(type.name, 'F'); 1741 expect(type.name, 'F');
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 serializeClassText('class C { static int i; }').fields[0]; 1849 serializeClassText('class C { static int i; }').fields[0];
1846 expect(variable.isStatic, isTrue); 1850 expect(variable.isStatic, isTrue);
1847 } 1851 }
1848 1852
1849 test_variable_type() { 1853 test_variable_type() {
1850 UnlinkedVariable variable = 1854 UnlinkedVariable variable =
1851 serializeVariableText('int i;', variableName: 'i'); 1855 serializeVariableText('int i;', variableName: 'i');
1852 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); 1856 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int');
1853 } 1857 }
1854 } 1858 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_elements.dart ('k') | pkg/analyzer/tool/summary/idl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698