Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.src.generated.resolver; | 5 library analyzer.src.generated.resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 6591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6602 */ | 6602 */ |
| 6603 Namespace createExportNamespaceForDirective(ExportElement element) { | 6603 Namespace createExportNamespaceForDirective(ExportElement element) { |
| 6604 LibraryElement exportedLibrary = element.exportedLibrary; | 6604 LibraryElement exportedLibrary = element.exportedLibrary; |
| 6605 if (exportedLibrary == null) { | 6605 if (exportedLibrary == null) { |
| 6606 // | 6606 // |
| 6607 // The exported library will be null if the URI does not reference a valid | 6607 // The exported library will be null if the URI does not reference a valid |
| 6608 // library. | 6608 // library. |
| 6609 // | 6609 // |
| 6610 return Namespace.EMPTY; | 6610 return Namespace.EMPTY; |
| 6611 } | 6611 } |
| 6612 HashMap<String, Element> definedNames = | 6612 HashMap<String, Element> exportedNames = _getExportMapping(exportedLibrary); |
| 6613 _createExportMapping(exportedLibrary, new HashSet<LibraryElement>()); | 6613 exportedNames = _applyCombinators(exportedNames, element.combinators); |
| 6614 definedNames = _applyCombinators(definedNames, element.combinators); | 6614 return new Namespace(exportedNames); |
| 6615 return new Namespace(definedNames); | |
| 6616 } | 6615 } |
| 6617 | 6616 |
| 6618 /** | 6617 /** |
| 6619 * Create a namespace representing the export namespace of the given library. | 6618 * Create a namespace representing the export namespace of the given library. |
| 6620 * | 6619 * |
| 6621 * @param library the library whose export namespace is to be created | 6620 * @param library the library whose export namespace is to be created |
| 6622 * @return the export namespace that was created | 6621 * @return the export namespace that was created |
| 6623 */ | 6622 */ |
| 6624 Namespace createExportNamespaceForLibrary(LibraryElement library) => | 6623 Namespace createExportNamespaceForLibrary(LibraryElement library) { |
| 6625 new Namespace( | 6624 HashMap<String, Element> exportedNames = _getExportMapping(library); |
| 6626 _createExportMapping(library, new HashSet<LibraryElement>())); | 6625 return new Namespace(exportedNames); |
| 6626 } | |
| 6627 | 6627 |
| 6628 /** | 6628 /** |
| 6629 * Create a namespace representing the import namespace of the given library. | 6629 * Create a namespace representing the import namespace of the given library. |
| 6630 * | 6630 * |
| 6631 * @param library the library whose import namespace is to be created | 6631 * @param library the library whose import namespace is to be created |
| 6632 * @return the import namespace that was created | 6632 * @return the import namespace that was created |
| 6633 */ | 6633 */ |
| 6634 Namespace createImportNamespaceForDirective(ImportElement element) { | 6634 Namespace createImportNamespaceForDirective(ImportElement element) { |
| 6635 LibraryElement importedLibrary = element.importedLibrary; | 6635 LibraryElement importedLibrary = element.importedLibrary; |
| 6636 if (importedLibrary == null) { | 6636 if (importedLibrary == null) { |
| 6637 // | 6637 // |
| 6638 // The imported library will be null if the URI does not reference a valid | 6638 // The imported library will be null if the URI does not reference a valid |
| 6639 // library. | 6639 // library. |
| 6640 // | 6640 // |
| 6641 return Namespace.EMPTY; | 6641 return Namespace.EMPTY; |
| 6642 } | 6642 } |
| 6643 HashMap<String, Element> definedNames = | 6643 HashMap<String, Element> exportedNames = _getExportMapping(importedLibrary); |
| 6644 _createExportMapping(importedLibrary, new HashSet<LibraryElement>()); | 6644 exportedNames = _applyCombinators(exportedNames, element.combinators); |
| 6645 definedNames = _applyCombinators(definedNames, element.combinators); | 6645 exportedNames = _applyPrefix(exportedNames, element.prefix); |
| 6646 definedNames = _applyPrefix(definedNames, element.prefix); | 6646 return new Namespace(exportedNames); |
| 6647 return new Namespace(definedNames); | |
| 6648 } | 6647 } |
| 6649 | 6648 |
| 6650 /** | 6649 /** |
| 6651 * Create a namespace representing the public namespace of the given library. | 6650 * Create a namespace representing the public namespace of the given library. |
| 6652 * | 6651 * |
| 6653 * @param library the library whose public namespace is to be created | 6652 * @param library the library whose public namespace is to be created |
| 6654 * @return the public namespace that was created | 6653 * @return the public namespace that was created |
| 6655 */ | 6654 */ |
| 6656 Namespace createPublicNamespaceForLibrary(LibraryElement library) { | 6655 Namespace createPublicNamespaceForLibrary(LibraryElement library) { |
| 6657 HashMap<String, Element> definedNames = new HashMap<String, Element>(); | 6656 HashMap<String, Element> definedNames = new HashMap<String, Element>(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6752 HashMap<String, Element> newNames = new HashMap<String, Element>(); | 6751 HashMap<String, Element> newNames = new HashMap<String, Element>(); |
| 6753 definedNames.forEach((String name, Element element) { | 6752 definedNames.forEach((String name, Element element) { |
| 6754 newNames["$prefix.$name"] = element; | 6753 newNames["$prefix.$name"] = element; |
| 6755 }); | 6754 }); |
| 6756 return newNames; | 6755 return newNames; |
| 6757 } else { | 6756 } else { |
| 6758 return definedNames; | 6757 return definedNames; |
| 6759 } | 6758 } |
| 6760 } | 6759 } |
| 6761 | 6760 |
| 6761 HashMap<String, Element> _getExportMapping(LibraryElement library) { | |
| 6762 if (library is LibraryElementImpl) { | |
| 6763 if (library.exportNamespace != null) { | |
| 6764 return library.exportNamespace.definedNames; | |
| 6765 } else { | |
| 6766 HashMap<String, Element> exportMapping = | |
| 6767 _computeExportMapping(library, new HashSet<LibraryElement>()); | |
| 6768 library.exportNamespace = new Namespace(exportMapping); | |
|
Brian Wilkerson
2016/03/20 21:26:29
Shouldn't we just return 'exportMapping' at this p
scheglov
2016/03/20 22:16:47
Fixed.
Thanks!
| |
| 6769 } | |
| 6770 } | |
| 6771 return _computeExportMapping(library, new HashSet<LibraryElement>()); | |
| 6772 } | |
| 6773 | |
| 6762 /** | 6774 /** |
| 6763 * Create a mapping table representing the export namespace of the given libra ry. | 6775 * Create a mapping table representing the export namespace of the given libra ry. |
| 6764 * | 6776 * |
| 6765 * @param library the library whose public namespace is to be created | 6777 * @param library the library whose public namespace is to be created |
| 6766 * @param visitedElements a set of libraries that do not need to be visited wh en processing the | 6778 * @param visitedElements a set of libraries that do not need to be visited wh en processing the |
| 6767 * export directives of the given library because all of the names de fined by them will | 6779 * export directives of the given library because all of the names de fined by them will |
| 6768 * be added by another library | 6780 * be added by another library |
| 6769 * @return the mapping table that was created | 6781 * @return the mapping table that was created |
| 6770 */ | 6782 */ |
| 6771 HashMap<String, Element> _createExportMapping( | 6783 HashMap<String, Element> _computeExportMapping( |
| 6772 LibraryElement library, HashSet<LibraryElement> visitedElements) { | 6784 LibraryElement library, HashSet<LibraryElement> visitedElements) { |
| 6773 visitedElements.add(library); | 6785 visitedElements.add(library); |
| 6774 try { | 6786 try { |
| 6775 HashMap<String, Element> definedNames = new HashMap<String, Element>(); | 6787 HashMap<String, Element> definedNames = new HashMap<String, Element>(); |
| 6776 for (ExportElement element in library.exports) { | 6788 for (ExportElement element in library.exports) { |
| 6777 LibraryElement exportedLibrary = element.exportedLibrary; | 6789 LibraryElement exportedLibrary = element.exportedLibrary; |
| 6778 if (exportedLibrary != null && | 6790 if (exportedLibrary != null && |
| 6779 !visitedElements.contains(exportedLibrary)) { | 6791 !visitedElements.contains(exportedLibrary)) { |
| 6780 // | 6792 // |
| 6781 // The exported library will be null if the URI does not reference a | 6793 // The exported library will be null if the URI does not reference a |
| 6782 // valid library. | 6794 // valid library. |
| 6783 // | 6795 // |
| 6784 HashMap<String, Element> exportedNames = | 6796 HashMap<String, Element> exportedNames = |
| 6785 _createExportMapping(exportedLibrary, visitedElements); | 6797 _computeExportMapping(exportedLibrary, visitedElements); |
| 6786 exportedNames = _applyCombinators(exportedNames, element.combinators); | 6798 exportedNames = _applyCombinators(exportedNames, element.combinators); |
| 6787 definedNames.addAll(exportedNames); | 6799 definedNames.addAll(exportedNames); |
| 6788 } | 6800 } |
| 6789 } | 6801 } |
| 6790 _addAllFromNamespace( | 6802 _addAllFromNamespace( |
| 6791 definedNames, | 6803 definedNames, |
| 6792 (library.context as InternalAnalysisContext) | 6804 (library.context as InternalAnalysisContext) |
| 6793 .getPublicNamespace(library)); | 6805 .getPublicNamespace(library)); |
| 6794 return definedNames; | 6806 return definedNames; |
| 6795 } finally { | 6807 } finally { |
| (...skipping 6164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12960 nonFields.add(node); | 12972 nonFields.add(node); |
| 12961 return null; | 12973 return null; |
| 12962 } | 12974 } |
| 12963 | 12975 |
| 12964 @override | 12976 @override |
| 12965 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 12977 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 12966 | 12978 |
| 12967 @override | 12979 @override |
| 12968 Object visitWithClause(WithClause node) => null; | 12980 Object visitWithClause(WithClause node) => null; |
| 12969 } | 12981 } |
| OLD | NEW |