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.engine_plugin; | 5 library analyzer.src.plugin.engine_plugin; |
6 | 6 |
7 import 'package:analyzer/plugin/task.dart'; | 7 import 'package:analyzer/plugin/task.dart'; |
8 import 'package:analyzer/src/generated/engine.dart' | 8 import 'package:analyzer/src/generated/engine.dart' |
9 show InternalAnalysisContext; | 9 show InternalAnalysisContext; |
10 import 'package:analyzer/src/generated/error.dart' show AnalysisError; | 10 import 'package:analyzer/src/generated/error.dart' show AnalysisError; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 /** | 60 /** |
61 * The unique identifier of this plugin. | 61 * The unique identifier of this plugin. |
62 */ | 62 */ |
63 static const String UNIQUE_IDENTIFIER = 'analysis_engine.core'; | 63 static const String UNIQUE_IDENTIFIER = 'analysis_engine.core'; |
64 | 64 |
65 /** | 65 /** |
66 * The extension point that allows plugins to register new analysis error | 66 * The extension point that allows plugins to register new analysis error |
67 * results for a Dart source. | 67 * results for a Dart source. |
68 */ | 68 */ |
69 ExtensionPoint dartErrorsForSourceExtensionPoint; | 69 ExtensionPoint<ListResultDescriptor<AnalysisError>> |
| 70 dartErrorsForSourceExtensionPoint; |
70 | 71 |
71 /** | 72 /** |
72 * The extension point that allows plugins to register new analysis error | 73 * The extension point that allows plugins to register new analysis error |
73 * results for a Dart library specific unit. | 74 * results for a Dart library specific unit. |
74 */ | 75 */ |
75 ExtensionPoint dartErrorsForUnitExtensionPoint; | 76 ExtensionPoint<ListResultDescriptor<AnalysisError>> |
| 77 dartErrorsForUnitExtensionPoint; |
76 | 78 |
77 /** | 79 /** |
78 * The extension point that allows plugins to register new analysis error | 80 * The extension point that allows plugins to register new analysis error |
79 * results for an HTML source. | 81 * results for an HTML source. |
80 */ | 82 */ |
81 ExtensionPoint htmlErrorsExtensionPoint; | 83 ExtensionPoint<ListResultDescriptor<AnalysisError>> htmlErrorsExtensionPoint; |
82 | 84 |
83 /** | 85 /** |
84 * The extension point that allows plugins to register new analysis tasks with | 86 * The extension point that allows plugins to register new analysis tasks with |
85 * the analysis engine. | 87 * the analysis engine. |
86 */ | 88 */ |
87 ExtensionPoint taskExtensionPoint; | 89 ExtensionPoint<TaskDescriptor> taskExtensionPoint; |
88 | 90 |
89 /** | 91 /** |
90 * The extension point that allows plugins to register new work manager | 92 * The extension point that allows plugins to register new work manager |
91 * factories with the analysis engine. | 93 * factories with the analysis engine. |
92 */ | 94 */ |
93 ExtensionPoint workManagerFactoryExtensionPoint; | 95 ExtensionPoint<WorkManagerFactory> workManagerFactoryExtensionPoint; |
94 | 96 |
95 /** | 97 /** |
96 * Initialize a newly created plugin. | 98 * Initialize a newly created plugin. |
97 */ | 99 */ |
98 EnginePlugin(); | 100 EnginePlugin(); |
99 | 101 |
100 /** | 102 /** |
101 * Return a list containing all of the contributed analysis error result | 103 * Return a list containing all of the contributed analysis error result |
102 * descriptors for Dart sources. | 104 * descriptors for Dart sources. |
103 */ | 105 */ |
(...skipping 26 matching lines...) Expand all Loading... |
130 | 132 |
131 /** | 133 /** |
132 * Return a list containing all of the work manager factories that were | 134 * Return a list containing all of the work manager factories that were |
133 * contributed. | 135 * contributed. |
134 */ | 136 */ |
135 List<WorkManagerFactory> get workManagerFactories => | 137 List<WorkManagerFactory> get workManagerFactories => |
136 workManagerFactoryExtensionPoint.extensions; | 138 workManagerFactoryExtensionPoint.extensions; |
137 | 139 |
138 @override | 140 @override |
139 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { | 141 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { |
140 dartErrorsForSourceExtensionPoint = registerExtensionPoint( | 142 dartErrorsForSourceExtensionPoint = |
141 DART_ERRORS_FOR_SOURCE_EXTENSION_POINT, | 143 new ExtensionPoint<ListResultDescriptor<AnalysisError>>( |
142 _validateAnalysisErrorListResultDescriptor); | 144 this, DART_ERRORS_FOR_SOURCE_EXTENSION_POINT, null); |
143 dartErrorsForUnitExtensionPoint = registerExtensionPoint( | 145 registerExtensionPoint(dartErrorsForSourceExtensionPoint); |
144 DART_ERRORS_FOR_UNIT_EXTENSION_POINT, | 146 dartErrorsForUnitExtensionPoint = |
145 _validateAnalysisErrorListResultDescriptor); | 147 new ExtensionPoint<ListResultDescriptor<AnalysisError>>( |
146 htmlErrorsExtensionPoint = registerExtensionPoint( | 148 this, DART_ERRORS_FOR_UNIT_EXTENSION_POINT, null); |
147 HTML_ERRORS_EXTENSION_POINT, | 149 registerExtensionPoint(dartErrorsForUnitExtensionPoint); |
148 _validateAnalysisErrorListResultDescriptor); | 150 htmlErrorsExtensionPoint = |
| 151 new ExtensionPoint<ListResultDescriptor<AnalysisError>>( |
| 152 this, HTML_ERRORS_EXTENSION_POINT, null); |
| 153 registerExtensionPoint(htmlErrorsExtensionPoint); |
149 taskExtensionPoint = | 154 taskExtensionPoint = |
150 registerExtensionPoint(TASK_EXTENSION_POINT, _validateTaskExtension); | 155 new ExtensionPoint<TaskDescriptor>(this, TASK_EXTENSION_POINT, null); |
151 workManagerFactoryExtensionPoint = registerExtensionPoint( | 156 registerExtensionPoint(taskExtensionPoint); |
152 WORK_MANAGER_FACTORY_EXTENSION_POINT, | 157 workManagerFactoryExtensionPoint = new ExtensionPoint<WorkManagerFactory>( |
153 _validateWorkManagerFactoryExtension); | 158 this, WORK_MANAGER_FACTORY_EXTENSION_POINT, null); |
| 159 registerExtensionPoint(workManagerFactoryExtensionPoint); |
154 } | 160 } |
155 | 161 |
156 @override | 162 @override |
157 void registerExtensions(RegisterExtension registerExtension) { | 163 void registerExtensions(RegisterExtension registerExtension) { |
158 _registerTaskExtensions(registerExtension); | 164 _registerTaskExtensions(registerExtension); |
159 _registerWorkManagerFactoryExtensions(registerExtension); | 165 _registerWorkManagerFactoryExtensions(registerExtension); |
160 _registerDartErrorsForSource(registerExtension); | 166 _registerDartErrorsForSource(registerExtension); |
161 _registerDartErrorsForUnit(registerExtension); | 167 _registerDartErrorsForUnit(registerExtension); |
162 _registerHtmlErrors(registerExtension); | 168 _registerHtmlErrors(registerExtension); |
163 } | 169 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 void _registerWorkManagerFactoryExtensions( | 258 void _registerWorkManagerFactoryExtensions( |
253 RegisterExtension registerExtension) { | 259 RegisterExtension registerExtension) { |
254 String taskId = WORK_MANAGER_EXTENSION_POINT_ID; | 260 String taskId = WORK_MANAGER_EXTENSION_POINT_ID; |
255 registerExtension(taskId, | 261 registerExtension(taskId, |
256 (InternalAnalysisContext context) => new DartWorkManager(context)); | 262 (InternalAnalysisContext context) => new DartWorkManager(context)); |
257 registerExtension(taskId, | 263 registerExtension(taskId, |
258 (InternalAnalysisContext context) => new HtmlWorkManager(context)); | 264 (InternalAnalysisContext context) => new HtmlWorkManager(context)); |
259 registerExtension(taskId, | 265 registerExtension(taskId, |
260 (InternalAnalysisContext context) => new OptionsWorkManager(context)); | 266 (InternalAnalysisContext context) => new OptionsWorkManager(context)); |
261 } | 267 } |
262 | |
263 /** | |
264 * Validate the given extension by throwing an [ExtensionError] if it is not | |
265 * a [ListResultDescriptor] of [AnalysisError]s. | |
266 */ | |
267 void _validateAnalysisErrorListResultDescriptor(Object extension) { | |
268 if (extension is! ListResultDescriptor<AnalysisError>) { | |
269 String id = taskExtensionPoint.uniqueIdentifier; | |
270 throw new ExtensionError( | |
271 'Extensions to $id must be a ListResultDescriptor<AnalysisError>'); | |
272 } | |
273 } | |
274 | |
275 /** | |
276 * Validate the given extension by throwing an [ExtensionError] if it is not | |
277 * a [TaskDescriptor]. | |
278 */ | |
279 void _validateTaskExtension(Object extension) { | |
280 if (extension is! TaskDescriptor) { | |
281 String id = taskExtensionPoint.uniqueIdentifier; | |
282 throw new ExtensionError('Extensions to $id must be a TaskDescriptor'); | |
283 } | |
284 } | |
285 | |
286 /** | |
287 * Validate the given extension by throwing an [ExtensionError] if it is not | |
288 * a [WorkManagerFactory]. | |
289 */ | |
290 void _validateWorkManagerFactoryExtension(Object extension) { | |
291 if (extension is! WorkManagerFactory) { | |
292 String id = taskExtensionPoint.uniqueIdentifier; | |
293 throw new ExtensionError( | |
294 'Extensions to $id must be a WorkManagerFactory'); | |
295 } | |
296 } | |
297 } | 268 } |
298 | 269 |
299 /** | 270 /** |
300 * Annotation describing the relationship between a getter in [EnginePlugin] | 271 * Annotation describing the relationship between a getter in [EnginePlugin] |
301 * and the associated identifier (in '../../plugin/task.dart') which can be | 272 * and the associated identifier (in '../../plugin/task.dart') which can be |
302 * passed to the extension manager to populate it. | 273 * passed to the extension manager to populate it. |
303 * | 274 * |
304 * This annotation is not used at runtime; it is used to aid in static analysis | 275 * This annotation is not used at runtime; it is used to aid in static analysis |
305 * of the task model during development. | 276 * of the task model during development. |
306 */ | 277 */ |
307 class ExtensionPointId { | 278 class ExtensionPointId { |
308 final String extensionPointId; | 279 final String extensionPointId; |
309 | 280 |
310 const ExtensionPointId(this.extensionPointId); | 281 const ExtensionPointId(this.extensionPointId); |
311 } | 282 } |
OLD | NEW |