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.sdk_io; | 5 library analyzer.src.generated.sdk_io; |
| 6 | 6 |
| 7 import 'dart:collection'; | |
| 7 import 'dart:io'; | 8 import 'dart:io'; |
| 8 | 9 |
| 9 import 'package:analyzer/src/context/context.dart'; | 10 import 'package:analyzer/src/context/context.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 11 import 'package:analyzer/src/generated/ast.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:analyzer/src/generated/error.dart'; | 13 import 'package:analyzer/src/generated/error.dart'; |
| 13 import 'package:analyzer/src/generated/java_core.dart'; | 14 import 'package:analyzer/src/generated/java_core.dart'; |
| 14 import 'package:analyzer/src/generated/java_engine.dart'; | 15 import 'package:analyzer/src/generated/java_engine.dart'; |
| 15 import 'package:analyzer/src/generated/java_engine_io.dart'; | 16 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 16 import 'package:analyzer/src/generated/java_io.dart'; | 17 import 'package:analyzer/src/generated/java_io.dart'; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 * The [AnalysisContext] which is used for all of the sources in this sdk. | 195 * The [AnalysisContext] which is used for all of the sources in this sdk. |
| 195 */ | 196 */ |
| 196 InternalAnalysisContext _analysisContext; | 197 InternalAnalysisContext _analysisContext; |
| 197 | 198 |
| 198 /** | 199 /** |
| 199 * The directory containing the SDK. | 200 * The directory containing the SDK. |
| 200 */ | 201 */ |
| 201 JavaFile _sdkDirectory; | 202 JavaFile _sdkDirectory; |
| 202 | 203 |
| 203 /** | 204 /** |
| 205 * The directory within the SDK directory that contains the libraries. | |
| 206 */ | |
| 207 JavaFile _libraryDirectory; | |
| 208 | |
| 209 /** | |
| 204 * The revision number of this SDK, or `"0"` if the revision number cannot be | 210 * The revision number of this SDK, or `"0"` if the revision number cannot be |
| 205 * discovered. | 211 * discovered. |
| 206 */ | 212 */ |
| 207 String _sdkVersion; | 213 String _sdkVersion; |
| 208 | 214 |
| 209 /** | 215 /** |
| 210 * The file containing the dart2js executable. | 216 * The file containing the dart2js executable. |
| 211 */ | 217 */ |
| 212 JavaFile _dart2jsExecutable; | 218 JavaFile _dart2jsExecutable; |
| 213 | 219 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 225 * The file containing the VM executable. | 231 * The file containing the VM executable. |
| 226 */ | 232 */ |
| 227 JavaFile _vmExecutable; | 233 JavaFile _vmExecutable; |
| 228 | 234 |
| 229 /** | 235 /** |
| 230 * A mapping from Dart library URI's to the library represented by that URI. | 236 * A mapping from Dart library URI's to the library represented by that URI. |
| 231 */ | 237 */ |
| 232 LibraryMap _libraryMap; | 238 LibraryMap _libraryMap; |
| 233 | 239 |
| 234 /** | 240 /** |
| 241 * The mapping from Dart URI's to the corresponding sources. | |
| 242 */ | |
| 243 Map<String, Source> _uriToSourceMap = new HashMap<String, Source>(); | |
| 244 | |
| 245 /** | |
| 235 * Initialize a newly created SDK to represent the Dart SDK installed in the | 246 * Initialize a newly created SDK to represent the Dart SDK installed in the |
| 236 * [sdkDirectory]. The flag [useDart2jsPaths] is `true` if the dart2js path | 247 * [sdkDirectory]. The flag [useDart2jsPaths] is `true` if the dart2js path |
| 237 * should be used when it is available | 248 * should be used when it is available |
| 238 */ | 249 */ |
| 239 DirectoryBasedDartSdk(JavaFile sdkDirectory, [bool useDart2jsPaths = false]) { | 250 DirectoryBasedDartSdk(JavaFile sdkDirectory, [bool useDart2jsPaths = false]) { |
| 240 this._sdkDirectory = sdkDirectory.getAbsoluteFile(); | 251 this._sdkDirectory = sdkDirectory.getAbsoluteFile(); |
| 241 _libraryMap = initialLibraryMap(useDart2jsPaths); | 252 _libraryMap = initialLibraryMap(useDart2jsPaths); |
| 242 } | 253 } |
| 243 | 254 |
| 244 @override | 255 @override |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 bool get hasDocumentation => docDirectory.exists(); | 337 bool get hasDocumentation => docDirectory.exists(); |
| 327 | 338 |
| 328 /** | 339 /** |
| 329 * Return `true` if the Dartium binary is available. | 340 * Return `true` if the Dartium binary is available. |
| 330 */ | 341 */ |
| 331 bool get isDartiumInstalled => dartiumExecutable != null; | 342 bool get isDartiumInstalled => dartiumExecutable != null; |
| 332 | 343 |
| 333 /** | 344 /** |
| 334 * Return the directory within the SDK directory that contains the libraries. | 345 * Return the directory within the SDK directory that contains the libraries. |
| 335 */ | 346 */ |
| 336 JavaFile get libraryDirectory => | 347 JavaFile get libraryDirectory { |
| 337 new JavaFile.relative(_sdkDirectory, _LIB_DIRECTORY_NAME); | 348 if (_libraryDirectory == null) { |
| 349 _libraryDirectory = | |
| 350 new JavaFile.relative(_sdkDirectory, _LIB_DIRECTORY_NAME); | |
| 351 } | |
| 352 return _libraryDirectory; | |
| 353 } | |
| 338 | 354 |
| 339 /** | 355 /** |
| 340 * Return the file containing the Pub executable, or `null` if it does not exi st. | 356 * Return the file containing the Pub executable, or `null` if it does not exi st. |
| 341 */ | 357 */ |
| 342 JavaFile get pubExecutable { | 358 JavaFile get pubExecutable { |
| 343 if (_pubExecutable == null) { | 359 if (_pubExecutable == null) { |
| 344 _pubExecutable = _verifyExecutable(new JavaFile.relative( | 360 _pubExecutable = _verifyExecutable(new JavaFile.relative( |
| 345 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), | 361 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), |
| 346 OSUtilities.isWindows() | 362 OSUtilities.isWindows() |
| 347 ? _PUB_EXECUTABLE_NAME_WIN | 363 ? _PUB_EXECUTABLE_NAME_WIN |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 | 501 |
| 486 @override | 502 @override |
| 487 SdkLibrary getSdkLibrary(String dartUri) => _libraryMap.getLibrary(dartUri); | 503 SdkLibrary getSdkLibrary(String dartUri) => _libraryMap.getLibrary(dartUri); |
| 488 | 504 |
| 489 /** | 505 /** |
| 490 * Read all of the configuration files to initialize the library maps. The | 506 * Read all of the configuration files to initialize the library maps. The |
| 491 * flag [useDart2jsPaths] is `true` if the dart2js path should be used when it | 507 * flag [useDart2jsPaths] is `true` if the dart2js path should be used when it |
| 492 * is available. Return the initialized library map. | 508 * is available. Return the initialized library map. |
| 493 */ | 509 */ |
| 494 LibraryMap initialLibraryMap(bool useDart2jsPaths) { | 510 LibraryMap initialLibraryMap(bool useDart2jsPaths) { |
| 511 print('initialLibraryMap'); | |
|
Brian Wilkerson
2016/01/12 20:23:36
Remove?
| |
| 495 List<String> searchedPaths = <String>[]; | 512 List<String> searchedPaths = <String>[]; |
| 496 var lastStackTrace = null; | 513 var lastStackTrace = null; |
| 497 var lastException = null; | 514 var lastException = null; |
| 498 for (JavaFile librariesFile in _libraryMapLocations) { | 515 for (JavaFile librariesFile in _libraryMapLocations) { |
| 499 try { | 516 try { |
| 500 String contents = librariesFile.readAsStringSync(); | 517 String contents = librariesFile.readAsStringSync(); |
| 501 return new SdkLibrariesReader(useDart2jsPaths) | 518 return new SdkLibrariesReader(useDart2jsPaths) |
| 502 .readFromFile(librariesFile, contents); | 519 .readFromFile(librariesFile, contents); |
| 503 } catch (exception, stackTrace) { | 520 } catch (exception, stackTrace) { |
| 504 searchedPaths.add(librariesFile.getAbsolutePath()); | 521 searchedPaths.add(librariesFile.getAbsolutePath()); |
| 505 lastException = exception; | 522 lastException = exception; |
| 506 lastStackTrace = stackTrace; | 523 lastStackTrace = stackTrace; |
| 507 } | 524 } |
| 508 } | 525 } |
| 509 AnalysisEngine.instance.logger.logError( | 526 AnalysisEngine.instance.logger.logError( |
| 510 "Could not initialize the library map from $searchedPaths", | 527 "Could not initialize the library map from $searchedPaths", |
| 511 new CaughtException(lastException, lastStackTrace)); | 528 new CaughtException(lastException, lastStackTrace)); |
| 512 return new LibraryMap(); | 529 return new LibraryMap(); |
| 513 } | 530 } |
| 514 | 531 |
| 515 @override | 532 @override |
| 516 Source mapDartUri(String dartUri) { | 533 Source mapDartUri(String dartUri) { |
| 534 Source source = _uriToSourceMap[dartUri]; | |
| 535 if (source == null) { | |
| 536 source = _mapDartUri(dartUri); | |
| 537 _uriToSourceMap[dartUri] = source; | |
| 538 } | |
| 539 return source; | |
| 540 } | |
| 541 | |
| 542 /** | |
| 543 * Return the [SdkBundle] for this SDK, if it exists, or `null` otherwise. | |
| 544 */ | |
| 545 SdkBundle _getSummarySdkBundle() { | |
| 546 String rootPath = directory.getAbsolutePath(); | |
| 547 String path = pathos.join(rootPath, 'lib', '_internal', 'analysis_summary'); | |
| 548 try { | |
| 549 File file = new File(path); | |
| 550 if (file.existsSync()) { | |
| 551 List<int> bytes = file.readAsBytesSync(); | |
| 552 return new SdkBundle.fromBuffer(bytes); | |
| 553 } | |
| 554 } catch (exception, stackTrace) { | |
| 555 AnalysisEngine.instance.logger.logError( | |
| 556 'Failed to load SDK analysis summary from $path', | |
| 557 new CaughtException(exception, stackTrace)); | |
| 558 } | |
| 559 return null; | |
| 560 } | |
| 561 | |
| 562 FileBasedSource _mapDartUri(String dartUri) { | |
| 517 String libraryName; | 563 String libraryName; |
| 518 String relativePath; | 564 String relativePath; |
| 519 int index = dartUri.indexOf('/'); | 565 int index = dartUri.indexOf('/'); |
| 520 if (index >= 0) { | 566 if (index >= 0) { |
| 521 libraryName = dartUri.substring(0, index); | 567 libraryName = dartUri.substring(0, index); |
| 522 relativePath = dartUri.substring(index + 1); | 568 relativePath = dartUri.substring(index + 1); |
| 523 } else { | 569 } else { |
| 524 libraryName = dartUri; | 570 libraryName = dartUri; |
| 525 relativePath = ""; | 571 relativePath = ""; |
| 526 } | 572 } |
| 527 SdkLibrary library = getSdkLibrary(libraryName); | 573 SdkLibrary library = getSdkLibrary(libraryName); |
| 528 if (library == null) { | 574 if (library == null) { |
| 529 return null; | 575 return null; |
| 530 } | 576 } |
| 531 try { | 577 try { |
| 532 JavaFile file = new JavaFile.relative(libraryDirectory, library.path); | 578 JavaFile file = new JavaFile.relative(libraryDirectory, library.path); |
| 533 if (!relativePath.isEmpty) { | 579 if (!relativePath.isEmpty) { |
| 534 file = file.getParentFile(); | 580 file = file.getParentFile(); |
| 535 file = new JavaFile.relative(file, relativePath); | 581 file = new JavaFile.relative(file, relativePath); |
| 536 } | 582 } |
| 537 return new FileBasedSource(file, parseUriWithException(dartUri)); | 583 return new FileBasedSource(file, parseUriWithException(dartUri)); |
| 538 } on URISyntaxException { | 584 } on URISyntaxException { |
| 539 return null; | 585 return null; |
| 540 } | 586 } |
| 541 } | 587 } |
| 542 | 588 |
| 543 /** | 589 /** |
| 544 * Return the [SdkBundle] for this SDK, if it exists, or `null` otherwise. | |
| 545 */ | |
| 546 SdkBundle _getSummarySdkBundle() { | |
| 547 String rootPath = directory.getAbsolutePath(); | |
| 548 String path = pathos.join(rootPath, 'lib', '_internal', 'analysis_summary'); | |
| 549 try { | |
| 550 File file = new File(path); | |
| 551 if (file.existsSync()) { | |
| 552 List<int> bytes = file.readAsBytesSync(); | |
| 553 return new SdkBundle.fromBuffer(bytes); | |
| 554 } | |
| 555 } catch (exception, stackTrace) { | |
| 556 AnalysisEngine.instance.logger.logError( | |
| 557 'Failed to load SDK analysis summary from $path', | |
| 558 new CaughtException(exception, stackTrace)); | |
| 559 } | |
| 560 return null; | |
| 561 } | |
| 562 | |
| 563 /** | |
| 564 * Return the given [file] if it exists and is executable, or `null` if it | 590 * Return the given [file] if it exists and is executable, or `null` if it |
| 565 * does not exist or is not executable. | 591 * does not exist or is not executable. |
| 566 */ | 592 */ |
| 567 JavaFile _verifyExecutable(JavaFile file) => | 593 JavaFile _verifyExecutable(JavaFile file) => |
| 568 file.isExecutable() ? file : null; | 594 file.isExecutable() ? file : null; |
| 569 } | 595 } |
| 570 | 596 |
| 571 /** | 597 /** |
| 572 * An object used to read and parse the libraries file | 598 * An object used to read and parse the libraries file |
| 573 * (dart-sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart) for informat ion | 599 * (dart-sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart) for informat ion |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 SdkLibrariesReader_LibraryBuilder libraryBuilder = | 650 SdkLibrariesReader_LibraryBuilder libraryBuilder = |
| 625 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); | 651 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); |
| 626 // If any syntactic errors were found then don't try to visit the AST | 652 // If any syntactic errors were found then don't try to visit the AST |
| 627 // structure. | 653 // structure. |
| 628 if (!errorListener.errorReported) { | 654 if (!errorListener.errorReported) { |
| 629 unit.accept(libraryBuilder); | 655 unit.accept(libraryBuilder); |
| 630 } | 656 } |
| 631 return libraryBuilder.librariesMap; | 657 return libraryBuilder.librariesMap; |
| 632 } | 658 } |
| 633 } | 659 } |
| OLD | NEW |