| 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' show Namespace; |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 assertNoErrors(source); | 575 assertNoErrors(source); |
| 576 } | 576 } |
| 577 String uri = source.uri.toString(); | 577 String uri = source.uri.toString(); |
| 578 addLibrary('dart:core'); | 578 addLibrary('dart:core'); |
| 579 return resynthesizeLibraryElement(uri, original); | 579 return resynthesizeLibraryElement(uri, original); |
| 580 } | 580 } |
| 581 | 581 |
| 582 LibraryElementImpl resynthesizeLibraryElement( | 582 LibraryElementImpl resynthesizeLibraryElement( |
| 583 String uri, LibraryElementImpl original) { | 583 String uri, LibraryElementImpl original) { |
| 584 Map<String, UnlinkedUnit> unlinkedSummaries = <String, UnlinkedUnit>{}; | 584 Map<String, UnlinkedUnit> unlinkedSummaries = <String, UnlinkedUnit>{}; |
| 585 PrelinkedLibrary getPrelinkedSummaryFor(LibraryElement lib) { | 585 LinkedLibrary getLinkedSummaryFor(LibraryElement lib) { |
| 586 LibrarySerializationResult serialized = | 586 LibrarySerializationResult serialized = |
| 587 serializeLibrary(lib, typeProvider); | 587 serializeLibrary(lib, typeProvider); |
| 588 for (int i = 0; i < serialized.unlinkedUnits.length; i++) { | 588 for (int i = 0; i < serialized.unlinkedUnits.length; i++) { |
| 589 unlinkedSummaries[serialized.unitUris[i]] = | 589 unlinkedSummaries[serialized.unitUris[i]] = |
| 590 new UnlinkedUnit.fromBuffer(serialized.unlinkedUnits[i].toBuffer()); | 590 new UnlinkedUnit.fromBuffer(serialized.unlinkedUnits[i].toBuffer()); |
| 591 } | 591 } |
| 592 return new PrelinkedLibrary.fromBuffer(serialized.prelinked.toBuffer()); | 592 return new LinkedLibrary.fromBuffer(serialized.linked.toBuffer()); |
| 593 } | 593 } |
| 594 Map<String, PrelinkedLibrary> prelinkedSummaries = | 594 Map<String, LinkedLibrary> linkedSummaries = <String, LinkedLibrary>{ |
| 595 <String, PrelinkedLibrary>{uri: getPrelinkedSummaryFor(original)}; | 595 uri: getLinkedSummaryFor(original) |
| 596 }; |
| 596 for (Source source in otherLibrarySources) { | 597 for (Source source in otherLibrarySources) { |
| 597 LibraryElement original = resolve2(source); | 598 LibraryElement original = resolve2(source); |
| 598 String uri = source.uri.toString(); | 599 String uri = source.uri.toString(); |
| 599 prelinkedSummaries[uri] = getPrelinkedSummaryFor(original); | 600 linkedSummaries[uri] = getLinkedSummaryFor(original); |
| 600 } | 601 } |
| 601 PrelinkedLibrary getPrelinkedSummary(String uri) { | 602 LinkedLibrary getLinkedSummary(String uri) { |
| 602 PrelinkedLibrary serializedLibrary = prelinkedSummaries[uri]; | 603 LinkedLibrary serializedLibrary = linkedSummaries[uri]; |
| 603 if (serializedLibrary == null) { | 604 if (serializedLibrary == null) { |
| 604 fail('Unexpectedly tried to get prelinked summary for $uri'); | 605 fail('Unexpectedly tried to get linked summary for $uri'); |
| 605 } | 606 } |
| 606 return serializedLibrary; | 607 return serializedLibrary; |
| 607 } | 608 } |
| 608 UnlinkedUnit getUnlinkedSummary(String uri) { | 609 UnlinkedUnit getUnlinkedSummary(String uri) { |
| 609 UnlinkedUnit serializedUnit = unlinkedSummaries[uri]; | 610 UnlinkedUnit serializedUnit = unlinkedSummaries[uri]; |
| 610 if (serializedUnit == null) { | 611 if (serializedUnit == null) { |
| 611 fail('Unexpectedly tried to get unlinked summary for $uri'); | 612 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 612 } | 613 } |
| 613 return serializedUnit; | 614 return serializedUnit; |
| 614 } | 615 } |
| 615 SummaryResynthesizer resynthesizer = new SummaryResynthesizer( | 616 SummaryResynthesizer resynthesizer = new SummaryResynthesizer( |
| 616 analysisContext, | 617 analysisContext, |
| 617 analysisContext.typeProvider, | 618 analysisContext.typeProvider, |
| 618 getPrelinkedSummary, | 619 getLinkedSummary, |
| 619 getUnlinkedSummary, | 620 getUnlinkedSummary, |
| 620 analysisContext.sourceFactory); | 621 analysisContext.sourceFactory); |
| 621 LibraryElementImpl resynthesized = resynthesizer.getLibraryElement(uri); | 622 LibraryElementImpl resynthesized = resynthesizer.getLibraryElement(uri); |
| 622 // Check that no other summaries needed to be resynthesized to resynthesize | 623 // Check that no other summaries needed to be resynthesized to resynthesize |
| 623 // the library element. | 624 // the library element. |
| 624 expect(resynthesizer.resynthesisCount, 1); | 625 expect(resynthesizer.resynthesisCount, 1); |
| 625 return resynthesized; | 626 return resynthesized; |
| 626 } | 627 } |
| 627 | 628 |
| 628 test_class_alias() { | 629 test_class_alias() { |
| (...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1579 test_variable_setterInPart_getterInPart() { | 1580 test_variable_setterInPart_getterInPart() { |
| 1580 addNamedSource('/a.dart', 'part of my.lib; void set x(int _) {}'); | 1581 addNamedSource('/a.dart', 'part of my.lib; void set x(int _) {}'); |
| 1581 addNamedSource('/b.dart', 'part of my.lib; int get x => 42;'); | 1582 addNamedSource('/b.dart', 'part of my.lib; int get x => 42;'); |
| 1582 checkLibrary('library my.lib; part "a.dart"; part "b.dart";'); | 1583 checkLibrary('library my.lib; part "a.dart"; part "b.dart";'); |
| 1583 } | 1584 } |
| 1584 | 1585 |
| 1585 test_variables() { | 1586 test_variables() { |
| 1586 checkLibrary('int i; int j;'); | 1587 checkLibrary('int i; int j;'); |
| 1587 } | 1588 } |
| 1588 } | 1589 } |
| OLD | NEW |