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

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

Issue 1574113002: Record information about parts of dependent libraries in summaries. (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/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/error.dart'; 10 import 'package:analyzer/src/generated/error.dart';
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 <String, UnlinkedPublicNamespace>{}; 105 <String, UnlinkedPublicNamespace>{};
106 List<LibraryElement> libraries = [ 106 List<LibraryElement> libraries = [
107 analysisContext.typeProvider.objectType.element.library, 107 analysisContext.typeProvider.objectType.element.library,
108 analysisContext.typeProvider.futureType.element.library 108 analysisContext.typeProvider.futureType.element.library
109 ]; 109 ];
110 for (LibraryElement library in libraries) { 110 for (LibraryElement library in libraries) {
111 summarize_elements.LibrarySerializationResult serializedLibrary = 111 summarize_elements.LibrarySerializationResult serializedLibrary =
112 summarize_elements.serializeLibrary( 112 summarize_elements.serializeLibrary(
113 library, analysisContext.typeProvider); 113 library, analysisContext.typeProvider);
114 for (int i = 0; i < serializedLibrary.unlinkedUnits.length; i++) { 114 for (int i = 0; i < serializedLibrary.unlinkedUnits.length; i++) {
115 uriToNamespace[serializedLibrary.unitUris[i]] = 115 uriToNamespace[
116 new UnlinkedUnit.fromBuffer( 116 serializedLibrary.unitUris[i]] = new UnlinkedUnit.fromBuffer(
117 serializedLibrary.unlinkedUnits[i].toBuffer()) 117 serializedLibrary.unlinkedUnits[i].toBuffer()).publicNamespace;
118 .publicNamespace;
119 } 118 }
120 } 119 }
121 return uriToNamespace; 120 return uriToNamespace;
122 } catch (_) { 121 } catch (_) {
123 return null; 122 return null;
124 } 123 }
125 }(); 124 }();
126 125
127 final Map<String, UnlinkedPublicNamespace> uriToPublicNamespace = 126 final Map<String, UnlinkedPublicNamespace> uriToPublicNamespace =
128 <String, UnlinkedPublicNamespace>{}; 127 <String, UnlinkedPublicNamespace>{};
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // The element model doesn't (yet) store enough information to recover 363 // The element model doesn't (yet) store enough information to recover
365 // relative URIs, so we have to use the absolute URI. 364 // relative URIs, so we have to use the absolute URI.
366 // TODO(paulberry): fix this. 365 // TODO(paulberry): fix this.
367 relativeUri = absoluteUri; 366 relativeUri = absoluteUri;
368 } 367 }
369 expect(dependency, new isInstanceOf<int>()); 368 expect(dependency, new isInstanceOf<int>());
370 expect(prelinked.dependencies[dependency].uri, relativeUri); 369 expect(prelinked.dependencies[dependency].uri, relativeUri);
371 } 370 }
372 371
373 /** 372 /**
373 * Verify that the given [dependency] lists the given [absoluteUris] or
374 * [relativeUris] as its parts.
375 */
376 void checkDependencyParts(PrelinkedDependency dependency,
377 List<String> absoluteUris, List<String> relativeUris) {
378 if (expectAbsoluteUrisInDependencies) {
379 // The element model doesn't (yet) store enough information to recover
380 // relative URIs, so we have to use the absolute URI.
381 // TODO(paulberry): fix this.
382 relativeUris = absoluteUris;
383 }
384 expect(dependency.parts, relativeUris);
385 }
386
387 /**
374 * Check that the given [documentationComment] matches the first 388 * Check that the given [documentationComment] matches the first
375 * Javadoc-style comment found in [text]. 389 * Javadoc-style comment found in [text].
376 * 390 *
377 * Note that the algorithm for finding the Javadoc-style comment in [text] is 391 * Note that the algorithm for finding the Javadoc-style comment in [text] is
378 * a simple-minded text search; it is easily confused by corner cases such as 392 * a simple-minded text search; it is easily confused by corner cases such as
379 * strings containing comments, nested comments, etc. 393 * strings containing comments, nested comments, etc.
380 */ 394 */
381 void checkDocumentationComment( 395 void checkDocumentationComment(
382 UnlinkedDocumentationComment documentationComment, String text) { 396 UnlinkedDocumentationComment documentationComment, String text) {
383 expect(documentationComment, isNotNull); 397 expect(documentationComment, isNotNull);
(...skipping 12 matching lines...) Expand all
396 /** 410 /**
397 * Verify that the given [typeRef] represents the type `dynamic`. 411 * Verify that the given [typeRef] represents the type `dynamic`.
398 */ 412 */
399 void checkDynamicTypeRef(UnlinkedTypeRef typeRef) { 413 void checkDynamicTypeRef(UnlinkedTypeRef typeRef) {
400 checkTypeRef(typeRef, null, null, null); 414 checkTypeRef(typeRef, null, null, null);
401 } 415 }
402 416
403 /** 417 /**
404 * Verify that the dependency table contains an entry for a file reachable 418 * Verify that the dependency table contains an entry for a file reachable
405 * via the given [absoluteUri] and [relativeUri]. 419 * via the given [absoluteUri] and [relativeUri].
420 *
421 * The [PrelinkedDependency] is returned.
406 */ 422 */
407 void checkHasDependency(String absoluteUri, String relativeUri) { 423 PrelinkedDependency checkHasDependency(
424 String absoluteUri, String relativeUri) {
408 if (expectAbsoluteUrisInDependencies) { 425 if (expectAbsoluteUrisInDependencies) {
409 // The element model doesn't (yet) store enough information to recover 426 // The element model doesn't (yet) store enough information to recover
410 // relative URIs, so we have to use the absolute URI. 427 // relative URIs, so we have to use the absolute URI.
411 // TODO(paulberry): fix this. 428 // TODO(paulberry): fix this.
412 relativeUri = absoluteUri; 429 relativeUri = absoluteUri;
413 } 430 }
414 List<String> found = <String>[]; 431 List<String> found = <String>[];
415 for (PrelinkedDependency dep in prelinked.dependencies) { 432 for (PrelinkedDependency dep in prelinked.dependencies) {
416 if (dep.uri == relativeUri) { 433 if (dep.uri == relativeUri) {
417 return; 434 return dep;
418 } 435 }
419 found.add(dep.uri); 436 found.add(dep.uri);
420 } 437 }
421 fail('Did not find dependency $relativeUri. Found: $found'); 438 fail('Did not find dependency $relativeUri. Found: $found');
439 return null;
422 } 440 }
423 441
424 /** 442 /**
425 * Verify that the dependency table *does not* contain any entries for a file 443 * Verify that the dependency table *does not* contain any entries for a file
426 * reachable via the given [absoluteUri] and [relativeUri]. 444 * reachable via the given [absoluteUri] and [relativeUri].
427 */ 445 */
428 void checkLacksDependency(String absoluteUri, String relativeUri) { 446 void checkLacksDependency(String absoluteUri, String relativeUri) {
429 if (expectAbsoluteUrisInDependencies) { 447 if (expectAbsoluteUrisInDependencies) {
430 // The element model doesn't (yet) store enough information to recover 448 // The element model doesn't (yet) store enough information to recover
431 // relative URIs, so we have to use the absolute URI. 449 // relative URIs, so we have to use the absolute URI.
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 797
780 /** 798 /**
781 * Serialize a type declaration using the given [text] as a type name, and 799 * Serialize a type declaration using the given [text] as a type name, and
782 * return a summary of the corresponding [UnlinkedTypeRef]. If the type 800 * return a summary of the corresponding [UnlinkedTypeRef]. If the type
783 * declaration needs to refer to types that are not available in core, those 801 * declaration needs to refer to types that are not available in core, those
784 * types may be declared in [otherDeclarations]. 802 * types may be declared in [otherDeclarations].
785 */ 803 */
786 UnlinkedTypeRef serializeTypeText(String text, 804 UnlinkedTypeRef serializeTypeText(String text,
787 {String otherDeclarations: '', bool allowErrors: false}) { 805 {String otherDeclarations: '', bool allowErrors: false}) {
788 return serializeVariableText('$otherDeclarations\n$text v;', 806 return serializeVariableText('$otherDeclarations\n$text v;',
789 allowErrors: allowErrors) 807 allowErrors: allowErrors).type;
790 .type;
791 } 808 }
792 809
793 /** 810 /**
794 * Serialize the given library [text] and return the summary of the variable 811 * Serialize the given library [text] and return the summary of the variable
795 * with the given [variableName]. 812 * with the given [variableName].
796 */ 813 */
797 UnlinkedVariable serializeVariableText(String text, 814 UnlinkedVariable serializeVariableText(String text,
798 {String variableName: 'v', bool allowErrors: false}) { 815 {String variableName: 'v', bool allowErrors: false}) {
799 serializeLibraryText(text, allowErrors: allowErrors); 816 serializeLibraryText(text, allowErrors: allowErrors);
800 return findVariable(variableName, failIfAbsent: true); 817 return findVariable(variableName, failIfAbsent: true);
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 1451
1435 test_constructor_return_type_parameterized() { 1452 test_constructor_return_type_parameterized() {
1436 UnlinkedExecutable executable = findExecutable('', 1453 UnlinkedExecutable executable = findExecutable('',
1437 executables: serializeClassText('class C<T, U> { C(); }').executables); 1454 executables: serializeClassText('class C<T, U> { C(); }').executables);
1438 expect(executable.returnType, isNull); 1455 expect(executable.returnType, isNull);
1439 } 1456 }
1440 1457
1441 test_dependencies_export_none() { 1458 test_dependencies_export_none() {
1442 // Exports are not listed as dependencies since no change to the exported 1459 // Exports are not listed as dependencies since no change to the exported
1443 // file can change the summary of the exporting file. 1460 // file can change the summary of the exporting file.
1461 // TODO(paulberry): this needs to change since the element model for a
1462 // library includes its export namespace.
1444 addNamedSource('/a.dart', 'library a; export "b.dart";'); 1463 addNamedSource('/a.dart', 'library a; export "b.dart";');
1445 addNamedSource('/b.dart', 'library b;'); 1464 addNamedSource('/b.dart', 'library b;');
1446 serializeLibraryText('export "a.dart";'); 1465 serializeLibraryText('export "a.dart";');
1447 checkLacksDependency(absUri('/a.dart'), 'a.dart'); 1466 checkLacksDependency(absUri('/a.dart'), 'a.dart');
1448 checkLacksDependency(absUri('/b.dart'), 'b.dart'); 1467 checkLacksDependency(absUri('/b.dart'), 'b.dart');
1449 } 1468 }
1450 1469
1451 test_dependencies_import_to_export() { 1470 test_dependencies_import_to_export() {
1452 addNamedSource('/a.dart', 'library a; export "b.dart"; class A {}'); 1471 addNamedSource('/a.dart', 'library a; export "b.dart"; class A {}');
1453 addNamedSource('/b.dart', 'library b;'); 1472 addNamedSource('/b.dart', 'library b;');
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 addNamedSource( 1533 addNamedSource(
1515 '/a.dart', 'library a; import "b.dart"; class A extends B {}'); 1534 '/a.dart', 'library a; import "b.dart"; class A extends B {}');
1516 addNamedSource('/b.dart', 'library b; class B {}'); 1535 addNamedSource('/b.dart', 'library b; class B {}');
1517 serializeLibraryText('import "a.dart"; A a;'); 1536 serializeLibraryText('import "a.dart"; A a;');
1518 checkHasDependency(absUri('/a.dart'), 'a.dart'); 1537 checkHasDependency(absUri('/a.dart'), 'a.dart');
1519 // The main test library doesn't depend on b.dart, because no change to 1538 // The main test library doesn't depend on b.dart, because no change to
1520 // b.dart can possibly affect the serialized element model for it. 1539 // b.dart can possibly affect the serialized element model for it.
1521 checkLacksDependency(absUri('/b.dart'), 'b.dart'); 1540 checkLacksDependency(absUri('/b.dart'), 'b.dart');
1522 } 1541 }
1523 1542
1543 test_dependencies_parts() {
1544 addNamedSource(
1545 '/a.dart', 'library a; part "b.dart"; part "c.dart"; class A {}');
1546 addNamedSource('/b.dart', 'part of a;');
1547 addNamedSource('/c.dart', 'part of a;');
1548 serializeLibraryText('import "a.dart"; A a;');
1549 PrelinkedDependency dep = checkHasDependency(absUri('/a.dart'), 'a.dart');
1550 checkDependencyParts(
1551 dep, [absUri('/b.dart'), absUri('/c.dart')], ['b.dart', 'c.dart']);
1552 }
1553
1554 test_dependencies_parts_relative_to_importing_library() {
1555 addNamedSource('/a/b.dart', 'export "c/d.dart";');
1556 addNamedSource('/a/c/d.dart',
1557 'library d; part "e/f.dart"; part "g/h.dart"; class D {}');
1558 addNamedSource('/a/c/e/f.dart', 'part of d;');
1559 addNamedSource('/a/c/g/h.dart', 'part of d;');
1560 serializeLibraryText('import "a/b.dart"; D d;');
1561 PrelinkedDependency dep =
1562 checkHasDependency(absUri('/a/c/d.dart'), 'a/c/d.dart');
1563 checkDependencyParts(
1564 dep,
1565 [absUri('/a/c/e/f.dart'), absUri('/a/c/g/h.dart')],
1566 ['a/c/e/f.dart', 'a/c/g/h.dart']);
1567 }
1568
1524 test_elements_in_part() { 1569 test_elements_in_part() {
1525 addNamedSource( 1570 addNamedSource(
1526 '/part1.dart', 1571 '/part1.dart',
1527 ''' 1572 '''
1528 part of my.lib; 1573 part of my.lib;
1529 1574
1530 class C {} 1575 class C {}
1531 enum E { v } 1576 enum E { v }
1532 var v; 1577 var v;
1533 f() {} 1578 f() {}
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 expect(executable.isConst, false); 1850 expect(executable.isConst, false);
1806 expect(executable.isFactory, false); 1851 expect(executable.isFactory, false);
1807 expect(executable.isStatic, false); 1852 expect(executable.isStatic, false);
1808 expect(executable.parameters, hasLength(1)); 1853 expect(executable.parameters, hasLength(1));
1809 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool'); 1854 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool');
1810 expect(executable.typeParameters, isEmpty); 1855 expect(executable.typeParameters, isEmpty);
1811 } 1856 }
1812 1857
1813 test_executable_operator_index_set() { 1858 test_executable_operator_index_set() {
1814 UnlinkedExecutable executable = serializeClassText( 1859 UnlinkedExecutable executable = serializeClassText(
1815 'class C { void operator[]=(int i, bool v) => null; }') 1860 'class C { void operator[]=(int i, bool v) => null; }').executables[0];
1816 .executables[0];
1817 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); 1861 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod);
1818 expect(executable.name, '[]='); 1862 expect(executable.name, '[]=');
1819 expect(executable.hasImplicitReturnType, false); 1863 expect(executable.hasImplicitReturnType, false);
1820 expect(executable.isAbstract, false); 1864 expect(executable.isAbstract, false);
1821 expect(executable.isConst, false); 1865 expect(executable.isConst, false);
1822 expect(executable.isFactory, false); 1866 expect(executable.isFactory, false);
1823 expect(executable.isStatic, false); 1867 expect(executable.isStatic, false);
1824 expect(executable.parameters, hasLength(2)); 1868 expect(executable.parameters, hasLength(2));
1825 expect(executable.returnType, isNull); 1869 expect(executable.returnType, isNull);
1826 expect(executable.typeParameters, isEmpty); 1870 expect(executable.typeParameters, isEmpty);
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after
2913 UnlinkedVariable variable = 2957 UnlinkedVariable variable =
2914 serializeVariableText('int i;', variableName: 'i'); 2958 serializeVariableText('int i;', variableName: 'i');
2915 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); 2959 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int');
2916 } 2960 }
2917 2961
2918 test_varible_private() { 2962 test_varible_private() {
2919 serializeVariableText('int _i;', variableName: '_i'); 2963 serializeVariableText('int _i;', variableName: '_i');
2920 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); 2964 expect(unlinkedUnits[0].publicNamespace.names, isEmpty);
2921 } 2965 }
2922 } 2966 }
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