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

Side by Side Diff: pkg/analyzer/lib/src/summary/resynthesize.dart

Issue 1543403002: Create a section of the summary for public namespace information. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 12 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 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 * Get the [LibraryElement] for the given [uri], resynthesizing it if it 174 * Get the [LibraryElement] for the given [uri], resynthesizing it if it
175 * hasn't been resynthesized already. 175 * hasn't been resynthesized already.
176 */ 176 */
177 LibraryElement getLibraryElement(String uri) { 177 LibraryElement getLibraryElement(String uri) {
178 return _resynthesizedLibraries.putIfAbsent(uri, () { 178 return _resynthesizedLibraries.putIfAbsent(uri, () {
179 PrelinkedLibrary serializedLibrary = getPrelinkedSummary(uri); 179 PrelinkedLibrary serializedLibrary = getPrelinkedSummary(uri);
180 List<UnlinkedUnit> serializedUnits = <UnlinkedUnit>[ 180 List<UnlinkedUnit> serializedUnits = <UnlinkedUnit>[
181 getUnlinkedSummary(uri) 181 getUnlinkedSummary(uri)
182 ]; 182 ];
183 Source librarySource = _getSource(uri); 183 Source librarySource = _getSource(uri);
184 for (UnlinkedPart part in serializedUnits[0].parts) { 184 for (UnlinkedPart part in serializedUnits[0].publicNamespace.parts) {
185 String partAbsUri = 185 String partAbsUri =
186 sourceFactory.resolveUri(librarySource, part.uri).uri.toString(); 186 sourceFactory.resolveUri(librarySource, part.uri).uri.toString();
187 serializedUnits.add(getUnlinkedSummary(partAbsUri)); 187 serializedUnits.add(getUnlinkedSummary(partAbsUri));
188 } 188 }
189 _LibraryResynthesizer libraryResynthesizer = new _LibraryResynthesizer( 189 _LibraryResynthesizer libraryResynthesizer = new _LibraryResynthesizer(
190 this, serializedLibrary, serializedUnits, librarySource); 190 this, serializedLibrary, serializedUnits, librarySource);
191 LibraryElement library = libraryResynthesizer.buildLibrary(); 191 LibraryElement library = libraryResynthesizer.buildLibrary();
192 _resynthesizedElements[uri] = libraryResynthesizer.resummarizedElements; 192 _resynthesizedElements[uri] = libraryResynthesizer.resummarizedElements;
193 return library; 193 return library;
194 }); 194 });
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 // TODO(paulberry): is it ok to pass -1 for offset and nameLength? 647 // TODO(paulberry): is it ok to pass -1 for offset and nameLength?
648 LibraryElementImpl libraryElement = new LibraryElementImpl( 648 LibraryElementImpl libraryElement = new LibraryElementImpl(
649 summaryResynthesizer.context, unlinkedUnits[0].libraryName, -1, -1); 649 summaryResynthesizer.context, unlinkedUnits[0].libraryName, -1, -1);
650 CompilationUnitElementImpl definingCompilationUnit = 650 CompilationUnitElementImpl definingCompilationUnit =
651 new CompilationUnitElementImpl(librarySource.shortName); 651 new CompilationUnitElementImpl(librarySource.shortName);
652 libraryElement.definingCompilationUnit = definingCompilationUnit; 652 libraryElement.definingCompilationUnit = definingCompilationUnit;
653 definingCompilationUnit.source = librarySource; 653 definingCompilationUnit.source = librarySource;
654 definingCompilationUnit.librarySource = librarySource; 654 definingCompilationUnit.librarySource = librarySource;
655 List<CompilationUnitElement> parts = <CompilationUnitElement>[]; 655 List<CompilationUnitElement> parts = <CompilationUnitElement>[];
656 UnlinkedUnit unlinkedDefiningUnit = unlinkedUnits[0]; 656 UnlinkedUnit unlinkedDefiningUnit = unlinkedUnits[0];
657 assert( 657 assert(unlinkedDefiningUnit.publicNamespace.parts.length + 1 ==
658 unlinkedDefiningUnit.parts.length + 1 == prelinkedLibrary.units.length); 658 prelinkedLibrary.units.length);
659 for (int i = 1; i < prelinkedLibrary.units.length; i++) { 659 for (int i = 1; i < prelinkedLibrary.units.length; i++) {
660 CompilationUnitElementImpl part = 660 CompilationUnitElementImpl part = buildPart(
661 buildPart(unlinkedDefiningUnit.parts[i - 1].uri, unlinkedUnits[i]); 661 unlinkedDefiningUnit.publicNamespace.parts[i - 1].uri,
662 unlinkedUnits[i]);
662 parts.add(part); 663 parts.add(part);
663 } 664 }
664 libraryElement.parts = parts; 665 libraryElement.parts = parts;
665 List<ImportElement> imports = <ImportElement>[]; 666 List<ImportElement> imports = <ImportElement>[];
666 for (int i = 0; i < unlinkedDefiningUnit.imports.length; i++) { 667 for (int i = 0; i < unlinkedDefiningUnit.imports.length; i++) {
667 imports.add(buildImport(unlinkedDefiningUnit.imports[i], 668 imports.add(buildImport(unlinkedDefiningUnit.imports[i],
668 prelinkedLibrary.importDependencies[i])); 669 prelinkedLibrary.importDependencies[i]));
669 } 670 }
670 libraryElement.imports = imports; 671 libraryElement.imports = imports;
671 libraryElement.exports = 672 libraryElement.exports =
672 unlinkedDefiningUnit.exports.map(buildExport).toList(); 673 unlinkedDefiningUnit.publicNamespace.exports.map(buildExport).toList();
673 populateUnit(definingCompilationUnit, 0); 674 populateUnit(definingCompilationUnit, 0);
674 for (int i = 0; i < parts.length; i++) { 675 for (int i = 0; i < parts.length; i++) {
675 populateUnit(parts[i], i + 1); 676 populateUnit(parts[i], i + 1);
676 } 677 }
677 return libraryElement; 678 return libraryElement;
678 } 679 }
679 680
680 /** 681 /**
681 * Resynthesize a [ParameterElement]. 682 * Resynthesize a [ParameterElement].
682 */ 683 */
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 prelinkedLibrary.dependencies[referenceResolution.dependency]; 759 prelinkedLibrary.dependencies[referenceResolution.dependency];
759 Source referencedLibrarySource = summaryResynthesizer.sourceFactory 760 Source referencedLibrarySource = summaryResynthesizer.sourceFactory
760 .resolveUri(librarySource, dependency.uri); 761 .resolveUri(librarySource, dependency.uri);
761 referencedLibraryUri = referencedLibrarySource.uri.toString(); 762 referencedLibraryUri = referencedLibrarySource.uri.toString();
762 // TODO(paulberry): consider changing Location format so that this is 763 // TODO(paulberry): consider changing Location format so that this is
763 // not necessary (2nd string in location should just be the unit 764 // not necessary (2nd string in location should just be the unit
764 // number). 765 // number).
765 if (referenceResolution.unit != 0) { 766 if (referenceResolution.unit != 0) {
766 UnlinkedUnit referencedLibraryDefiningUnit = 767 UnlinkedUnit referencedLibraryDefiningUnit =
767 summaryResynthesizer.getUnlinkedSummary(referencedLibraryUri); 768 summaryResynthesizer.getUnlinkedSummary(referencedLibraryUri);
768 String uri = referencedLibraryDefiningUnit.parts[0].uri; 769 String uri =
770 referencedLibraryDefiningUnit.publicNamespace.parts[0].uri;
769 Source partSource = summaryResynthesizer.sourceFactory 771 Source partSource = summaryResynthesizer.sourceFactory
770 .resolveUri(referencedLibrarySource, uri); 772 .resolveUri(referencedLibrarySource, uri);
771 partUri = partSource.uri.toString(); 773 partUri = partSource.uri.toString();
772 } else { 774 } else {
773 partUri = referencedLibraryUri; 775 partUri = referencedLibraryUri;
774 } 776 }
775 } else if (referenceResolution.kind == 777 } else if (referenceResolution.kind ==
776 PrelinkedReferenceKind.unresolved) { 778 PrelinkedReferenceKind.unresolved) {
777 return summaryResynthesizer.typeProvider.undefinedType; 779 return summaryResynthesizer.typeProvider.undefinedType;
778 } else if (reference.name.isEmpty) { 780 } else if (reference.name.isEmpty) {
779 return summaryResynthesizer.typeProvider.dynamicType; 781 return summaryResynthesizer.typeProvider.dynamicType;
780 } else { 782 } else {
781 referencedLibraryUri = librarySource.uri.toString(); 783 referencedLibraryUri = librarySource.uri.toString();
782 if (referenceResolution.unit != 0) { 784 if (referenceResolution.unit != 0) {
783 String uri = unlinkedUnits[0].parts[referenceResolution.unit - 1].uri; 785 String uri = unlinkedUnits[0].publicNamespace.parts[
786 referenceResolution.unit - 1].uri;
784 Source partSource = 787 Source partSource =
785 summaryResynthesizer.sourceFactory.resolveUri(librarySource, uri); 788 summaryResynthesizer.sourceFactory.resolveUri(librarySource, uri);
786 partUri = partSource.uri.toString(); 789 partUri = partSource.uri.toString();
787 } else { 790 } else {
788 partUri = referencedLibraryUri; 791 partUri = referencedLibraryUri;
789 } 792 }
790 } 793 }
791 ResynthesizedType resynthesizedType; 794 ResynthesizedType resynthesizedType;
792 ElementLocationImpl location = new ElementLocationImpl.con3( 795 ElementLocationImpl location = new ElementLocationImpl.con3(
793 <String>[referencedLibraryUri, partUri, reference.name]); 796 <String>[referencedLibraryUri, partUri, reference.name]);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 } 943 }
941 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { 944 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) {
942 elementMap[typeAlias.name] = typeAlias; 945 elementMap[typeAlias.name] = typeAlias;
943 } 946 }
944 resummarizedElements[absoluteUri] = elementMap; 947 resummarizedElements[absoluteUri] = elementMap;
945 unitHolder = null; 948 unitHolder = null;
946 prelinkedUnit = null; 949 prelinkedUnit = null;
947 unlinkedUnit = null; 950 unlinkedUnit = null;
948 } 951 }
949 } 952 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/format.dart ('k') | pkg/analyzer/lib/src/summary/summarize_elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698