| 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/plugin/analysis/analysis_domain.dart'; | 7 import 'package:analysis_server/plugin/analysis/analysis_domain.dart'; |
| 8 import 'package:analysis_server/plugin/analysis/analyzed_files.dart'; | 8 import 'package:analysis_server/plugin/analysis/analyzed_files.dart'; |
| 9 import 'package:analysis_server/plugin/analysis/navigation/navigation.dart'; | 9 import 'package:analysis_server/plugin/analysis/navigation/navigation.dart'; |
| 10 import 'package:analysis_server/plugin/analysis/navigation/navigation_core.dart'
; | 10 import 'package:analysis_server/plugin/analysis/navigation/navigation_core.dart'
; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 102 |
| 103 /** | 103 /** |
| 104 * The unique identifier of this plugin. | 104 * The unique identifier of this plugin. |
| 105 */ | 105 */ |
| 106 static const String UNIQUE_IDENTIFIER = 'analysis_server.core'; | 106 static const String UNIQUE_IDENTIFIER = 'analysis_server.core'; |
| 107 | 107 |
| 108 /** | 108 /** |
| 109 * The extension point that allows plugins to register file patterns that will | 109 * The extension point that allows plugins to register file patterns that will |
| 110 * cause files to be analyzed. | 110 * cause files to be analyzed. |
| 111 */ | 111 */ |
| 112 ExtensionPoint analyzedFilePatternsExtensionPoint; | 112 ExtensionPoint<List<String>> analyzedFilePatternsExtensionPoint; |
| 113 | 113 |
| 114 /** | 114 /** |
| 115 * The extension point that allows plugins to register assist contributors. | 115 * The extension point that allows plugins to register assist contributors. |
| 116 */ | 116 */ |
| 117 ExtensionPoint assistContributorExtensionPoint; | 117 ExtensionPoint<AssistContributor> assistContributorExtensionPoint; |
| 118 | 118 |
| 119 /** | 119 /** |
| 120 * The extension point that allows plugins to register completion | 120 * The extension point that allows plugins to register completion |
| 121 * contributors. | 121 * contributors. |
| 122 */ | 122 */ |
| 123 ExtensionPoint completionContributorExtensionPoint; | 123 ExtensionPoint<CompletionContributorFactory> |
| 124 completionContributorExtensionPoint; |
| 124 | 125 |
| 125 /** | 126 /** |
| 126 * The extension point that allows plugins to register domains with the | 127 * The extension point that allows plugins to register domains with the |
| 127 * server. | 128 * server. |
| 128 */ | 129 */ |
| 129 ExtensionPoint domainExtensionPoint; | 130 ExtensionPoint<RequestHandlerFactory> domainExtensionPoint; |
| 130 | 131 |
| 131 /** | 132 /** |
| 132 * The extension point that allows plugins to register fix contributors with | 133 * The extension point that allows plugins to register fix contributors with |
| 133 * the server. | 134 * the server. |
| 134 */ | 135 */ |
| 135 ExtensionPoint fixContributorExtensionPoint; | 136 ExtensionPoint<FixContributor> fixContributorExtensionPoint; |
| 136 | 137 |
| 137 /** | 138 /** |
| 138 * The extension point that allows plugins to register navigation | 139 * The extension point that allows plugins to register navigation |
| 139 * contributors. | 140 * contributors. |
| 140 */ | 141 */ |
| 141 ExtensionPoint navigationContributorExtensionPoint; | 142 ExtensionPoint<NavigationContributor> navigationContributorExtensionPoint; |
| 142 | 143 |
| 143 /** | 144 /** |
| 144 * The extension point that allows plugins to register occurrences | 145 * The extension point that allows plugins to register occurrences |
| 145 * contributors. | 146 * contributors. |
| 146 */ | 147 */ |
| 147 ExtensionPoint occurrencesContributorExtensionPoint; | 148 ExtensionPoint<OccurrencesContributor> occurrencesContributorExtensionPoint; |
| 148 | 149 |
| 149 /** | 150 /** |
| 150 * The extension point that allows plugins to get access to the `analysis` | 151 * The extension point that allows plugins to get access to the `analysis` |
| 151 * domain. | 152 * domain. |
| 152 */ | 153 */ |
| 153 ExtensionPoint setAnalysisDomainExtensionPoint; | 154 ExtensionPoint<SetAnalysisDomain> setAnalysisDomainExtensionPoint; |
| 154 | 155 |
| 155 /** | 156 /** |
| 156 * Initialize a newly created plugin. | 157 * Initialize a newly created plugin. |
| 157 */ | 158 */ |
| 158 ServerPlugin(); | 159 ServerPlugin(); |
| 159 | 160 |
| 160 /** | 161 /** |
| 161 * Return a list containing all of the file patterns that can cause files to | 162 * Return a list containing all of the file patterns that can cause files to |
| 162 * be analyzed. | 163 * be analyzed. |
| 163 */ | 164 */ |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 if (domainExtensionPoint == null) { | 224 if (domainExtensionPoint == null) { |
| 224 return <RequestHandler>[]; | 225 return <RequestHandler>[]; |
| 225 } | 226 } |
| 226 return domainExtensionPoint.extensions | 227 return domainExtensionPoint.extensions |
| 227 .map((RequestHandlerFactory factory) => factory(server)) | 228 .map((RequestHandlerFactory factory) => factory(server)) |
| 228 .toList(); | 229 .toList(); |
| 229 } | 230 } |
| 230 | 231 |
| 231 @override | 232 @override |
| 232 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { | 233 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { |
| 233 setAnalysisDomainExtensionPoint = registerExtensionPoint( | 234 analyzedFilePatternsExtensionPoint = new ExtensionPoint<List<String>>( |
| 234 SET_ANALISYS_DOMAIN_EXTENSION_POINT, | 235 this, ANALYZED_FILE_PATTERNS_EXTENSION_POINT, null); |
| 235 _validateSetAnalysisDomainFunction); | 236 registerExtensionPoint(analyzedFilePatternsExtensionPoint); |
| 236 analyzedFilePatternsExtensionPoint = registerExtensionPoint( | 237 assistContributorExtensionPoint = new ExtensionPoint<AssistContributor>( |
| 237 ANALYZED_FILE_PATTERNS_EXTENSION_POINT, | 238 this, ASSIST_CONTRIBUTOR_EXTENSION_POINT, null); |
| 238 _validateAnalyzedFilePatternsExtension); | 239 registerExtensionPoint(assistContributorExtensionPoint); |
| 239 assistContributorExtensionPoint = registerExtensionPoint( | 240 completionContributorExtensionPoint = |
| 240 ASSIST_CONTRIBUTOR_EXTENSION_POINT, | 241 new ExtensionPoint<CompletionContributorFactory>( |
| 241 _validateAssistContributorExtension); | 242 this, COMPLETION_CONTRIBUTOR_EXTENSION_POINT, null); |
| 242 completionContributorExtensionPoint = registerExtensionPoint( | 243 registerExtensionPoint(completionContributorExtensionPoint); |
| 243 COMPLETION_CONTRIBUTOR_EXTENSION_POINT, | 244 domainExtensionPoint = new ExtensionPoint<RequestHandlerFactory>( |
| 244 _validateCompletionContributorExtension); | 245 this, DOMAIN_EXTENSION_POINT, null); |
| 245 domainExtensionPoint = registerExtensionPoint( | 246 registerExtensionPoint(domainExtensionPoint); |
| 246 DOMAIN_EXTENSION_POINT, _validateDomainExtension); | 247 fixContributorExtensionPoint = new ExtensionPoint<FixContributor>( |
| 247 fixContributorExtensionPoint = registerExtensionPoint( | 248 this, FIX_CONTRIBUTOR_EXTENSION_POINT, null); |
| 248 FIX_CONTRIBUTOR_EXTENSION_POINT, _validateFixContributorExtension); | 249 registerExtensionPoint(fixContributorExtensionPoint); |
| 249 navigationContributorExtensionPoint = registerExtensionPoint( | 250 navigationContributorExtensionPoint = |
| 250 NAVIGATION_CONTRIBUTOR_EXTENSION_POINT, | 251 new ExtensionPoint<NavigationContributor>( |
| 251 _validateNavigationContributorExtension); | 252 this, NAVIGATION_CONTRIBUTOR_EXTENSION_POINT, null); |
| 252 occurrencesContributorExtensionPoint = registerExtensionPoint( | 253 registerExtensionPoint(navigationContributorExtensionPoint); |
| 253 OCCURRENCES_CONTRIBUTOR_EXTENSION_POINT, | 254 occurrencesContributorExtensionPoint = |
| 254 _validateOccurrencesContributorExtension); | 255 new ExtensionPoint<OccurrencesContributor>( |
| 256 this, OCCURRENCES_CONTRIBUTOR_EXTENSION_POINT, null); |
| 257 registerExtensionPoint(occurrencesContributorExtensionPoint); |
| 258 setAnalysisDomainExtensionPoint = new ExtensionPoint<SetAnalysisDomain>( |
| 259 this, SET_ANALISYS_DOMAIN_EXTENSION_POINT, null); |
| 260 registerExtensionPoint(setAnalysisDomainExtensionPoint); |
| 255 } | 261 } |
| 256 | 262 |
| 257 @override | 263 @override |
| 258 void registerExtensions(RegisterExtension registerExtension) { | 264 void registerExtensions(RegisterExtension registerExtension) { |
| 259 // | 265 // |
| 260 // Register analyzed file patterns. | 266 // Register analyzed file patterns. |
| 261 // | 267 // |
| 262 List<String> patterns = <String>[ | 268 List<String> patterns = <String>[ |
| 263 '**/*.${AnalysisEngine.SUFFIX_DART}', | 269 '**/*.${AnalysisEngine.SUFFIX_DART}', |
| 264 '**/*.${AnalysisEngine.SUFFIX_HTML}', | 270 '**/*.${AnalysisEngine.SUFFIX_HTML}', |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 registerExtension(domainId, | 306 registerExtension(domainId, |
| 301 (AnalysisServer server) => new ExecutionDomainHandler(server)); | 307 (AnalysisServer server) => new ExecutionDomainHandler(server)); |
| 302 registerExtension(domainId, | 308 registerExtension(domainId, |
| 303 (AnalysisServer server) => new DiagnosticDomainHandler(server)); | 309 (AnalysisServer server) => new DiagnosticDomainHandler(server)); |
| 304 // | 310 // |
| 305 // Register fix contributors. | 311 // Register fix contributors. |
| 306 // | 312 // |
| 307 registerExtension( | 313 registerExtension( |
| 308 FIX_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultFixContributor()); | 314 FIX_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultFixContributor()); |
| 309 } | 315 } |
| 310 | |
| 311 /** | |
| 312 * Return `true` if the list being used as an [extension] contains any | |
| 313 * elements that are not strings. | |
| 314 */ | |
| 315 bool _containsNonString(List extension) { | |
| 316 for (Object element in extension) { | |
| 317 if (element is! String) { | |
| 318 return true; | |
| 319 } | |
| 320 } | |
| 321 return false; | |
| 322 } | |
| 323 | |
| 324 /** | |
| 325 * Validate the given extension by throwing an [ExtensionError] if it is not a | |
| 326 * valid list of analyzed file patterns. | |
| 327 */ | |
| 328 void _validateAnalyzedFilePatternsExtension(Object extension) { | |
| 329 if (extension is! List || _containsNonString(extension)) { | |
| 330 String id = analyzedFilePatternsExtensionPoint.uniqueIdentifier; | |
| 331 throw new ExtensionError('Extensions to $id must be a List of Strings'); | |
| 332 } | |
| 333 } | |
| 334 | |
| 335 /** | |
| 336 * Validate the given extension by throwing an [ExtensionError] if it is not a | |
| 337 * valid assist contributor. | |
| 338 */ | |
| 339 void _validateAssistContributorExtension(Object extension) { | |
| 340 if (extension is! AssistContributor) { | |
| 341 String id = assistContributorExtensionPoint.uniqueIdentifier; | |
| 342 throw new ExtensionError( | |
| 343 'Extensions to $id must be an AssistContributor'); | |
| 344 } | |
| 345 } | |
| 346 | |
| 347 /** | |
| 348 * Validate the given extension by throwing an [ExtensionError] if it is not a | |
| 349 * valid completion contributor. | |
| 350 */ | |
| 351 void _validateCompletionContributorExtension(Object extension) { | |
| 352 if (extension is! CompletionContributorFactory) { | |
| 353 String id = completionContributorExtensionPoint.uniqueIdentifier; | |
| 354 throw new ExtensionError( | |
| 355 'Extensions to $id must be an CompletionContributorFactory'); | |
| 356 } | |
| 357 } | |
| 358 | |
| 359 /** | |
| 360 * Validate the given extension by throwing an [ExtensionError] if it is not a | |
| 361 * valid domain. | |
| 362 */ | |
| 363 void _validateDomainExtension(Object extension) { | |
| 364 if (extension is! RequestHandlerFactory) { | |
| 365 String id = domainExtensionPoint.uniqueIdentifier; | |
| 366 throw new ExtensionError( | |
| 367 'Extensions to $id must be a RequestHandlerFactory'); | |
| 368 } | |
| 369 } | |
| 370 | |
| 371 /** | |
| 372 * Validate the given extension by throwing an [ExtensionError] if it is not a | |
| 373 * valid fix contributor. | |
| 374 */ | |
| 375 void _validateFixContributorExtension(Object extension) { | |
| 376 if (extension is! FixContributor) { | |
| 377 String id = fixContributorExtensionPoint.uniqueIdentifier; | |
| 378 throw new ExtensionError('Extensions to $id must be a FixContributor'); | |
| 379 } | |
| 380 } | |
| 381 | |
| 382 /** | |
| 383 * Validate the given extension by throwing an [ExtensionError] if it is not a | |
| 384 * valid navigation contributor. | |
| 385 */ | |
| 386 void _validateNavigationContributorExtension(Object extension) { | |
| 387 if (extension is! NavigationContributor) { | |
| 388 String id = navigationContributorExtensionPoint.uniqueIdentifier; | |
| 389 throw new ExtensionError( | |
| 390 'Extensions to $id must be an NavigationContributor'); | |
| 391 } | |
| 392 } | |
| 393 | |
| 394 /** | |
| 395 * Validate the given extension by throwing an [ExtensionError] if it is not a | |
| 396 * valid occurrences contributor. | |
| 397 */ | |
| 398 void _validateOccurrencesContributorExtension(Object extension) { | |
| 399 if (extension is! OccurrencesContributor) { | |
| 400 String id = occurrencesContributorExtensionPoint.uniqueIdentifier; | |
| 401 throw new ExtensionError( | |
| 402 'Extensions to $id must be an OccurrencesContributor'); | |
| 403 } | |
| 404 } | |
| 405 | |
| 406 /** | |
| 407 * Validate the given extension by throwing an [ExtensionError] if it is not a | |
| 408 * valid analysis domain receiver. | |
| 409 */ | |
| 410 void _validateSetAnalysisDomainFunction(Object extension) { | |
| 411 if (extension is! SetAnalysisDomain) { | |
| 412 String id = setAnalysisDomainExtensionPoint.uniqueIdentifier; | |
| 413 throw new ExtensionError( | |
| 414 'Extensions to $id must be a SetAnalysisDomain function'); | |
| 415 } | |
| 416 } | |
| 417 } | 316 } |
| OLD | NEW |