| 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/task/dart.dart'; | 11 import 'package:analyzer/src/task/dart.dart'; |
| 11 import 'package:analyzer/src/task/dart_work_manager.dart'; | 12 import 'package:analyzer/src/task/dart_work_manager.dart'; |
| 12 import 'package:analyzer/src/task/general.dart'; | 13 import 'package:analyzer/src/task/general.dart'; |
| 13 import 'package:analyzer/src/task/html.dart'; | 14 import 'package:analyzer/src/task/html.dart'; |
| 14 import 'package:analyzer/src/task/html_work_manager.dart'; | 15 import 'package:analyzer/src/task/html_work_manager.dart'; |
| 15 import 'package:analyzer/task/model.dart'; | 16 import 'package:analyzer/task/model.dart'; |
| 16 import 'package:plugin/plugin.dart'; | 17 import 'package:plugin/plugin.dart'; |
| 17 | 18 |
| 18 /** | 19 /** |
| 19 * A plugin that defines the extension points and extensions that are inherently | 20 * A plugin that defines the extension points and extensions that are inherently |
| (...skipping 10 matching lines...) Expand all Loading... |
| 30 /** | 31 /** |
| 31 * The simple identifier of the extension point that allows plugins to | 32 * The simple identifier of the extension point that allows plugins to |
| 32 * register new analysis error results to compute for a Dart library | 33 * register new analysis error results to compute for a Dart library |
| 33 * specific unit. | 34 * specific unit. |
| 34 */ | 35 */ |
| 35 static const String DART_ERRORS_FOR_UNIT_EXTENSION_POINT = | 36 static const String DART_ERRORS_FOR_UNIT_EXTENSION_POINT = |
| 36 'dartErrorsForUnit'; | 37 'dartErrorsForUnit'; |
| 37 | 38 |
| 38 /** | 39 /** |
| 39 * The simple identifier of the extension point that allows plugins to | 40 * The simple identifier of the extension point that allows plugins to |
| 41 * register new analysis error results to compute for an HTML source. |
| 42 */ |
| 43 static const String HTML_ERRORS_EXTENSION_POINT = 'htmlErrors'; |
| 44 |
| 45 /** |
| 46 * The simple identifier of the extension point that allows plugins to |
| 40 * register new analysis tasks with the analysis engine. | 47 * register new analysis tasks with the analysis engine. |
| 41 */ | 48 */ |
| 42 static const String TASK_EXTENSION_POINT = 'task'; | 49 static const String TASK_EXTENSION_POINT = 'task'; |
| 43 | 50 |
| 44 /** | 51 /** |
| 45 * The simple identifier of the extension point that allows plugins to | 52 * The simple identifier of the extension point that allows plugins to |
| 46 * register new work manager factories with the analysis engine. | 53 * register new work manager factories with the analysis engine. |
| 47 */ | 54 */ |
| 48 static const String WORK_MANAGER_FACTORY_EXTENSION_POINT = | 55 static const String WORK_MANAGER_FACTORY_EXTENSION_POINT = |
| 49 'workManagerFactory'; | 56 'workManagerFactory'; |
| 50 | 57 |
| 51 /** | 58 /** |
| 52 * The unique identifier of this plugin. | 59 * The unique identifier of this plugin. |
| 53 */ | 60 */ |
| 54 static const String UNIQUE_IDENTIFIER = 'analysis_engine.core'; | 61 static const String UNIQUE_IDENTIFIER = 'analysis_engine.core'; |
| 55 | 62 |
| 56 /** | 63 /** |
| 57 * The extension point that allows plugins to register new analysis error | 64 * The extension point that allows plugins to register new analysis error |
| 58 * results for a Dart source. | 65 * results for a Dart source. |
| 59 */ | 66 */ |
| 60 ExtensionPoint dartErrorsForSourceExtensionPoint; | 67 ExtensionPoint dartErrorsForSourceExtensionPoint; |
| 61 | 68 |
| 62 /** | 69 /** |
| 63 * The extension point that allows plugins to register new analysis error | 70 * The extension point that allows plugins to register new analysis error |
| 64 * results for a Dart library specific unit. | 71 * results for a Dart library specific unit. |
| 65 */ | 72 */ |
| 66 ExtensionPoint dartErrorsForUnitExtensionPoint; | 73 ExtensionPoint dartErrorsForUnitExtensionPoint; |
| 67 | 74 |
| 68 /** | 75 /** |
| 76 * The extension point that allows plugins to register new analysis error |
| 77 * results for an HTML source. |
| 78 */ |
| 79 ExtensionPoint htmlErrorsExtensionPoint; |
| 80 |
| 81 /** |
| 69 * The extension point that allows plugins to register new analysis tasks with | 82 * The extension point that allows plugins to register new analysis tasks with |
| 70 * the analysis engine. | 83 * the analysis engine. |
| 71 */ | 84 */ |
| 72 ExtensionPoint taskExtensionPoint; | 85 ExtensionPoint taskExtensionPoint; |
| 73 | 86 |
| 74 /** | 87 /** |
| 75 * The extension point that allows plugins to register new work manager | 88 * The extension point that allows plugins to register new work manager |
| 76 * factories with the analysis engine. | 89 * factories with the analysis engine. |
| 77 */ | 90 */ |
| 78 ExtensionPoint workManagerFactoryExtensionPoint; | 91 ExtensionPoint workManagerFactoryExtensionPoint; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 90 dartErrorsForSourceExtensionPoint.extensions; | 103 dartErrorsForSourceExtensionPoint.extensions; |
| 91 | 104 |
| 92 /** | 105 /** |
| 93 * Return a list containing all of the contributed analysis error result | 106 * Return a list containing all of the contributed analysis error result |
| 94 * descriptors for Dart library specific units. | 107 * descriptors for Dart library specific units. |
| 95 */ | 108 */ |
| 96 List<TaskDescriptor> get dartErrorsForUnit => | 109 List<TaskDescriptor> get dartErrorsForUnit => |
| 97 dartErrorsForUnitExtensionPoint.extensions; | 110 dartErrorsForUnitExtensionPoint.extensions; |
| 98 | 111 |
| 99 /** | 112 /** |
| 113 * Return a list containing all of the contributed analysis error result |
| 114 * descriptors for HTML sources. |
| 115 */ |
| 116 List<TaskDescriptor> get htmlErrors => htmlErrorsExtensionPoint.extensions; |
| 117 |
| 118 /** |
| 100 * Return a list containing all of the task descriptors that were contributed. | 119 * Return a list containing all of the task descriptors that were contributed. |
| 101 */ | 120 */ |
| 102 List<TaskDescriptor> get taskDescriptors => taskExtensionPoint.extensions; | 121 List<TaskDescriptor> get taskDescriptors => taskExtensionPoint.extensions; |
| 103 | 122 |
| 104 @override | 123 @override |
| 105 String get uniqueIdentifier => UNIQUE_IDENTIFIER; | 124 String get uniqueIdentifier => UNIQUE_IDENTIFIER; |
| 106 | 125 |
| 107 /** | 126 /** |
| 108 * Return a list containing all of the work manager factories that were | 127 * Return a list containing all of the work manager factories that were |
| 109 * contributed. | 128 * contributed. |
| 110 */ | 129 */ |
| 111 List<WorkManagerFactory> get workManagerFactories => | 130 List<WorkManagerFactory> get workManagerFactories => |
| 112 workManagerFactoryExtensionPoint.extensions; | 131 workManagerFactoryExtensionPoint.extensions; |
| 113 | 132 |
| 114 @override | 133 @override |
| 115 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { | 134 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { |
| 116 dartErrorsForSourceExtensionPoint = registerExtensionPoint( | 135 dartErrorsForSourceExtensionPoint = registerExtensionPoint( |
| 117 DART_ERRORS_FOR_SOURCE_EXTENSION_POINT, _validateResultDescriptor); | 136 DART_ERRORS_FOR_SOURCE_EXTENSION_POINT, |
| 137 _validateAnalysisErrorListResultDescriptor); |
| 118 dartErrorsForUnitExtensionPoint = registerExtensionPoint( | 138 dartErrorsForUnitExtensionPoint = registerExtensionPoint( |
| 119 DART_ERRORS_FOR_UNIT_EXTENSION_POINT, _validateResultDescriptor); | 139 DART_ERRORS_FOR_UNIT_EXTENSION_POINT, |
| 140 _validateAnalysisErrorListResultDescriptor); |
| 141 htmlErrorsExtensionPoint = registerExtensionPoint( |
| 142 HTML_ERRORS_EXTENSION_POINT, |
| 143 _validateAnalysisErrorListResultDescriptor); |
| 120 taskExtensionPoint = | 144 taskExtensionPoint = |
| 121 registerExtensionPoint(TASK_EXTENSION_POINT, _validateTaskExtension); | 145 registerExtensionPoint(TASK_EXTENSION_POINT, _validateTaskExtension); |
| 122 workManagerFactoryExtensionPoint = registerExtensionPoint( | 146 workManagerFactoryExtensionPoint = registerExtensionPoint( |
| 123 WORK_MANAGER_FACTORY_EXTENSION_POINT, | 147 WORK_MANAGER_FACTORY_EXTENSION_POINT, |
| 124 _validateWorkManagerFactoryExtension); | 148 _validateWorkManagerFactoryExtension); |
| 125 } | 149 } |
| 126 | 150 |
| 127 @override | 151 @override |
| 128 void registerExtensions(RegisterExtension registerExtension) { | 152 void registerExtensions(RegisterExtension registerExtension) { |
| 129 _registerTaskExtensions(registerExtension); | 153 _registerTaskExtensions(registerExtension); |
| 130 _registerWorkManagerFactoryExtensions(registerExtension); | 154 _registerWorkManagerFactoryExtensions(registerExtension); |
| 131 _registerDartErrorsForSource(registerExtension); | 155 _registerDartErrorsForSource(registerExtension); |
| 132 _registerDartErrorsForUnit(registerExtension); | 156 _registerDartErrorsForUnit(registerExtension); |
| 157 _registerHtmlErrors(registerExtension); |
| 133 } | 158 } |
| 134 | 159 |
| 135 void _registerDartErrorsForSource(RegisterExtension registerExtension) { | 160 void _registerDartErrorsForSource(RegisterExtension registerExtension) { |
| 136 String id = DART_ERRORS_FOR_SOURCE_EXTENSION_POINT_ID; | 161 String id = DART_ERRORS_FOR_SOURCE_EXTENSION_POINT_ID; |
| 137 registerExtension(id, BUILD_DIRECTIVES_ERRORS); | 162 registerExtension(id, BUILD_DIRECTIVES_ERRORS); |
| 138 registerExtension(id, BUILD_LIBRARY_ERRORS); | 163 registerExtension(id, BUILD_LIBRARY_ERRORS); |
| 139 registerExtension(id, PARSE_ERRORS); | 164 registerExtension(id, PARSE_ERRORS); |
| 140 registerExtension(id, SCAN_ERRORS); | 165 registerExtension(id, SCAN_ERRORS); |
| 141 } | 166 } |
| 142 | 167 |
| 143 void _registerDartErrorsForUnit(RegisterExtension registerExtension) { | 168 void _registerDartErrorsForUnit(RegisterExtension registerExtension) { |
| 144 String id = DART_ERRORS_FOR_UNIT_EXTENSION_POINT_ID; | 169 String id = DART_ERRORS_FOR_UNIT_EXTENSION_POINT_ID; |
| 145 registerExtension(id, LIBRARY_UNIT_ERRORS); | 170 registerExtension(id, LIBRARY_UNIT_ERRORS); |
| 146 } | 171 } |
| 147 | 172 |
| 173 void _registerHtmlErrors(RegisterExtension registerExtension) { |
| 174 String id = HTML_ERRORS_EXTENSION_POINT_ID; |
| 175 registerExtension(id, HTML_DOCUMENT_ERRORS); |
| 176 } |
| 177 |
| 148 void _registerTaskExtensions(RegisterExtension registerExtension) { | 178 void _registerTaskExtensions(RegisterExtension registerExtension) { |
| 149 String taskId = TASK_EXTENSION_POINT_ID; | 179 String taskId = TASK_EXTENSION_POINT_ID; |
| 150 // | 180 // |
| 151 // Register general tasks. | 181 // Register general tasks. |
| 152 // | 182 // |
| 153 registerExtension(taskId, GetContentTask.DESCRIPTOR); | 183 registerExtension(taskId, GetContentTask.DESCRIPTOR); |
| 154 // | 184 // |
| 155 // Register Dart tasks. | 185 // Register Dart tasks. |
| 156 // | 186 // |
| 157 registerExtension(taskId, BuildCompilationUnitElementTask.DESCRIPTOR); | 187 registerExtension(taskId, BuildCompilationUnitElementTask.DESCRIPTOR); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 RegisterExtension registerExtension) { | 229 RegisterExtension registerExtension) { |
| 200 String taskId = WORK_MANAGER_EXTENSION_POINT_ID; | 230 String taskId = WORK_MANAGER_EXTENSION_POINT_ID; |
| 201 registerExtension(taskId, | 231 registerExtension(taskId, |
| 202 (InternalAnalysisContext context) => new DartWorkManager(context)); | 232 (InternalAnalysisContext context) => new DartWorkManager(context)); |
| 203 registerExtension(taskId, | 233 registerExtension(taskId, |
| 204 (InternalAnalysisContext context) => new HtmlWorkManager(context)); | 234 (InternalAnalysisContext context) => new HtmlWorkManager(context)); |
| 205 } | 235 } |
| 206 | 236 |
| 207 /** | 237 /** |
| 208 * Validate the given extension by throwing an [ExtensionError] if it is not | 238 * Validate the given extension by throwing an [ExtensionError] if it is not |
| 209 * a [ResultDescriptor]. | 239 * a [ListResultDescriptor] of [AnalysisError]s. |
| 210 */ | 240 */ |
| 211 void _validateResultDescriptor(Object extension) { | 241 void _validateAnalysisErrorListResultDescriptor(Object extension) { |
| 212 if (extension is! ResultDescriptor) { | 242 if (extension is! ListResultDescriptor<AnalysisError>) { |
| 213 String id = taskExtensionPoint.uniqueIdentifier; | 243 String id = taskExtensionPoint.uniqueIdentifier; |
| 214 throw new ExtensionError('Extensions to $id must be a ResultDescriptor'); | 244 throw new ExtensionError( |
| 245 'Extensions to $id must be a ListResultDescriptor<AnalysisError>'); |
| 215 } | 246 } |
| 216 } | 247 } |
| 217 | 248 |
| 218 /** | 249 /** |
| 219 * Validate the given extension by throwing an [ExtensionError] if it is not | 250 * Validate the given extension by throwing an [ExtensionError] if it is not |
| 220 * a [TaskDescriptor]. | 251 * a [TaskDescriptor]. |
| 221 */ | 252 */ |
| 222 void _validateTaskExtension(Object extension) { | 253 void _validateTaskExtension(Object extension) { |
| 223 if (extension is! TaskDescriptor) { | 254 if (extension is! TaskDescriptor) { |
| 224 String id = taskExtensionPoint.uniqueIdentifier; | 255 String id = taskExtensionPoint.uniqueIdentifier; |
| 225 throw new ExtensionError('Extensions to $id must be a TaskDescriptor'); | 256 throw new ExtensionError('Extensions to $id must be a TaskDescriptor'); |
| 226 } | 257 } |
| 227 } | 258 } |
| 228 | 259 |
| 229 /** | 260 /** |
| 230 * Validate the given extension by throwing an [ExtensionError] if it is not | 261 * Validate the given extension by throwing an [ExtensionError] if it is not |
| 231 * a [WorkManagerFactory]. | 262 * a [WorkManagerFactory]. |
| 232 */ | 263 */ |
| 233 void _validateWorkManagerFactoryExtension(Object extension) { | 264 void _validateWorkManagerFactoryExtension(Object extension) { |
| 234 if (extension is! WorkManagerFactory) { | 265 if (extension is! WorkManagerFactory) { |
| 235 String id = taskExtensionPoint.uniqueIdentifier; | 266 String id = taskExtensionPoint.uniqueIdentifier; |
| 236 throw new ExtensionError( | 267 throw new ExtensionError( |
| 237 'Extensions to $id must be a WorkManagerFactory'); | 268 'Extensions to $id must be a WorkManagerFactory'); |
| 238 } | 269 } |
| 239 } | 270 } |
| 240 } | 271 } |
| OLD | NEW |