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 library analyzer.src.plugin.options_plugin; | 5 library analyzer.src.plugin.options_plugin; |
6 | 6 |
7 import 'package:analyzer/plugin/options.dart'; | 7 import 'package:analyzer/plugin/options.dart'; |
8 import 'package:analyzer/plugin/task.dart'; | 8 import 'package:analyzer/plugin/task.dart'; |
9 import 'package:analyzer/src/task/options.dart'; | 9 import 'package:analyzer/src/task/options.dart'; |
10 import 'package:plugin/plugin.dart'; | 10 import 'package:plugin/plugin.dart'; |
11 | 11 |
12 /// A plugin that defines the extension points and extensions that are defined | 12 /// A plugin that defines the extension points and extensions that are defined |
13 /// by applications that want to consume options defined in the analysis | 13 /// by applications that want to consume options defined in the analysis |
14 /// options file. | 14 /// options file. |
15 class OptionsPlugin implements Plugin { | 15 class OptionsPlugin implements Plugin { |
16 /// The simple identifier of the extension point that allows plugins to | 16 /// The simple identifier of the extension point that allows plugins to |
17 /// register new options processors. | 17 /// register new options processors. |
18 static const String OPTIONS_PROCESSOR_EXTENSION_POINT = 'optionsProcessor'; | 18 static const String OPTIONS_PROCESSOR_EXTENSION_POINT = 'optionsProcessor'; |
19 | 19 |
20 /// The simple identifier of the extension point that allows plugins to | 20 /// The simple identifier of the extension point that allows plugins to |
21 /// register new options validators. | 21 /// register new options validators. |
22 static const String OPTIONS_VALIDATOR_EXTENSION_POINT = 'optionsValidator'; | 22 static const String OPTIONS_VALIDATOR_EXTENSION_POINT = 'optionsValidator'; |
23 | 23 |
24 /// The unique identifier of this plugin. | 24 /// The unique identifier of this plugin. |
25 static const String UNIQUE_IDENTIFIER = 'options.core'; | 25 static const String UNIQUE_IDENTIFIER = 'options.core'; |
26 | 26 |
27 /// The extension point that allows plugins to register new options | 27 /// The extension point that allows plugins to register new options |
28 /// processors. | 28 /// processors. |
29 ExtensionPoint optionsProcessorExtensionPoint; | 29 ExtensionPoint<OptionsProcessor> optionsProcessorExtensionPoint; |
30 | 30 |
31 /// The extension point that allows plugins to register new options | 31 /// The extension point that allows plugins to register new options |
32 /// validators. | 32 /// validators. |
33 ExtensionPoint optionsValidatorExtensionPoint; | 33 ExtensionPoint<OptionsValidator> optionsValidatorExtensionPoint; |
34 | 34 |
35 /// All contributed options processors. | 35 /// All contributed options processors. |
36 List<OptionsProcessor> get optionsProcessors => | 36 List<OptionsProcessor> get optionsProcessors => |
37 optionsProcessorExtensionPoint?.extensions as List<OptionsProcessor> ?? | 37 optionsProcessorExtensionPoint?.extensions ?? const <OptionsProcessor>[]; |
38 const <OptionsProcessor>[]; | |
39 | 38 |
40 /// All contributed options validators. | 39 /// All contributed options validators. |
41 List<OptionsValidator> get optionsValidators => | 40 List<OptionsValidator> get optionsValidators => |
42 optionsValidatorExtensionPoint?.extensions as List<OptionsValidator> ?? | 41 optionsValidatorExtensionPoint?.extensions ?? const <OptionsValidator>[]; |
43 const <OptionsValidator>[]; | |
44 | 42 |
45 @override | 43 @override |
46 String get uniqueIdentifier => UNIQUE_IDENTIFIER; | 44 String get uniqueIdentifier => UNIQUE_IDENTIFIER; |
47 | 45 |
48 @override | 46 @override |
49 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { | 47 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { |
50 optionsProcessorExtensionPoint = registerExtensionPoint( | 48 optionsProcessorExtensionPoint = new ExtensionPoint<OptionsProcessor>( |
51 OPTIONS_PROCESSOR_EXTENSION_POINT, _validateOptionsProcessorExtension); | 49 this, OPTIONS_PROCESSOR_EXTENSION_POINT, null); |
52 optionsValidatorExtensionPoint = registerExtensionPoint( | 50 registerExtensionPoint(optionsProcessorExtensionPoint); |
53 OPTIONS_VALIDATOR_EXTENSION_POINT, _validateOptionsValidatorExtension); | 51 optionsValidatorExtensionPoint = new ExtensionPoint<OptionsValidator>( |
| 52 this, OPTIONS_VALIDATOR_EXTENSION_POINT, null); |
| 53 registerExtensionPoint(optionsValidatorExtensionPoint); |
54 } | 54 } |
55 | 55 |
56 @override | 56 @override |
57 void registerExtensions(RegisterExtension registerExtension) { | 57 void registerExtensions(RegisterExtension registerExtension) { |
58 // Analyze options files. | 58 // Analyze options files. |
59 registerExtension( | 59 registerExtension( |
60 TASK_EXTENSION_POINT_ID, GenerateOptionsErrorsTask.DESCRIPTOR); | 60 TASK_EXTENSION_POINT_ID, GenerateOptionsErrorsTask.DESCRIPTOR); |
61 // Validate analyzer analysis options. | 61 // Validate analyzer analysis options. |
62 registerExtension( | 62 registerExtension( |
63 OPTIONS_VALIDATOR_EXTENSION_POINT_ID, new AnalyzerOptionsValidator()); | 63 OPTIONS_VALIDATOR_EXTENSION_POINT_ID, new AnalyzerOptionsValidator()); |
64 } | 64 } |
65 | |
66 /// Validate the given extension by throwing an [ExtensionError] if it is not | |
67 /// a valid options processor. | |
68 void _validateOptionsProcessorExtension(Object extension) { | |
69 if (extension is! OptionsProcessor) { | |
70 String id = optionsProcessorExtensionPoint.uniqueIdentifier; | |
71 throw new ExtensionError('Extensions to $id must be an OptionsProcessor'); | |
72 } | |
73 } | |
74 | |
75 /// Validate the given extension by throwing an [ExtensionError] if it is not | |
76 /// a valid options validator. | |
77 void _validateOptionsValidatorExtension(Object extension) { | |
78 if (extension is! OptionsValidator) { | |
79 String id = optionsValidatorExtensionPoint.uniqueIdentifier; | |
80 throw new ExtensionError('Extensions to $id must be an OptionsValidator'); | |
81 } | |
82 } | |
83 } | 65 } |
OLD | NEW |