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

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

Issue 1610043002: Add propagated types to summary files. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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_test; 5 library analyzer.test.src.summary.summary_test;
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 */ 130 */
131 @reflectiveTest 131 @reflectiveTest
132 class PrelinkerTest extends SummarizeElementsTest { 132 class PrelinkerTest extends SummarizeElementsTest {
133 final Map<String, UnlinkedPublicNamespace> uriToPublicNamespace = 133 final Map<String, UnlinkedPublicNamespace> uriToPublicNamespace =
134 <String, UnlinkedPublicNamespace>{}; 134 <String, UnlinkedPublicNamespace>{};
135 135
136 @override 136 @override
137 bool get expectAbsoluteUrisInDependencies => false; 137 bool get expectAbsoluteUrisInDependencies => false;
138 138
139 @override 139 @override
140 bool get skipFullyLinkedData => true;
141
142 @override
140 Source addNamedSource(String filePath, String contents) { 143 Source addNamedSource(String filePath, String contents) {
141 Source source = super.addNamedSource(filePath, contents); 144 Source source = super.addNamedSource(filePath, contents);
142 uriToPublicNamespace[absUri(filePath)] = 145 uriToPublicNamespace[absUri(filePath)] =
143 computePublicNamespaceFromText(contents, source); 146 computePublicNamespaceFromText(contents, source);
144 return source; 147 return source;
145 } 148 }
146 149
147 String resolveToAbsoluteUri(LibraryElement library, String relativeUri) { 150 String resolveToAbsoluteUri(LibraryElement library, String relativeUri) {
148 Source resolvedSource = 151 Source resolvedSource =
149 analysisContext.sourceFactory.resolveUri(library.source, relativeUri); 152 analysisContext.sourceFactory.resolveUri(library.source, relativeUri);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 @override 214 @override
212 List<UnlinkedUnit> unlinkedUnits; 215 List<UnlinkedUnit> unlinkedUnits;
213 216
214 @override 217 @override
215 bool get checkAstDerivedData => false; 218 bool get checkAstDerivedData => false;
216 219
217 @override 220 @override
218 bool get expectAbsoluteUrisInDependencies => true; 221 bool get expectAbsoluteUrisInDependencies => true;
219 222
220 @override 223 @override
224 bool get skipFullyLinkedData => false;
225
226 @override
221 Source addNamedSource(String filePath, String contents) { 227 Source addNamedSource(String filePath, String contents) {
222 Source source = super.addNamedSource(filePath, contents); 228 Source source = super.addNamedSource(filePath, contents);
223 _fileContents[source] = contents; 229 _fileContents[source] = contents;
224 return source; 230 return source;
225 } 231 }
226 232
227 /** 233 /**
228 * Serialize the library containing the given class [element], then 234 * Serialize the library containing the given class [element], then
229 * deserialize it and return the summary of the class. 235 * deserialize it and return the summary of the class.
230 */ 236 */
(...skipping 26 matching lines...) Expand all
257 _fileContents[source] = text; 263 _fileContents[source] = text;
258 LibraryElement library = resolve2(source); 264 LibraryElement library = resolve2(source);
259 if (!allowErrors) { 265 if (!allowErrors) {
260 assertNoErrors(source); 266 assertNoErrors(source);
261 } 267 }
262 serializeLibraryElement(library); 268 serializeLibraryElement(library);
263 expect(unlinkedUnits[0].imports.length, linked.importDependencies.length); 269 expect(unlinkedUnits[0].imports.length, linked.importDependencies.length);
264 expect(linked.units.length, unlinkedUnits.length); 270 expect(linked.units.length, unlinkedUnits.length);
265 for (int i = 0; i < linked.units.length; i++) { 271 for (int i = 0; i < linked.units.length; i++) {
266 expect(unlinkedUnits[i].references.length, 272 expect(unlinkedUnits[i].references.length,
267 linked.units[i].references.length); 273 lessThanOrEqualTo(linked.units[i].references.length));
268 } 274 }
269 verifyPublicNamespace(); 275 verifyPublicNamespace();
270 } 276 }
271 277
272 @override 278 @override
273 void setUp() { 279 void setUp() {
274 super.setUp(); 280 super.setUp();
275 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 281 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
276 options.enableGenericMethods = true; 282 options.enableGenericMethods = true;
277 resetWithOptions(options); 283 resetWithOptions(options);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 */ 346 */
341 bool get expectAbsoluteUrisInDependencies; 347 bool get expectAbsoluteUrisInDependencies;
342 348
343 /** 349 /**
344 * Get access to the linked summary that results from serializing and 350 * Get access to the linked summary that results from serializing and
345 * then deserializing the library under test. 351 * then deserializing the library under test.
346 */ 352 */
347 LinkedLibrary get linked; 353 LinkedLibrary get linked;
348 354
349 /** 355 /**
356 * `true` if the linked portion of the summary only contains prelinked data.
357 * This happens because we don't yet have a full linker; only a prelinker.
358 */
359 bool get skipFullyLinkedData;
360
361 /**
350 * Get access to the unlinked compilation unit summaries that result from 362 * Get access to the unlinked compilation unit summaries that result from
351 * serializing and deserializing the library under test. 363 * serializing and deserializing the library under test.
352 */ 364 */
353 List<UnlinkedUnit> get unlinkedUnits; 365 List<UnlinkedUnit> get unlinkedUnits;
354 366
355 /** 367 /**
356 * Convert [path] to a suitably formatted absolute path URI for the current 368 * Convert [path] to a suitably formatted absolute path URI for the current
357 * platform. 369 * platform.
358 */ 370 */
359 String absUri(String path) { 371 String absUri(String path) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 // Exported names must come from other libraries. 453 // Exported names must come from other libraries.
442 expect(exportName.dependency, isNot(0)); 454 expect(exportName.dependency, isNot(0));
443 checkDependency(exportName.dependency, absoluteUri, relativeUri); 455 checkDependency(exportName.dependency, absoluteUri, relativeUri);
444 expect(exportName.name, expectedName); 456 expect(exportName.name, expectedName);
445 expect(exportName.kind, expectedKind); 457 expect(exportName.kind, expectedKind);
446 expect(exportName.unit, expectedTargetUnit); 458 expect(exportName.unit, expectedTargetUnit);
447 } 459 }
448 460
449 /** 461 /**
450 * Verify that the dependency table contains an entry for a file reachable 462 * Verify that the dependency table contains an entry for a file reachable
451 * via the given [absoluteUri] and [relativeUri]. 463 * via the given [absoluteUri] and [relativeUri]. If [fullyLinked] is
464 * `true`, then the dependency should be a fully-linked dependency; otherwise
465 * it should be a prelinked dependency.
452 * 466 *
453 * The [LinkedDependency] is returned. 467 * The index of the [LinkedDependency] is returned.
454 */ 468 */
455 LinkedDependency checkHasDependency(String absoluteUri, String relativeUri) { 469 int checkHasDependency(String absoluteUri, String relativeUri,
470 {bool fullyLinked: false}) {
456 if (expectAbsoluteUrisInDependencies) { 471 if (expectAbsoluteUrisInDependencies) {
457 // The element model doesn't (yet) store enough information to recover 472 // The element model doesn't (yet) store enough information to recover
458 // relative URIs, so we have to use the absolute URI. 473 // relative URIs, so we have to use the absolute URI.
459 // TODO(paulberry): fix this. 474 // TODO(paulberry): fix this.
460 relativeUri = absoluteUri; 475 relativeUri = absoluteUri;
461 } 476 }
462 List<String> found = <String>[]; 477 List<String> found = <String>[];
463 for (LinkedDependency dep in linked.dependencies) { 478 for (int i = 0; i < linked.dependencies.length; i++) {
479 LinkedDependency dep = linked.dependencies[i];
464 if (dep.uri == relativeUri) { 480 if (dep.uri == relativeUri) {
465 return dep; 481 if (fullyLinked) {
482 expect(i, greaterThanOrEqualTo(linked.numPrelinkedDependencies));
483 } else {
484 expect(i, lessThan(linked.numPrelinkedDependencies));
485 }
486 return i;
466 } 487 }
467 found.add(dep.uri); 488 found.add(dep.uri);
468 } 489 }
469 fail('Did not find dependency $relativeUri. Found: $found'); 490 fail('Did not find dependency $relativeUri. Found: $found');
470 return null; 491 return null;
471 } 492 }
472 493
473 /** 494 /**
474 * Verify that the dependency table *does not* contain any entries for a file 495 * Verify that the dependency table *does not* contain any entries for a file
475 * reachable via the given [absoluteUri] and [relativeUri]. 496 * reachable via the given [absoluteUri] and [relativeUri].
476 */ 497 */
477 void checkLacksDependency(String absoluteUri, String relativeUri) { 498 void checkLacksDependency(String absoluteUri, String relativeUri) {
478 if (expectAbsoluteUrisInDependencies) { 499 if (expectAbsoluteUrisInDependencies) {
479 // The element model doesn't (yet) store enough information to recover 500 // The element model doesn't (yet) store enough information to recover
480 // relative URIs, so we have to use the absolute URI. 501 // relative URIs, so we have to use the absolute URI.
481 // TODO(paulberry): fix this. 502 // TODO(paulberry): fix this.
482 relativeUri = absoluteUri; 503 relativeUri = absoluteUri;
483 } 504 }
484 for (LinkedDependency dep in linked.dependencies) { 505 for (LinkedDependency dep in linked.dependencies) {
485 if (dep.uri == relativeUri) { 506 if (dep.uri == relativeUri) {
486 fail('Unexpected dependency found: $relativeUri'); 507 fail('Unexpected dependency found: $relativeUri');
487 } 508 }
488 } 509 }
489 } 510 }
490 511
491 /** 512 /**
513 * Verify that the given [typeRef] represents a reference to a type declared
514 * in a file reachable via [absoluteUri] and [relativeUri], having name
515 * [expectedName]. If [allowTypeParameters] is true, allow the type
516 * reference to supply type parameters. [expectedKind] is the kind of object
517 * referenced. [linkedSourceUnit] and [unlinkedSourceUnit] refer to the
518 * compilation unit within which the [typeRef] appears; if not specified they
519 * are assumed to refer to the defining compilation unit.
520 * [expectedTargetUnit] is the index of the compilation unit in which the
521 * target of the [typeRef] is expected to appear; if not specified it is
522 * assumed to be the defining compilation unit. [numTypeParameters] is the
523 * number of type parameters of the thing being referred to.
524 */
525 void checkLinkedTypeRef(TypeRef typeRef, String absoluteUri,
526 String relativeUri, String expectedName,
527 {bool allowTypeParameters: false,
528 ReferenceKind expectedKind: ReferenceKind.classOrEnum,
529 int expectedTargetUnit: 0,
530 LinkedUnit linkedSourceUnit,
531 UnlinkedUnit unlinkedSourceUnit,
532 int numTypeParameters: 0}) {
533 linkedSourceUnit ??= definingUnit;
534 expect(typeRef, isNotNull,
535 reason: 'No entry in linkedSourceUnit.types matching slotId');
536 expect(typeRef.paramReference, 0);
537 int index = typeRef.reference;
538 if (!allowTypeParameters) {
539 expect(typeRef.typeArguments, isEmpty);
540 }
541 checkTypeRefCommonElements(
542 index,
543 absoluteUri,
544 relativeUri,
545 expectedName,
546 expectedKind,
547 expectedTargetUnit,
548 linkedSourceUnit,
549 unlinkedSourceUnit,
550 numTypeParameters);
551 }
552
553 /**
554 * Verify that the given [slotId] represents a reference to a type declared
555 * in a file reachable via [absoluteUri] and [relativeUri], having name
556 * [expectedName]. If [allowTypeParameters] is true, allow the type
557 * reference to supply type parameters. [expectedKind] is the kind of object
558 * referenced. [linkedSourceUnit] and [unlinkedSourceUnit] refer to the
559 * compilation unit within which the [typeRef] appears; if not specified they
560 * are assumed to refer to the defining compilation unit.
561 * [expectedTargetUnit] is the index of the compilation unit in which the
562 * target of the [typeRef] is expected to appear; if not specified it is
563 * assumed to be the defining compilation unit. [numTypeParameters] is the
564 * number of type parameters of the thing being referred to.
565 */
566 void checkLinkedTypeSlot(
567 int slotId, String absoluteUri, String relativeUri, String expectedName,
568 {bool allowTypeParameters: false,
569 ReferenceKind expectedKind: ReferenceKind.classOrEnum,
570 int expectedTargetUnit: 0,
571 LinkedUnit linkedSourceUnit,
572 UnlinkedUnit unlinkedSourceUnit,
573 int numTypeParameters: 0}) {
574 // Slot ids should be nonzero, since zero means "no associated slot".
575 expect(slotId, isNot(0));
576 if (skipFullyLinkedData) {
577 return;
578 }
579 linkedSourceUnit ??= definingUnit;
580 checkLinkedTypeRef(
581 getTypeRefForSlot(slotId, linkedSourceUnit: linkedSourceUnit),
582 absoluteUri,
583 relativeUri,
584 expectedName,
585 allowTypeParameters: allowTypeParameters,
586 expectedKind: expectedKind,
587 expectedTargetUnit: expectedTargetUnit,
588 linkedSourceUnit: linkedSourceUnit,
589 unlinkedSourceUnit: unlinkedSourceUnit,
590 numTypeParameters: numTypeParameters);
591 }
592
593 /**
492 * Verify that the given [typeRef] represents a reference to a type parameter 594 * Verify that the given [typeRef] represents a reference to a type parameter
493 * having the given [deBruijnIndex]. 595 * having the given [deBruijnIndex].
494 */ 596 */
495 void checkParamTypeRef(TypeRef typeRef, int deBruijnIndex) { 597 void checkParamTypeRef(TypeRef typeRef, int deBruijnIndex) {
496 expect(typeRef, new isInstanceOf<TypeRef>()); 598 expect(typeRef, new isInstanceOf<TypeRef>());
497 expect(typeRef.reference, 0); 599 expect(typeRef.reference, 0);
498 expect(typeRef.typeArguments, isEmpty); 600 expect(typeRef.typeArguments, isEmpty);
499 expect(typeRef.paramReference, deBruijnIndex); 601 expect(typeRef.paramReference, deBruijnIndex);
500 } 602 }
501 603
(...skipping 27 matching lines...) Expand all
529 void checkTypeRef(TypeRef typeRef, String absoluteUri, String relativeUri, 631 void checkTypeRef(TypeRef typeRef, String absoluteUri, String relativeUri,
530 String expectedName, 632 String expectedName,
531 {String expectedPrefix, 633 {String expectedPrefix,
532 bool allowTypeParameters: false, 634 bool allowTypeParameters: false,
533 ReferenceKind expectedKind: ReferenceKind.classOrEnum, 635 ReferenceKind expectedKind: ReferenceKind.classOrEnum,
534 int expectedTargetUnit: 0, 636 int expectedTargetUnit: 0,
535 LinkedUnit linkedSourceUnit, 637 LinkedUnit linkedSourceUnit,
536 UnlinkedUnit unlinkedSourceUnit, 638 UnlinkedUnit unlinkedSourceUnit,
537 int numTypeParameters: 0}) { 639 int numTypeParameters: 0}) {
538 linkedSourceUnit ??= definingUnit; 640 linkedSourceUnit ??= definingUnit;
539 unlinkedSourceUnit ??= unlinkedUnits[0];
540 expect(typeRef, new isInstanceOf<TypeRef>()); 641 expect(typeRef, new isInstanceOf<TypeRef>());
541 expect(typeRef.paramReference, 0); 642 expect(typeRef.paramReference, 0);
542 int index = typeRef.reference; 643 int index = typeRef.reference;
543 UnlinkedReference reference = unlinkedSourceUnit.references[index]; 644 if (!allowTypeParameters) {
544 LinkedReference referenceResolution = linkedSourceUnit.references[index]; 645 expect(typeRef.typeArguments, isEmpty);
545 if (index == 0) { 646 }
647 UnlinkedReference reference = checkTypeRefCommonElements(
648 index,
649 absoluteUri,
650 relativeUri,
651 expectedName,
652 expectedKind,
653 expectedTargetUnit,
654 linkedSourceUnit,
655 unlinkedSourceUnit,
656 numTypeParameters);
657 expect(reference, isNotNull,
658 reason: 'Unlinked type refs must refer to an explicit reference');
659 if (expectedKind == ReferenceKind.unresolved && !checkAstDerivedData) {
660 // summarize_elements.dart isn't yet able to record the prefix of
661 // unresolved references. TODO(paulberry): fix this.
662 expect(reference.prefixReference, 0);
663 } else if (expectedPrefix == null) {
664 expect(reference.prefixReference, 0);
665 } else {
666 checkPrefix(reference.prefixReference, expectedPrefix);
667 }
668 }
669
670 /**
671 * Check the data structures that are common between [checkTypeRef] and
672 * [checkLinkedTypeRef]. If the type reference in question is an explicit
673 * reference, return the [UnlinkedReference] that is used to make the
674 * explicit reference. If the type reference in question is an implicit
675 * reference, return `null`.
676 */
677 UnlinkedReference checkTypeRefCommonElements(
678 int referenceIndex,
679 String absoluteUri,
680 String relativeUri,
681 String expectedName,
682 ReferenceKind expectedKind,
683 int expectedTargetUnit,
684 LinkedUnit linkedSourceUnit,
685 UnlinkedUnit unlinkedSourceUnit,
686 int numTypeParameters) {
687 unlinkedSourceUnit ??= unlinkedUnits[0];
688 LinkedReference referenceResolution =
689 linkedSourceUnit.references[referenceIndex];
690 String name;
691 UnlinkedReference reference;
692 if (referenceIndex < unlinkedSourceUnit.references.length) {
693 // This is an explicit reference, so its name and prefix should be in
694 // [UnlinkedUnit.references].
695 expect(referenceResolution.name, isEmpty);
696 reference = unlinkedSourceUnit.references[referenceIndex];
697 name = reference.name;
698 if (reference.prefixReference != 0) {
699 // Prefixes should appear in the references table before any reference
700 // that uses them.
701 expect(reference.prefixReference, lessThan(referenceIndex));
702 }
703 } else {
704 // This is an implicit reference, so its name should be in
705 // [LinkedUnit.references].
706 name = referenceResolution.name;
707 }
708 if (referenceIndex == 0) {
546 // Index 0 is reserved for "dynamic". 709 // Index 0 is reserved for "dynamic".
547 expect(reference.name, isEmpty); 710 expect(name, isEmpty);
548 expect(reference.prefixReference, 0);
549 } 711 }
550 if (absoluteUri == null) { 712 if (absoluteUri == null) {
551 expect(referenceResolution.dependency, 0); 713 expect(referenceResolution.dependency, 0);
552 } else { 714 } else {
553 checkDependency(referenceResolution.dependency, absoluteUri, relativeUri); 715 checkDependency(referenceResolution.dependency, absoluteUri, relativeUri);
554 } 716 }
555 if (!allowTypeParameters) {
556 expect(typeRef.typeArguments, isEmpty);
557 }
558 if (expectedKind == ReferenceKind.unresolved && !checkAstDerivedData) { 717 if (expectedKind == ReferenceKind.unresolved && !checkAstDerivedData) {
559 // summarize_elements.dart isn't yet able to record the name or prefix of 718 // summarize_elements.dart isn't yet able to record the name of
560 // unresolved references. TODO(paulberry): fix this. 719 // unresolved references. TODO(paulberry): fix this.
561 expect(reference.name, '*unresolved*'); 720 expect(name, '*unresolved*');
562 expect(reference.prefixReference, 0);
563 } else { 721 } else {
564 if (expectedName == null) { 722 if (expectedName == null) {
565 expect(reference.name, isEmpty); 723 expect(name, isEmpty);
566 } else { 724 } else {
567 expect(reference.name, expectedName); 725 expect(name, expectedName);
568 }
569 if (expectedPrefix == null) {
570 expect(reference.prefixReference, 0);
571 } else {
572 checkPrefix(reference.prefixReference, expectedPrefix);
573 } 726 }
574 } 727 }
575 expect(referenceResolution.kind, expectedKind); 728 expect(referenceResolution.kind, expectedKind);
576 expect(referenceResolution.unit, expectedTargetUnit); 729 expect(referenceResolution.unit, expectedTargetUnit);
577 expect(referenceResolution.numTypeParameters, numTypeParameters); 730 expect(referenceResolution.numTypeParameters, numTypeParameters);
731 return reference;
578 } 732 }
579 733
580 /** 734 /**
581 * Verify that the given [typeRef] represents a reference to an unresolved 735 * Verify that the given [typeRef] represents a reference to an unresolved
582 * type. 736 * type.
583 */ 737 */
584 void checkUnresolvedTypeRef( 738 void checkUnresolvedTypeRef(
585 TypeRef typeRef, String expectedPrefix, String expectedName, 739 TypeRef typeRef, String expectedPrefix, String expectedName,
586 {LinkedUnit linkedSourceUnit, UnlinkedUnit unlinkedSourceUnit}) { 740 {LinkedUnit linkedSourceUnit, UnlinkedUnit unlinkedSourceUnit}) {
587 // When serializing from the element model, unresolved type refs lose their 741 // When serializing from the element model, unresolved type refs lose their
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 result = variable; 886 result = variable;
733 } 887 }
734 } 888 }
735 if (result == null && failIfAbsent) { 889 if (result == null && failIfAbsent) {
736 fail('Variable $variableName not found in serialized output'); 890 fail('Variable $variableName not found in serialized output');
737 } 891 }
738 return result; 892 return result;
739 } 893 }
740 894
741 /** 895 /**
896 * Find the entry in [linkedSourceUnit.types] matching [slotId].
897 */
898 TypeRef getTypeRefForSlot(int slotId, {LinkedUnit linkedSourceUnit}) {
899 linkedSourceUnit ??= definingUnit;
900 for (TypeRef typeRef in linkedSourceUnit.types) {
901 if (typeRef.slot == slotId) {
902 return typeRef;
903 }
904 }
905 return null;
906 }
907
908 /**
742 * Serialize the given library [text] and return the summary of the class 909 * Serialize the given library [text] and return the summary of the class
743 * with the given [className]. 910 * with the given [className].
744 */ 911 */
745 UnlinkedClass serializeClassText(String text, 912 UnlinkedClass serializeClassText(String text,
746 {String className: 'C', bool allowErrors: false}) { 913 {String className: 'C', bool allowErrors: false}) {
747 serializeLibraryText(text, allowErrors: allowErrors); 914 serializeLibraryText(text, allowErrors: allowErrors);
748 return findClass(className, failIfAbsent: true); 915 return findClass(className, failIfAbsent: true);
749 } 916 }
750 917
751 /** 918 /**
(...skipping 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after
2241 // start exporting a name that the main test library *does* use. 2408 // start exporting a name that the main test library *does* use.
2242 checkHasDependency(absUri('/a.dart'), 'a.dart'); 2409 checkHasDependency(absUri('/a.dart'), 'a.dart');
2243 } 2410 }
2244 2411
2245 test_dependencies_parts() { 2412 test_dependencies_parts() {
2246 addNamedSource( 2413 addNamedSource(
2247 '/a.dart', 'library a; part "b.dart"; part "c.dart"; class A {}'); 2414 '/a.dart', 'library a; part "b.dart"; part "c.dart"; class A {}');
2248 addNamedSource('/b.dart', 'part of a;'); 2415 addNamedSource('/b.dart', 'part of a;');
2249 addNamedSource('/c.dart', 'part of a;'); 2416 addNamedSource('/c.dart', 'part of a;');
2250 serializeLibraryText('import "a.dart"; A a;'); 2417 serializeLibraryText('import "a.dart"; A a;');
2251 LinkedDependency dep = checkHasDependency(absUri('/a.dart'), 'a.dart'); 2418 int dep = checkHasDependency(absUri('/a.dart'), 'a.dart');
2252 checkDependencyParts( 2419 checkDependencyParts(linked.dependencies[dep],
2253 dep, [absUri('/b.dart'), absUri('/c.dart')], ['b.dart', 'c.dart']); 2420 [absUri('/b.dart'), absUri('/c.dart')], ['b.dart', 'c.dart']);
2254 } 2421 }
2255 2422
2256 test_dependencies_parts_relative_to_importing_library() { 2423 test_dependencies_parts_relative_to_importing_library() {
2257 addNamedSource('/a/b.dart', 'export "c/d.dart";'); 2424 addNamedSource('/a/b.dart', 'export "c/d.dart";');
2258 addNamedSource('/a/c/d.dart', 2425 addNamedSource('/a/c/d.dart',
2259 'library d; part "e/f.dart"; part "g/h.dart"; class D {}'); 2426 'library d; part "e/f.dart"; part "g/h.dart"; class D {}');
2260 addNamedSource('/a/c/e/f.dart', 'part of d;'); 2427 addNamedSource('/a/c/e/f.dart', 'part of d;');
2261 addNamedSource('/a/c/g/h.dart', 'part of d;'); 2428 addNamedSource('/a/c/g/h.dart', 'part of d;');
2262 serializeLibraryText('import "a/b.dart"; D d;'); 2429 serializeLibraryText('import "a/b.dart"; D d;');
2263 LinkedDependency dep = 2430 int dep = checkHasDependency(absUri('/a/c/d.dart'), 'a/c/d.dart');
2264 checkHasDependency(absUri('/a/c/d.dart'), 'a/c/d.dart');
2265 checkDependencyParts( 2431 checkDependencyParts(
2266 dep, 2432 linked.dependencies[dep],
2267 [absUri('/a/c/e/f.dart'), absUri('/a/c/g/h.dart')], 2433 [absUri('/a/c/e/f.dart'), absUri('/a/c/g/h.dart')],
2268 ['a/c/e/f.dart', 'a/c/g/h.dart']); 2434 ['a/c/e/f.dart', 'a/c/g/h.dart']);
2269 } 2435 }
2270 2436
2271 test_elements_in_part() { 2437 test_elements_in_part() {
2272 addNamedSource( 2438 addNamedSource(
2273 '/part1.dart', 2439 '/part1.dart',
2274 ''' 2440 '''
2275 part of my.lib; 2441 part of my.lib;
2276 2442
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
3042 expect(variable.documentationComment, isNotNull); 3208 expect(variable.documentationComment, isNotNull);
3043 checkDocumentationComment(variable.documentationComment, text); 3209 checkDocumentationComment(variable.documentationComment, text);
3044 } 3210 }
3045 3211
3046 test_field_final() { 3212 test_field_final() {
3047 UnlinkedVariable variable = 3213 UnlinkedVariable variable =
3048 serializeClassText('class C { final int i = 0; }').fields[0]; 3214 serializeClassText('class C { final int i = 0; }').fields[0];
3049 expect(variable.isFinal, isTrue); 3215 expect(variable.isFinal, isTrue);
3050 } 3216 }
3051 3217
3218 test_field_propagated_type_final_immediate() {
3219 UnlinkedVariable v =
3220 serializeClassText('class C { final v = 0; }').fields[0];
3221 checkLinkedTypeSlot(v.propagatedTypeSlot, 'dart:core', 'dart:core', 'int');
3222 }
3223
3052 test_field_static() { 3224 test_field_static() {
3053 UnlinkedVariable variable = 3225 UnlinkedVariable variable =
3054 serializeClassText('class C { static int i; }').fields[0]; 3226 serializeClassText('class C { static int i; }').fields[0];
3055 expect(variable.isStatic, isTrue); 3227 expect(variable.isStatic, isTrue);
3056 } 3228 }
3057 3229
3230 test_fully_linked_references_follow_other_references() {
3231 if (skipFullyLinkedData) {
3232 return;
3233 }
3234 serializeLibraryText('final x = 0; String y;');
3235 checkLinkedTypeSlot(unlinkedUnits[0].variables[0].propagatedTypeSlot,
3236 'dart:core', 'dart:core', 'int');
3237 checkTypeRef(
3238 unlinkedUnits[0].variables[1].type, 'dart:core', 'dart:core', 'String');
3239 // Even though the definition of y follows the definition of x, the linked
3240 // type reference for x should use a higher numbered reference than the
3241 // unlinked type reference for y.
3242 TypeRef propagatedType =
3243 getTypeRefForSlot(unlinkedUnits[0].variables[0].propagatedTypeSlot);
3244 expect(unlinkedUnits[0].variables[1].type.reference,
3245 lessThan(propagatedType.reference));
3246 }
3247
3058 test_function_documented() { 3248 test_function_documented() {
3059 String text = ''' 3249 String text = '''
3060 // Extra comment so doc comment offset != 0 3250 // Extra comment so doc comment offset != 0
3061 /** 3251 /**
3062 * Docs 3252 * Docs
3063 */ 3253 */
3064 f() {}'''; 3254 f() {}''';
3065 UnlinkedExecutable executable = serializeExecutableText(text); 3255 UnlinkedExecutable executable = serializeExecutableText(text);
3066 expect(executable.documentationComment, isNotNull); 3256 expect(executable.documentationComment, isNotNull);
3067 checkDocumentationComment(executable.documentationComment, text); 3257 checkDocumentationComment(executable.documentationComment, text);
(...skipping 14 matching lines...) Expand all
3082 // Extra comment so doc comment offset != 0 3272 // Extra comment so doc comment offset != 0
3083 /** 3273 /**
3084 * Docs 3274 * Docs
3085 */ 3275 */
3086 get f => null;'''; 3276 get f => null;''';
3087 UnlinkedExecutable executable = serializeExecutableText(text); 3277 UnlinkedExecutable executable = serializeExecutableText(text);
3088 expect(executable.documentationComment, isNotNull); 3278 expect(executable.documentationComment, isNotNull);
3089 checkDocumentationComment(executable.documentationComment, text); 3279 checkDocumentationComment(executable.documentationComment, text);
3090 } 3280 }
3091 3281
3282 test_implicit_dependencies_follow_other_dependencies() {
3283 if (skipFullyLinkedData) {
3284 return;
3285 }
3286 addNamedSource('/a.dart', 'import "b.dart"; class C {} D f() => null;');
3287 addNamedSource('/b.dart', 'class D {}');
3288 serializeLibraryText('import "a.dart"; final x = f(); C y;');
3289 // The dependency on b.dart is implicit, so it should be placed at the end
3290 // of the dependency list, after a.dart, even though the code that refers
3291 // to b.dart comes before the code that refers to a.dart.
3292 int aDep =
3293 checkHasDependency(absUri('/a.dart'), 'a.dart', fullyLinked: false);
3294 int bDep =
3295 checkHasDependency(absUri('/b.dart'), 'b.dart', fullyLinked: true);
3296 expect(aDep, lessThan(bDep));
3297 }
3298
3092 test_import_deferred() { 3299 test_import_deferred() {
3093 serializeLibraryText( 3300 serializeLibraryText(
3094 'import "dart:async" deferred as a; main() { print(a.Future); }'); 3301 'import "dart:async" deferred as a; main() { print(a.Future); }');
3095 expect(unlinkedUnits[0].imports[0].isDeferred, isTrue); 3302 expect(unlinkedUnits[0].imports[0].isDeferred, isTrue);
3096 } 3303 }
3097 3304
3098 test_import_dependency() { 3305 test_import_dependency() {
3099 serializeLibraryText('import "dart:async"; Future x;'); 3306 serializeLibraryText('import "dart:async"; Future x;');
3100 // Second import is the implicit import of dart:core 3307 // Second import is the implicit import of dart:core
3101 expect(unlinkedUnits[0].imports, hasLength(2)); 3308 expect(unlinkedUnits[0].imports, hasLength(2));
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
3391 // References to other parts should still be resolved. 3598 // References to other parts should still be resolved.
3392 allowMissingFiles = true; 3599 allowMissingFiles = true;
3393 addNamedSource('/bar.dart', 'part of my.lib; class C {}'); 3600 addNamedSource('/bar.dart', 'part of my.lib; class C {}');
3394 serializeLibraryText( 3601 serializeLibraryText(
3395 'library my.lib; part "foo.dart"; part "bar.dart"; C c;', 3602 'library my.lib; part "foo.dart"; part "bar.dart"; C c;',
3396 allowErrors: true); 3603 allowErrors: true);
3397 checkTypeRef(findVariable('c').type, null, null, 'C', 3604 checkTypeRef(findVariable('c').type, null, null, 'C',
3398 expectedTargetUnit: 2); 3605 expectedTargetUnit: 2);
3399 } 3606 }
3400 3607
3608 test_linked_reference_reuse() {
3609 if (skipFullyLinkedData) {
3610 return;
3611 }
3612 // When the reference for a linked type is the same as an explicitly
3613 // referenced type, the explicit reference should be re-used.
3614 addNamedSource('/a.dart', 'class C {}');
3615 addNamedSource('/b.dart', 'import "a.dart"; C f() => null;');
3616 serializeLibraryText(
3617 'import "a.dart"; import "b.dart"; C c1; final c2 = f();');
3618 int explicitReference = findVariable('c1').type.reference;
3619 expect(getTypeRefForSlot(findVariable('c2').propagatedTypeSlot).reference,
3620 explicitReference);
3621 }
3622
3623 test_linked_type_dependency_reuse() {
3624 if (skipFullyLinkedData) {
3625 return;
3626 }
3627 // When the dependency for a linked type is the same as an explicit
3628 // dependency, the explicit dependency should be re-used.
3629 addNamedSource('/a.dart', 'class C {} class D {}');
3630 addNamedSource('/b.dart', 'import "a.dart"; D f() => null;');
3631 serializeLibraryText(
3632 'import "a.dart"; import "b.dart"; C c; final d = f();');
3633 int cReference = findVariable('c').type.reference;
3634 int explicitDependency = linked.units[0].references[cReference].dependency;
3635 int dReference =
3636 getTypeRefForSlot(findVariable('d').propagatedTypeSlot).reference;
3637 expect(
3638 linked.units[0].references[dReference].dependency, explicitDependency);
3639 }
3640
3401 test_local_names_take_precedence_over_imported_names() { 3641 test_local_names_take_precedence_over_imported_names() {
3402 addNamedSource('/a.dart', 'class C {} class D {}'); 3642 addNamedSource('/a.dart', 'class C {} class D {}');
3403 serializeLibraryText(''' 3643 serializeLibraryText('''
3404 import 'a.dart'; 3644 import 'a.dart';
3405 class C {} 3645 class C {}
3406 C c; 3646 C c;
3407 D d;'''); 3647 D d;''');
3408 checkTypeRef(findVariable('c').type, null, null, 'C'); 3648 checkTypeRef(findVariable('c').type, null, null, 'C');
3409 checkTypeRef(findVariable('d').type, absUri('/a.dart'), 'a.dart', 'D'); 3649 checkTypeRef(findVariable('d').type, absUri('/a.dart'), 'a.dart', 'D');
3410 } 3650 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3462 // Extra comment so doc comment offset != 0 3702 // Extra comment so doc comment offset != 0
3463 /** 3703 /**
3464 * Docs 3704 * Docs
3465 */ 3705 */
3466 void set f(value) {}'''; 3706 void set f(value) {}''';
3467 UnlinkedExecutable executable = serializeExecutableText(text, 'f='); 3707 UnlinkedExecutable executable = serializeExecutableText(text, 'f=');
3468 expect(executable.documentationComment, isNotNull); 3708 expect(executable.documentationComment, isNotNull);
3469 checkDocumentationComment(executable.documentationComment, text); 3709 checkDocumentationComment(executable.documentationComment, text);
3470 } 3710 }
3471 3711
3712 test_slot_reuse() {
3713 // Different compilation units have independent notions of slot id, so slot
3714 // ids should be reused.
3715 addNamedSource('/a.dart', 'part of foo; final v = 0;');
3716 serializeLibraryText('library foo; part "a.dart"; final w = 0;');
3717 expect(unlinkedUnits[0].variables[0].propagatedTypeSlot, 1);
3718 expect(unlinkedUnits[1].variables[0].propagatedTypeSlot, 1);
3719 }
3720
3472 test_type_arguments_explicit() { 3721 test_type_arguments_explicit() {
3473 TypeRef typeRef = serializeTypeText('List<int>'); 3722 TypeRef typeRef = serializeTypeText('List<int>');
3474 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List', 3723 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List',
3475 allowTypeParameters: true, numTypeParameters: 1); 3724 allowTypeParameters: true, numTypeParameters: 1);
3476 expect(typeRef.typeArguments, hasLength(1)); 3725 expect(typeRef.typeArguments, hasLength(1));
3477 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int'); 3726 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int');
3478 } 3727 }
3479 3728
3480 test_type_arguments_explicit_dynamic() { 3729 test_type_arguments_explicit_dynamic() {
3481 TypeRef typeRef = serializeTypeText('List<dynamic>'); 3730 TypeRef typeRef = serializeTypeText('List<dynamic>');
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
4018 UnlinkedVariable variable = 4267 UnlinkedVariable variable =
4019 serializeVariableText('int i;', variableName: 'i'); 4268 serializeVariableText('int i;', variableName: 'i');
4020 expect(variable.isStatic, isFalse); 4269 expect(variable.isStatic, isFalse);
4021 } 4270 }
4022 4271
4023 test_variable_private() { 4272 test_variable_private() {
4024 serializeVariableText('int _i;', variableName: '_i'); 4273 serializeVariableText('int _i;', variableName: '_i');
4025 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); 4274 expect(unlinkedUnits[0].publicNamespace.names, isEmpty);
4026 } 4275 }
4027 4276
4277 test_variable_propagated_type_final_immediate() {
4278 UnlinkedVariable v = serializeVariableText('final v = 0;');
4279 checkLinkedTypeSlot(v.propagatedTypeSlot, 'dart:core', 'dart:core', 'int');
4280 }
4281
4282 test_variable_propagated_type_new_reference() {
4283 if (skipFullyLinkedData) {
4284 return;
4285 }
4286 UnlinkedVariable v = serializeVariableText('final v = 0;');
4287 // Since the propagated type of `v` is `int`, and there are no references
4288 // to `int` elsewhere in the source file, a new linked reference should
4289 // have been created for it, with no associated unlinked reference.
4290 expect(v.propagatedTypeSlot, isNot(0));
4291 TypeRef type = getTypeRefForSlot(v.propagatedTypeSlot);
4292 expect(type, isNotNull);
4293 expect(type.reference,
4294 greaterThanOrEqualTo(unlinkedUnits[0].references.length));
4295 }
4296
4297 test_variable_propagated_type_omit_dynamic() {
4298 if (skipFullyLinkedData) {
4299 return;
4300 }
4301 UnlinkedVariable v = serializeVariableText('final v = <int, dynamic>{};');
4302 TypeRef type = getTypeRefForSlot(v.propagatedTypeSlot);
4303 checkLinkedTypeRef(type, 'dart:core', 'dart:core', 'Map',
4304 allowTypeParameters: true, numTypeParameters: 2);
4305 expect(type.typeArguments, hasLength(1));
4306 checkLinkedTypeRef(type.typeArguments[0], 'dart:core', 'dart:core', 'int');
4307 }
4308
4309 test_variable_propagatedTypeSlot_const() {
4310 // Const variables are propagable so they have a nonzero
4311 // propagatedTypeSlot.
4312 UnlinkedVariable variable = serializeVariableText('const v = 0;');
4313 expect(variable.propagatedTypeSlot, isNot(0));
4314 }
4315
4316 test_variable_propagatedTypeSlot_final() {
4317 // Final variables are propagable so they have a nonzero
4318 // propagatedTypeSlot.
4319 UnlinkedVariable variable = serializeVariableText('final v = 0;');
4320 expect(variable.propagatedTypeSlot, isNot(0));
4321 }
4322
4323 test_variable_propagatedTypeSlot_non_propagable() {
4324 // Non-final non-const variables aren't propagable so they don't have a
4325 // propagatedTypeSlot.
4326 UnlinkedVariable variable = serializeVariableText('var v;');
4327 expect(variable.propagatedTypeSlot, 0);
4328 }
4329
4028 test_variable_static() { 4330 test_variable_static() {
4029 UnlinkedVariable variable = 4331 UnlinkedVariable variable =
4030 serializeClassText('class C { static int i; }').fields[0]; 4332 serializeClassText('class C { static int i; }').fields[0];
4031 expect(variable.isStatic, isTrue); 4333 expect(variable.isStatic, isTrue);
4032 } 4334 }
4033 4335
4034 test_variable_type() { 4336 test_variable_type() {
4035 UnlinkedVariable variable = 4337 UnlinkedVariable variable =
4036 serializeVariableText('int i;', variableName: 'i'); 4338 serializeVariableText('int i;', variableName: 'i');
4037 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); 4339 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int');
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4074 */ 4376 */
4075 Map<String, UnlinkedUnit> uriToUnit = <String, UnlinkedUnit>{}; 4377 Map<String, UnlinkedUnit> uriToUnit = <String, UnlinkedUnit>{};
4076 4378
4077 @override 4379 @override
4078 bool get checkAstDerivedData => true; 4380 bool get checkAstDerivedData => true;
4079 4381
4080 @override 4382 @override
4081 bool get expectAbsoluteUrisInDependencies => false; 4383 bool get expectAbsoluteUrisInDependencies => false;
4082 4384
4083 @override 4385 @override
4386 bool get skipFullyLinkedData => true;
4387
4388 @override
4084 addNamedSource(String filePath, String contents) { 4389 addNamedSource(String filePath, String contents) {
4085 CompilationUnit unit = _parseText(contents); 4390 CompilationUnit unit = _parseText(contents);
4086 UnlinkedUnit unlinkedUnit = 4391 UnlinkedUnit unlinkedUnit =
4087 new UnlinkedUnit.fromBuffer(serializeAstUnlinked(unit).toBuffer()); 4392 new UnlinkedUnit.fromBuffer(serializeAstUnlinked(unit).toBuffer());
4088 uriToUnit[absUri(filePath)] = unlinkedUnit; 4393 uriToUnit[absUri(filePath)] = unlinkedUnit;
4089 } 4394 }
4090 4395
4091 @override 4396 @override
4092 void serializeLibraryText(String text, {bool allowErrors: false}) { 4397 void serializeLibraryText(String text, {bool allowErrors: false}) {
4093 Uri testDartUri = Uri.parse(absUri('/test.dart')); 4398 Uri testDartUri = Uri.parse(absUri('/test.dart'));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
4136 CompilationUnit _parseText(String text) { 4441 CompilationUnit _parseText(String text) {
4137 CharSequenceReader reader = new CharSequenceReader(text); 4442 CharSequenceReader reader = new CharSequenceReader(text);
4138 Scanner scanner = 4443 Scanner scanner =
4139 new Scanner(null, reader, AnalysisErrorListener.NULL_LISTENER); 4444 new Scanner(null, reader, AnalysisErrorListener.NULL_LISTENER);
4140 Token token = scanner.tokenize(); 4445 Token token = scanner.tokenize();
4141 Parser parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER); 4446 Parser parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER);
4142 parser.parseGenericMethods = true; 4447 parser.parseGenericMethods = true;
4143 return parser.parseCompilationUnit(token); 4448 return parser.parseCompilationUnit(token);
4144 } 4449 }
4145 } 4450 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/summary/resynthesize_test.dart ('k') | pkg/analyzer/tool/summary/idl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698