| 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.plugin_impl; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/plugin.dart'; | 9 import 'package:analysis_server/plugin/plugin.dart'; |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 /** | 23 /** |
| 24 * Process each of the given [plugins] by allowing them to register extension | 24 * Process each of the given [plugins] by allowing them to register extension |
| 25 * points and extensions. | 25 * points and extensions. |
| 26 * | 26 * |
| 27 * An [ExtensionError] will be thrown if any of the plugins throws such an | 27 * An [ExtensionError] will be thrown if any of the plugins throws such an |
| 28 * exception while registering with this manager. | 28 * exception while registering with this manager. |
| 29 */ | 29 */ |
| 30 void processPlugins(List<Plugin> plugins) { | 30 void processPlugins(List<Plugin> plugins) { |
| 31 for (Plugin plugin in plugins) { | 31 for (Plugin plugin in plugins) { |
| 32 plugin.registerExtensionPoints( | 32 plugin.registerExtensionPoints( |
| 33 (String identifier, [ExtensionValidator validator]) => | 33 (String identifier, [ValidateExtension validateExtension]) => |
| 34 registerExtensionPoint(plugin, identifier, validator)); | 34 registerExtensionPoint(plugin, identifier, validateExtension)); |
| 35 } | 35 } |
| 36 for (Plugin plugin in plugins) { | 36 for (Plugin plugin in plugins) { |
| 37 plugin.registerExtensions(registerExtension); | 37 plugin.registerExtensions(registerExtension); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 /** | 41 /** |
| 42 * Register an [extension] to the extension point with the given unique | 42 * Register an [extension] to the extension point with the given unique |
| 43 * [identifier]. | 43 * [identifier]. |
| 44 */ | 44 */ |
| 45 void registerExtension(String identifier, Object extension) { | 45 void registerExtension(String identifier, Object extension) { |
| 46 ExtensionPointImpl extensionPoint = extensionPoints[identifier]; | 46 ExtensionPointImpl extensionPoint = extensionPoints[identifier]; |
| 47 if (extensionPoint == null) { | 47 if (extensionPoint == null) { |
| 48 throw new ExtensionError( | 48 throw new ExtensionError( |
| 49 'There is no extension point with the id "$identifier"'); | 49 'There is no extension point with the id "$identifier"'); |
| 50 } | 50 } |
| 51 extensionPoint.add(extension); | 51 extensionPoint.add(extension); |
| 52 } | 52 } |
| 53 | 53 |
| 54 /** | 54 /** |
| 55 * Register an extension point being defined by the given [plugin] with the | 55 * Register an extension point being defined by the given [plugin] with the |
| 56 * given simple [identifier] and [validator]. | 56 * given simple [identifier] and [validateExtension]. |
| 57 */ | 57 */ |
| 58 ExtensionPoint registerExtensionPoint(Plugin plugin, String identifier, | 58 ExtensionPoint registerExtensionPoint(Plugin plugin, String identifier, |
| 59 ExtensionValidator validator) { | 59 ValidateExtension validateExtension) { |
| 60 String uniqueIdentifier = Plugin.buildUniqueIdentifier(plugin, identifier); | 60 String uniqueIdentifier = Plugin.buildUniqueIdentifier(plugin, identifier); |
| 61 if (extensionPoints.containsKey(uniqueIdentifier)) { | 61 if (extensionPoints.containsKey(uniqueIdentifier)) { |
| 62 throw new ExtensionError( | 62 throw new ExtensionError( |
| 63 'There is already an extension point with the id "$identifier"'); | 63 'There is already an extension point with the id "$identifier"'); |
| 64 } | 64 } |
| 65 ExtensionPointImpl extensionPoint = | 65 ExtensionPointImpl extensionPoint = |
| 66 new ExtensionPointImpl(plugin, identifier, validator); | 66 new ExtensionPointImpl(plugin, identifier, validateExtension); |
| 67 extensionPoints[uniqueIdentifier] = extensionPoint; | 67 extensionPoints[uniqueIdentifier] = extensionPoint; |
| 68 return extensionPoint; | 68 return extensionPoint; |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 /** | 72 /** |
| 73 * A concrete representation of an extension point. | 73 * A concrete representation of an extension point. |
| 74 */ | 74 */ |
| 75 class ExtensionPointImpl implements ExtensionPoint { | 75 class ExtensionPointImpl implements ExtensionPoint { |
| 76 @override | 76 @override |
| 77 final Plugin plugin; | 77 final Plugin plugin; |
| 78 | 78 |
| 79 @override | 79 @override |
| 80 final String simpleIdentifier; | 80 final String simpleIdentifier; |
| 81 | 81 |
| 82 /** | 82 /** |
| 83 * The validator used to validate extensions to this extension point. | 83 * The function used to validate extensions to this extension point. |
| 84 */ | 84 */ |
| 85 final ExtensionValidator validator; | 85 final ValidateExtension validateExtension; |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * The list of extensions to this extension point. | 88 * The list of extensions to this extension point. |
| 89 */ | 89 */ |
| 90 final List<Object> _extensions = <Object>[]; | 90 final List<Object> _extensions = <Object>[]; |
| 91 | 91 |
| 92 /** | 92 /** |
| 93 * Initialize a newly create extension point to belong to the given [plugin] | 93 * Initialize a newly create extension point to belong to the given [plugin] |
| 94 * and have the given [simpleIdentifier]. If the [validator] is non-`null` it | 94 * and have the given [simpleIdentifier]. If [validateExtension] is non-`null` |
| 95 * will be used to validate extensions associated with this extension point. | 95 * it will be used to validate extensions associated with this extension |
| 96 * point. |
| 96 */ | 97 */ |
| 97 ExtensionPointImpl(this.plugin, this.simpleIdentifier, this.validator); | 98 ExtensionPointImpl(this.plugin, this.simpleIdentifier, |
| 99 this.validateExtension); |
| 98 | 100 |
| 99 /** | 101 /** |
| 100 * Return a list containing all of the extensions that have been registered | 102 * Return a list containing all of the extensions that have been registered |
| 101 * for this extension point. | 103 * for this extension point. |
| 102 */ | 104 */ |
| 103 List<Object> get extensions => new UnmodifiableListView(_extensions); | 105 List<Object> get extensions => new UnmodifiableListView(_extensions); |
| 104 | 106 |
| 105 /** | 107 /** |
| 106 * Return the identifier used to uniquely identify this extension point. The | 108 * Return the identifier used to uniquely identify this extension point. The |
| 107 * unique identifier is the identifier for the plugin, followed by a period | 109 * unique identifier is the identifier for the plugin, followed by a period |
| 108 * (`.`), followed by the [simpleIdentifier] for the extension point. | 110 * (`.`), followed by the [simpleIdentifier] for the extension point. |
| 109 */ | 111 */ |
| 110 String get uniqueIdentifier => | 112 String get uniqueIdentifier => |
| 111 Plugin.buildUniqueIdentifier(plugin, simpleIdentifier); | 113 Plugin.buildUniqueIdentifier(plugin, simpleIdentifier); |
| 112 | 114 |
| 113 /** | 115 /** |
| 114 * Validate that the given [extension] is appropriate for this extension | 116 * Validate that the given [extension] is appropriate for this extension |
| 115 * point, and if it is then add it to the list of registered exceptions. | 117 * point, and if it is then add it to the list of registered exceptions. |
| 116 */ | 118 */ |
| 117 void add(Object extension) { | 119 void add(Object extension) { |
| 118 if (validator != null) { | 120 if (validateExtension != null) { |
| 119 validator(extension); | 121 validateExtension(extension); |
| 120 } | 122 } |
| 121 _extensions.add(extension); | 123 _extensions.add(extension); |
| 122 } | 124 } |
| 123 } | 125 } |
| OLD | NEW |