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

Side by Side Diff: pkg/analysis_server/lib/src/watch_manager.dart

Issue 1900503002: More steps toward making server strong mode clean (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library context.directory.manager; 5 library context.directory.manager;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:core' hide Resource; 9 import 'dart:core' hide Resource;
10 10
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 /** 169 /**
170 * The folder for which information is being maintained. This is `null` for 170 * The folder for which information is being maintained. This is `null` for
171 * the unique "root" node that maintains references to all of the top-level 171 * the unique "root" node that maintains references to all of the top-level
172 * folders being watched. 172 * folders being watched.
173 */ 173 */
174 final Folder folder; 174 final Folder folder;
175 175
176 /** 176 /**
177 * The parent of this node. 177 * The parent of this node.
178 */ 178 */
179 WatchNode parent; 179 WatchNode<T> parent;
180 180
181 /** 181 /**
182 * The information for the children of this node. 182 * The information for the children of this node.
183 */ 183 */
184 final List<WatchNode> _children = <WatchNode>[]; 184 final List<WatchNode<T>> _children = <WatchNode<T>>[];
185 185
186 /** 186 /**
187 * The tokens that were used to register interest in watching this folder. 187 * The tokens that were used to register interest in watching this folder.
188 */ 188 */
189 final Set<T> tokens = new HashSet<T>(); 189 final Set<T> tokens = new HashSet<T>();
190 190
191 /** 191 /**
192 * The subscription being used to watch the folder, or `null` if the folder 192 * The subscription being used to watch the folder, or `null` if the folder
193 * is being watched as part of a containing folder (in other words, if the 193 * is being watched as part of a containing folder (in other words, if the
194 * parent is not the special "root"). 194 * parent is not the special "root").
195 */ 195 */
196 StreamSubscription<WatchEvent> subscription; 196 StreamSubscription<WatchEvent> subscription;
197 197
198 /** 198 /**
199 * Initialize a newly created node to represent the given [folder]. 199 * Initialize a newly created node to represent the given [folder].
200 */ 200 */
201 WatchNode(this.folder); 201 WatchNode(this.folder);
202 202
203 /** 203 /**
204 * Return a list containing the children of this node. 204 * Return a list containing the children of this node.
205 */ 205 */
206 Iterable<WatchNode> get children => _children; 206 Iterable<WatchNode<T>> get children => _children;
207 207
208 /** 208 /**
209 * Remove this node from the tree of watched folders. 209 * Remove this node from the tree of watched folders.
210 */ 210 */
211 void delete() { 211 void delete() {
212 if (parent != null) { 212 if (parent != null) {
213 parent._removeChild(this); 213 parent._removeChild(this);
214 parent = null; 214 parent = null;
215 } 215 }
216 } 216 }
217 217
218 /** 218 /**
219 * Return the highest node reachable from this node that contains the given 219 * Return the highest node reachable from this node that contains the given
220 * [filePath]. If no other node is found, return this node, even if this node 220 * [filePath]. If no other node is found, return this node, even if this node
221 * does not contain the path. 221 * does not contain the path.
222 */ 222 */
223 WatchNode findParent(String filePath) { 223 WatchNode<T> findParent(String filePath) {
224 if (_children == null) { 224 if (_children == null) {
225 return this; 225 return this;
226 } 226 }
227 for (WatchNode childNode in _children) { 227 for (WatchNode<T> childNode in _children) {
228 if (childNode.folder.isOrContains(filePath)) { 228 if (childNode.folder.isOrContains(filePath)) {
229 return childNode.findParent(filePath); 229 return childNode.findParent(filePath);
230 } 230 }
231 } 231 }
232 return this; 232 return this;
233 } 233 }
234 234
235 /** 235 /**
236 * Insert the given [node] into the tree of watched folders, either as a child 236 * Insert the given [node] into the tree of watched folders, either as a child
237 * of this node or as a descendent of one of this node's children. Return the 237 * of this node or as a descendent of one of this node's children. Return the
238 * immediate parent of the newly added node. 238 * immediate parent of the newly added node.
239 */ 239 */
240 WatchNode insert(WatchNode node) { 240 WatchNode<T> insert(WatchNode<T> node) {
241 WatchNode parentNode = findParent(node.folder.path); 241 WatchNode<T> parentNode = findParent(node.folder.path);
242 parentNode._addChild(node, true); 242 parentNode._addChild(node, true);
243 return parentNode; 243 return parentNode;
244 } 244 }
245 245
246 @override 246 @override
247 String toString() => 'WatchNode (' 247 String toString() => 'WatchNode ('
248 'folder = ${folder == null ? '<root>' : folder.path}, ' 248 'folder = ${folder == null ? '<root>' : folder.path}, '
249 'tokens = $tokens, ' 249 'tokens = $tokens, '
250 'subscription = ${subscription == null ? 'null' : 'non-null'})'; 250 'subscription = ${subscription == null ? 'null' : 'non-null'})';
251 251
252 /** 252 /**
253 * Add the given [newChild] as an immediate child of this node. 253 * Add the given [newChild] as an immediate child of this node.
254 * 254 *
255 * If [checkChildren] is `true`, check to see whether any of the previously 255 * If [checkChildren] is `true`, check to see whether any of the previously
256 * existing children of this node should now be children of the new child, and 256 * existing children of this node should now be children of the new child, and
257 * if so, move them. 257 * if so, move them.
258 */ 258 */
259 void _addChild(WatchNode newChild, bool checkChildren) { 259 void _addChild(WatchNode<T> newChild, bool checkChildren) {
260 if (checkChildren) { 260 if (checkChildren) {
261 Folder folder = newChild.folder; 261 Folder folder = newChild.folder;
262 for (int i = _children.length - 1; i >= 0; i--) { 262 for (int i = _children.length - 1; i >= 0; i--) {
263 WatchNode existingChild = _children[i]; 263 WatchNode<T> existingChild = _children[i];
264 if (folder.contains(existingChild.folder.path)) { 264 if (folder.contains(existingChild.folder.path)) {
265 newChild._addChild(existingChild, false); 265 newChild._addChild(existingChild, false);
266 _children.removeAt(i); 266 _children.removeAt(i);
267 } 267 }
268 } 268 }
269 } 269 }
270 newChild.parent = this; 270 newChild.parent = this;
271 _children.add(newChild); 271 _children.add(newChild);
272 } 272 }
273 273
274 /** 274 /**
275 * Remove the given [node] from the list of children of this node. Any 275 * Remove the given [node] from the list of children of this node. Any
276 * children of the [node] will become children of this node. 276 * children of the [node] will become children of this node.
277 */ 277 */
278 void _removeChild(WatchNode child) { 278 void _removeChild(WatchNode<T> child) {
279 _children.remove(child); 279 _children.remove(child);
280 Iterable<WatchNode> grandchildren = child.children; 280 Iterable<WatchNode<T>> grandchildren = child.children;
281 for (WatchNode grandchild in grandchildren) { 281 for (WatchNode<T> grandchild in grandchildren) {
282 grandchild.parent = this; 282 grandchild.parent = this;
283 _children.add(grandchild); 283 _children.add(grandchild);
284 } 284 }
285 child._children.clear(); 285 child._children.clear();
286 } 286 }
287 } 287 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/search/element_references.dart ('k') | pkg/analysis_server/test/mocks.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698