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/task/dart.dart'; |
| 11 import 'package:analyzer/src/task/dart_work_manager.dart'; |
| 12 import 'package:analyzer/src/task/general.dart'; |
| 13 import 'package:analyzer/src/task/html.dart'; |
| 14 import 'package:analyzer/src/task/html_work_manager.dart'; |
| 15 import 'package:analyzer/task/model.dart'; |
| 16 import 'package:plugin/plugin.dart'; |
| 17 |
| 18 /** |
| 19 * A plugin that defines the extension points and extensions that are inherently |
| 20 * defined by the analysis engine. |
| 21 */ |
| 22 class EnginePlugin implements Plugin { |
| 23 /** |
| 24 * The simple identifier of the extension point that allows plugins to |
| 25 * register new analysis tasks with the analysis engine. |
| 26 */ |
| 27 static const String TASK_EXTENSION_POINT = 'task'; |
| 28 |
| 29 /** |
| 30 * The simple identifier of the extension point that allows plugins to |
| 31 * register new work manager factories with the analysis engine. |
| 32 */ |
| 33 static const String WORK_MANAGER_FACTORY_EXTENSION_POINT = |
| 34 'workManagerFactory'; |
| 35 |
| 36 /** |
| 37 * The unique identifier of this plugin. |
| 38 */ |
| 39 static const String UNIQUE_IDENTIFIER = 'analysis_engine.core'; |
| 40 |
| 41 /** |
| 42 * The extension point that allows plugins to register new analysis tasks with |
| 43 * the analysis engine. |
| 44 */ |
| 45 ExtensionPoint taskExtensionPoint; |
| 46 |
| 47 /** |
| 48 * The extension point that allows plugins to register new work manager |
| 49 * factories with the analysis engine. |
| 50 */ |
| 51 ExtensionPoint workManagerFactoryExtensionPoint; |
| 52 |
| 53 /** |
| 54 * Initialize a newly created plugin. |
| 55 */ |
| 56 EnginePlugin(); |
| 57 |
| 58 /** |
| 59 * Return a list containing all of the task descriptors that were contributed. |
| 60 */ |
| 61 List<TaskDescriptor> get taskDescriptors => taskExtensionPoint.extensions; |
| 62 |
| 63 @override |
| 64 String get uniqueIdentifier => UNIQUE_IDENTIFIER; |
| 65 |
| 66 /** |
| 67 * Return a list containing all of the work manager factories that were |
| 68 * contributed. |
| 69 */ |
| 70 List<WorkManagerFactory> get workManagerFactories => |
| 71 workManagerFactoryExtensionPoint.extensions; |
| 72 |
| 73 @override |
| 74 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { |
| 75 taskExtensionPoint = |
| 76 registerExtensionPoint(TASK_EXTENSION_POINT, _validateTaskExtension); |
| 77 workManagerFactoryExtensionPoint = registerExtensionPoint( |
| 78 WORK_MANAGER_FACTORY_EXTENSION_POINT, |
| 79 _validateWorkManagerFactoryExtension); |
| 80 } |
| 81 |
| 82 @override |
| 83 void registerExtensions(RegisterExtension registerExtension) { |
| 84 _registerTaskExtensions(registerExtension); |
| 85 _registerWorkManagerFactoryExtensions(registerExtension); |
| 86 } |
| 87 |
| 88 void _registerTaskExtensions(RegisterExtension registerExtension) { |
| 89 String taskId = TASK_EXTENSION_POINT_ID; |
| 90 // |
| 91 // Register general tasks. |
| 92 // |
| 93 registerExtension(taskId, GetContentTask.DESCRIPTOR); |
| 94 // |
| 95 // Register Dart tasks. |
| 96 // |
| 97 registerExtension(taskId, BuildCompilationUnitElementTask.DESCRIPTOR); |
| 98 registerExtension(taskId, BuildDirectiveElementsTask.DESCRIPTOR); |
| 99 registerExtension(taskId, BuildEnumMemberElementsTask.DESCRIPTOR); |
| 100 registerExtension(taskId, BuildExportNamespaceTask.DESCRIPTOR); |
| 101 registerExtension(taskId, BuildLibraryElementTask.DESCRIPTOR); |
| 102 registerExtension(taskId, BuildPublicNamespaceTask.DESCRIPTOR); |
| 103 registerExtension(taskId, BuildSourceExportClosureTask.DESCRIPTOR); |
| 104 registerExtension(taskId, BuildSourceImportExportClosureTask.DESCRIPTOR); |
| 105 registerExtension(taskId, BuildTypeProviderTask.DESCRIPTOR); |
| 106 registerExtension(taskId, ComputeConstantDependenciesTask.DESCRIPTOR); |
| 107 registerExtension(taskId, ComputeConstantValueTask.DESCRIPTOR); |
| 108 registerExtension(taskId, ComputeInferableStaticVariableDependenciesTask.DES
CRIPTOR); |
| 109 registerExtension(taskId, ContainingLibrariesTask.DESCRIPTOR); |
| 110 registerExtension(taskId, DartErrorsTask.DESCRIPTOR); |
| 111 registerExtension(taskId, EvaluateUnitConstantsTask.DESCRIPTOR); |
| 112 registerExtension(taskId, GatherUsedImportedElementsTask.DESCRIPTOR); |
| 113 registerExtension(taskId, GatherUsedLocalElementsTask.DESCRIPTOR); |
| 114 registerExtension(taskId, GenerateHintsTask.DESCRIPTOR); |
| 115 registerExtension(taskId, InferStaticVariableTypesInUnitTask.DESCRIPTOR); |
| 116 registerExtension(taskId, InferStaticVariableTypeTask.DESCRIPTOR); |
| 117 registerExtension(taskId, LibraryErrorsReadyTask.DESCRIPTOR); |
| 118 registerExtension(taskId, LibraryUnitErrorsTask.DESCRIPTOR); |
| 119 registerExtension(taskId, ParseDartTask.DESCRIPTOR); |
| 120 registerExtension(taskId, PartiallyResolveUnitReferencesTask.DESCRIPTOR); |
| 121 registerExtension(taskId, ResolveLibraryReferencesTask.DESCRIPTOR); |
| 122 registerExtension(taskId, ResolveLibraryTypeNamesTask.DESCRIPTOR); |
| 123 registerExtension(taskId, ResolveUnitReferencesTask.DESCRIPTOR); |
| 124 registerExtension(taskId, ResolveUnitTypeNamesTask.DESCRIPTOR); |
| 125 registerExtension(taskId, ResolveVariableReferencesTask.DESCRIPTOR); |
| 126 registerExtension(taskId, ScanDartTask.DESCRIPTOR); |
| 127 registerExtension(taskId, VerifyUnitTask.DESCRIPTOR); |
| 128 // |
| 129 // Register HTML tasks. |
| 130 // |
| 131 registerExtension(taskId, DartScriptsTask.DESCRIPTOR); |
| 132 registerExtension(taskId, HtmlErrorsTask.DESCRIPTOR); |
| 133 registerExtension(taskId, ParseHtmlTask.DESCRIPTOR); |
| 134 } |
| 135 |
| 136 void _registerWorkManagerFactoryExtensions( |
| 137 RegisterExtension registerExtension) { |
| 138 String taskId = WORK_MANAGER_EXTENSION_POINT_ID; |
| 139 registerExtension(taskId, |
| 140 (InternalAnalysisContext context) => new DartWorkManager(context)); |
| 141 registerExtension(taskId, |
| 142 (InternalAnalysisContext context) => new HtmlWorkManager(context)); |
| 143 } |
| 144 |
| 145 /** |
| 146 * Validate the given extension by throwing an [ExtensionError] if it is not a |
| 147 * valid domain. |
| 148 */ |
| 149 void _validateTaskExtension(Object extension) { |
| 150 if (extension is! TaskDescriptor) { |
| 151 String id = taskExtensionPoint.uniqueIdentifier; |
| 152 throw new ExtensionError('Extensions to $id must be a TaskDescriptor'); |
| 153 } |
| 154 } |
| 155 |
| 156 /** |
| 157 * Validate the given extension by throwing an [ExtensionError] if it is not a |
| 158 * valid domain. |
| 159 */ |
| 160 void _validateWorkManagerFactoryExtension(Object extension) { |
| 161 if (extension is! WorkManagerFactory) { |
| 162 String id = taskExtensionPoint.uniqueIdentifier; |
| 163 throw new ExtensionError( |
| 164 'Extensions to $id must be a WorkManagerFactory'); |
| 165 } |
| 166 } |
| 167 } |
OLD | NEW |