| 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 |
| 38 /** | 37 /** |
| 39 * An exception indicating that an error occurred while attempting to register | 38 * An exception indicating that an error occurred while attempting to register |
| 40 * either an extension or an extension point. | 39 * either an extension or an extension point. |
| 41 * | 40 * |
| 42 * Clients are not expected to subtype this class. | 41 * Clients may not extend, implement or mix-in this class. |
| 43 */ | 42 */ |
| 44 class ExtensionError implements Exception { | 43 class ExtensionError implements Exception { |
| 45 /** | 44 /** |
| 46 * The message describing the error that occurred. | 45 * The message describing the error that occurred. |
| 47 */ | 46 */ |
| 48 final String message; | 47 final String message; |
| 49 | 48 |
| 50 /** | 49 /** |
| 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 are not expected to subtype 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 */ |
| 77 String get simpleIdentifier; | 84 String get simpleIdentifier; |
| 78 | 85 |
| 79 /** | 86 /** |
| 80 * Return the identifier used to uniquely identify this extension point. The | 87 * Return the identifier used to uniquely identify this extension point. The |
| 81 * unique identifier is the identifier for the plugin, followed by a period | 88 * unique identifier is the identifier for the plugin, followed by a period |
| 82 * (`.`), followed by the [simpleIdentifier] for the extension point. | 89 * (`.`), followed by the [simpleIdentifier] for the extension point. |
| 83 */ | 90 */ |
| 84 String get uniqueIdentifier; | 91 String get uniqueIdentifier; |
| 85 } | 92 } |
| 86 | 93 |
| 87 /** | 94 /** |
| 88 * A contribution to the host application that can extend the behavior of the | 95 * A contribution to the host application that can extend the behavior of the |
| 89 * application while also allowing other plugins to extend it's behavior. | 96 * application while also allowing other plugins to extend it's behavior. |
| 90 * | 97 * |
| 91 * Clients are expected to subtype this class when implementing plugins. | 98 * Clients may implement this class when implementing plugins. |
| 92 */ | 99 */ |
| 93 abstract class Plugin { | 100 abstract class Plugin { |
| 94 /** | 101 /** |
| 95 * Return the identifier used to uniquely identify this plugin. | 102 * Return the identifier used to uniquely identify this plugin. |
| 96 */ | 103 */ |
| 97 String get uniqueIdentifier; | 104 String get uniqueIdentifier; |
| 98 | 105 |
| 99 /** | 106 /** |
| 100 * Use the [register] function to register all of the extension points | 107 * Use the [register] function to register all of the extension points |
| 101 * contributed by this plugin. | 108 * contributed by this plugin. |
| (...skipping 19 matching lines...) Expand all 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 |