Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1309)

Side by Side Diff: pkg/analyzer/lib/src/plugin/options_plugin.dart

Issue 1418333002: OptionsValidator plugin extension and linter service. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Review feedback. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/plugin/options.dart ('k') | pkg/analyzer/lib/src/task/options.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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; 5 library analyzer.src.plugin.options;
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
21 /// register new options validators.
22 static const String OPTIONS_VALIDATOR_EXTENSION_POINT = 'optionsValidator';
23
20 /// The unique identifier of this plugin. 24 /// The unique identifier of this plugin.
21 static const String UNIQUE_IDENTIFIER = 'options.core'; 25 static const String UNIQUE_IDENTIFIER = 'options.core';
22 26
23 /// The extension point that allows plugins to register new options processors . 27 /// The extension point that allows plugins to register new options
28 /// processors.
24 ExtensionPoint optionsProcessorExtensionPoint; 29 ExtensionPoint optionsProcessorExtensionPoint;
25 30
31 /// The extension point that allows plugins to register new options
32 /// validators.
33 ExtensionPoint optionsValidatorExtensionPoint;
34
26 /// All contributed options processors. 35 /// All contributed options processors.
27 List<OptionsProcessor> get optionsProcessors => 36 List<OptionsProcessor> get optionsProcessors =>
28 optionsProcessorExtensionPoint == null 37 optionsProcessorExtensionPoint?.extensions ?? const [];
29 ? const [] 38
30 : optionsProcessorExtensionPoint.extensions; 39 /// All contributed options validators.
40 List<OptionsValidator> get optionsValidators =>
41 optionsValidatorExtensionPoint?.extensions ?? const [];
31 42
32 @override 43 @override
33 String get uniqueIdentifier => UNIQUE_IDENTIFIER; 44 String get uniqueIdentifier => UNIQUE_IDENTIFIER;
34 45
35 @override 46 @override
36 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { 47 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) {
37 optionsProcessorExtensionPoint = registerExtensionPoint( 48 optionsProcessorExtensionPoint = registerExtensionPoint(
38 OPTIONS_PROCESSOR_EXTENSION_POINT, _validateOptionsProcessorExtension); 49 OPTIONS_PROCESSOR_EXTENSION_POINT, _validateOptionsProcessorExtension);
50 optionsValidatorExtensionPoint = registerExtensionPoint(
51 OPTIONS_VALIDATOR_EXTENSION_POINT, _validateOptionsValidatorExtension);
39 } 52 }
40 53
41 @override 54 @override
42 void registerExtensions(RegisterExtension registerExtension) { 55 void registerExtensions(RegisterExtension registerExtension) {
43 // Analyze options files. 56 // Analyze options files.
44 registerExtension( 57 registerExtension(
45 TASK_EXTENSION_POINT_ID, GenerateOptionsErrorsTask.DESCRIPTOR); 58 TASK_EXTENSION_POINT_ID, GenerateOptionsErrorsTask.DESCRIPTOR);
59 // Validate analyzer analysis options.
60 registerExtension(
61 OPTIONS_VALIDATOR_EXTENSION_POINT_ID, new AnalyzerOptionsValidator());
46 } 62 }
47 63
48 /// Validate the given extension by throwing an [ExtensionError] if it is not a 64 /// Validate the given extension by throwing an [ExtensionError] if it is not
49 /// valid options processor. 65 /// a valid options processor.
50 void _validateOptionsProcessorExtension(Object extension) { 66 void _validateOptionsProcessorExtension(Object extension) {
51 if (extension is! OptionsProcessor) { 67 if (extension is! OptionsProcessor) {
52 String id = optionsProcessorExtensionPoint.uniqueIdentifier; 68 String id = optionsProcessorExtensionPoint.uniqueIdentifier;
53 throw new ExtensionError('Extensions to $id must be an OptionsProcessor'); 69 throw new ExtensionError('Extensions to $id must be an OptionsProcessor');
54 } 70 }
55 } 71 }
72
73 /// Validate the given extension by throwing an [ExtensionError] if it is not
74 /// a valid options validator.
75 void _validateOptionsValidatorExtension(Object extension) {
76 if (extension is! OptionsValidator) {
77 String id = optionsValidatorExtensionPoint.uniqueIdentifier;
78 throw new ExtensionError('Extensions to $id must be an OptionsValidator');
79 }
80 }
56 } 81 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/plugin/options.dart ('k') | pkg/analyzer/lib/src/task/options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698