| 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 test.src.serialization.elements_test; | 5 library test.src.serialization.elements_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/element.dart'; | 7 import 'package:analyzer/src/generated/element.dart'; |
| 8 import 'package:analyzer/src/generated/element_handle.dart'; | 8 import 'package:analyzer/src/generated/element_handle.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/resolver.dart' show Namespace; | 10 import 'package:analyzer/src/generated/resolver.dart' |
| 11 show Namespace, TypeProvider; |
| 11 import 'package:analyzer/src/generated/source.dart'; | 12 import 'package:analyzer/src/generated/source.dart'; |
| 12 import 'package:analyzer/src/summary/format.dart'; | 13 import 'package:analyzer/src/summary/format.dart'; |
| 13 import 'package:analyzer/src/summary/resynthesize.dart'; | 14 import 'package:analyzer/src/summary/resynthesize.dart'; |
| 14 import 'package:analyzer/src/summary/summarize_elements.dart'; | 15 import 'package:analyzer/src/summary/summarize_elements.dart'; |
| 15 import 'package:unittest/unittest.dart'; | 16 import 'package:unittest/unittest.dart'; |
| 16 | 17 |
| 17 import '../../generated/resolver_test.dart'; | 18 import '../../generated/resolver_test.dart'; |
| 18 import '../../reflective_tests.dart'; | 19 import '../../reflective_tests.dart'; |
| 19 | 20 |
| 20 main() { | 21 main() { |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 return new LinkedLibrary.fromBuffer(serialized.linked.toBuffer()); | 593 return new LinkedLibrary.fromBuffer(serialized.linked.toBuffer()); |
| 593 } | 594 } |
| 594 Map<String, LinkedLibrary> linkedSummaries = <String, LinkedLibrary>{ | 595 Map<String, LinkedLibrary> linkedSummaries = <String, LinkedLibrary>{ |
| 595 uri: getLinkedSummaryFor(original) | 596 uri: getLinkedSummaryFor(original) |
| 596 }; | 597 }; |
| 597 for (Source source in otherLibrarySources) { | 598 for (Source source in otherLibrarySources) { |
| 598 LibraryElement original = resolve2(source); | 599 LibraryElement original = resolve2(source); |
| 599 String uri = source.uri.toString(); | 600 String uri = source.uri.toString(); |
| 600 linkedSummaries[uri] = getLinkedSummaryFor(original); | 601 linkedSummaries[uri] = getLinkedSummaryFor(original); |
| 601 } | 602 } |
| 602 LinkedLibrary getLinkedSummary(String uri) { | 603 _TestSummaryResynthesizer resynthesizer = new _TestSummaryResynthesizer( |
| 603 LinkedLibrary serializedLibrary = linkedSummaries[uri]; | |
| 604 if (serializedLibrary == null) { | |
| 605 fail('Unexpectedly tried to get linked summary for $uri'); | |
| 606 } | |
| 607 return serializedLibrary; | |
| 608 } | |
| 609 UnlinkedUnit getUnlinkedSummary(String uri) { | |
| 610 UnlinkedUnit serializedUnit = unlinkedSummaries[uri]; | |
| 611 if (serializedUnit == null) { | |
| 612 fail('Unexpectedly tried to get unlinked summary for $uri'); | |
| 613 } | |
| 614 return serializedUnit; | |
| 615 } | |
| 616 SummaryResynthesizer resynthesizer = new SummaryResynthesizer( | |
| 617 null, | 604 null, |
| 618 analysisContext, | 605 analysisContext, |
| 619 analysisContext.typeProvider, | 606 analysisContext.typeProvider, |
| 620 (_) => true, | 607 analysisContext.sourceFactory, |
| 621 getLinkedSummary, | 608 unlinkedSummaries, |
| 622 getUnlinkedSummary, | 609 linkedSummaries); |
| 623 analysisContext.sourceFactory); | |
| 624 LibraryElementImpl resynthesized = resynthesizer.getLibraryElement(uri); | 610 LibraryElementImpl resynthesized = resynthesizer.getLibraryElement(uri); |
| 625 // Check that no other summaries needed to be resynthesized to resynthesize | 611 // Check that no other summaries needed to be resynthesized to resynthesize |
| 626 // the library element. | 612 // the library element. |
| 627 expect(resynthesizer.resynthesisCount, 1); | 613 expect(resynthesizer.resynthesisCount, 1); |
| 628 return resynthesized; | 614 return resynthesized; |
| 629 } | 615 } |
| 630 | 616 |
| 631 test_class_alias() { | 617 test_class_alias() { |
| 632 checkLibrary('class C = D with E, F; class D {} class E {} class F {}'); | 618 checkLibrary('class C = D with E, F; class D {} class E {} class F {}'); |
| 633 } | 619 } |
| (...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1582 test_variable_setterInPart_getterInPart() { | 1568 test_variable_setterInPart_getterInPart() { |
| 1583 addNamedSource('/a.dart', 'part of my.lib; void set x(int _) {}'); | 1569 addNamedSource('/a.dart', 'part of my.lib; void set x(int _) {}'); |
| 1584 addNamedSource('/b.dart', 'part of my.lib; int get x => 42;'); | 1570 addNamedSource('/b.dart', 'part of my.lib; int get x => 42;'); |
| 1585 checkLibrary('library my.lib; part "a.dart"; part "b.dart";'); | 1571 checkLibrary('library my.lib; part "a.dart"; part "b.dart";'); |
| 1586 } | 1572 } |
| 1587 | 1573 |
| 1588 test_variables() { | 1574 test_variables() { |
| 1589 checkLibrary('int i; int j;'); | 1575 checkLibrary('int i; int j;'); |
| 1590 } | 1576 } |
| 1591 } | 1577 } |
| 1578 |
| 1579 class _TestSummaryResynthesizer extends SummaryResynthesizer { |
| 1580 final Map<String, UnlinkedUnit> unlinkedSummaries; |
| 1581 final Map<String, LinkedLibrary> linkedSummaries; |
| 1582 |
| 1583 _TestSummaryResynthesizer( |
| 1584 SummaryResynthesizer parent, |
| 1585 AnalysisContext context, |
| 1586 TypeProvider typeProvider, |
| 1587 SourceFactory sourceFactory, |
| 1588 this.unlinkedSummaries, |
| 1589 this.linkedSummaries) |
| 1590 : super(parent, context, typeProvider, sourceFactory); |
| 1591 |
| 1592 @override |
| 1593 LinkedLibrary getLinkedSummary(String uri) { |
| 1594 LinkedLibrary serializedLibrary = linkedSummaries[uri]; |
| 1595 if (serializedLibrary == null) { |
| 1596 fail('Unexpectedly tried to get linked summary for $uri'); |
| 1597 } |
| 1598 return serializedLibrary; |
| 1599 } |
| 1600 |
| 1601 @override |
| 1602 UnlinkedUnit getUnlinkedSummary(String uri) { |
| 1603 UnlinkedUnit serializedUnit = unlinkedSummaries[uri]; |
| 1604 if (serializedUnit == null) { |
| 1605 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 1606 } |
| 1607 return serializedUnit; |
| 1608 } |
| 1609 |
| 1610 @override |
| 1611 bool hasLibrarySummary(String uri) { |
| 1612 return true; |
| 1613 } |
| 1614 } |
| OLD | NEW |