Chromium Code Reviews| Index: pkg/analyzer/lib/src/generated/sdk.dart |
| diff --git a/pkg/analyzer/lib/src/generated/sdk.dart b/pkg/analyzer/lib/src/generated/sdk.dart |
| index a2b6325a0ab50b5b6079f26de68e663487a1f362..42351c41c980482f72e07d8c24c416bd71eb7b76 100644 |
| --- a/pkg/analyzer/lib/src/generated/sdk.dart |
| +++ b/pkg/analyzer/lib/src/generated/sdk.dart |
| @@ -8,11 +8,17 @@ import 'dart:collection'; |
| import 'package:analyzer/dart/ast/ast.dart'; |
| import 'package:analyzer/dart/ast/visitor.dart'; |
| -import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; |
| +import 'package:analyzer/src/generated/engine.dart' |
| + show AnalysisContext, AnalysisOptions; |
| import 'package:analyzer/src/generated/source.dart' |
| show ContentCache, Source, UriKind; |
| /** |
| + * A function used to create a new DartSdk |
| + */ |
| +typedef DartSdk SdkCreator(); |
| + |
| +/** |
| * A Dart SDK installed in a specified location. |
| */ |
| abstract class DartSdk { |
| @@ -79,6 +85,54 @@ abstract class DartSdk { |
| } |
| /** |
| + * Manages the DartSdk's that |
|
Paul Berry
2016/02/09 18:21:18
Incomplete comment
|
| + */ |
| +class DartSdkManager { |
| + /** |
| + * The function used to create new SDK's. |
| + */ |
| + final SdkCreator sdkCreator; |
| + |
| + /** |
| + * A table mapping (an encoding of) analysis options to the SDK that has been |
| + * configured with those options. |
| + */ |
| + Map<int, DartSdk> sdkMap = new HashMap<int, DartSdk>(); |
| + |
| + /** |
| + * Initialize a newly created manager. |
| + */ |
| + DartSdkManager(this.sdkCreator); |
| + |
| + /** |
| + * Return any SDK that has been created, or `null` if no SDKs have been |
| + * created. |
| + */ |
| + DartSdk get anySdk { |
| + if (sdkMap.isEmpty) { |
| + return null; |
| + } |
| + return sdkMap.values.first; |
| + } |
| + |
| + /** |
| + * Return the Dart SDK that is appropriate for the given analysis [options]. |
| + * If such an SDK has not yet been created, then the [sdkCreator] will be |
| + * invoked to create it. |
| + */ |
| + DartSdk getSdkForOptions(AnalysisOptions options) { |
| + int encoding = options.encodeCrossContextOptions(); |
| + DartSdk sdk = sdkMap[encoding]; |
| + if (sdk == null) { |
| + sdk = sdkCreator(); |
| + sdkMap[encoding] = sdk; |
| + sdk.context.analysisOptions.setCrossContextOptionsFrom(options); |
| + } |
| + return sdk; |
| + } |
| +} |
| + |
| +/** |
| * A map from Dart library URI's to the [SdkLibraryImpl] representing that |
| * library. |
| */ |