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

Side by Side Diff: pkg/analyzer/lib/src/dart/element/builder.dart

Issue 2226613004: Suppress follow-on errors when a file is imported with either a prefix or a show clause (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Cache URI existence in a modifier' Created 4 years, 4 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) 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 147 }
148 // 148 //
149 // Ensure "dart:core" import. 149 // Ensure "dart:core" import.
150 // 150 //
151 Source librarySource = libraryElement.source; 151 Source librarySource = libraryElement.source;
152 Source coreLibrarySource = context.sourceFactory.forUri(DartSdk.DART_CORE); 152 Source coreLibrarySource = context.sourceFactory.forUri(DartSdk.DART_CORE);
153 if (!explicitlyImportsCore && coreLibrarySource != librarySource) { 153 if (!explicitlyImportsCore && coreLibrarySource != librarySource) {
154 ImportElementImpl importElement = new ImportElementImpl(-1); 154 ImportElementImpl importElement = new ImportElementImpl(-1);
155 importElement.importedLibrary = importLibraryMap[coreLibrarySource]; 155 importElement.importedLibrary = importLibraryMap[coreLibrarySource];
156 importElement.synthetic = true; 156 importElement.synthetic = true;
157 importElement.uriExists = true;
157 imports.add(importElement); 158 imports.add(importElement);
158 } 159 }
159 // 160 //
160 // Populate the library element. 161 // Populate the library element.
161 // 162 //
162 libraryElement.imports = imports; 163 libraryElement.imports = imports;
163 libraryElement.exports = exports; 164 libraryElement.exports = exports;
164 return null; 165 return null;
165 } 166 }
166 167
167 @override 168 @override
168 Object visitExportDirective(ExportDirective node) { 169 Object visitExportDirective(ExportDirective node) {
169 // Remove previous element. (It will remain null if the target is missing.) 170 // Remove previous element. (It will remain null if the target is missing.)
170 node.element = null; 171 node.element = null;
171 Source exportedSource = node.source; 172 Source exportedSource = node.source;
172 int exportedTime = sourceModificationTimeMap[exportedSource] ?? -1; 173 int exportedTime = sourceModificationTimeMap[exportedSource] ?? -1;
173 if (exportedTime != -1) { 174 if (exportedTime != -1) {
174 // The exported source will be null if the URI in the export 175 // The exported source will be null if the URI in the export
175 // directive was invalid. 176 // directive was invalid.
176 LibraryElement exportedLibrary = exportLibraryMap[exportedSource]; 177 LibraryElement exportedLibrary = exportLibraryMap[exportedSource];
177 if (exportedLibrary != null) { 178 if (exportedLibrary != null) {
178 ExportElementImpl exportElement = new ExportElementImpl(node.offset); 179 ExportElementImpl exportElement = new ExportElementImpl(node.offset);
179 exportElement.metadata = _getElementAnnotations(node.metadata); 180 exportElement.metadata = _getElementAnnotations(node.metadata);
180 StringLiteral uriLiteral = node.uri; 181 StringLiteral uriLiteral = node.uri;
181 if (uriLiteral != null) { 182 if (uriLiteral != null) {
182 exportElement.uriOffset = uriLiteral.offset; 183 exportElement.uriOffset = uriLiteral.offset;
183 exportElement.uriEnd = uriLiteral.end; 184 exportElement.uriEnd = uriLiteral.end;
184 } 185 }
185 exportElement.uri = node.uriContent; 186 exportElement.uri = node.uriContent;
187 exportElement.uriExists = exportedTime >= 0;
scheglov 2016/08/09 17:45:04 We have already checked "exportedTime != -1" above
Brian Wilkerson 2016/08/09 18:11:25 Good catch! The asymmetry was unintentional, so I
186 exportElement.combinators = _buildCombinators(node); 188 exportElement.combinators = _buildCombinators(node);
187 exportElement.exportedLibrary = exportedLibrary; 189 exportElement.exportedLibrary = exportedLibrary;
188 setElementDocumentationComment(exportElement, node); 190 setElementDocumentationComment(exportElement, node);
189 node.element = exportElement; 191 node.element = exportElement;
190 exports.add(exportElement); 192 exports.add(exportElement);
191 if (exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) { 193 if (exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) {
192 int offset = node.offset; 194 int offset = node.offset;
193 int length = node.length; 195 int length = node.length;
194 if (uriLiteral != null) { 196 if (uriLiteral != null) {
195 offset = uriLiteral.offset; 197 offset = uriLiteral.offset;
(...skipping 10 matching lines...) Expand all
206 } 208 }
207 return null; 209 return null;
208 } 210 }
209 211
210 @override 212 @override
211 Object visitImportDirective(ImportDirective node) { 213 Object visitImportDirective(ImportDirective node) {
212 // Remove previous element. (It will remain null if the target is missing.) 214 // Remove previous element. (It will remain null if the target is missing.)
213 node.element = null; 215 node.element = null;
214 Source importedSource = node.source; 216 Source importedSource = node.source;
215 int importedTime = sourceModificationTimeMap[importedSource] ?? -1; 217 int importedTime = sourceModificationTimeMap[importedSource] ?? -1;
216 if (importedTime != -1) { 218 // 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 219 // directive was invalid.
218 // directive was invalid. 220 LibraryElement importedLibrary = importLibraryMap[importedSource];
219 LibraryElement importedLibrary = importLibraryMap[importedSource]; 221 if (importedLibrary != null) {
220 if (importedLibrary != null) { 222 if (importedLibrary.isDartCore) {
221 if (importedLibrary.isDartCore) { 223 explicitlyImportsCore = true;
222 explicitlyImportsCore = true; 224 }
225 ImportElementImpl importElement = new ImportElementImpl(node.offset);
226 importElement.metadata = _getElementAnnotations(node.metadata);
227 StringLiteral uriLiteral = node.uri;
228 if (uriLiteral != null) {
229 importElement.uriOffset = uriLiteral.offset;
230 importElement.uriEnd = uriLiteral.end;
231 }
232 importElement.uri = node.uriContent;
233 importElement.uriExists = importedTime >= 0;
234 importElement.deferred = node.deferredKeyword != null;
235 importElement.combinators = _buildCombinators(node);
236 importElement.importedLibrary = importedLibrary;
237 setElementDocumentationComment(importElement, node);
238 SimpleIdentifier prefixNode = node.prefix;
239 if (prefixNode != null) {
240 importElement.prefixOffset = prefixNode.offset;
241 String prefixName = prefixNode.name;
242 PrefixElementImpl prefix = nameToPrefixMap[prefixName];
243 if (prefix == null) {
244 prefix = new PrefixElementImpl.forNode(prefixNode);
245 nameToPrefixMap[prefixName] = prefix;
223 } 246 }
224 ImportElementImpl importElement = new ImportElementImpl(node.offset); 247 importElement.prefix = prefix;
225 importElement.metadata = _getElementAnnotations(node.metadata); 248 prefixNode.staticElement = prefix;
226 StringLiteral uriLiteral = node.uri; 249 }
250 node.element = importElement;
251 imports.add(importElement);
252 if (importedTime >= 0 &&
253 importSourceKindMap[importedSource] != SourceKind.LIBRARY) {
254 int offset = node.offset;
255 int length = node.length;
227 if (uriLiteral != null) { 256 if (uriLiteral != null) {
228 importElement.uriOffset = uriLiteral.offset; 257 offset = uriLiteral.offset;
229 importElement.uriEnd = uriLiteral.end; 258 length = uriLiteral.length;
230 } 259 }
231 importElement.uri = node.uriContent; 260 ErrorCode errorCode = importElement.isDeferred
232 importElement.deferred = node.deferredKeyword != null; 261 ? StaticWarningCode.IMPORT_OF_NON_LIBRARY
233 importElement.combinators = _buildCombinators(node); 262 : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY;
234 importElement.importedLibrary = importedLibrary; 263 errors.add(new AnalysisError(libraryElement.source, offset, length,
235 setElementDocumentationComment(importElement, node); 264 errorCode, [uriLiteral.toSource()]));
236 SimpleIdentifier prefixNode = node.prefix;
237 if (prefixNode != null) {
238 importElement.prefixOffset = prefixNode.offset;
239 String prefixName = prefixNode.name;
240 PrefixElementImpl prefix = nameToPrefixMap[prefixName];
241 if (prefix == null) {
242 prefix = new PrefixElementImpl.forNode(prefixNode);
243 nameToPrefixMap[prefixName] = prefix;
244 }
245 importElement.prefix = prefix;
246 prefixNode.staticElement = prefix;
247 }
248 node.element = importElement;
249 imports.add(importElement);
250 if (importSourceKindMap[importedSource] != SourceKind.LIBRARY) {
251 int offset = node.offset;
252 int length = node.length;
253 if (uriLiteral != null) {
254 offset = uriLiteral.offset;
255 length = uriLiteral.length;
256 }
257 ErrorCode errorCode = (importElement.isDeferred
258 ? StaticWarningCode.IMPORT_OF_NON_LIBRARY
259 : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY);
260 errors.add(new AnalysisError(libraryElement.source, offset, length,
261 errorCode, [uriLiteral.toSource()]));
262 }
263 } 265 }
264 } 266 }
265 return null; 267 return null;
266 } 268 }
267 269
268 @override 270 @override
269 Object visitLibraryDirective(LibraryDirective node) { 271 Object visitLibraryDirective(LibraryDirective node) {
270 (node.element as LibraryElementImpl)?.metadata = 272 (node.element as LibraryElementImpl)?.metadata =
271 _getElementAnnotations(node.metadata); 273 _getElementAnnotations(node.metadata);
272 return null; 274 return null;
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 element.generator = true; 970 element.generator = true;
969 } 971 }
970 if (node.returnType == null) { 972 if (node.returnType == null) {
971 element.hasImplicitReturnType = true; 973 element.hasImplicitReturnType = true;
972 } 974 }
973 _currentHolder.addMethod(element); 975 _currentHolder.addMethod(element);
974 methodName.staticElement = element; 976 methodName.staticElement = element;
975 } else { 977 } else {
976 SimpleIdentifier propertyNameNode = node.name; 978 SimpleIdentifier propertyNameNode = node.name;
977 String propertyName = propertyNameNode.name; 979 String propertyName = propertyNameNode.name;
978 FieldElementImpl field = 980 FieldElementImpl field = _currentHolder.getField(propertyName,
979 _currentHolder.getField(propertyName, synthetic: true) as FieldEleme ntImpl; 981 synthetic: true) as FieldElementImpl;
980 if (field == null) { 982 if (field == null) {
981 field = new FieldElementImpl(node.name.name, -1); 983 field = new FieldElementImpl(node.name.name, -1);
982 field.final2 = true; 984 field.final2 = true;
983 field.static = isStatic; 985 field.static = isStatic;
984 field.synthetic = true; 986 field.synthetic = true;
985 _currentHolder.addField(field); 987 _currentHolder.addField(field);
986 } 988 }
987 if (node.isGetter) { 989 if (node.isGetter) {
988 PropertyAccessorElementImpl getter = 990 PropertyAccessorElementImpl getter =
989 new PropertyAccessorElementImpl.forNode(propertyNameNode); 991 new PropertyAccessorElementImpl.forNode(propertyNameNode);
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 return null; 1459 return null;
1458 } 1460 }
1459 1461
1460 /** 1462 /**
1461 * Return the lexical identifiers associated with the given [identifiers]. 1463 * Return the lexical identifiers associated with the given [identifiers].
1462 */ 1464 */
1463 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) { 1465 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) {
1464 return identifiers.map((identifier) => identifier.name).toList(); 1466 return identifiers.map((identifier) => identifier.name).toList();
1465 } 1467 }
1466 } 1468 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/dart/element/element.dart ('k') | pkg/analyzer/lib/src/dart/element/element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698