| 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:collection'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 if (docFile.exists()) { | 526 if (docFile.exists()) { |
| 527 return docFile; | 527 return docFile; |
| 528 } | 528 } |
| 529 return null; | 529 return null; |
| 530 } | 530 } |
| 531 | 531 |
| 532 @override | 532 @override |
| 533 SdkLibrary getSdkLibrary(String dartUri) => _libraryMap.getLibrary(dartUri); | 533 SdkLibrary getSdkLibrary(String dartUri) => _libraryMap.getLibrary(dartUri); |
| 534 | 534 |
| 535 /** | 535 /** |
| 536 * Return the [PackageBundle] for this SDK, if it exists, or `null` otherwise. |
| 537 * This method should not be used outside of `analyzer` and `analyzer_cli` |
| 538 * packages. |
| 539 */ |
| 540 PackageBundle getSummarySdkBundle() { |
| 541 String rootPath = directory.getAbsolutePath(); |
| 542 bool strongMode = _analysisOptions?.strongMode ?? false; |
| 543 String name = strongMode ? 'strong.sum' : 'spec.sum'; |
| 544 String path = pathos.join(rootPath, 'lib', '_internal', name); |
| 545 try { |
| 546 File file = new File(path); |
| 547 if (file.existsSync()) { |
| 548 List<int> bytes = file.readAsBytesSync(); |
| 549 return new PackageBundle.fromBuffer(bytes); |
| 550 } |
| 551 } catch (exception, stackTrace) { |
| 552 AnalysisEngine.instance.logger.logError( |
| 553 'Failed to load SDK analysis summary from $path', |
| 554 new CaughtException(exception, stackTrace)); |
| 555 } |
| 556 return null; |
| 557 } |
| 558 |
| 559 /** |
| 536 * Read all of the configuration files to initialize the library maps. The | 560 * Read all of the configuration files to initialize the library maps. The |
| 537 * flag [useDart2jsPaths] is `true` if the dart2js path should be used when it | 561 * flag [useDart2jsPaths] is `true` if the dart2js path should be used when it |
| 538 * is available. Return the initialized library map. | 562 * is available. Return the initialized library map. |
| 539 */ | 563 */ |
| 540 LibraryMap initialLibraryMap(bool useDart2jsPaths) { | 564 LibraryMap initialLibraryMap(bool useDart2jsPaths) { |
| 541 List<String> searchedPaths = <String>[]; | 565 List<String> searchedPaths = <String>[]; |
| 542 var lastStackTrace = null; | 566 var lastStackTrace = null; |
| 543 var lastException = null; | 567 var lastException = null; |
| 544 for (JavaFile librariesFile in _libraryMapLocations) { | 568 for (JavaFile librariesFile in _libraryMapLocations) { |
| 545 try { | 569 try { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 561 @override | 585 @override |
| 562 Source mapDartUri(String dartUri) { | 586 Source mapDartUri(String dartUri) { |
| 563 Source source = _uriToSourceMap[dartUri]; | 587 Source source = _uriToSourceMap[dartUri]; |
| 564 if (source == null) { | 588 if (source == null) { |
| 565 source = _mapDartUri(dartUri); | 589 source = _mapDartUri(dartUri); |
| 566 _uriToSourceMap[dartUri] = source; | 590 _uriToSourceMap[dartUri] = source; |
| 567 } | 591 } |
| 568 return source; | 592 return source; |
| 569 } | 593 } |
| 570 | 594 |
| 571 /** | |
| 572 * Return the [PackageBundle] for this SDK, if it exists, or `null` otherwise. | |
| 573 * This method should not be used outside of `analyzer` and `analyzer_cli` | |
| 574 * packages. | |
| 575 */ | |
| 576 PackageBundle getSummarySdkBundle() { | |
| 577 String rootPath = directory.getAbsolutePath(); | |
| 578 bool strongMode = _analysisOptions?.strongMode ?? false; | |
| 579 String name = strongMode ? 'strong.sum' : 'spec.sum'; | |
| 580 String path = pathos.join(rootPath, 'lib', '_internal', name); | |
| 581 try { | |
| 582 File file = new File(path); | |
| 583 if (file.existsSync()) { | |
| 584 List<int> bytes = file.readAsBytesSync(); | |
| 585 return new PackageBundle.fromBuffer(bytes); | |
| 586 } | |
| 587 } catch (exception, stackTrace) { | |
| 588 AnalysisEngine.instance.logger.logError( | |
| 589 'Failed to load SDK analysis summary from $path', | |
| 590 new CaughtException(exception, stackTrace)); | |
| 591 } | |
| 592 return null; | |
| 593 } | |
| 594 | |
| 595 FileBasedSource _mapDartUri(String dartUri) { | 595 FileBasedSource _mapDartUri(String dartUri) { |
| 596 String libraryName; | 596 String libraryName; |
| 597 String relativePath; | 597 String relativePath; |
| 598 int index = dartUri.indexOf('/'); | 598 int index = dartUri.indexOf('/'); |
| 599 if (index >= 0) { | 599 if (index >= 0) { |
| 600 libraryName = dartUri.substring(0, index); | 600 libraryName = dartUri.substring(0, index); |
| 601 relativePath = dartUri.substring(index + 1); | 601 relativePath = dartUri.substring(index + 1); |
| 602 } else { | 602 } else { |
| 603 libraryName = dartUri; | 603 libraryName = dartUri; |
| 604 relativePath = ""; | 604 relativePath = ""; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 SdkLibrariesReader_LibraryBuilder libraryBuilder = | 683 SdkLibrariesReader_LibraryBuilder libraryBuilder = |
| 684 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); | 684 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); |
| 685 // If any syntactic errors were found then don't try to visit the AST | 685 // If any syntactic errors were found then don't try to visit the AST |
| 686 // structure. | 686 // structure. |
| 687 if (!errorListener.errorReported) { | 687 if (!errorListener.errorReported) { |
| 688 unit.accept(libraryBuilder); | 688 unit.accept(libraryBuilder); |
| 689 } | 689 } |
| 690 return libraryBuilder.librariesMap; | 690 return libraryBuilder.librariesMap; |
| 691 } | 691 } |
| 692 } | 692 } |
| OLD | NEW |