OLD | NEW |
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 analyzer.src.task.dart; | 5 library analyzer.src.task.dart; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'dart:math' as math; | 8 import 'dart:math' as math; |
9 | 9 |
10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
(...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 for (Directive directive in definingCompilationUnit.directives) { | 1295 for (Directive directive in definingCompilationUnit.directives) { |
1296 if (directive is LibraryDirective) { | 1296 if (directive is LibraryDirective) { |
1297 if (libraryNameNode == null) { | 1297 if (libraryNameNode == null) { |
1298 libraryNameNode = directive.name; | 1298 libraryNameNode = directive.name; |
1299 directivesToResolve.add(directive); | 1299 directivesToResolve.add(directive); |
1300 } | 1300 } |
1301 } else if (directive is PartDirective) { | 1301 } else if (directive is PartDirective) { |
1302 PartDirective partDirective = directive; | 1302 PartDirective partDirective = directive; |
1303 StringLiteral partUri = partDirective.uri; | 1303 StringLiteral partUri = partDirective.uri; |
1304 Source partSource = partDirective.source; | 1304 Source partSource = partDirective.source; |
1305 if (context.exists(partSource)) { | 1305 hasPartDirective = true; |
1306 hasPartDirective = true; | 1306 CompilationUnit partUnit = partUnitMap[partSource]; |
1307 CompilationUnit partUnit = partUnitMap[partSource]; | 1307 CompilationUnitElementImpl partElement = partUnit.element; |
1308 CompilationUnitElementImpl partElement = partUnit.element; | 1308 partElement.uriOffset = partUri.offset; |
1309 partElement.uriOffset = partUri.offset; | 1309 partElement.uriEnd = partUri.end; |
1310 partElement.uriEnd = partUri.end; | 1310 partElement.uri = partDirective.uriContent; |
1311 partElement.uri = partDirective.uriContent; | 1311 // |
1312 // | 1312 // Validate that the part contains a part-of directive with the same |
1313 // Validate that the part contains a part-of directive with the same | 1313 // name as the library. |
1314 // name as the library. | 1314 // |
1315 // | 1315 String partLibraryName = |
1316 String partLibraryName = | 1316 _getPartLibraryName(partSource, partUnit, directivesToResolve); |
1317 _getPartLibraryName(partSource, partUnit, directivesToResolve); | 1317 if (partLibraryName == null) { |
1318 if (partLibraryName == null) { | 1318 errors.add(new AnalysisError(librarySource, partUri.offset, |
1319 errors.add(new AnalysisError(librarySource, partUri.offset, | 1319 partUri.length, CompileTimeErrorCode.PART_OF_NON_PART, |
1320 partUri.length, CompileTimeErrorCode.PART_OF_NON_PART, | 1320 [partUri.toSource()])); |
1321 [partUri.toSource()])); | 1321 } else if (libraryNameNode == null) { |
1322 } else if (libraryNameNode == null) { | 1322 if (partsLibraryName == _UNKNOWN_LIBRARY_NAME) { |
1323 if (partsLibraryName == _UNKNOWN_LIBRARY_NAME) { | 1323 partsLibraryName = partLibraryName; |
1324 partsLibraryName = partLibraryName; | 1324 } else if (partsLibraryName != partLibraryName) { |
1325 } else if (partsLibraryName != partLibraryName) { | 1325 partsLibraryName = null; |
1326 partsLibraryName = null; | |
1327 } | |
1328 } else if (libraryNameNode.name != partLibraryName) { | |
1329 errors.add(new AnalysisError(librarySource, partUri.offset, | |
1330 partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [ | |
1331 libraryNameNode.name, | |
1332 partLibraryName | |
1333 ])); | |
1334 } | 1326 } |
1335 if (entryPoint == null) { | 1327 } else if (libraryNameNode.name != partLibraryName) { |
1336 entryPoint = _findEntryPoint(partElement); | 1328 errors.add(new AnalysisError(librarySource, partUri.offset, |
1337 } | 1329 partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [ |
1338 directive.element = partElement; | 1330 libraryNameNode.name, |
1339 sourcedCompilationUnits.add(partElement); | 1331 partLibraryName |
| 1332 ])); |
1340 } | 1333 } |
| 1334 if (entryPoint == null) { |
| 1335 entryPoint = _findEntryPoint(partElement); |
| 1336 } |
| 1337 directive.element = partElement; |
| 1338 sourcedCompilationUnits.add(partElement); |
1341 } | 1339 } |
1342 } | 1340 } |
1343 if (hasPartDirective && libraryNameNode == null) { | 1341 if (hasPartDirective && libraryNameNode == null) { |
1344 AnalysisError error; | 1342 AnalysisError error; |
1345 if (partsLibraryName != _UNKNOWN_LIBRARY_NAME && | 1343 if (partsLibraryName != _UNKNOWN_LIBRARY_NAME && |
1346 partsLibraryName != null) { | 1344 partsLibraryName != null) { |
1347 error = new AnalysisErrorWithProperties(librarySource, 0, 0, | 1345 error = new AnalysisErrorWithProperties(librarySource, 0, 0, |
1348 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART) | 1346 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART) |
1349 ..setProperty(ErrorProperty.PARTS_LIBRARY_NAME, partsLibraryName); | 1347 ..setProperty(ErrorProperty.PARTS_LIBRARY_NAME, partsLibraryName); |
1350 } else { | 1348 } else { |
(...skipping 1917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3268 @override | 3266 @override |
3269 bool moveNext() { | 3267 bool moveNext() { |
3270 if (_newSources.isEmpty) { | 3268 if (_newSources.isEmpty) { |
3271 return false; | 3269 return false; |
3272 } | 3270 } |
3273 currentTarget = _newSources.first; | 3271 currentTarget = _newSources.first; |
3274 _newSources.remove(currentTarget); | 3272 _newSources.remove(currentTarget); |
3275 return true; | 3273 return true; |
3276 } | 3274 } |
3277 } | 3275 } |
OLD | NEW |