Chromium Code Reviews| 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.plugin_impl; | 5 library analysis_server.src.plugin.server_plugin; |
| 6 | 6 |
| 7 import 'package:analysis_server/plugin/plugin.dart'; | 7 import 'package:analysis_server/plugin/plugin.dart'; |
| 8 import 'package:analysis_server/src/analysis_server.dart'; | 8 import 'package:analysis_server/src/analysis_server.dart'; |
| 9 import 'package:analysis_server/src/domain_analysis.dart'; | |
| 10 import 'package:analysis_server/src/domain_completion.dart'; | |
| 11 import 'package:analysis_server/src/domain_execution.dart'; | |
| 9 import 'package:analysis_server/src/domain_server.dart'; | 12 import 'package:analysis_server/src/domain_server.dart'; |
| 13 import 'package:analysis_server/src/edit/edit_domain.dart'; | |
| 10 import 'package:analysis_server/src/protocol.dart'; | 14 import 'package:analysis_server/src/protocol.dart'; |
| 15 import 'package:analysis_server/src/search/search_domain.dart'; | |
| 11 | 16 |
| 12 /** | 17 /** |
| 13 * A function that will create a request handler that can be used by the given | 18 * A function that will create a request handler that can be used by the given |
| 14 * [server]. | 19 * [server]. |
| 15 * | 20 * |
| 16 * TODO(brianwilkerson) Move this into 'protocol.dart'. | 21 * TODO(brianwilkerson) Move this into 'protocol.dart'. |
| 17 */ | 22 */ |
| 18 typedef RequestHandler RequestHandlerFactory(AnalysisServer server); | 23 typedef RequestHandler RequestHandlerFactory(AnalysisServer server); |
| 19 | 24 |
| 20 /** | 25 /** |
| 21 * A plugin that defines the extension points and extensions that are inherently | 26 * A plugin that defines the extension points and extensions that are inherently |
| 22 * defined by the analysis server. | 27 * defined by the analysis server. |
| 23 */ | 28 */ |
| 24 class ServerPlugin implements Plugin { | 29 class ServerPlugin implements Plugin { |
| 25 /** | 30 /** |
| 26 * The simple identifier of the extension point that allows plugins to | 31 * The simple identifier of the extension point that allows plugins to |
| 27 * register new domains with the server. | 32 * register new domains with the server. |
| 28 */ | 33 */ |
| 29 static const String DOMAIN_EXTENSION_POINT = 'domain'; | 34 static const String DOMAIN_EXTENSION_POINT = 'domain'; |
| 30 | 35 |
| 31 /** | 36 /** |
| 32 * The unique identifier of this plugin. | 37 * The unique identifier of this plugin. |
| 33 */ | 38 */ |
| 34 static const String UNIQUE_IDENTIFIER = 'analysis_server.core'; | 39 static const String UNIQUE_IDENTIFIER = 'analysis_server.core'; |
| 35 | 40 |
| 36 /** | 41 /** |
| 42 * The extension point that allows plugins to register new domains with the | |
| 43 * server. | |
| 44 */ | |
| 45 ExtensionPoint domainExtensionPoint; | |
| 46 | |
| 47 /** | |
| 37 * Initialize a newly created plugin. | 48 * Initialize a newly created plugin. |
| 38 */ | 49 */ |
| 39 ServerPlugin(); | 50 ServerPlugin(); |
| 40 | 51 |
| 41 @override | 52 @override |
| 42 String get uniqueIdentifier => UNIQUE_IDENTIFIER; | 53 String get uniqueIdentifier => UNIQUE_IDENTIFIER; |
| 43 | 54 |
| 44 @override | 55 /** |
| 45 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { | 56 * Use the given [server] to create all of the domains ([RequestHandler]'s) |
| 46 registerExtensionPoint( | 57 * that have been registered and return the newly created domains. |
| 47 DOMAIN_EXTENSION_POINT, | 58 */ |
| 48 (Object extension) => extension is RequestHandlerFactory); | 59 List<RequestHandler> createDomains(AnalysisServer server) { |
| 60 if (domainExtensionPoint == null) { | |
| 61 return <RequestHandler>[]; | |
| 62 } | |
| 63 return domainExtensionPoint.extensions.map( | |
| 64 (RequestHandlerFactory factory) => factory(server)).toList(); | |
| 49 } | 65 } |
| 50 | 66 |
| 51 @override | 67 @override |
| 68 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { | |
| 69 domainExtensionPoint = | |
| 70 registerExtensionPoint(DOMAIN_EXTENSION_POINT, _validateDomainExtension) ; | |
| 71 } | |
| 72 | |
| 73 @override | |
| 52 void registerExtensions(RegisterExtension registerExtension) { | 74 void registerExtensions(RegisterExtension registerExtension) { |
| 53 String domainId = Plugin.join(UNIQUE_IDENTIFIER, DOMAIN_EXTENSION_POINT); | 75 String domainId = Plugin.join(UNIQUE_IDENTIFIER, DOMAIN_EXTENSION_POINT); |
| 54 registerExtension( | 76 registerExtension( |
| 55 domainId, | 77 domainId, |
| 56 (AnalysisServer server) => new ServerDomainHandler(server)); | 78 (AnalysisServer server) => new ServerDomainHandler(server)); |
| 57 // TODO(brianwilkerson) Register the other domains. | 79 registerExtension( |
| 80 domainId, | |
| 81 (AnalysisServer server) => new AnalysisDomainHandler(server)); | |
| 82 registerExtension( | |
| 83 domainId, | |
| 84 (AnalysisServer server) => new EditDomainHandler(server)); | |
| 85 registerExtension( | |
| 86 domainId, | |
| 87 (AnalysisServer server) => new SearchDomainHandler(server)); | |
| 88 registerExtension( | |
| 89 domainId, | |
| 90 (AnalysisServer server) => new CompletionDomainHandler(server)); | |
| 91 registerExtension( | |
| 92 domainId, | |
| 93 (AnalysisServer server) => new ExecutionDomainHandler(server)); | |
| 94 } | |
| 95 | |
| 96 /** | |
| 97 * Validate the given extension by throwing an [ExtensionError] if it is not a | |
| 98 * valid domain. | |
| 99 */ | |
| 100 void _validateDomainExtension(Object extension) { | |
| 101 if (extension is! RequestHandlerFactory) { | |
| 102 var id = domainExtensionPoint.uniqueIdentifier; | |
|
scheglov
2015/01/09 21:37:46
String?
Brian Wilkerson
2015/01/09 22:14:52
Done
| |
| 103 throw new ExtensionError( | |
| 104 'Extensions to the $id must be a RequestHandlerFactory'); | |
| 105 } | |
| 58 } | 106 } |
| 59 } | 107 } |
| OLD | NEW |