| 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 import 'package:analyzer/file_system/file_system.dart'; | 5 import 'package:analyzer/file_system/file_system.dart'; |
| 6 import 'package:analyzer/source/analysis_options_provider.dart'; | 6 import 'package:analyzer/source/analysis_options_provider.dart'; |
| 7 import 'package:analyzer/src/generated/engine.dart'; | 7 import 'package:analyzer/src/generated/engine.dart'; |
| 8 import 'package:analyzer/src/task/model.dart'; | 8 import 'package:analyzer/src/task/model.dart'; |
| 9 import 'package:analyzer/task/model.dart'; | 9 import 'package:analyzer/task/model.dart'; |
| 10 import 'package:package_config/packages.dart'; | 10 import 'package:package_config/packages.dart'; |
| 11 import 'package:yaml/src/yaml_node.dart'; | 11 import 'package:yaml/src/yaml_node.dart'; |
| 12 import 'package:yaml/yaml.dart'; | 12 import 'package:yaml/yaml.dart'; |
| 13 | 13 |
| 14 /// The descriptor used to associate analysis configuration with analysis | 14 /// The descriptor used to associate analysis configuration with analysis |
| 15 /// contexts in configuration data. | 15 /// contexts in configuration data. |
| 16 final ResultDescriptor<AnalysisConfiguration> ANALYSIS_CONFIGURATION = | 16 final ResultDescriptor<AnalysisConfiguration> ANALYSIS_CONFIGURATION = |
| 17 new ResultDescriptorImpl('analysis.config', null); | 17 new ResultDescriptorImpl('analysis.config', null); |
| 18 | 18 |
| 19 /// Return configuration associated with this [context], or `null` if there is | 19 /// Return configuration associated with this [context], or `null` if there is |
| 20 /// none. | 20 /// none. |
| 21 AnalysisConfiguration getConfiguration(AnalysisContext context) => | 21 AnalysisConfiguration getConfiguration(AnalysisContext context) => |
| 22 context.getConfigurationData(ANALYSIS_CONFIGURATION) | 22 context.getConfigurationData(ANALYSIS_CONFIGURATION); |
| 23 as AnalysisConfiguration; | |
| 24 | 23 |
| 25 /// Associate this [config] with the given [context]. | 24 /// Associate this [config] with the given [context]. |
| 26 void setConfiguration(AnalysisContext context, AnalysisConfiguration config) { | 25 void setConfiguration(AnalysisContext context, AnalysisConfiguration config) { |
| 27 context.setConfigurationData(ANALYSIS_CONFIGURATION, config); | 26 context.setConfigurationData(ANALYSIS_CONFIGURATION, config); |
| 28 } | 27 } |
| 29 | 28 |
| 30 /// Analysis configuration. | 29 /// Analysis configuration. |
| 31 abstract class AnalysisConfiguration { | 30 abstract class AnalysisConfiguration { |
| 32 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); | 31 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); |
| 33 final Packages packages; | 32 final Packages packages; |
| 34 final ResourceProvider resourceProvider; | 33 final ResourceProvider resourceProvider; |
| 35 AnalysisConfiguration(this.resourceProvider, this.packages); | 34 AnalysisConfiguration(this.resourceProvider, this.packages); |
| 36 | 35 |
| 37 factory AnalysisConfiguration.fromPubspec( | 36 factory AnalysisConfiguration.fromPubspec( |
| 38 File pubspec, ResourceProvider resourceProvider, Packages packages) => | 37 File pubspec, ResourceProvider resourceProvider, Packages packages) => |
| 39 new PubspecConfiguration(pubspec, resourceProvider, packages); | 38 new PubspecConfiguration(pubspec, resourceProvider, packages); |
| 40 | 39 |
| 41 /// Get a map of options defined by this configuration (or `null` if none | 40 /// Get a map of options defined by this configuration (or `null` if none |
| 42 /// are specified). | 41 /// are specified). |
| 43 Map get options; | 42 Map get options; |
| 44 } | 43 } |
| 45 | 44 |
| 46 /// Describes an analysis configuration. | 45 /// Describes an analysis configuration. |
| 47 class AnalysisConfigurationDescriptor { | 46 class AnalysisConfigurationDescriptor { |
| 48 /// The name of the package hosting the configuration. | 47 /// The name of the package hosting the configuration. |
| 49 String package; | 48 String package; |
| 49 |
| 50 /// The name of the configuration "pragma". | 50 /// The name of the configuration "pragma". |
| 51 String pragma; | 51 String pragma; |
| 52 | 52 |
| 53 AnalysisConfigurationDescriptor.fromAnalyzerOptions(Map analyzerOptions) { | 53 AnalysisConfigurationDescriptor.fromAnalyzerOptions(Map analyzerOptions) { |
| 54 Object config = analyzerOptions['configuration']; | 54 Object config = analyzerOptions['configuration']; |
| 55 if (config is String) { | 55 if (config is String) { |
| 56 List<String> items = config.split('/'); | 56 List<String> items = config.split('/'); |
| 57 if (items.length == 2) { | 57 if (items.length == 2) { |
| 58 package = items[0].trim(); | 58 package = items[0].trim(); |
| 59 pragma = items[1].trim(); | 59 pragma = items[1].trim(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 } catch (_) { | 101 } catch (_) { |
| 102 // Skip exceptional configurations. | 102 // Skip exceptional configurations. |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 return null; | 105 return null; |
| 106 } | 106 } |
| 107 } | 107 } |
| OLD | NEW |