| 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 summary_resynthesizer; | 5 library summary_resynthesizer; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 9 import 'package:analyzer/src/generated/element_handle.dart'; | 9 import 'package:analyzer/src/generated/element_handle.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 * hasn't been resynthesized already. | 111 * hasn't been resynthesized already. |
| 112 */ | 112 */ |
| 113 LibraryElement getLibraryElement(String uri) { | 113 LibraryElement getLibraryElement(String uri) { |
| 114 return _resynthesizedLibraries.putIfAbsent(uri, () { | 114 return _resynthesizedLibraries.putIfAbsent(uri, () { |
| 115 PrelinkedLibrary serializedLibrary = getPrelinkedSummary(uri); | 115 PrelinkedLibrary serializedLibrary = getPrelinkedSummary(uri); |
| 116 List<UnlinkedUnit> serializedUnits = <UnlinkedUnit>[ | 116 List<UnlinkedUnit> serializedUnits = <UnlinkedUnit>[ |
| 117 getUnlinkedSummary(uri) | 117 getUnlinkedSummary(uri) |
| 118 ]; | 118 ]; |
| 119 Source librarySource = _getSource(uri); | 119 Source librarySource = _getSource(uri); |
| 120 for (UnlinkedPart part in serializedUnits[0].publicNamespace.parts) { | 120 for (UnlinkedPart part in serializedUnits[0].publicNamespace.parts) { |
| 121 String partAbsUri = | 121 Source partSource = sourceFactory.resolveUri(librarySource, part.uri); |
| 122 sourceFactory.resolveUri(librarySource, part.uri).uri.toString(); | 122 String partAbsUri = partSource.uri.toString(); |
| 123 serializedUnits.add(getUnlinkedSummary(partAbsUri)); | 123 serializedUnits.add(getUnlinkedSummary(partAbsUri)); |
| 124 } | 124 } |
| 125 _LibraryResynthesizer libraryResynthesizer = new _LibraryResynthesizer( | 125 _LibraryResynthesizer libraryResynthesizer = new _LibraryResynthesizer( |
| 126 this, serializedLibrary, serializedUnits, librarySource); | 126 this, serializedLibrary, serializedUnits, librarySource); |
| 127 LibraryElement library = libraryResynthesizer.buildLibrary(); | 127 LibraryElement library = libraryResynthesizer.buildLibrary(); |
| 128 _resynthesizedElements[uri] = libraryResynthesizer.resummarizedElements; | 128 _resynthesizedElements[uri] = libraryResynthesizer.resummarizedElements; |
| 129 return library; | 129 return library; |
| 130 }); | 130 }); |
| 131 } | 131 } |
| 132 | 132 |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 /** | 696 /** |
| 697 * Build a [DartType] object based on an [UnlinkedTypeRef]. This [DartType] | 697 * Build a [DartType] object based on an [UnlinkedTypeRef]. This [DartType] |
| 698 * may refer to elements in other libraries than the library being | 698 * may refer to elements in other libraries than the library being |
| 699 * deserialized, so handles are used to avoid having to deserialize other | 699 * deserialized, so handles are used to avoid having to deserialize other |
| 700 * libraries in the process. | 700 * libraries in the process. |
| 701 */ | 701 */ |
| 702 DartType buildType(UnlinkedTypeRef type) { | 702 DartType buildType(UnlinkedTypeRef type) { |
| 703 if (type.paramReference != 0) { | 703 if (type.paramReference != 0) { |
| 704 // TODO(paulberry): make this work for generic methods. | 704 // TODO(paulberry): make this work for generic methods. |
| 705 return currentTypeParameters[ | 705 return currentTypeParameters[ |
| 706 currentTypeParameters.length - type.paramReference].type; | 706 currentTypeParameters.length - type.paramReference] |
| 707 .type; |
| 707 } else { | 708 } else { |
| 708 // TODO(paulberry): handle references to things other than classes (note: | 709 // TODO(paulberry): handle references to things other than classes (note: |
| 709 // this should only occur in the case of erroneous code). | 710 // this should only occur in the case of erroneous code). |
| 710 // TODO(paulberry): test reference to something inside a part. | 711 // TODO(paulberry): test reference to something inside a part. |
| 711 // TODO(paulberry): test reference to something inside a part of the | 712 // TODO(paulberry): test reference to something inside a part of the |
| 712 // current lib. | 713 // current lib. |
| 713 UnlinkedReference reference = unlinkedUnit.references[type.reference]; | 714 UnlinkedReference reference = unlinkedUnit.references[type.reference]; |
| 714 PrelinkedReference referenceResolution = | 715 PrelinkedReference referenceResolution = |
| 715 prelinkedUnit.references[type.reference]; | 716 prelinkedUnit.references[type.reference]; |
| 716 String referencedLibraryUri; | 717 String referencedLibraryUri; |
| 717 String partUri; | 718 String partUri; |
| 718 if (referenceResolution.dependency != 0) { | 719 if (referenceResolution.dependency != 0) { |
| 719 PrelinkedDependency dependency = | 720 PrelinkedDependency dependency = |
| 720 prelinkedLibrary.dependencies[referenceResolution.dependency]; | 721 prelinkedLibrary.dependencies[referenceResolution.dependency]; |
| 721 Source referencedLibrarySource = summaryResynthesizer.sourceFactory | 722 Source referencedLibrarySource = summaryResynthesizer.sourceFactory |
| 722 .resolveUri(librarySource, dependency.uri); | 723 .resolveUri(librarySource, dependency.uri); |
| 723 referencedLibraryUri = referencedLibrarySource.uri.toString(); | 724 referencedLibraryUri = referencedLibrarySource.uri.toString(); |
| 724 // TODO(paulberry): consider changing Location format so that this is | 725 // TODO(paulberry): consider changing Location format so that this is |
| 725 // not necessary (2nd string in location should just be the unit | 726 // not necessary (2nd string in location should just be the unit |
| 726 // number). | 727 // number). |
| 727 if (referenceResolution.unit != 0) { | 728 if (referenceResolution.unit != 0) { |
| 728 UnlinkedUnit referencedLibraryDefiningUnit = | 729 UnlinkedUnit referencedLibraryDefiningUnit = |
| 729 summaryResynthesizer.getUnlinkedSummary(referencedLibraryUri); | 730 summaryResynthesizer.getUnlinkedSummary(referencedLibraryUri); |
| 730 String uri = referencedLibraryDefiningUnit.publicNamespace.parts[ | 731 String uri = referencedLibraryDefiningUnit |
| 731 referenceResolution.unit - 1].uri; | 732 .publicNamespace.parts[referenceResolution.unit - 1].uri; |
| 732 Source partSource = summaryResynthesizer.sourceFactory | 733 Source partSource = summaryResynthesizer.sourceFactory |
| 733 .resolveUri(referencedLibrarySource, uri); | 734 .resolveUri(referencedLibrarySource, uri); |
| 734 partUri = partSource.uri.toString(); | 735 partUri = partSource.uri.toString(); |
| 735 } else { | 736 } else { |
| 736 partUri = referencedLibraryUri; | 737 partUri = referencedLibraryUri; |
| 737 } | 738 } |
| 738 } else if (referenceResolution.kind == | 739 } else if (referenceResolution.kind == |
| 739 PrelinkedReferenceKind.unresolved) { | 740 PrelinkedReferenceKind.unresolved) { |
| 740 return summaryResynthesizer.typeProvider.undefinedType; | 741 return summaryResynthesizer.typeProvider.undefinedType; |
| 741 } else if (reference.name.isEmpty) { | 742 } else if (reference.name.isEmpty) { |
| 742 return summaryResynthesizer.typeProvider.dynamicType; | 743 return summaryResynthesizer.typeProvider.dynamicType; |
| 743 } else { | 744 } else { |
| 744 referencedLibraryUri = librarySource.uri.toString(); | 745 referencedLibraryUri = librarySource.uri.toString(); |
| 745 if (referenceResolution.unit != 0) { | 746 if (referenceResolution.unit != 0) { |
| 746 String uri = unlinkedUnits[0].publicNamespace.parts[ | 747 String uri = unlinkedUnits[0] |
| 747 referenceResolution.unit - 1].uri; | 748 .publicNamespace |
| 749 .parts[referenceResolution.unit - 1] |
| 750 .uri; |
| 748 Source partSource = | 751 Source partSource = |
| 749 summaryResynthesizer.sourceFactory.resolveUri(librarySource, uri); | 752 summaryResynthesizer.sourceFactory.resolveUri(librarySource, uri); |
| 750 partUri = partSource.uri.toString(); | 753 partUri = partSource.uri.toString(); |
| 751 } else { | 754 } else { |
| 752 partUri = referencedLibraryUri; | 755 partUri = referencedLibraryUri; |
| 753 } | 756 } |
| 754 } | 757 } |
| 755 ElementLocationImpl location = new ElementLocationImpl.con3( | 758 ElementLocationImpl location = new ElementLocationImpl.con3( |
| 756 <String>[referencedLibraryUri, partUri, reference.name]); | 759 <String>[referencedLibraryUri, partUri, reference.name]); |
| 757 List<DartType> typeArguments = const <DartType>[]; | 760 List<DartType> typeArguments = const <DartType>[]; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 } | 910 } |
| 908 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { | 911 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { |
| 909 elementMap[typeAlias.name] = typeAlias; | 912 elementMap[typeAlias.name] = typeAlias; |
| 910 } | 913 } |
| 911 resummarizedElements[absoluteUri] = elementMap; | 914 resummarizedElements[absoluteUri] = elementMap; |
| 912 unitHolder = null; | 915 unitHolder = null; |
| 913 prelinkedUnit = null; | 916 prelinkedUnit = null; |
| 914 unlinkedUnit = null; | 917 unlinkedUnit = null; |
| 915 } | 918 } |
| 916 } | 919 } |
| OLD | NEW |