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.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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 } | 206 } |
| 207 return null; | 207 return null; |
| 208 } | 208 } |
| 209 | 209 |
| 210 @override | 210 @override |
| 211 Object visitImportDirective(ImportDirective node) { | 211 Object visitImportDirective(ImportDirective node) { |
| 212 // 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.) |
| 213 node.element = null; | 213 node.element = null; |
| 214 Source importedSource = node.source; | 214 Source importedSource = node.source; |
| 215 int importedTime = sourceModificationTimeMap[importedSource] ?? -1; | 215 int importedTime = sourceModificationTimeMap[importedSource] ?? -1; |
| 216 if (importedTime != -1) { | 216 // The imported source will be null if the URI in the import |
|
Brian Wilkerson
2016/08/08 20:50:38
I moved the test for a missing source to line 249
| |
| 217 // The imported source will be null if the URI in the import | 217 // directive was invalid. |
| 218 // directive was invalid. | 218 LibraryElement importedLibrary = importLibraryMap[importedSource]; |
| 219 LibraryElement importedLibrary = importLibraryMap[importedSource]; | 219 if (importedLibrary != null) { |
| 220 if (importedLibrary != null) { | 220 if (importedLibrary.isDartCore) { |
| 221 if (importedLibrary.isDartCore) { | 221 explicitlyImportsCore = true; |
| 222 explicitlyImportsCore = true; | 222 } |
| 223 ImportElementImpl importElement = new ImportElementImpl(node.offset); | |
| 224 importElement.metadata = _getElementAnnotations(node.metadata); | |
| 225 StringLiteral uriLiteral = node.uri; | |
| 226 if (uriLiteral != null) { | |
| 227 importElement.uriOffset = uriLiteral.offset; | |
| 228 importElement.uriEnd = uriLiteral.end; | |
| 229 } | |
| 230 importElement.uri = node.uriContent; | |
| 231 importElement.deferred = node.deferredKeyword != null; | |
| 232 importElement.combinators = _buildCombinators(node); | |
| 233 importElement.importedLibrary = importedLibrary; | |
| 234 setElementDocumentationComment(importElement, node); | |
| 235 SimpleIdentifier prefixNode = node.prefix; | |
| 236 if (prefixNode != null) { | |
| 237 importElement.prefixOffset = prefixNode.offset; | |
| 238 String prefixName = prefixNode.name; | |
| 239 PrefixElementImpl prefix = nameToPrefixMap[prefixName]; | |
| 240 if (prefix == null) { | |
| 241 prefix = new PrefixElementImpl.forNode(prefixNode); | |
| 242 nameToPrefixMap[prefixName] = prefix; | |
| 223 } | 243 } |
| 224 ImportElementImpl importElement = new ImportElementImpl(node.offset); | 244 importElement.prefix = prefix; |
| 225 importElement.metadata = _getElementAnnotations(node.metadata); | 245 prefixNode.staticElement = prefix; |
| 226 StringLiteral uriLiteral = node.uri; | 246 } |
| 247 node.element = importElement; | |
| 248 imports.add(importElement); | |
| 249 if (importedTime >= 0 && | |
| 250 importSourceKindMap[importedSource] != SourceKind.LIBRARY) { | |
| 251 int offset = node.offset; | |
| 252 int length = node.length; | |
| 227 if (uriLiteral != null) { | 253 if (uriLiteral != null) { |
| 228 importElement.uriOffset = uriLiteral.offset; | 254 offset = uriLiteral.offset; |
| 229 importElement.uriEnd = uriLiteral.end; | 255 length = uriLiteral.length; |
| 230 } | 256 } |
| 231 importElement.uri = node.uriContent; | 257 ErrorCode errorCode = importElement.isDeferred |
| 232 importElement.deferred = node.deferredKeyword != null; | 258 ? StaticWarningCode.IMPORT_OF_NON_LIBRARY |
| 233 importElement.combinators = _buildCombinators(node); | 259 : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY; |
| 234 importElement.importedLibrary = importedLibrary; | 260 errors.add(new AnalysisError(libraryElement.source, offset, length, |
| 235 setElementDocumentationComment(importElement, node); | 261 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 } | 262 } |
| 264 } | 263 } |
| 265 return null; | 264 return null; |
| 266 } | 265 } |
| 267 | 266 |
| 268 @override | 267 @override |
| 269 Object visitLibraryDirective(LibraryDirective node) { | 268 Object visitLibraryDirective(LibraryDirective node) { |
| 270 (node.element as LibraryElementImpl)?.metadata = | 269 (node.element as LibraryElementImpl)?.metadata = |
| 271 _getElementAnnotations(node.metadata); | 270 _getElementAnnotations(node.metadata); |
| 272 return null; | 271 return null; |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 968 element.generator = true; | 967 element.generator = true; |
| 969 } | 968 } |
| 970 if (node.returnType == null) { | 969 if (node.returnType == null) { |
| 971 element.hasImplicitReturnType = true; | 970 element.hasImplicitReturnType = true; |
| 972 } | 971 } |
| 973 _currentHolder.addMethod(element); | 972 _currentHolder.addMethod(element); |
| 974 methodName.staticElement = element; | 973 methodName.staticElement = element; |
| 975 } else { | 974 } else { |
| 976 SimpleIdentifier propertyNameNode = node.name; | 975 SimpleIdentifier propertyNameNode = node.name; |
| 977 String propertyName = propertyNameNode.name; | 976 String propertyName = propertyNameNode.name; |
| 978 FieldElementImpl field = | 977 FieldElementImpl field = _currentHolder.getField(propertyName, |
| 979 _currentHolder.getField(propertyName, synthetic: true) as FieldEleme ntImpl; | 978 synthetic: true) as FieldElementImpl; |
| 980 if (field == null) { | 979 if (field == null) { |
| 981 field = new FieldElementImpl(node.name.name, -1); | 980 field = new FieldElementImpl(node.name.name, -1); |
| 982 field.final2 = true; | 981 field.final2 = true; |
| 983 field.static = isStatic; | 982 field.static = isStatic; |
| 984 field.synthetic = true; | 983 field.synthetic = true; |
| 985 _currentHolder.addField(field); | 984 _currentHolder.addField(field); |
| 986 } | 985 } |
| 987 if (node.isGetter) { | 986 if (node.isGetter) { |
| 988 PropertyAccessorElementImpl getter = | 987 PropertyAccessorElementImpl getter = |
| 989 new PropertyAccessorElementImpl.forNode(propertyNameNode); | 988 new PropertyAccessorElementImpl.forNode(propertyNameNode); |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1457 return null; | 1456 return null; |
| 1458 } | 1457 } |
| 1459 | 1458 |
| 1460 /** | 1459 /** |
| 1461 * Return the lexical identifiers associated with the given [identifiers]. | 1460 * Return the lexical identifiers associated with the given [identifiers]. |
| 1462 */ | 1461 */ |
| 1463 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) { | 1462 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) { |
| 1464 return identifiers.map((identifier) => identifier.name).toList(); | 1463 return identifiers.map((identifier) => identifier.name).toList(); |
| 1465 } | 1464 } |
| 1466 } | 1465 } |
| OLD | NEW |