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

Side by Side 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, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 library operation;
6
7 import 'package:analysis_server/src/analysis_server.dart';
8 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
9
10
11 /**
12 * The enumeration [ServerOperationPriority] defines the priority levels used
13 * to organize [ServerOperation]s in an optimal order. A smaller ordinal value
14 * equates to a higher priority.
15 */
16 class ServerOperationPriority {
17 final int ordinal;
18 final String name;
19
20 static const int COUNT = 7;
21
22 static const ServerOperationPriority ANALYSIS_NOTIFICATION = const ServerOpera tionPriority._(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.
23 static const ServerOperationPriority ANALYSIS_PRIORITY_CONTINUE = const Server OperationPriority._(1, "ANALYSIS_PRIORITY_CONTINUE");
24 static const ServerOperationPriority ANALYSIS_PRIORITY = const ServerOperation Priority._(2, "ANALYSIS_PRIORITY");
25 static const ServerOperationPriority ANALYSIS_CONTINUE = const ServerOperation Priority._(3, "ANALYSIS_CONTINUE");
26 static const ServerOperationPriority ANALYSIS = const ServerOperationPriority. _(4, "ANALYSIS");
27 static const ServerOperationPriority SEARCH = const ServerOperationPriority._( 5, "SEARCH");
28 static const ServerOperationPriority REFACTORING = const ServerOperationPriori ty._(6, "REFACTORING");
29
30 @override
31 String toString() => name;
32
33 const ServerOperationPriority._(this.ordinal, this.name);
34 }
35
36
37 /**
38 * The class [ServerOperation] defines the behavior of objects used to perform
39 * operations on a [AnalysisServer].
40 */
41 abstract class ServerOperation {
42 /**
43 * Returns the priority of this operation.
44 */
45 ServerOperationPriority get priority;
46
47 /**
48 * Performs the operation implemented by this operation.
49 */
50 void perform(AnalysisServer server);
51 }
52
53
54 /**
55 * The interface [MergeableOperation] is a [ServerOperation] which can be merged
56 * with (and into) another [ServerOperation].
57 */
58 abstract class MergeableOperation extends ServerOperation {
59 /**
60 * Merges the given operation into this one.
61 *
62 * Returns `true` if merge was successful.
63 */
64 bool mergeWith(ServerOperation operation);
65 }
66
67
68 /**
69 * Instances of [PerformAnalysisOperation] perform a single analysis task.
70 */
71 class PerformAnalysisOperation extends ServerOperation {
72 final AnalysisContext _context;
73 final bool _isPriority;
74 final bool _isContinue;
75
76 PerformAnalysisOperation(this._context, this._isPriority, this._isContinue);
77
78 @override
79 ServerOperationPriority get priority {
80 if (_isPriority) {
81 if (_isContinue) {
82 return ServerOperationPriority.ANALYSIS_PRIORITY_CONTINUE;
83 } else {
84 return ServerOperationPriority.ANALYSIS_PRIORITY;
85 }
86 } else {
87 if (_isContinue) {
88 return ServerOperationPriority.ANALYSIS_CONTINUE;
89 } else {
90 return ServerOperationPriority.ANALYSIS;
91 }
92 }
93 }
94
95 @override
96 void perform(AnalysisServer server) {
97 server.internalPerformAnalysis(_context);
98 }
99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698