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

Unified Diff: pkg/analysis_server/lib/src/operation/operation.dart

Issue 308003009: Add ServerOperation and queue. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove some priorities Created 6 years, 7 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: pkg/analysis_server/lib/src/operation/operation.dart
diff --git a/pkg/analysis_server/lib/src/operation/operation.dart b/pkg/analysis_server/lib/src/operation/operation.dart
new file mode 100644
index 0000000000000000000000000000000000000000..fcc4d2e404394c765da1801fc314b6d2df1b6daa
--- /dev/null
+++ b/pkg/analysis_server/lib/src/operation/operation.dart
@@ -0,0 +1,99 @@
+// Copyright (c) 2014, 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 operation;
+
+import 'package:analysis_server/src/analysis_server.dart';
+import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
+
+
+/**
+ * The enumeration [ServerOperationPriority] defines the priority levels used
+ * to organize [ServerOperation]s in an optimal order. A smaller ordinal value
+ * equates to a higher priority.
+ */
+class ServerOperationPriority {
+ final int ordinal;
+ final String name;
+
+ static const int COUNT = 7;
+
+ static const ServerOperationPriority ANALYSIS_NOTIFICATION = const ServerOperationPriority._(0, "ANALYSIS_NOTIFICATION");
Paul Berry 2014/06/02 16:04:41 I don't understand why analysis notifications need
Brian Wilkerson 2014/06/02 16:21:01 There are two advantage I can think of. First, if
Paul Berry 2014/06/02 16:29:25 I would understand that if notifications weren't t
Brian Wilkerson 2014/06/02 16:42:33 True, which means that this might not be worthwhil
scheglov 2014/06/02 17:56:59 I will remove separate priorities for notification
Paul Berry 2014/06/02 18:49:32 Shoot, I think we've had some miscommunications.
+ static const ServerOperationPriority ANALYSIS_PRIORITY_CONTINUE = const ServerOperationPriority._(1, "ANALYSIS_PRIORITY_CONTINUE");
+ static const ServerOperationPriority ANALYSIS_PRIORITY = const ServerOperationPriority._(2, "ANALYSIS_PRIORITY");
+ static const ServerOperationPriority ANALYSIS_CONTINUE = const ServerOperationPriority._(3, "ANALYSIS_CONTINUE");
+ static const ServerOperationPriority ANALYSIS = const ServerOperationPriority._(4, "ANALYSIS");
+ static const ServerOperationPriority SEARCH = const ServerOperationPriority._(5, "SEARCH");
+ static const ServerOperationPriority REFACTORING = const ServerOperationPriority._(6, "REFACTORING");
+
+ @override
+ String toString() => name;
+
+ const ServerOperationPriority._(this.ordinal, this.name);
+}
+
+
+/**
+ * The class [ServerOperation] defines the behavior of objects used to perform
+ * operations on a [AnalysisServer].
+ */
+abstract class ServerOperation {
+ /**
+ * Returns the priority of this operation.
+ */
+ ServerOperationPriority get priority;
+
+ /**
+ * Performs the operation implemented by this operation.
+ */
+ void perform(AnalysisServer server);
+}
+
+
+/**
+ * The interface [MergeableOperation] is a [ServerOperation] which can be merged
+ * with (and into) another [ServerOperation].
+ */
+abstract class MergeableOperation extends ServerOperation {
+ /**
+ * Merges the given operation into this one.
+ *
+ * Returns `true` if merge was successful.
+ */
+ bool mergeWith(ServerOperation operation);
+}
+
+
+/**
+ * Instances of [PerformAnalysisOperation] perform a single analysis task.
+ */
+class PerformAnalysisOperation extends ServerOperation {
+ final AnalysisContext _context;
+ final bool _isPriority;
+ final bool _isContinue;
+
+ PerformAnalysisOperation(this._context, this._isPriority, this._isContinue);
+
+ @override
+ ServerOperationPriority get priority {
+ if (_isPriority) {
+ if (_isContinue) {
+ return ServerOperationPriority.ANALYSIS_PRIORITY_CONTINUE;
+ } else {
+ return ServerOperationPriority.ANALYSIS_PRIORITY;
+ }
+ } else {
+ if (_isContinue) {
+ return ServerOperationPriority.ANALYSIS_CONTINUE;
+ } else {
+ return ServerOperationPriority.ANALYSIS;
+ }
+ }
+ }
+
+ @override
+ void perform(AnalysisServer server) {
+ server.internalPerformAnalysis(_context);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698