Index: pkg/analyzer/lib/src/context/builder.dart |
diff --git a/pkg/analyzer/lib/src/context/builder.dart b/pkg/analyzer/lib/src/context/builder.dart |
index aad53cfdde47479da00382605de164cd7c689fcc..943d24d7b54c2cc27912a164ed05de083245a9cf 100644 |
--- a/pkg/analyzer/lib/src/context/builder.dart |
+++ b/pkg/analyzer/lib/src/context/builder.dart |
@@ -14,6 +14,10 @@ import 'package:analyzer/source/analysis_options_provider.dart'; |
import 'package:analyzer/source/package_map_resolver.dart'; |
import 'package:analyzer/src/command_line/arguments.dart' |
show applyAnalysisOptionFlags; |
+import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
+import 'package:analyzer/src/dart/analysis/driver.dart' |
+ show AnalysisDriver, AnalysisDriverScheduler, PerformanceLog; |
+import 'package:analyzer/src/dart/analysis/file_state.dart'; |
import 'package:analyzer/src/dart/sdk/sdk.dart'; |
import 'package:analyzer/src/generated/bazel.dart'; |
import 'package:analyzer/src/generated/engine.dart'; |
@@ -66,7 +70,8 @@ class ContextBuilder { |
final DartSdkManager sdkManager; |
/** |
- * The cache containing the contents of overlaid files. |
+ * The cache containing the contents of overlaid files. If this builder will |
+ * be used to build analysis drivers, set the [fileContentOverlay] instead. |
*/ |
final ContentCache contentCache; |
@@ -88,6 +93,28 @@ class ContextBuilder { |
ResolverProvider fileResolverProvider; |
/** |
+ * The scheduler used by any analysis drivers created through this interface. |
+ */ |
+ AnalysisDriverScheduler analysisDriverScheduler; |
+ |
+ /** |
+ * The performance log used by any analysis drivers created through this |
+ * interface. |
+ */ |
+ PerformanceLog performanceLog; |
+ |
+ /** |
+ * The byte store used by any analysis drivers created through this interface. |
+ */ |
+ ByteStore byteStore; |
+ |
+ /** |
+ * The file content overlay used by analysis drivers. If this builder will be |
+ * used to build analysis contexts, set the [contentCache] instead. |
+ */ |
+ FileContentOverlay fileContentOverlay; |
+ |
+ /** |
* Initialize a newly created builder to be ready to build a context rooted in |
* the directory with the given [rootDirectoryPath]. |
*/ |
@@ -116,6 +143,26 @@ class ContextBuilder { |
} |
/** |
+ * Return an analysis driver that is configured correctly to analyze code in |
+ * the directory with the given [path]. |
+ */ |
+ AnalysisDriver buildDriver(String path) { |
+ AnalysisOptions options = getAnalysisOptions(path); |
+ //_processAnalysisOptions(context, optionMap); |
+ AnalysisDriver driver = new AnalysisDriver( |
+ analysisDriverScheduler, |
+ performanceLog, |
+ resourceProvider, |
+ byteStore, |
+ fileContentOverlay, |
+ path, |
+ createSourceFactory(path, options), |
+ options); |
+ declareVariablesInDriver(driver); |
+ return driver; |
+ } |
+ |
+ /** |
* Configure the context to make use of summaries. |
*/ |
void configureSummaries(InternalAnalysisContext context) { |
@@ -233,6 +280,20 @@ class ContextBuilder { |
} |
/** |
+ * Add any [declaredVariables] to the list of declared variables used by the |
+ * given analysis [driver]. |
+ */ |
+ void declareVariablesInDriver(AnalysisDriver driver) { |
+ Map<String, String> variables = builderOptions.declaredVariables; |
+ if (variables != null && variables.isNotEmpty) { |
+ DeclaredVariables contextVariables = driver.declaredVariables; |
+ variables.forEach((String variableName, String value) { |
+ contextVariables.define(variableName, value); |
+ }); |
+ } |
+ } |
+ |
+ /** |
* Finds a package resolution strategy for the directory at the given absolute |
* [path]. |
* |