OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library analyzer.src.plugin.engine_plugin; |
| 6 |
| 7 import 'package:analyzer/plugin/task.dart'; |
| 8 import 'package:analyzer/src/generated/engine.dart' |
| 9 show InternalAnalysisContext; |
| 10 import 'package:analyzer/src/generated/error.dart' show AnalysisError; |
| 11 import 'package:analyzer/src/task/dart.dart'; |
| 12 import 'package:analyzer/src/task/dart_work_manager.dart'; |
| 13 import 'package:analyzer/src/task/general.dart'; |
| 14 import 'package:analyzer/src/task/html.dart'; |
| 15 import 'package:analyzer/src/task/html_work_manager.dart'; |
| 16 import 'package:analyzer/task/model.dart'; |
| 17 import 'package:plugin/plugin.dart'; |
| 18 |
| 19 /** |
| 20 * A plugin that defines the extension points and extensions that are inherently |
| 21 * defined by the analysis engine. |
| 22 */ |
| 23 class EnginePlugin implements Plugin { |
| 24 /** |
| 25 * The simple identifier of the extension point that allows plugins to |
| 26 * register new analysis error results to compute for a Dart source. |
| 27 */ |
| 28 static const String DART_ERRORS_FOR_SOURCE_EXTENSION_POINT = |
| 29 'dartErrorsForSource'; |
| 30 |
| 31 /** |
| 32 * The simple identifier of the extension point that allows plugins to |
| 33 * register new analysis error results to compute for a Dart library |
| 34 * specific unit. |
| 35 */ |
| 36 static const String DART_ERRORS_FOR_UNIT_EXTENSION_POINT = |
| 37 'dartErrorsForUnit'; |
| 38 |
| 39 /** |
| 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 |
| 47 * register new analysis tasks with the analysis engine. |
| 48 */ |
| 49 static const String TASK_EXTENSION_POINT = 'task'; |
| 50 |
| 51 /** |
| 52 * The simple identifier of the extension point that allows plugins to |
| 53 * register new work manager factories with the analysis engine. |
| 54 */ |
| 55 static const String WORK_MANAGER_FACTORY_EXTENSION_POINT = |
| 56 'workManagerFactory'; |
| 57 |
| 58 /** |
| 59 * The unique identifier of this plugin. |
| 60 */ |
| 61 static const String UNIQUE_IDENTIFIER = 'analysis_engine.core'; |
| 62 |
| 63 /** |
| 64 * The extension point that allows plugins to register new analysis error |
| 65 * results for a Dart source. |
| 66 */ |
| 67 ExtensionPoint dartErrorsForSourceExtensionPoint; |
| 68 |
| 69 /** |
| 70 * The extension point that allows plugins to register new analysis error |
| 71 * results for a Dart library specific unit. |
| 72 */ |
| 73 ExtensionPoint dartErrorsForUnitExtensionPoint; |
| 74 |
| 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 /** |
| 82 * The extension point that allows plugins to register new analysis tasks with |
| 83 * the analysis engine. |
| 84 */ |
| 85 ExtensionPoint taskExtensionPoint; |
| 86 |
| 87 /** |
| 88 * The extension point that allows plugins to register new work manager |
| 89 * factories with the analysis engine. |
| 90 */ |
| 91 ExtensionPoint workManagerFactoryExtensionPoint; |
| 92 |
| 93 /** |
| 94 * Initialize a newly created plugin. |
| 95 */ |
| 96 EnginePlugin(); |
| 97 |
| 98 /** |
| 99 * Return a list containing all of the contributed analysis error result |
| 100 * descriptors for Dart sources. |
| 101 */ |
| 102 List<TaskDescriptor> get dartErrorsForSource => |
| 103 dartErrorsForSourceExtensionPoint.extensions; |
| 104 |
| 105 /** |
| 106 * Return a list containing all of the contributed analysis error result |
| 107 * descriptors for Dart library specific units. |
| 108 */ |
| 109 List<TaskDescriptor> get dartErrorsForUnit => |
| 110 dartErrorsForUnitExtensionPoint.extensions; |
| 111 |
| 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 /** |
| 119 * Return a list containing all of the task descriptors that were contributed. |
| 120 */ |
| 121 List<TaskDescriptor> get taskDescriptors => taskExtensionPoint.extensions; |
| 122 |
| 123 @override |
| 124 String get uniqueIdentifier => UNIQUE_IDENTIFIER; |
| 125 |
| 126 /** |
| 127 * Return a list containing all of the work manager factories that were |
| 128 * contributed. |
| 129 */ |
| 130 List<WorkManagerFactory> get workManagerFactories => |
| 131 workManagerFactoryExtensionPoint.extensions; |
| 132 |
| 133 @override |
| 134 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { |
| 135 dartErrorsForSourceExtensionPoint = registerExtensionPoint( |
| 136 DART_ERRORS_FOR_SOURCE_EXTENSION_POINT, |
| 137 _validateAnalysisErrorListResultDescriptor); |
| 138 dartErrorsForUnitExtensionPoint = registerExtensionPoint( |
| 139 DART_ERRORS_FOR_UNIT_EXTENSION_POINT, |
| 140 _validateAnalysisErrorListResultDescriptor); |
| 141 htmlErrorsExtensionPoint = registerExtensionPoint( |
| 142 HTML_ERRORS_EXTENSION_POINT, |
| 143 _validateAnalysisErrorListResultDescriptor); |
| 144 taskExtensionPoint = |
| 145 registerExtensionPoint(TASK_EXTENSION_POINT, _validateTaskExtension); |
| 146 workManagerFactoryExtensionPoint = registerExtensionPoint( |
| 147 WORK_MANAGER_FACTORY_EXTENSION_POINT, |
| 148 _validateWorkManagerFactoryExtension); |
| 149 } |
| 150 |
| 151 @override |
| 152 void registerExtensions(RegisterExtension registerExtension) { |
| 153 _registerTaskExtensions(registerExtension); |
| 154 _registerWorkManagerFactoryExtensions(registerExtension); |
| 155 _registerDartErrorsForSource(registerExtension); |
| 156 _registerDartErrorsForUnit(registerExtension); |
| 157 _registerHtmlErrors(registerExtension); |
| 158 } |
| 159 |
| 160 void _registerDartErrorsForSource(RegisterExtension registerExtension) { |
| 161 String id = DART_ERRORS_FOR_SOURCE_EXTENSION_POINT_ID; |
| 162 registerExtension(id, PARSE_ERRORS); |
| 163 registerExtension(id, SCAN_ERRORS); |
| 164 } |
| 165 |
| 166 void _registerDartErrorsForUnit(RegisterExtension registerExtension) { |
| 167 String id = DART_ERRORS_FOR_UNIT_EXTENSION_POINT_ID; |
| 168 registerExtension(id, LIBRARY_UNIT_ERRORS); |
| 169 } |
| 170 |
| 171 void _registerHtmlErrors(RegisterExtension registerExtension) { |
| 172 String id = HTML_ERRORS_EXTENSION_POINT_ID; |
| 173 registerExtension(id, HTML_DOCUMENT_ERRORS); |
| 174 } |
| 175 |
| 176 void _registerTaskExtensions(RegisterExtension registerExtension) { |
| 177 String taskId = TASK_EXTENSION_POINT_ID; |
| 178 // |
| 179 // Register general tasks. |
| 180 // |
| 181 registerExtension(taskId, GetContentTask.DESCRIPTOR); |
| 182 // |
| 183 // Register Dart tasks. |
| 184 // |
| 185 registerExtension(taskId, BuildCompilationUnitElementTask.DESCRIPTOR); |
| 186 registerExtension(taskId, BuildDirectiveElementsTask.DESCRIPTOR); |
| 187 registerExtension(taskId, BuildEnumMemberElementsTask.DESCRIPTOR); |
| 188 registerExtension(taskId, BuildExportNamespaceTask.DESCRIPTOR); |
| 189 registerExtension(taskId, BuildLibraryElementTask.DESCRIPTOR); |
| 190 registerExtension(taskId, BuildPublicNamespaceTask.DESCRIPTOR); |
| 191 registerExtension(taskId, BuildSourceExportClosureTask.DESCRIPTOR); |
| 192 registerExtension(taskId, BuildSourceImportExportClosureTask.DESCRIPTOR); |
| 193 registerExtension(taskId, BuildTypeProviderTask.DESCRIPTOR); |
| 194 registerExtension(taskId, ComputeConstantDependenciesTask.DESCRIPTOR); |
| 195 registerExtension(taskId, ComputeConstantValueTask.DESCRIPTOR); |
| 196 registerExtension( |
| 197 taskId, ComputeInferableStaticVariableDependenciesTask.DESCRIPTOR); |
| 198 registerExtension(taskId, ComputeLibraryCycleTask.DESCRIPTOR); |
| 199 registerExtension(taskId, ContainingLibrariesTask.DESCRIPTOR); |
| 200 registerExtension(taskId, DartErrorsTask.DESCRIPTOR); |
| 201 registerExtension(taskId, EvaluateUnitConstantsTask.DESCRIPTOR); |
| 202 registerExtension(taskId, GatherUsedImportedElementsTask.DESCRIPTOR); |
| 203 registerExtension(taskId, GatherUsedLocalElementsTask.DESCRIPTOR); |
| 204 registerExtension(taskId, GenerateHintsTask.DESCRIPTOR); |
| 205 registerExtension(taskId, GenerateLintsTask.DESCRIPTOR); |
| 206 registerExtension(taskId, InferInstanceMembersInUnitTask.DESCRIPTOR); |
| 207 registerExtension(taskId, InferStaticVariableTypesInUnitTask.DESCRIPTOR); |
| 208 registerExtension(taskId, InferStaticVariableTypeTask.DESCRIPTOR); |
| 209 registerExtension(taskId, LibraryErrorsReadyTask.DESCRIPTOR); |
| 210 registerExtension(taskId, LibraryUnitErrorsTask.DESCRIPTOR); |
| 211 registerExtension(taskId, ParseDartTask.DESCRIPTOR); |
| 212 registerExtension(taskId, PartiallyResolveUnitReferencesTask.DESCRIPTOR); |
| 213 registerExtension(taskId, ResolveInstanceFieldsInUnitTask.DESCRIPTOR); |
| 214 registerExtension(taskId, ResolveLibraryReferencesTask.DESCRIPTOR); |
| 215 registerExtension(taskId, ResolveLibraryTypeNamesTask.DESCRIPTOR); |
| 216 registerExtension(taskId, ResolveUnitTask.DESCRIPTOR); |
| 217 registerExtension(taskId, ResolveUnitTypeNamesTask.DESCRIPTOR); |
| 218 registerExtension(taskId, ResolveVariableReferencesTask.DESCRIPTOR); |
| 219 registerExtension(taskId, ScanDartTask.DESCRIPTOR); |
| 220 registerExtension(taskId, VerifyUnitTask.DESCRIPTOR); |
| 221 // |
| 222 // Register HTML tasks. |
| 223 // |
| 224 registerExtension(taskId, DartScriptsTask.DESCRIPTOR); |
| 225 registerExtension(taskId, HtmlErrorsTask.DESCRIPTOR); |
| 226 registerExtension(taskId, ParseHtmlTask.DESCRIPTOR); |
| 227 } |
| 228 |
| 229 void _registerWorkManagerFactoryExtensions( |
| 230 RegisterExtension registerExtension) { |
| 231 String taskId = WORK_MANAGER_EXTENSION_POINT_ID; |
| 232 registerExtension(taskId, |
| 233 (InternalAnalysisContext context) => new DartWorkManager(context)); |
| 234 registerExtension(taskId, |
| 235 (InternalAnalysisContext context) => new HtmlWorkManager(context)); |
| 236 } |
| 237 |
| 238 /** |
| 239 * Validate the given extension by throwing an [ExtensionError] if it is not |
| 240 * a [ListResultDescriptor] of [AnalysisError]s. |
| 241 */ |
| 242 void _validateAnalysisErrorListResultDescriptor(Object extension) { |
| 243 if (extension is! ListResultDescriptor<AnalysisError>) { |
| 244 String id = taskExtensionPoint.uniqueIdentifier; |
| 245 throw new ExtensionError( |
| 246 'Extensions to $id must be a ListResultDescriptor<AnalysisError>'); |
| 247 } |
| 248 } |
| 249 |
| 250 /** |
| 251 * Validate the given extension by throwing an [ExtensionError] if it is not |
| 252 * a [TaskDescriptor]. |
| 253 */ |
| 254 void _validateTaskExtension(Object extension) { |
| 255 if (extension is! TaskDescriptor) { |
| 256 String id = taskExtensionPoint.uniqueIdentifier; |
| 257 throw new ExtensionError('Extensions to $id must be a TaskDescriptor'); |
| 258 } |
| 259 } |
| 260 |
| 261 /** |
| 262 * Validate the given extension by throwing an [ExtensionError] if it is not |
| 263 * a [WorkManagerFactory]. |
| 264 */ |
| 265 void _validateWorkManagerFactoryExtension(Object extension) { |
| 266 if (extension is! WorkManagerFactory) { |
| 267 String id = taskExtensionPoint.uniqueIdentifier; |
| 268 throw new ExtensionError( |
| 269 'Extensions to $id must be a WorkManagerFactory'); |
| 270 } |
| 271 } |
| 272 } |
OLD | NEW |