| 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:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/context/context.dart'; | 9 import 'package:analyzer/src/context/context.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart'; | 11 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:analyzer/src/generated/error.dart'; | 12 import 'package:analyzer/src/generated/error.dart'; |
| 13 import 'package:analyzer/src/generated/java_core.dart'; | 13 import 'package:analyzer/src/generated/java_core.dart'; |
| 14 import 'package:analyzer/src/generated/java_engine.dart'; | 14 import 'package:analyzer/src/generated/java_engine.dart'; |
| 15 import 'package:analyzer/src/generated/java_engine_io.dart'; | 15 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 16 import 'package:analyzer/src/generated/java_io.dart'; | 16 import 'package:analyzer/src/generated/java_io.dart'; |
| 17 import 'package:analyzer/src/generated/parser.dart'; | 17 import 'package:analyzer/src/generated/parser.dart'; |
| 18 import 'package:analyzer/src/generated/scanner.dart'; | 18 import 'package:analyzer/src/generated/scanner.dart'; |
| 19 import 'package:analyzer/src/generated/sdk.dart'; | 19 import 'package:analyzer/src/generated/sdk.dart'; |
| 20 import 'package:analyzer/src/generated/source_io.dart'; | 20 import 'package:analyzer/src/generated/source_io.dart'; |
| 21 import 'package:analyzer/src/summary/format.dart' show SdkBundle; |
| 22 import 'package:analyzer/src/summary/summary_sdk.dart'; |
| 23 import 'package:path/path.dart' as pathos; |
| 21 | 24 |
| 22 /** | 25 /** |
| 23 * A Dart SDK installed in a specified directory. Typical Dart SDK layout is | 26 * A Dart SDK installed in a specified directory. Typical Dart SDK layout is |
| 24 * something like... | 27 * something like... |
| 25 * | 28 * |
| 26 * dart-sdk/ | 29 * dart-sdk/ |
| 27 * bin/ | 30 * bin/ |
| 28 * dart[.exe] <-- VM | 31 * dart[.exe] <-- VM |
| 29 * lib/ | 32 * lib/ |
| 30 * core/ | 33 * core/ |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 * should be used when it is available | 237 * should be used when it is available |
| 235 */ | 238 */ |
| 236 DirectoryBasedDartSdk(JavaFile sdkDirectory, [bool useDart2jsPaths = false]) { | 239 DirectoryBasedDartSdk(JavaFile sdkDirectory, [bool useDart2jsPaths = false]) { |
| 237 this._sdkDirectory = sdkDirectory.getAbsoluteFile(); | 240 this._sdkDirectory = sdkDirectory.getAbsoluteFile(); |
| 238 _libraryMap = initialLibraryMap(useDart2jsPaths); | 241 _libraryMap = initialLibraryMap(useDart2jsPaths); |
| 239 } | 242 } |
| 240 | 243 |
| 241 @override | 244 @override |
| 242 AnalysisContext get context { | 245 AnalysisContext get context { |
| 243 if (_analysisContext == null) { | 246 if (_analysisContext == null) { |
| 244 _analysisContext = new SdkAnalysisContext(); | 247 SdkBundle sdkBundle = _getSummarySdkBundle(); |
| 248 if (sdkBundle != null) { |
| 249 _analysisContext = new SummarySdkAnalysisContext(sdkBundle); |
| 250 } else { |
| 251 _analysisContext = new SdkAnalysisContext(); |
| 252 } |
| 245 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); | 253 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); |
| 246 _analysisContext.sourceFactory = factory; | 254 _analysisContext.sourceFactory = factory; |
| 247 List<String> uris = this.uris; | 255 List<String> uris = this.uris; |
| 248 ChangeSet changeSet = new ChangeSet(); | 256 ChangeSet changeSet = new ChangeSet(); |
| 249 for (String uri in uris) { | 257 for (String uri in uris) { |
| 250 changeSet.addedSource(factory.forUri(uri)); | 258 changeSet.addedSource(factory.forUri(uri)); |
| 251 } | 259 } |
| 252 _analysisContext.applyChanges(changeSet); | 260 _analysisContext.applyChanges(changeSet); |
| 253 } | 261 } |
| 254 return _analysisContext; | 262 return _analysisContext; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 file = file.getParentFile(); | 534 file = file.getParentFile(); |
| 527 file = new JavaFile.relative(file, relativePath); | 535 file = new JavaFile.relative(file, relativePath); |
| 528 } | 536 } |
| 529 return new FileBasedSource(file, parseUriWithException(dartUri)); | 537 return new FileBasedSource(file, parseUriWithException(dartUri)); |
| 530 } on URISyntaxException { | 538 } on URISyntaxException { |
| 531 return null; | 539 return null; |
| 532 } | 540 } |
| 533 } | 541 } |
| 534 | 542 |
| 535 /** | 543 /** |
| 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 /** |
| 536 * Return the given [file] if it exists and is executable, or `null` if it | 564 * Return the given [file] if it exists and is executable, or `null` if it |
| 537 * does not exist or is not executable. | 565 * does not exist or is not executable. |
| 538 */ | 566 */ |
| 539 JavaFile _verifyExecutable(JavaFile file) => | 567 JavaFile _verifyExecutable(JavaFile file) => |
| 540 file.isExecutable() ? file : null; | 568 file.isExecutable() ? file : null; |
| 541 } | 569 } |
| 542 | 570 |
| 543 /** | 571 /** |
| 544 * An object used to read and parse the libraries file | 572 * An object used to read and parse the libraries file |
| 545 * (dart-sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart) for informat
ion | 573 * (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... |
| 596 SdkLibrariesReader_LibraryBuilder libraryBuilder = | 624 SdkLibrariesReader_LibraryBuilder libraryBuilder = |
| 597 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); | 625 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); |
| 598 // If any syntactic errors were found then don't try to visit the AST | 626 // If any syntactic errors were found then don't try to visit the AST |
| 599 // structure. | 627 // structure. |
| 600 if (!errorListener.errorReported) { | 628 if (!errorListener.errorReported) { |
| 601 unit.accept(libraryBuilder); | 629 unit.accept(libraryBuilder); |
| 602 } | 630 } |
| 603 return libraryBuilder.librariesMap; | 631 return libraryBuilder.librariesMap; |
| 604 } | 632 } |
| 605 } | 633 } |
| OLD | NEW |