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

Side by Side Diff: pkg/analysis_services/lib/src/refactoring/progress_monitor.dart

Issue 458063002: Initial work on refactorings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information.
7
8 library services.src.refactoring.progress_monitor;
9
10 import 'package:analysis_services/refactoring/progress_monitor.dart';
11
12
13 /**
14 * A [ProgressMonitor] which represents a part of a bigger [ProgressMonitor].
15 */
16 class SubProgressMonitor implements ProgressMonitor {
17 final ProgressMonitor _parent;
18 final int _parentTicks;
19
20 int _nestedBeginTasks = 0;
21
22 double _scale = 0.0;
23
24 int _sentToParent = 0;
25
26 bool _usedUp = false;
27
28 bool _hasSubTask = false;
29
30 SubProgressMonitor(this._parent, this._parentTicks);
31
32 @override
33 bool get isCanceled => _parent.isCanceled;
34
35 @override
36 void beginTask(String name, int totalWork) {
37 _nestedBeginTasks++;
38 // ignore nested begin task calls
39 if (_nestedBeginTasks > 1) {
40 return;
41 }
42 // prepare scale to convert this PM to parent PM
43 _scale = totalWork <= 0 ? 0.0 : _parentTicks / totalWork;
44 _sentToParent = 0;
45 _usedUp = false;
46 }
47
48 @override
49 void done() {
50 // ignore if already done
51 if (_nestedBeginTasks == 0 || --_nestedBeginTasks > 0) {
52 return;
53 }
54 // send any remaining ticks
55 double remaining = (_parentTicks - _sentToParent).toDouble();
56 if (remaining > 0) {
57 _parent.internalWorked(remaining);
58 }
59 // clear the sub task if there was one
60 if (_hasSubTask) {
61 _parent.subTask("");
62 }
63 }
64
65 @override
66 void internalWorked(double work) {
67 // may be ignore
68 if (_usedUp || _nestedBeginTasks != 1) {
69 return;
70 }
71 // send to parent
72 double parentWork = work > 0.0 ? _scale * work : 0.0;
73 _parent.internalWorked(parentWork);
74 _sentToParent += parentWork;
75 // may be used up
76 if (_sentToParent >= _parentTicks) {
77 _usedUp = true;
78 }
79 }
80
81 @override
82 void setCanceled() {
83 _parent.setCanceled();
84 }
85
86 @override
87 void subTask(String name) {
88 _hasSubTask = true;
89 _parent.subTask(name);
90 }
91
92 @override
93 void worked(int work) {
94 double workDouble = work.toDouble();
95 internalWorked(workDouble);
96 }
97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698