| 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 plugin; | 5 library plugin; |
| 6 | 6 |
| 7 import 'package:plugin/src/plugin_impl.dart'; |
| 8 |
| 7 /** | 9 /** |
| 8 * A function used to register the given [extension] to the extension point with | 10 * A function used to register the given [extension] to the extension point with |
| 9 * the given unique [identifier]. | 11 * the given unique [identifier]. |
| 10 * | 12 * |
| 11 * An [ExtensionError] will be thrown if the [extension] is not appropriate | 13 * An [ExtensionError] will be thrown if the [extension] is not appropriate |
| 12 * for the extension point, such as an [extension] that does not implement the | 14 * for the extension point, such as an [extension] that does not implement the |
| 13 * required interface. | 15 * required interface. |
| 14 */ | 16 */ |
| 15 typedef void RegisterExtension(String identifier, Object extension); | 17 typedef void RegisterExtension(String identifier, Object extension); |
| 16 | 18 |
| 17 /** | 19 /** |
| 18 * A function used to register an extension point with the given simple | 20 * A function used to register the given [extensionPoint]. |
| 19 * [identifier]. If given, the [validator] will be used to validate extensions | |
| 20 * to the extension point. | |
| 21 * | 21 * |
| 22 * An [ExtensionError] will be thrown if the extension point cannot be | 22 * An [ExtensionError] will be thrown if the extension point cannot be |
| 23 * registered, such as when a plugin attempts to define two extension points | 23 * registered, such as when a plugin attempts to define two extension points |
| 24 * with the same simple identifier. | 24 * with the same identifier. |
| 25 */ | 25 */ |
| 26 typedef ExtensionPoint RegisterExtensionPoint(String identifier, | 26 typedef void RegisterExtensionPoint(ExtensionPoint extensionPoint); |
| 27 [ValidateExtension validateExtension]); | |
| 28 | 27 |
| 29 /** | 28 /** |
| 30 * A function used by a plugin to validate an [extension] to a extension point. | 29 * A function used by a plugin to validate an [extension] to a extension point. |
| 31 * | 30 * |
| 32 * An [ExtensionError] should be thrown if the [extension] is not valid for the | 31 * An [ExtensionError] should be thrown if the [extension] is not valid for the |
| 33 * extension point, such as an [extension] that does not implement the required | 32 * extension point, such as an [extension] that does not implement the required |
| 34 * interface. | 33 * interface. |
| 35 */ | 34 */ |
| 36 typedef void ValidateExtension(Object extension); | 35 typedef void ValidateExtension(Object extension); |
| 37 | 36 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 51 * Initialize a newly created error to have the given message. | 50 * Initialize a newly created error to have the given message. |
| 52 */ | 51 */ |
| 53 ExtensionError(this.message); | 52 ExtensionError(this.message); |
| 54 } | 53 } |
| 55 | 54 |
| 56 /** | 55 /** |
| 57 * A representation of an extension point. | 56 * A representation of an extension point. |
| 58 * | 57 * |
| 59 * Clients may not extend, implement or mix-in this class. | 58 * Clients may not extend, implement or mix-in this class. |
| 60 */ | 59 */ |
| 61 abstract class ExtensionPoint { | 60 abstract class ExtensionPoint<E> { |
| 61 /** |
| 62 * Initialize a newly created extension point to be defined by the given |
| 63 * [plugin] with the given [simpleIdentifier]. The [validateExtension] |
| 64 * function will be used to validate extensions for this extension point. |
| 65 */ |
| 66 factory ExtensionPoint(Plugin plugin, String simpleIdentifier, |
| 67 ValidateExtension validateExtension) = ExtensionPointImpl<E>; |
| 68 |
| 62 /** | 69 /** |
| 63 * Return an immutable list containing all of the extensions that were | 70 * Return an immutable list containing all of the extensions that were |
| 64 * registered for this extension point. | 71 * registered for this extension point. |
| 65 */ | 72 */ |
| 66 List<Object> get extensions; | 73 List<E> get extensions; |
| 67 | 74 |
| 68 /** | 75 /** |
| 69 * Return the plugin that defined this extension point. | 76 * Return the plugin that defined this extension point. |
| 70 */ | 77 */ |
| 71 Plugin get plugin; | 78 Plugin get plugin; |
| 72 | 79 |
| 73 /** | 80 /** |
| 74 * Return the identifier used to uniquely identify this extension point within | 81 * Return the identifier used to uniquely identify this extension point within |
| 75 * the defining plugin. | 82 * the defining plugin. |
| 76 */ | 83 */ |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 static String buildUniqueIdentifier(Plugin plugin, String simpleIdentifier) => | 128 static String buildUniqueIdentifier(Plugin plugin, String simpleIdentifier) => |
| 122 join(plugin.uniqueIdentifier, simpleIdentifier); | 129 join(plugin.uniqueIdentifier, simpleIdentifier); |
| 123 | 130 |
| 124 /** | 131 /** |
| 125 * Return an identifier created by joining the [pluginIdentifier] and the | 132 * Return an identifier created by joining the [pluginIdentifier] and the |
| 126 * [simpleIdentifier]. | 133 * [simpleIdentifier]. |
| 127 */ | 134 */ |
| 128 static String join(String pluginIdentifier, String simpleIdentifier) => | 135 static String join(String pluginIdentifier, String simpleIdentifier) => |
| 129 '$pluginIdentifier.$simpleIdentifier'; | 136 '$pluginIdentifier.$simpleIdentifier'; |
| 130 } | 137 } |
| OLD | NEW |