Chromium Code Reviews| 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/context_root.dart'; | 10 import 'package:analyzer/context/context_root.dart'; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 declareVariables(context); | 154 declareVariables(context); |
| 155 return context; | 155 return context; |
| 156 } | 156 } |
| 157 | 157 |
| 158 /** | 158 /** |
| 159 * Return an analysis driver that is configured correctly to analyze code in | 159 * Return an analysis driver that is configured correctly to analyze code in |
| 160 * the directory with the given [path]. | 160 * the directory with the given [path]. |
| 161 */ | 161 */ |
| 162 AnalysisDriver buildDriver(ContextRoot contextRoot) { | 162 AnalysisDriver buildDriver(ContextRoot contextRoot) { |
| 163 String path = contextRoot.root; | 163 String path = contextRoot.root; |
| 164 AnalysisOptions options = getAnalysisOptions(path); | 164 AnalysisOptions options = |
| 165 getAnalysisOptions(path, contextRoot: contextRoot); | |
| 165 //_processAnalysisOptions(context, optionMap); | 166 //_processAnalysisOptions(context, optionMap); |
| 166 final sf = createSourceFactory(path, options); | 167 final sf = createSourceFactory(path, options); |
| 167 AnalysisDriver driver = new AnalysisDriver( | 168 AnalysisDriver driver = new AnalysisDriver( |
| 168 analysisDriverScheduler, | 169 analysisDriverScheduler, |
| 169 performanceLog, | 170 performanceLog, |
| 170 resourceProvider, | 171 resourceProvider, |
| 171 byteStore, | 172 byteStore, |
| 172 fileContentOverlay, | 173 fileContentOverlay, |
| 173 contextRoot, | 174 contextRoot, |
| 174 sf, | 175 sf, |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 return sdk; | 384 return sdk; |
| 384 }); | 385 }); |
| 385 } | 386 } |
| 386 | 387 |
| 387 /** | 388 /** |
| 388 * Return the analysis options that should be used to analyze code in the | 389 * Return the analysis options that should be used to analyze code in the |
| 389 * directory with the given [path]. Use [verbosePrint] to echo verbose | 390 * directory with the given [path]. Use [verbosePrint] to echo verbose |
| 390 * information about the analysis options selection process. | 391 * information about the analysis options selection process. |
| 391 */ | 392 */ |
| 392 AnalysisOptions getAnalysisOptions(String path, | 393 AnalysisOptions getAnalysisOptions(String path, |
| 393 {void verbosePrint(String text)}) { | 394 {void verbosePrint(String text), ContextRoot contextRoot}) { |
|
Brian Wilkerson
2017/05/30 14:26:39
Are there invocations where we won't have a Contex
devoncarew
2017/05/30 20:23:32
There are places where we don't have a ContextRoot
| |
| 394 void verbose(String text) { | 395 void verbose(String text) { |
| 395 if (verbosePrint != null) { | 396 if (verbosePrint != null) { |
| 396 verbosePrint(text); | 397 verbosePrint(text); |
| 397 } | 398 } |
| 398 } | 399 } |
| 399 | 400 |
| 400 // TODO(danrubel) restructure so that we don't create a workspace | 401 // TODO(danrubel) restructure so that we don't create a workspace |
| 401 // both here and in createSourceFactory | 402 // both here and in createSourceFactory |
| 402 Workspace workspace = createWorkspace(path); | 403 Workspace workspace = createWorkspace(path); |
| 403 SourceFactory sourceFactory = workspace.createSourceFactory(null); | 404 SourceFactory sourceFactory = workspace.createSourceFactory(null); |
| 404 AnalysisOptionsProvider optionsProvider = | 405 AnalysisOptionsProvider optionsProvider = |
| 405 new AnalysisOptionsProvider(sourceFactory); | 406 new AnalysisOptionsProvider(sourceFactory); |
| 406 | 407 |
| 407 AnalysisOptionsImpl options = createDefaultOptions(); | 408 AnalysisOptionsImpl options = createDefaultOptions(); |
| 408 File optionsFile = getOptionsFile(path); | 409 File optionsFile = getOptionsFile(path); |
| 409 Map<String, YamlNode> optionMap; | 410 Map<String, YamlNode> optionMap; |
| 410 | 411 |
| 411 if (optionsFile != null) { | 412 if (optionsFile != null) { |
| 412 try { | 413 try { |
| 413 optionMap = optionsProvider.getOptionsFromFile(optionsFile); | 414 optionMap = optionsProvider.getOptionsFromFile(optionsFile); |
| 415 if (contextRoot != null) { | |
| 416 contextRoot.optionsFilePath = optionsFile.path; | |
| 417 } | |
| 414 verbose('Loaded analysis options from ${optionsFile.path}'); | 418 verbose('Loaded analysis options from ${optionsFile.path}'); |
| 415 } catch (e) { | 419 } catch (e) { |
| 416 // Ignore exceptions thrown while trying to load the options file. | 420 // Ignore exceptions thrown while trying to load the options file. |
| 417 verbose('Exception: $e\n when loading ${optionsFile.path}'); | 421 verbose('Exception: $e\n when loading ${optionsFile.path}'); |
| 418 } | 422 } |
| 419 } else { | 423 } else { |
| 420 // Search for the default analysis options | 424 // Search for the default analysis options |
| 421 // unless explicitly directed not to do so. | 425 // unless explicitly directed not to do so. |
| 422 Source source; | 426 Source source; |
| 423 if (builderOptions.packageDefaultAnalysisOptions) { | 427 if (builderOptions.packageDefaultAnalysisOptions) { |
| 424 // TODO(danrubel) determine if bazel or gn project depends upon flutter | 428 // TODO(danrubel) determine if bazel or gn project depends upon flutter |
| 425 if (workspace.hasFlutterDependency) { | 429 if (workspace.hasFlutterDependency) { |
| 426 source = sourceFactory.forUri(flutterAnalysisOptionsPath); | 430 source = sourceFactory.forUri(flutterAnalysisOptionsPath); |
| 427 } | 431 } |
| 428 if (source == null || !source.exists()) { | 432 if (source == null || !source.exists()) { |
| 429 source = sourceFactory.forUri(bazelAnalysisOptionsPath); | 433 source = sourceFactory.forUri(bazelAnalysisOptionsPath); |
| 430 } | 434 } |
| 431 if (source != null && source.exists()) { | 435 if (source != null && source.exists()) { |
| 432 try { | 436 try { |
| 433 optionMap = optionsProvider.getOptionsFromSource(source); | 437 optionMap = optionsProvider.getOptionsFromSource(source); |
| 438 if (contextRoot != null) { | |
| 439 contextRoot.optionsFilePath = source.fullName; | |
| 440 } | |
| 434 verbose('Loaded analysis options from ${source.fullName}'); | 441 verbose('Loaded analysis options from ${source.fullName}'); |
| 435 } catch (e) { | 442 } catch (e) { |
| 436 // Ignore exceptions thrown while trying to load the options file. | 443 // Ignore exceptions thrown while trying to load the options file. |
| 437 verbose('Exception: $e\n when loading ${source.fullName}'); | 444 verbose('Exception: $e\n when loading ${source.fullName}'); |
| 438 } | 445 } |
| 439 } | 446 } |
| 440 } | 447 } |
| 441 } | 448 } |
| 442 | 449 |
| 443 if (optionMap != null) { | 450 if (optionMap != null) { |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 818 throw new ArgumentError('not absolute: $path'); | 825 throw new ArgumentError('not absolute: $path'); |
| 819 } | 826 } |
| 820 path = context.normalize(path); | 827 path = context.normalize(path); |
| 821 Resource resource = provider.getResource(path); | 828 Resource resource = provider.getResource(path); |
| 822 if (resource is File) { | 829 if (resource is File) { |
| 823 path = resource.parent.path; | 830 path = resource.parent.path; |
| 824 } | 831 } |
| 825 return new _BasicWorkspace._(provider, path, builder); | 832 return new _BasicWorkspace._(provider, path, builder); |
| 826 } | 833 } |
| 827 } | 834 } |
| OLD | NEW |