| 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 analysis_server.src.plugin.server_plugin; | 5 library analysis_server.src.plugin.server_plugin; |
| 6 | 6 |
| 7 import 'package:analysis_server/edit/fix/fix_core.dart'; |
| 8 import 'package:analysis_server/plugin/fix.dart'; |
| 7 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
| 8 import 'package:analysis_server/src/domain_analysis.dart'; | 10 import 'package:analysis_server/src/domain_analysis.dart'; |
| 9 import 'package:analysis_server/src/domain_completion.dart'; | 11 import 'package:analysis_server/src/domain_completion.dart'; |
| 10 import 'package:analysis_server/src/domain_execution.dart'; | 12 import 'package:analysis_server/src/domain_execution.dart'; |
| 11 import 'package:analysis_server/src/domain_server.dart'; | 13 import 'package:analysis_server/src/domain_server.dart'; |
| 12 import 'package:analysis_server/src/edit/edit_domain.dart'; | 14 import 'package:analysis_server/src/edit/edit_domain.dart'; |
| 13 import 'package:analysis_server/src/protocol.dart'; | 15 import 'package:analysis_server/src/protocol.dart'; |
| 14 import 'package:analysis_server/src/search/search_domain.dart'; | 16 import 'package:analysis_server/src/search/search_domain.dart'; |
| 17 import 'package:analysis_server/src/services/correction/fix_internal.dart'; |
| 15 import 'package:analyzer/plugin/plugin.dart'; | 18 import 'package:analyzer/plugin/plugin.dart'; |
| 16 | 19 |
| 17 /** | 20 /** |
| 18 * A function that will create a request handler that can be used by the given | 21 * A function that will create a request handler that can be used by the given |
| 19 * [server]. | 22 * [server]. |
| 20 */ | 23 */ |
| 21 typedef RequestHandler RequestHandlerFactory(AnalysisServer server); | 24 typedef RequestHandler RequestHandlerFactory(AnalysisServer server); |
| 22 | 25 |
| 23 /** | 26 /** |
| 24 * A plugin that defines the extension points and extensions that are inherently | 27 * A plugin that defines the extension points and extensions that are inherently |
| 25 * defined by the analysis server. | 28 * defined by the analysis server. |
| 26 */ | 29 */ |
| 27 class ServerPlugin implements Plugin { | 30 class ServerPlugin implements Plugin { |
| 28 /** | 31 /** |
| 29 * The simple identifier of the extension point that allows plugins to | 32 * The simple identifier of the extension point that allows plugins to |
| 30 * register new domains with the server. | 33 * register new domains with the server. |
| 31 */ | 34 */ |
| 32 static const String DOMAIN_EXTENSION_POINT = 'domain'; | 35 static const String DOMAIN_EXTENSION_POINT = 'domain'; |
| 33 | 36 |
| 34 /** | 37 /** |
| 38 * The simple identifier of the extension point that allows plugins to |
| 39 * register new fix contributors with the server. |
| 40 */ |
| 41 static const String FIX_CONTRIBUTOR_EXTENSION_POINT = 'fixContributor'; |
| 42 |
| 43 /** |
| 35 * The unique identifier of this plugin. | 44 * The unique identifier of this plugin. |
| 36 */ | 45 */ |
| 37 static const String UNIQUE_IDENTIFIER = 'analysis_server.core'; | 46 static const String UNIQUE_IDENTIFIER = 'analysis_server.core'; |
| 38 | 47 |
| 39 /** | 48 /** |
| 40 * The extension point that allows plugins to register new domains with the | 49 * The extension point that allows plugins to register new domains with the |
| 41 * server. | 50 * server. |
| 42 */ | 51 */ |
| 43 ExtensionPoint domainExtensionPoint; | 52 ExtensionPoint domainExtensionPoint; |
| 44 | 53 |
| 45 /** | 54 /** |
| 55 * The extension point that allows plugins to register new fix contributors |
| 56 * with the server. |
| 57 */ |
| 58 ExtensionPoint fixContributorExtensionPoint; |
| 59 |
| 60 /** |
| 46 * Initialize a newly created plugin. | 61 * Initialize a newly created plugin. |
| 47 */ | 62 */ |
| 48 ServerPlugin(); | 63 ServerPlugin(); |
| 49 | 64 |
| 50 @override | 65 @override |
| 51 String get uniqueIdentifier => UNIQUE_IDENTIFIER; | 66 String get uniqueIdentifier => UNIQUE_IDENTIFIER; |
| 52 | 67 |
| 53 /** | 68 /** |
| 54 * Use the given [server] to create all of the domains ([RequestHandler]'s) | 69 * Use the given [server] to create all of the domains ([RequestHandler]'s) |
| 55 * that have been registered and return the newly created domains. | 70 * that have been registered and return the newly created domains. |
| 56 */ | 71 */ |
| 57 List<RequestHandler> createDomains(AnalysisServer server) { | 72 List<RequestHandler> createDomains(AnalysisServer server) { |
| 58 if (domainExtensionPoint == null) { | 73 if (domainExtensionPoint == null) { |
| 59 return <RequestHandler>[]; | 74 return <RequestHandler>[]; |
| 60 } | 75 } |
| 61 return domainExtensionPoint.extensions | 76 return domainExtensionPoint.extensions |
| 62 .map((RequestHandlerFactory factory) => factory(server)) | 77 .map((RequestHandlerFactory factory) => factory(server)) |
| 63 .toList(); | 78 .toList(); |
| 64 } | 79 } |
| 65 | 80 |
| 81 /** |
| 82 * Return a list containing all of the fix contributors that were contributed. |
| 83 */ |
| 84 List<FixContributor> fixContributors() { |
| 85 return fixContributorExtensionPoint.extensions; |
| 86 } |
| 87 |
| 66 @override | 88 @override |
| 67 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { | 89 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { |
| 68 domainExtensionPoint = registerExtensionPoint( | 90 domainExtensionPoint = registerExtensionPoint( |
| 69 DOMAIN_EXTENSION_POINT, _validateDomainExtension); | 91 DOMAIN_EXTENSION_POINT, _validateDomainExtension); |
| 92 fixContributorExtensionPoint = registerExtensionPoint( |
| 93 FIX_CONTRIBUTOR_EXTENSION_POINT, _validateFixContributorExtension); |
| 70 } | 94 } |
| 71 | 95 |
| 72 @override | 96 @override |
| 73 void registerExtensions(RegisterExtension registerExtension) { | 97 void registerExtensions(RegisterExtension registerExtension) { |
| 98 // |
| 99 // Register domains. |
| 100 // |
| 74 String domainId = Plugin.join(UNIQUE_IDENTIFIER, DOMAIN_EXTENSION_POINT); | 101 String domainId = Plugin.join(UNIQUE_IDENTIFIER, DOMAIN_EXTENSION_POINT); |
| 75 registerExtension( | 102 registerExtension( |
| 76 domainId, (AnalysisServer server) => new ServerDomainHandler(server)); | 103 domainId, (AnalysisServer server) => new ServerDomainHandler(server)); |
| 77 registerExtension( | 104 registerExtension( |
| 78 domainId, (AnalysisServer server) => new AnalysisDomainHandler(server)); | 105 domainId, (AnalysisServer server) => new AnalysisDomainHandler(server)); |
| 79 registerExtension( | 106 registerExtension(domainId, |
| 80 domainId, (AnalysisServer server) => new EditDomainHandler(server)); | 107 (AnalysisServer server) => new EditDomainHandler(server, this)); |
| 81 registerExtension( | 108 registerExtension( |
| 82 domainId, (AnalysisServer server) => new SearchDomainHandler(server)); | 109 domainId, (AnalysisServer server) => new SearchDomainHandler(server)); |
| 83 registerExtension(domainId, | 110 registerExtension(domainId, |
| 84 (AnalysisServer server) => new CompletionDomainHandler(server)); | 111 (AnalysisServer server) => new CompletionDomainHandler(server)); |
| 85 registerExtension(domainId, | 112 registerExtension(domainId, |
| 86 (AnalysisServer server) => new ExecutionDomainHandler(server)); | 113 (AnalysisServer server) => new ExecutionDomainHandler(server)); |
| 114 // |
| 115 // Register fix contributors. |
| 116 // |
| 117 registerExtension( |
| 118 FIX_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultFixContributor()); |
| 87 } | 119 } |
| 88 | 120 |
| 89 /** | 121 /** |
| 90 * Validate the given extension by throwing an [ExtensionError] if it is not a | 122 * Validate the given extension by throwing an [ExtensionError] if it is not a |
| 91 * valid domain. | 123 * valid domain. |
| 92 */ | 124 */ |
| 93 void _validateDomainExtension(Object extension) { | 125 void _validateDomainExtension(Object extension) { |
| 94 if (extension is! RequestHandlerFactory) { | 126 if (extension is! RequestHandlerFactory) { |
| 95 String id = domainExtensionPoint.uniqueIdentifier; | 127 String id = domainExtensionPoint.uniqueIdentifier; |
| 96 throw new ExtensionError( | 128 throw new ExtensionError( |
| 97 'Extensions to $id must be a RequestHandlerFactory'); | 129 'Extensions to $id must be a RequestHandlerFactory'); |
| 98 } | 130 } |
| 99 } | 131 } |
| 132 |
| 133 /** |
| 134 * Validate the given extension by throwing an [ExtensionError] if it is not a |
| 135 * valid fix contributor. |
| 136 */ |
| 137 void _validateFixContributorExtension(Object extension) { |
| 138 if (extension is! FixContributor) { |
| 139 String id = domainExtensionPoint.uniqueIdentifier; |
| 140 throw new ExtensionError('Extensions to $id must be a FixContributor'); |
| 141 } |
| 142 } |
| 100 } | 143 } |
| OLD | NEW |