Chromium Code Reviews| Index: pkg/analysis_server/lib/src/plugin/plugin_impl.dart |
| diff --git a/pkg/analysis_server/lib/src/plugin/plugin_impl.dart b/pkg/analysis_server/lib/src/plugin/plugin_impl.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b4affcf5ee3d6d3f198067abab8f1dc45ebf7183 |
| --- /dev/null |
| +++ b/pkg/analysis_server/lib/src/plugin/plugin_impl.dart |
| @@ -0,0 +1,124 @@ |
| +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library analysis_server.src.plugin.plugin_impl; |
| + |
| +import 'dart:collection'; |
| + |
| +import 'package:analysis_server/plugin/plugin.dart'; |
| + |
| +/** |
| + * An object that manages the extension points for a single instance of the |
| + * analysis server. |
| + */ |
| +class ExtensionManager { |
| + /** |
| + * A table mapping the id's of extension points to the corresponding |
| + * extension points. |
| + */ |
| + Map<String, ExtensionPointImpl> extensionPoints = |
| + new HashMap<String, ExtensionPointImpl>(); |
| + |
| + /** |
| + * Process each of the given [plugins] by allowing them to register extension |
| + * points and extensions. |
| + * |
| + * An [ExtensionError] will be thrown if any of the plugins throws such an |
| + * exception while registering with this manager. |
| + */ |
| + void processPlugins(List<Plugin> plugins) { |
| + for (Plugin plugin in plugins) { |
|
danrubel
2015/01/08 19:46:37
Do we want to validate that none of the plugins in
Brian Wilkerson
2015/01/08 22:00:54
Good question. I'm tempted to check at the point a
|
| + plugin.registerExtensionPoints( |
| + (String identifier, [ExtensionValidator validator]) { |
| + registerExtensionPoint(plugin, identifier, validator); |
| + }); |
| + } |
| + for (Plugin plugin in plugins) { |
| + plugin.registerExtensions(registerExtension); |
| + } |
| + } |
| + |
| + /** |
| + * Register an [extension] to the extension point with the given unique |
| + * [identifier]. |
| + */ |
| + void registerExtension(String identifier, Object extension) { |
| + ExtensionPointImpl extensionPoint = extensionPoints[identifier]; |
| + if (extensionPoint == null) { |
| + throw new ExtensionError( |
| + 'There is no extension point with the id "$identifier"'); |
| + } |
| + extensionPoint.add(extension); |
| + } |
| + |
| + /** |
| + * Register an extension point being defined by the given [plugin] with the |
| + * given simple [identifier] and [validator]. |
| + */ |
| + ExtensionPoint registerExtensionPoint(Plugin plugin, String identifier, |
| + ExtensionValidator validator) { |
| + String uniqueIdentifier = Plugin.buildUniqueIdentifier(plugin, identifier); |
| + if (extensionPoints.containsKey(uniqueIdentifier)) { |
| + throw new ExtensionError( |
| + 'There is already an extension point with the id "$identifier"'); |
| + } |
| + ExtensionPointImpl extensionPoint = |
| + new ExtensionPointImpl(plugin, identifier, validator); |
| + extensionPoints[uniqueIdentifier] = extensionPoint; |
| + return extensionPoint; |
| + } |
| +} |
| + |
| +/** |
| + * A concrete representation of an extension point. |
| + */ |
| +class ExtensionPointImpl implements ExtensionPoint { |
| + @override |
| + final Plugin plugin; |
| + |
| + @override |
| + final String simpleIdentifier; |
| + |
| + /** |
| + * The validator used to validate extensions to this extension point. |
| + */ |
| + final ExtensionValidator validator; |
| + |
| + /** |
| + * The list of extensions to this extension point. |
| + */ |
| + final List<Object> _extensions = <Object>[]; |
| + |
| + /** |
| + * Initialize a newly create extension point to belong to the given [plugin] |
| + * and have the given [simpleIdentifier]. If the [validator] is non-`null` it |
| + * will be used to validate extensions associated with this extension point. |
| + */ |
| + ExtensionPointImpl(this.plugin, this.simpleIdentifier, this.validator); |
| + |
| + /** |
| + * Return a list containing all of the extensions that have been registered |
| + * for this extension point. |
| + */ |
| + List<Object> get extensions => new UnmodifiableListView(_extensions); |
| + |
| + /** |
| + * Return the identifier used to uniquely identify this extension point. The |
| + * unique identifier is the identifier for the plugin, followed by a period |
| + * (`.`), followed by the [simpleIdentifier] for the extension point. |
| + */ |
| + String get uniqueIdentifier => |
| + Plugin.buildUniqueIdentifier(plugin, simpleIdentifier); |
| + |
| + /** |
| + * Validate that the given [extension] is appropriate for this extension |
| + * point, and if it is then add it to the list of registered exceptions. |
| + */ |
| + void add(Object extension) { |
| + if (validator != null) { |
| + validator(extension); |
| + } |
| + _extensions.add(extension); |
| + } |
| +} |