| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:core'; | 10 import 'dart:core'; |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 * folder is or contains the given path. ("innermost" refers to the nesting | 294 * folder is or contains the given path. ("innermost" refers to the nesting |
| 295 * of contexts, so if there is a context for path /foo and a context for | 295 * of contexts, so if there is a context for path /foo and a context for |
| 296 * path /foo/bar, then the innermost context containing /foo/bar/baz.dart is | 296 * path /foo/bar, then the innermost context containing /foo/bar/baz.dart is |
| 297 * the context for /foo/bar.) | 297 * the context for /foo/bar.) |
| 298 * | 298 * |
| 299 * If no driver contains the given path, `null` is returned. | 299 * If no driver contains the given path, `null` is returned. |
| 300 */ | 300 */ |
| 301 AnalysisDriver getDriverFor(String path); | 301 AnalysisDriver getDriverFor(String path); |
| 302 | 302 |
| 303 /** | 303 /** |
| 304 * Return the [ContextInfo] for the "innermost" context whose associated |
| 305 * folder is or contains the given path. ("innermost" refers to the nesting |
| 306 * of contexts, so if there is a context for path /foo and a context for |
| 307 * path /foo/bar, then the innermost context containing /foo/bar/baz.dart is |
| 308 * the context for /foo/bar.) |
| 309 * |
| 310 * If no context contains the given path, `null` is returned. |
| 311 * |
| 312 * This is public at least temporarily, for plugin support until the new API |
| 313 * is ready. |
| 314 */ |
| 315 ContextInfo getInnermostContextInfoFor(String path); |
| 316 |
| 317 /** |
| 304 * Return a list of all of the analysis drivers reachable from the given | 318 * Return a list of all of the analysis drivers reachable from the given |
| 305 * [analysisRoot] (the driver associated with [analysisRoot] and all of its | 319 * [analysisRoot] (the driver associated with [analysisRoot] and all of its |
| 306 * descendants). | 320 * descendants). |
| 307 */ | 321 */ |
| 308 List<AnalysisDriver> getDriversInAnalysisRoot(Folder analysisRoot); | 322 List<AnalysisDriver> getDriversInAnalysisRoot(Folder analysisRoot); |
| 309 | 323 |
| 310 /** | 324 /** |
| 311 * Return `true` if the given [path] is ignored by a [ContextInfo] whose | 325 * Return `true` if the given [path] is ignored by a [ContextInfo] whose |
| 312 * folder contains it. | 326 * folder contains it. |
| 313 */ | 327 */ |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 throw new StateError('Should not be used with the new analysis driver'); | 575 throw new StateError('Should not be used with the new analysis driver'); |
| 562 } else { | 576 } else { |
| 563 return _folderMap; | 577 return _folderMap; |
| 564 } | 578 } |
| 565 } | 579 } |
| 566 | 580 |
| 567 @override | 581 @override |
| 568 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot) { | 582 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot) { |
| 569 List<AnalysisContext> contexts = <AnalysisContext>[]; | 583 List<AnalysisContext> contexts = <AnalysisContext>[]; |
| 570 ContextInfo innermostContainingInfo = | 584 ContextInfo innermostContainingInfo = |
| 571 _getInnermostContextInfoFor(analysisRoot.path); | 585 getInnermostContextInfoFor(analysisRoot.path); |
| 572 void addContextAndDescendants(ContextInfo info) { | 586 void addContextAndDescendants(ContextInfo info) { |
| 573 contexts.add(info.context); | 587 contexts.add(info.context); |
| 574 info.children.forEach(addContextAndDescendants); | 588 info.children.forEach(addContextAndDescendants); |
| 575 } | 589 } |
| 576 | 590 |
| 577 if (innermostContainingInfo != null) { | 591 if (innermostContainingInfo != null) { |
| 578 if (analysisRoot == innermostContainingInfo.folder) { | 592 if (analysisRoot == innermostContainingInfo.folder) { |
| 579 addContextAndDescendants(innermostContainingInfo); | 593 addContextAndDescendants(innermostContainingInfo); |
| 580 } else { | 594 } else { |
| 581 for (ContextInfo info in innermostContainingInfo.children) { | 595 for (ContextInfo info in innermostContainingInfo.children) { |
| 582 if (analysisRoot.isOrContains(info.folder.path)) { | 596 if (analysisRoot.isOrContains(info.folder.path)) { |
| 583 addContextAndDescendants(info); | 597 addContextAndDescendants(info); |
| 584 } | 598 } |
| 585 } | 599 } |
| 586 } | 600 } |
| 587 } | 601 } |
| 588 return contexts; | 602 return contexts; |
| 589 } | 603 } |
| 590 | 604 |
| 591 /** | 605 /** |
| 592 * Check if this map defines embedded libraries. | 606 * Check if this map defines embedded libraries. |
| 593 */ | 607 */ |
| 594 bool definesEmbeddedLibs(Map map) => map[_EMBEDDED_LIB_MAP_KEY] != null; | 608 bool definesEmbeddedLibs(Map map) => map[_EMBEDDED_LIB_MAP_KEY] != null; |
| 595 | 609 |
| 596 @override | 610 @override |
| 597 AnalysisContext getContextFor(String path) { | 611 AnalysisContext getContextFor(String path) { |
| 598 return _getInnermostContextInfoFor(path)?.context; | 612 return getInnermostContextInfoFor(path)?.context; |
| 599 } | 613 } |
| 600 | 614 |
| 601 /** | 615 /** |
| 602 * For testing: get the [ContextInfo] object for the given [folder], if any. | 616 * For testing: get the [ContextInfo] object for the given [folder], if any. |
| 603 */ | 617 */ |
| 604 ContextInfo getContextInfoFor(Folder folder) { | 618 ContextInfo getContextInfoFor(Folder folder) { |
| 605 ContextInfo info = _getInnermostContextInfoFor(folder.path); | 619 ContextInfo info = getInnermostContextInfoFor(folder.path); |
| 606 if (info != null && folder == info.folder) { | 620 if (info != null && folder == info.folder) { |
| 607 return info; | 621 return info; |
| 608 } | 622 } |
| 609 return null; | 623 return null; |
| 610 } | 624 } |
| 611 | 625 |
| 612 @override | 626 @override |
| 613 AnalysisDriver getDriverFor(String path) { | 627 AnalysisDriver getDriverFor(String path) { |
| 614 return _getInnermostContextInfoFor(path)?.analysisDriver; | 628 return getInnermostContextInfoFor(path)?.analysisDriver; |
| 615 } | 629 } |
| 616 | 630 |
| 617 @override | 631 @override |
| 618 List<AnalysisDriver> getDriversInAnalysisRoot(Folder analysisRoot) { | 632 List<AnalysisDriver> getDriversInAnalysisRoot(Folder analysisRoot) { |
| 619 List<AnalysisDriver> drivers = <AnalysisDriver>[]; | 633 List<AnalysisDriver> drivers = <AnalysisDriver>[]; |
| 620 void addContextAndDescendants(ContextInfo info) { | 634 void addContextAndDescendants(ContextInfo info) { |
| 621 drivers.add(info.analysisDriver); | 635 drivers.add(info.analysisDriver); |
| 622 info.children.forEach(addContextAndDescendants); | 636 info.children.forEach(addContextAndDescendants); |
| 623 } | 637 } |
| 624 | 638 |
| 625 ContextInfo innermostContainingInfo = | 639 ContextInfo innermostContainingInfo = |
| 626 _getInnermostContextInfoFor(analysisRoot.path); | 640 getInnermostContextInfoFor(analysisRoot.path); |
| 627 if (innermostContainingInfo != null) { | 641 if (innermostContainingInfo != null) { |
| 628 if (analysisRoot == innermostContainingInfo.folder) { | 642 if (analysisRoot == innermostContainingInfo.folder) { |
| 629 addContextAndDescendants(innermostContainingInfo); | 643 addContextAndDescendants(innermostContainingInfo); |
| 630 } else { | 644 } else { |
| 631 for (ContextInfo info in innermostContainingInfo.children) { | 645 for (ContextInfo info in innermostContainingInfo.children) { |
| 632 if (analysisRoot.isOrContains(info.folder.path)) { | 646 if (analysisRoot.isOrContains(info.folder.path)) { |
| 633 addContextAndDescendants(info); | 647 addContextAndDescendants(info); |
| 634 } | 648 } |
| 635 } | 649 } |
| 636 } | 650 } |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 | 1345 |
| 1332 /** | 1346 /** |
| 1333 * Return the [ContextInfo] for the "innermost" context whose associated | 1347 * Return the [ContextInfo] for the "innermost" context whose associated |
| 1334 * folder is or contains the given path. ("innermost" refers to the nesting | 1348 * folder is or contains the given path. ("innermost" refers to the nesting |
| 1335 * of contexts, so if there is a context for path /foo and a context for | 1349 * of contexts, so if there is a context for path /foo and a context for |
| 1336 * path /foo/bar, then the innermost context containing /foo/bar/baz.dart is | 1350 * path /foo/bar, then the innermost context containing /foo/bar/baz.dart is |
| 1337 * the context for /foo/bar.) | 1351 * the context for /foo/bar.) |
| 1338 * | 1352 * |
| 1339 * If no context contains the given path, `null` is returned. | 1353 * If no context contains the given path, `null` is returned. |
| 1340 */ | 1354 */ |
| 1341 ContextInfo _getInnermostContextInfoFor(String path) { | 1355 ContextInfo getInnermostContextInfoFor(String path) { |
| 1342 ContextInfo info = rootInfo.findChildInfoFor(path); | 1356 ContextInfo info = rootInfo.findChildInfoFor(path); |
| 1343 if (info == null) { | 1357 if (info == null) { |
| 1344 return null; | 1358 return null; |
| 1345 } | 1359 } |
| 1346 while (true) { | 1360 while (true) { |
| 1347 ContextInfo childInfo = info.findChildInfoFor(path); | 1361 ContextInfo childInfo = info.findChildInfoFor(path); |
| 1348 if (childInfo == null) { | 1362 if (childInfo == null) { |
| 1349 return info; | 1363 return info; |
| 1350 } | 1364 } |
| 1351 info = childInfo; | 1365 info = childInfo; |
| 1352 } | 1366 } |
| 1353 } | 1367 } |
| 1354 | 1368 |
| 1355 /** | 1369 /** |
| 1356 * Return the parent for a new [ContextInfo] with the given [path] folder. | 1370 * Return the parent for a new [ContextInfo] with the given [path] folder. |
| 1357 */ | 1371 */ |
| 1358 ContextInfo _getParentForNewContext(String path) { | 1372 ContextInfo _getParentForNewContext(String path) { |
| 1359 ContextInfo parent = _getInnermostContextInfoFor(path); | 1373 ContextInfo parent = getInnermostContextInfoFor(path); |
| 1360 if (parent != null) { | 1374 if (parent != null) { |
| 1361 return parent; | 1375 return parent; |
| 1362 } | 1376 } |
| 1363 return rootInfo; | 1377 return rootInfo; |
| 1364 } | 1378 } |
| 1365 | 1379 |
| 1366 void _handleWatchEvent(WatchEvent event) { | 1380 void _handleWatchEvent(WatchEvent event) { |
| 1367 // Figure out which context this event applies to. | 1381 // Figure out which context this event applies to. |
| 1368 // TODO(brianwilkerson) If a file is explicitly included in one context | 1382 // TODO(brianwilkerson) If a file is explicitly included in one context |
| 1369 // but implicitly referenced in another context, we will only send a | 1383 // but implicitly referenced in another context, we will only send a |
| 1370 // changeSet to the context that explicitly includes the file (because | 1384 // changeSet to the context that explicitly includes the file (because |
| 1371 // that's the only context that's watching the file). | 1385 // that's the only context that's watching the file). |
| 1372 ContextInfo info = _getInnermostContextInfoFor(event.path); | 1386 ContextInfo info = getInnermostContextInfoFor(event.path); |
| 1373 if (info == null) { | 1387 if (info == null) { |
| 1374 // This event doesn't apply to any context. This could happen due to a | 1388 // This event doesn't apply to any context. This could happen due to a |
| 1375 // race condition (e.g. a context was removed while one of its events was | 1389 // race condition (e.g. a context was removed while one of its events was |
| 1376 // in the event loop). The event is inapplicable now, so just ignore it. | 1390 // in the event loop). The event is inapplicable now, so just ignore it. |
| 1377 return; | 1391 return; |
| 1378 } | 1392 } |
| 1379 _instrumentationService.logWatchEvent( | 1393 _instrumentationService.logWatchEvent( |
| 1380 info.folder.path, event.path, event.type.toString()); | 1394 info.folder.path, event.path, event.type.toString()); |
| 1381 String path = event.path; | 1395 String path = event.path; |
| 1382 // First handle changes that affect folderDisposition (since these need to | 1396 // First handle changes that affect folderDisposition (since these need to |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1941 } | 1955 } |
| 1942 return _embedderLocator; | 1956 return _embedderLocator; |
| 1943 } | 1957 } |
| 1944 | 1958 |
| 1945 @override | 1959 @override |
| 1946 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { | 1960 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { |
| 1947 return _sdkExtensionFinder ??= | 1961 return _sdkExtensionFinder ??= |
| 1948 new SdkExtensionFinder(buildPackageMap(resourceProvider)); | 1962 new SdkExtensionFinder(buildPackageMap(resourceProvider)); |
| 1949 } | 1963 } |
| 1950 } | 1964 } |
| OLD | NEW |