| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.context.context_builder; | 5 library analyzer.src.context.context_builder; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:core'; | 8 import 'dart:core'; |
| 9 | 9 |
| 10 import 'package:analyzer/context/declared_variables.dart'; | 10 import 'package:analyzer/context/declared_variables.dart'; |
| 11 import 'package:analyzer/file_system/file_system.dart'; | 11 import 'package:analyzer/file_system/file_system.dart'; |
| 12 import 'package:analyzer/plugin/resolver_provider.dart'; | 12 import 'package:analyzer/plugin/resolver_provider.dart'; |
| 13 import 'package:analyzer/source/analysis_options_provider.dart'; | 13 import 'package:analyzer/source/analysis_options_provider.dart'; |
| 14 import 'package:analyzer/source/package_map_resolver.dart'; | 14 import 'package:analyzer/source/package_map_resolver.dart'; |
| 15 import 'package:analyzer/src/command_line/arguments.dart' | 15 import 'package:analyzer/src/command_line/arguments.dart' |
| 16 show applyAnalysisOptionFlags; | 16 show applyAnalysisOptionFlags; |
| 17 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
| 18 import 'package:analyzer/src/dart/analysis/driver.dart' |
| 19 show AnalysisDriver, AnalysisDriverScheduler, PerformanceLog; |
| 20 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
| 17 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 21 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
| 18 import 'package:analyzer/src/generated/bazel.dart'; | 22 import 'package:analyzer/src/generated/bazel.dart'; |
| 19 import 'package:analyzer/src/generated/engine.dart'; | 23 import 'package:analyzer/src/generated/engine.dart'; |
| 20 import 'package:analyzer/src/generated/sdk.dart'; | 24 import 'package:analyzer/src/generated/sdk.dart'; |
| 21 import 'package:analyzer/src/generated/source.dart'; | 25 import 'package:analyzer/src/generated/source.dart'; |
| 22 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 26 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
| 23 import 'package:analyzer/src/summary/pub_summary.dart'; | 27 import 'package:analyzer/src/summary/pub_summary.dart'; |
| 24 import 'package:analyzer/src/summary/summary_sdk.dart'; | 28 import 'package:analyzer/src/summary/summary_sdk.dart'; |
| 25 import 'package:analyzer/src/task/options.dart'; | 29 import 'package:analyzer/src/task/options.dart'; |
| 26 import 'package:args/args.dart'; | 30 import 'package:args/args.dart'; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 */ | 63 */ |
| 60 final ResourceProvider resourceProvider; | 64 final ResourceProvider resourceProvider; |
| 61 | 65 |
| 62 /** | 66 /** |
| 63 * The manager used to manage the DartSdk's that have been created so that | 67 * The manager used to manage the DartSdk's that have been created so that |
| 64 * they can be shared across contexts. | 68 * they can be shared across contexts. |
| 65 */ | 69 */ |
| 66 final DartSdkManager sdkManager; | 70 final DartSdkManager sdkManager; |
| 67 | 71 |
| 68 /** | 72 /** |
| 69 * The cache containing the contents of overlaid files. | 73 * The cache containing the contents of overlaid files. If this builder will |
| 74 * be used to build analysis drivers, set the [fileContentOverlay] instead. |
| 70 */ | 75 */ |
| 71 final ContentCache contentCache; | 76 final ContentCache contentCache; |
| 72 | 77 |
| 73 /** | 78 /** |
| 74 * The options used by the context builder. | 79 * The options used by the context builder. |
| 75 */ | 80 */ |
| 76 final ContextBuilderOptions builderOptions; | 81 final ContextBuilderOptions builderOptions; |
| 77 | 82 |
| 78 /** | 83 /** |
| 79 * The resolver provider used to create a package: URI resolver, or `null` if | 84 * The resolver provider used to create a package: URI resolver, or `null` if |
| 80 * the normal (Package Specification DEP) lookup mechanism is to be used. | 85 * the normal (Package Specification DEP) lookup mechanism is to be used. |
| 81 */ | 86 */ |
| 82 ResolverProvider packageResolverProvider; | 87 ResolverProvider packageResolverProvider; |
| 83 | 88 |
| 84 /** | 89 /** |
| 85 * The resolver provider used to create a file: URI resolver, or `null` if | 90 * The resolver provider used to create a file: URI resolver, or `null` if |
| 86 * the normal file URI resolver is to be used. | 91 * the normal file URI resolver is to be used. |
| 87 */ | 92 */ |
| 88 ResolverProvider fileResolverProvider; | 93 ResolverProvider fileResolverProvider; |
| 89 | 94 |
| 90 /** | 95 /** |
| 96 * The scheduler used by any analysis drivers created through this interface. |
| 97 */ |
| 98 AnalysisDriverScheduler analysisDriverScheduler; |
| 99 |
| 100 /** |
| 101 * The performance log used by any analysis drivers created through this |
| 102 * interface. |
| 103 */ |
| 104 PerformanceLog performanceLog; |
| 105 |
| 106 /** |
| 107 * The byte store used by any analysis drivers created through this interface. |
| 108 */ |
| 109 ByteStore byteStore; |
| 110 |
| 111 /** |
| 112 * The file content overlay used by analysis drivers. If this builder will be |
| 113 * used to build analysis contexts, set the [contentCache] instead. |
| 114 */ |
| 115 FileContentOverlay fileContentOverlay; |
| 116 |
| 117 /** |
| 91 * Initialize a newly created builder to be ready to build a context rooted in | 118 * Initialize a newly created builder to be ready to build a context rooted in |
| 92 * the directory with the given [rootDirectoryPath]. | 119 * the directory with the given [rootDirectoryPath]. |
| 93 */ | 120 */ |
| 94 ContextBuilder(this.resourceProvider, this.sdkManager, this.contentCache, | 121 ContextBuilder(this.resourceProvider, this.sdkManager, this.contentCache, |
| 95 {ContextBuilderOptions options}) | 122 {ContextBuilderOptions options}) |
| 96 : builderOptions = options ?? new ContextBuilderOptions(); | 123 : builderOptions = options ?? new ContextBuilderOptions(); |
| 97 | 124 |
| 98 /** | 125 /** |
| 99 * Return an analysis context that is configured correctly to analyze code in | 126 * Return an analysis context that is configured correctly to analyze code in |
| 100 * the directory with the given [path]. | 127 * the directory with the given [path]. |
| 101 * | 128 * |
| 102 * *Note:* This method is not yet fully implemented and should not be used. | 129 * *Note:* This method is not yet fully implemented and should not be used. |
| 103 */ | 130 */ |
| 104 AnalysisContext buildContext(String path) { | 131 AnalysisContext buildContext(String path) { |
| 105 InternalAnalysisContext context = | 132 InternalAnalysisContext context = |
| 106 AnalysisEngine.instance.createAnalysisContext(); | 133 AnalysisEngine.instance.createAnalysisContext(); |
| 107 AnalysisOptions options = getAnalysisOptions(path); | 134 AnalysisOptions options = getAnalysisOptions(path); |
| 108 context.contentCache = contentCache; | 135 context.contentCache = contentCache; |
| 109 context.sourceFactory = createSourceFactory(path, options); | 136 context.sourceFactory = createSourceFactory(path, options); |
| 110 context.analysisOptions = options; | 137 context.analysisOptions = options; |
| 111 context.name = path; | 138 context.name = path; |
| 112 //_processAnalysisOptions(context, optionMap); | 139 //_processAnalysisOptions(context, optionMap); |
| 113 declareVariables(context); | 140 declareVariables(context); |
| 114 configureSummaries(context); | 141 configureSummaries(context); |
| 115 return context; | 142 return context; |
| 116 } | 143 } |
| 117 | 144 |
| 118 /** | 145 /** |
| 146 * Return an analysis driver that is configured correctly to analyze code in |
| 147 * the directory with the given [path]. |
| 148 */ |
| 149 AnalysisDriver buildDriver(String path) { |
| 150 AnalysisOptions options = getAnalysisOptions(path); |
| 151 //_processAnalysisOptions(context, optionMap); |
| 152 AnalysisDriver driver = new AnalysisDriver( |
| 153 analysisDriverScheduler, |
| 154 performanceLog, |
| 155 resourceProvider, |
| 156 byteStore, |
| 157 fileContentOverlay, |
| 158 path, |
| 159 createSourceFactory(path, options), |
| 160 options); |
| 161 declareVariablesInDriver(driver); |
| 162 return driver; |
| 163 } |
| 164 |
| 165 /** |
| 119 * Configure the context to make use of summaries. | 166 * Configure the context to make use of summaries. |
| 120 */ | 167 */ |
| 121 void configureSummaries(InternalAnalysisContext context) { | 168 void configureSummaries(InternalAnalysisContext context) { |
| 122 PubSummaryManager manager = builderOptions.pubSummaryManager; | 169 PubSummaryManager manager = builderOptions.pubSummaryManager; |
| 123 if (manager != null) { | 170 if (manager != null) { |
| 124 List<LinkedPubPackage> linkedBundles = manager.getLinkedBundles(context); | 171 List<LinkedPubPackage> linkedBundles = manager.getLinkedBundles(context); |
| 125 if (linkedBundles.isNotEmpty) { | 172 if (linkedBundles.isNotEmpty) { |
| 126 SummaryDataStore store = new SummaryDataStore([]); | 173 SummaryDataStore store = new SummaryDataStore([]); |
| 127 for (LinkedPubPackage package in linkedBundles) { | 174 for (LinkedPubPackage package in linkedBundles) { |
| 128 store.addBundle(null, package.unlinked); | 175 store.addBundle(null, package.unlinked); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 Map<String, String> variables = builderOptions.declaredVariables; | 273 Map<String, String> variables = builderOptions.declaredVariables; |
| 227 if (variables != null && variables.isNotEmpty) { | 274 if (variables != null && variables.isNotEmpty) { |
| 228 DeclaredVariables contextVariables = context.declaredVariables; | 275 DeclaredVariables contextVariables = context.declaredVariables; |
| 229 variables.forEach((String variableName, String value) { | 276 variables.forEach((String variableName, String value) { |
| 230 contextVariables.define(variableName, value); | 277 contextVariables.define(variableName, value); |
| 231 }); | 278 }); |
| 232 } | 279 } |
| 233 } | 280 } |
| 234 | 281 |
| 235 /** | 282 /** |
| 283 * Add any [declaredVariables] to the list of declared variables used by the |
| 284 * given analysis [driver]. |
| 285 */ |
| 286 void declareVariablesInDriver(AnalysisDriver driver) { |
| 287 Map<String, String> variables = builderOptions.declaredVariables; |
| 288 if (variables != null && variables.isNotEmpty) { |
| 289 DeclaredVariables contextVariables = driver.declaredVariables; |
| 290 variables.forEach((String variableName, String value) { |
| 291 contextVariables.define(variableName, value); |
| 292 }); |
| 293 } |
| 294 } |
| 295 |
| 296 /** |
| 236 * Finds a package resolution strategy for the directory at the given absolute | 297 * Finds a package resolution strategy for the directory at the given absolute |
| 237 * [path]. | 298 * [path]. |
| 238 * | 299 * |
| 239 * This function first tries to locate a `.packages` file in the directory. If | 300 * This function first tries to locate a `.packages` file in the directory. If |
| 240 * that is not found, it instead checks for the presence of a `packages/` | 301 * that is not found, it instead checks for the presence of a `packages/` |
| 241 * directory in the same place. If that also fails, it starts checking parent | 302 * directory in the same place. If that also fails, it starts checking parent |
| 242 * directories for a `.packages` file, and stops if it finds it. Otherwise it | 303 * directories for a `.packages` file, and stops if it finds it. Otherwise it |
| 243 * gives up and returns [Packages.noPackages]. | 304 * gives up and returns [Packages.noPackages]. |
| 244 */ | 305 */ |
| 245 Packages findPackagesFromFile(String path) { | 306 Packages findPackagesFromFile(String path) { |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 String _readEmbedderYaml(Folder libDir) { | 692 String _readEmbedderYaml(Folder libDir) { |
| 632 File file = libDir.getChild(EMBEDDER_FILE_NAME); | 693 File file = libDir.getChild(EMBEDDER_FILE_NAME); |
| 633 try { | 694 try { |
| 634 return file.readAsStringSync(); | 695 return file.readAsStringSync(); |
| 635 } on FileSystemException { | 696 } on FileSystemException { |
| 636 // File can't be read. | 697 // File can't be read. |
| 637 return null; | 698 return null; |
| 638 } | 699 } |
| 639 } | 700 } |
| 640 } | 701 } |
| OLD | NEW |