OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Support for client code that wants to consume options contributed to the | 5 /// Support for client code that wants to consume options contributed to the |
6 /// analysis options file. | 6 /// analysis options file. |
7 library analyzer.plugin.options; | 7 library analyzer.plugin.options; |
8 | 8 |
9 import 'package:analyzer/src/plugin/options_plugin.dart'; | 9 import 'package:analyzer/src/plugin/options_plugin.dart'; |
10 import 'package:plugin/plugin.dart'; | 10 import 'package:plugin/plugin.dart'; |
11 import 'package:yaml/yaml.dart'; | 11 import 'package:yaml/yaml.dart'; |
12 | 12 |
13 /// The identifier of the extension point that allows plugins to access | 13 /// The identifier of the extension point that allows plugins to access |
14 /// options defined in the analysis options file. The object used as an | 14 /// options defined in the analysis options file. The object used as an |
15 /// extension must be an [OptionsProcessor]. | 15 /// extension must be an [OptionsProcessor]. |
16 final String OPTIONS_PROCESSOR_EXTENSION_POINT_ID = Plugin.join( | 16 final String OPTIONS_PROCESSOR_EXTENSION_POINT_ID = Plugin.join( |
17 OptionsPlugin.UNIQUE_IDENTIFIER, | 17 OptionsPlugin.UNIQUE_IDENTIFIER, |
18 OptionsPlugin.OPTIONS_PROCESSOR_EXTENSION_POINT); | 18 OptionsPlugin.OPTIONS_PROCESSOR_EXTENSION_POINT); |
19 | 19 |
20 /// Processes options defined in the analysis options file. | 20 /// Processes options defined in the analysis options file. |
21 /// | 21 /// |
22 /// The options file format is intentionally very open-ended, giving clients | 22 /// The options file format is intentionally very open-ended, giving clients |
23 /// utmost flexibility in defining their own options. The only hardfast | 23 /// utmost flexibility in defining their own options. The only hardfast |
24 /// expectation is that options files will contain a mapping from Strings | 24 /// expectation is that options files will contain a mapping from Strings |
25 /// (identifying 'scopes') to associated options. For example, the given | 25 /// (identifying 'scopes') to associated options. For example, the given |
26 /// content | 26 /// content |
27 /// | 27 /// |
28 /// linter: | 28 /// linter: |
29 /// rules: | 29 /// rules: |
30 /// camel_case_types: true | 30 /// camel_case_types: true |
31 /// compiler: | 31 /// compiler: |
32 /// resolver: | 32 /// resolver: |
33 /// useMultiPackage: true | 33 /// useMultiPackage: true |
34 /// packagePaths: | 34 /// packagePaths: |
35 /// - /foo/bar/pkg | 35 /// - /foo/bar/pkg |
36 /// - /bar/baz/pkg | 36 /// - /bar/baz/pkg |
37 /// | 37 /// |
38 /// defines two scopes, `linter` and `compiler`. Parsing would result in a | 38 /// defines two scopes, `linter` and `compiler`. Parsing would result in a |
39 /// map, mapping the `linter` and `compiler` scope identifiers to their | 39 /// map, mapping the `linter` and `compiler` scope identifiers to their |
40 /// respective parsed option node contents. Extracting values is a simple | 40 /// respective parsed option node contents. Extracting values is a simple |
41 /// matter of inspecting the parsed nodes. For example, testing whether the | 41 /// matter of inspecting the parsed nodes. For example, testing whether the |
42 /// compiler's resolver is set to use the `useMultiPackage` option might look | 42 /// compiler's resolver is set to use the `useMultiPackage` option might look |
43 /// something like this (eliding error-checking): | 43 /// something like this (eliding error-checking): |
44 /// | 44 /// |
45 /// bool useMultiPackage = | 45 /// bool useMultiPackage = |
46 /// options['compiler']['resolver']['useMultiPackage']; | 46 /// options['compiler']['resolver']['useMultiPackage']; |
47 abstract class OptionsProcessor { | 47 abstract class OptionsProcessor { |
48 | |
49 /// Called when an error occurs in processing options. | 48 /// Called when an error occurs in processing options. |
50 void onError(Exception exception); | 49 void onError(Exception exception); |
51 | 50 |
52 /// Called when the options file is processed. | 51 /// Called when the options file is processed. |
53 /// | 52 /// |
54 /// The options file is processed on analyzer initialization and | 53 /// The options file is processed on analyzer initialization and |
55 /// subsequently when the file is changed on disk. In the event of a | 54 /// subsequently when the file is changed on disk. In the event of a |
56 /// change notification, note that the notification simply indicates | 55 /// change notification, note that the notification simply indicates |
57 /// a change on disk. Content in specific option scopes may or may not | 56 /// a change on disk. Content in specific option scopes may or may not |
58 /// be different. It is up to the implementer to check whether specific | 57 /// be different. It is up to the implementer to check whether specific |
59 /// options have changed and to handle those changes appropriately. | 58 /// options have changed and to handle those changes appropriately. |
60 void optionsProcessed(Map<String, YamlNode> options); | 59 void optionsProcessed(Map<String, YamlNode> options); |
61 } | 60 } |
OLD | NEW |