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.dart.element.builder; | 5 library analyzer.src.dart.element.builder; |
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 * The analysis context within which directive elements are being built. | 67 * The analysis context within which directive elements are being built. |
68 */ | 68 */ |
69 final AnalysisContext context; | 69 final AnalysisContext context; |
70 | 70 |
71 /** | 71 /** |
72 * The library element for which directive elements are being built. | 72 * The library element for which directive elements are being built. |
73 */ | 73 */ |
74 final LibraryElementImpl libraryElement; | 74 final LibraryElementImpl libraryElement; |
75 | 75 |
76 /** | 76 /** |
77 * Map from sources imported by this library to their modification times. | 77 * Map from sources referenced by this library to their modification times. |
78 */ | 78 */ |
79 final Map<Source, int> importModificationTimeMap; | 79 final Map<Source, int> sourceModificationTimeMap; |
80 | 80 |
81 /** | 81 /** |
82 * Map from sources imported by this library to their corresponding library | 82 * Map from sources imported by this library to their corresponding library |
83 * elements. | 83 * elements. |
84 */ | 84 */ |
85 final Map<Source, LibraryElement> importLibraryMap; | 85 final Map<Source, LibraryElement> importLibraryMap; |
86 | 86 |
87 /** | 87 /** |
88 * Map from sources imported by this library to their corresponding source | 88 * Map from sources imported by this library to their corresponding source |
89 * kinds. | 89 * kinds. |
90 */ | 90 */ |
91 final Map<Source, SourceKind> importSourceKindMap; | 91 final Map<Source, SourceKind> importSourceKindMap; |
92 | 92 |
93 /** | 93 /** |
94 * Map from sources exported by this library to their modification times. | |
95 */ | |
96 final Map<Source, int> exportModificationTimeMap; | |
97 | |
98 /** | |
99 * Map from sources exported by this library to their corresponding library | 94 * Map from sources exported by this library to their corresponding library |
100 * elements. | 95 * elements. |
101 */ | 96 */ |
102 final Map<Source, LibraryElement> exportLibraryMap; | 97 final Map<Source, LibraryElement> exportLibraryMap; |
103 | 98 |
104 /** | 99 /** |
105 * Map from sources exported by this library to their corresponding source | 100 * Map from sources exported by this library to their corresponding source |
106 * kinds. | 101 * kinds. |
107 */ | 102 */ |
108 final Map<Source, SourceKind> exportSourceKindMap; | 103 final Map<Source, SourceKind> exportSourceKindMap; |
(...skipping 20 matching lines...) Expand all Loading... |
129 new HashMap<String, PrefixElementImpl>(); | 124 new HashMap<String, PrefixElementImpl>(); |
130 | 125 |
131 /** | 126 /** |
132 * Indicates whether an explicit import of `dart:core` has been found. | 127 * Indicates whether an explicit import of `dart:core` has been found. |
133 */ | 128 */ |
134 bool explicitlyImportsCore = false; | 129 bool explicitlyImportsCore = false; |
135 | 130 |
136 DirectiveElementBuilder( | 131 DirectiveElementBuilder( |
137 this.context, | 132 this.context, |
138 this.libraryElement, | 133 this.libraryElement, |
139 this.importModificationTimeMap, | 134 this.sourceModificationTimeMap, |
140 this.importLibraryMap, | 135 this.importLibraryMap, |
141 this.importSourceKindMap, | 136 this.importSourceKindMap, |
142 this.exportModificationTimeMap, | |
143 this.exportLibraryMap, | 137 this.exportLibraryMap, |
144 this.exportSourceKindMap); | 138 this.exportSourceKindMap); |
145 | 139 |
146 @override | 140 @override |
147 Object visitCompilationUnit(CompilationUnit node) { | 141 Object visitCompilationUnit(CompilationUnit node) { |
148 // | 142 // |
149 // Resolve directives. | 143 // Resolve directives. |
150 // | 144 // |
151 for (Directive directive in node.directives) { | 145 for (Directive directive in node.directives) { |
152 directive.accept(this); | 146 directive.accept(this); |
(...skipping 15 matching lines...) Expand all Loading... |
168 libraryElement.imports = imports; | 162 libraryElement.imports = imports; |
169 libraryElement.exports = exports; | 163 libraryElement.exports = exports; |
170 return null; | 164 return null; |
171 } | 165 } |
172 | 166 |
173 @override | 167 @override |
174 Object visitExportDirective(ExportDirective node) { | 168 Object visitExportDirective(ExportDirective node) { |
175 // Remove previous element. (It will remain null if the target is missing.) | 169 // Remove previous element. (It will remain null if the target is missing.) |
176 node.element = null; | 170 node.element = null; |
177 Source exportedSource = node.source; | 171 Source exportedSource = node.source; |
178 int exportedTime = exportModificationTimeMap[exportedSource] ?? -1; | 172 int exportedTime = sourceModificationTimeMap[exportedSource] ?? -1; |
179 if (exportedTime != -1) { | 173 if (exportedTime != -1) { |
180 // The exported source will be null if the URI in the export | 174 // The exported source will be null if the URI in the export |
181 // directive was invalid. | 175 // directive was invalid. |
182 LibraryElement exportedLibrary = exportLibraryMap[exportedSource]; | 176 LibraryElement exportedLibrary = exportLibraryMap[exportedSource]; |
183 if (exportedLibrary != null) { | 177 if (exportedLibrary != null) { |
184 ExportElementImpl exportElement = new ExportElementImpl(node.offset); | 178 ExportElementImpl exportElement = new ExportElementImpl(node.offset); |
185 exportElement.metadata = _getElementAnnotations(node.metadata); | 179 exportElement.metadata = _getElementAnnotations(node.metadata); |
186 StringLiteral uriLiteral = node.uri; | 180 StringLiteral uriLiteral = node.uri; |
187 if (uriLiteral != null) { | 181 if (uriLiteral != null) { |
188 exportElement.uriOffset = uriLiteral.offset; | 182 exportElement.uriOffset = uriLiteral.offset; |
(...skipping 22 matching lines...) Expand all Loading... |
211 } | 205 } |
212 } | 206 } |
213 return null; | 207 return null; |
214 } | 208 } |
215 | 209 |
216 @override | 210 @override |
217 Object visitImportDirective(ImportDirective node) { | 211 Object visitImportDirective(ImportDirective node) { |
218 // Remove previous element. (It will remain null if the target is missing.) | 212 // Remove previous element. (It will remain null if the target is missing.) |
219 node.element = null; | 213 node.element = null; |
220 Source importedSource = node.source; | 214 Source importedSource = node.source; |
221 int importedTime = importModificationTimeMap[importedSource] ?? -1; | 215 int importedTime = sourceModificationTimeMap[importedSource] ?? -1; |
222 if (importedTime != -1) { | 216 if (importedTime != -1) { |
223 // The imported source will be null if the URI in the import | 217 // The imported source will be null if the URI in the import |
224 // directive was invalid. | 218 // directive was invalid. |
225 LibraryElement importedLibrary = importLibraryMap[importedSource]; | 219 LibraryElement importedLibrary = importLibraryMap[importedSource]; |
226 if (importedLibrary != null) { | 220 if (importedLibrary != null) { |
227 if (importedLibrary.isDartCore) { | 221 if (importedLibrary.isDartCore) { |
228 explicitlyImportsCore = true; | 222 explicitlyImportsCore = true; |
229 } | 223 } |
230 ImportElementImpl importElement = new ImportElementImpl(node.offset); | 224 ImportElementImpl importElement = new ImportElementImpl(node.offset); |
231 importElement.metadata = _getElementAnnotations(node.metadata); | 225 importElement.metadata = _getElementAnnotations(node.metadata); |
(...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1512 return null; | 1506 return null; |
1513 } | 1507 } |
1514 | 1508 |
1515 /** | 1509 /** |
1516 * Return the lexical identifiers associated with the given [identifiers]. | 1510 * Return the lexical identifiers associated with the given [identifiers]. |
1517 */ | 1511 */ |
1518 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) { | 1512 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) { |
1519 return identifiers.map((identifier) => identifier.name).toList(); | 1513 return identifiers.map((identifier) => identifier.name).toList(); |
1520 } | 1514 } |
1521 } | 1515 } |
OLD | NEW |