Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: mojo/public/dart/third_party/plugin/lib/src/plugin_impl.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/dart/third_party/plugin/lib/src/plugin_impl.dart
diff --git a/mojo/public/dart/third_party/plugin/lib/src/plugin_impl.dart b/mojo/public/dart/third_party/plugin/lib/src/plugin_impl.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a65a0d3e6c61bc7e8845d84bdc47c933e77da23d
--- /dev/null
+++ b/mojo/public/dart/third_party/plugin/lib/src/plugin_impl.dart
@@ -0,0 +1,119 @@
+// 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 plugin.src.plugin_impl;
+
+import 'dart:collection';
+
+import 'package:plugin/manager.dart';
+import 'package:plugin/plugin.dart';
+
+/**
+ * A concrete implementation of an [ExtensionManager].
+ */
+class ExtensionManagerImpl implements ExtensionManager {
+ /**
+ * A table mapping the id's of extension points to the corresponding
+ * extension points.
+ */
+ Map<String, ExtensionPointImpl> extensionPoints =
+ new HashMap<String, ExtensionPointImpl>();
+
+ @override
+ void processPlugins(List<Plugin> plugins) {
+ for (Plugin plugin in plugins) {
+ plugin.registerExtensionPoints((String identifier,
+ [ValidateExtension validateExtension]) =>
+ registerExtensionPoint(plugin, identifier, validateExtension));
+ }
+ 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 [validateExtension].
+ */
+ ExtensionPoint registerExtensionPoint(
+ Plugin plugin, String identifier, ValidateExtension validateExtension) {
+ 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, validateExtension);
+ 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 function used to validate extensions to this extension point.
+ */
+ final ValidateExtension validateExtension;
+
+ /**
+ * 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 [validateExtension] is non-`null`
+ * it will be used to validate extensions associated with this extension
+ * point.
+ */
+ ExtensionPointImpl(
+ this.plugin, this.simpleIdentifier, this.validateExtension);
+
+ /**
+ * 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 (validateExtension != null) {
+ validateExtension(extension);
+ }
+ _extensions.add(extension);
+ }
+}
« no previous file with comments | « mojo/public/dart/third_party/plugin/lib/plugin.dart ('k') | mojo/public/dart/third_party/plugin/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698