| 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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 List<String> get includedPaths; | 272 List<String> get includedPaths; |
| 273 | 273 |
| 274 /** | 274 /** |
| 275 * Return a list of all of the contexts reachable from the given | 275 * Return a list of all of the contexts reachable from the given |
| 276 * [analysisRoot] (the context associated with [analysisRoot] and all of its | 276 * [analysisRoot] (the context associated with [analysisRoot] and all of its |
| 277 * descendants). | 277 * descendants). |
| 278 */ | 278 */ |
| 279 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot); | 279 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot); |
| 280 | 280 |
| 281 /** | 281 /** |
| 282 * Return the [AnalysisContext] for the "innermost" context whose associated |
| 283 * folder is or contains the given path. ("innermost" refers to the nesting |
| 284 * of contexts, so if there is a context for path /foo and a context for |
| 285 * path /foo/bar, then the innermost context containing /foo/bar/baz.dart is |
| 286 * the context for /foo/bar.) |
| 287 * |
| 288 * If no context contains the given path, `null` is returned. |
| 289 */ |
| 290 AnalysisContext getContextFor(String path); |
| 291 |
| 292 /** |
| 282 * Return the [AnalysisDriver] for the "innermost" context whose associated | 293 * Return the [AnalysisDriver] for the "innermost" context whose associated |
| 283 * 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 |
| 284 * 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 |
| 285 * 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 |
| 286 * the context for /foo/bar.) | 297 * the context for /foo/bar.) |
| 287 * | 298 * |
| 288 * If no driver contains the given path, `null` is returned. | 299 * If no driver contains the given path, `null` is returned. |
| 289 */ | 300 */ |
| 290 AnalysisDriver getDriverFor(String path); | 301 AnalysisDriver getDriverFor(String path); |
| 291 | 302 |
| 292 /** | 303 /** |
| 293 * Return the [AnalysisContext] for the "innermost" context whose associated | |
| 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 | |
| 296 * path /foo/bar, then the innermost context containing /foo/bar/baz.dart is | |
| 297 * the context for /foo/bar.) | |
| 298 * | |
| 299 * If no context contains the given path, `null` is returned. | |
| 300 */ | |
| 301 AnalysisContext getContextFor(String path); | |
| 302 | |
| 303 /** | |
| 304 * Return a list of all of the analysis drivers reachable from the given | 304 * Return a list of all of the analysis drivers reachable from the given |
| 305 * [analysisRoot] (the driver associated with [analysisRoot] and all of its | 305 * [analysisRoot] (the driver associated with [analysisRoot] and all of its |
| 306 * descendants). | 306 * descendants). |
| 307 */ | 307 */ |
| 308 List<AnalysisDriver> getDriversInAnalysisRoot(Folder analysisRoot); | 308 List<AnalysisDriver> getDriversInAnalysisRoot(Folder analysisRoot); |
| 309 | 309 |
| 310 /** | 310 /** |
| 311 * Return `true` if the given [path] is ignored by a [ContextInfo] whose | 311 * Return `true` if the given [path] is ignored by a [ContextInfo] whose |
| 312 * folder contains it. | 312 * folder contains it. |
| 313 */ | 313 */ |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 } | 587 } |
| 588 return contexts; | 588 return contexts; |
| 589 } | 589 } |
| 590 | 590 |
| 591 /** | 591 /** |
| 592 * Check if this map defines embedded libraries. | 592 * Check if this map defines embedded libraries. |
| 593 */ | 593 */ |
| 594 bool definesEmbeddedLibs(Map map) => map[_EMBEDDED_LIB_MAP_KEY] != null; | 594 bool definesEmbeddedLibs(Map map) => map[_EMBEDDED_LIB_MAP_KEY] != null; |
| 595 | 595 |
| 596 @override | 596 @override |
| 597 AnalysisDriver getDriverFor(String path) { | |
| 598 return _getInnermostContextInfoFor(path)?.analysisDriver; | |
| 599 } | |
| 600 | |
| 601 @override | |
| 602 AnalysisContext getContextFor(String path) { | 597 AnalysisContext getContextFor(String path) { |
| 603 return _getInnermostContextInfoFor(path)?.context; | 598 return _getInnermostContextInfoFor(path)?.context; |
| 604 } | 599 } |
| 605 | 600 |
| 606 /** | 601 /** |
| 607 * For testing: get the [ContextInfo] object for the given [folder], if any. | 602 * For testing: get the [ContextInfo] object for the given [folder], if any. |
| 608 */ | 603 */ |
| 609 ContextInfo getContextInfoFor(Folder folder) { | 604 ContextInfo getContextInfoFor(Folder folder) { |
| 610 ContextInfo info = _getInnermostContextInfoFor(folder.path); | 605 ContextInfo info = _getInnermostContextInfoFor(folder.path); |
| 611 if (info != null && folder == info.folder) { | 606 if (info != null && folder == info.folder) { |
| 612 return info; | 607 return info; |
| 613 } | 608 } |
| 614 return null; | 609 return null; |
| 615 } | 610 } |
| 616 | 611 |
| 617 @override | 612 @override |
| 613 AnalysisDriver getDriverFor(String path) { |
| 614 return _getInnermostContextInfoFor(path)?.analysisDriver; |
| 615 } |
| 616 |
| 617 @override |
| 618 List<AnalysisDriver> getDriversInAnalysisRoot(Folder analysisRoot) { | 618 List<AnalysisDriver> getDriversInAnalysisRoot(Folder analysisRoot) { |
| 619 List<AnalysisDriver> drivers = <AnalysisDriver>[]; | 619 List<AnalysisDriver> drivers = <AnalysisDriver>[]; |
| 620 void addContextAndDescendants(ContextInfo info) { | 620 void addContextAndDescendants(ContextInfo info) { |
| 621 drivers.add(info.analysisDriver); | 621 drivers.add(info.analysisDriver); |
| 622 info.children.forEach(addContextAndDescendants); | 622 info.children.forEach(addContextAndDescendants); |
| 623 } | 623 } |
| 624 | 624 |
| 625 ContextInfo innermostContainingInfo = | 625 ContextInfo innermostContainingInfo = |
| 626 _getInnermostContextInfoFor(analysisRoot.path); | 626 _getInnermostContextInfoFor(analysisRoot.path); |
| 627 if (innermostContainingInfo != null) { | 627 if (innermostContainingInfo != null) { |
| (...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1699 } else { | 1699 } else { |
| 1700 return null; | 1700 return null; |
| 1701 } | 1701 } |
| 1702 } | 1702 } |
| 1703 return stringMap; | 1703 return stringMap; |
| 1704 } | 1704 } |
| 1705 return null; | 1705 return null; |
| 1706 } | 1706 } |
| 1707 | 1707 |
| 1708 void _updateContextPackageUriResolver(Folder contextFolder) { | 1708 void _updateContextPackageUriResolver(Folder contextFolder) { |
| 1709 AnalysisContext context = folderMap[contextFolder]; | 1709 if (enableNewAnalysisDriver) { |
| 1710 context.sourceFactory = | 1710 ContextInfo info = getContextInfoFor(contextFolder); |
| 1711 _createSourceFactory(context, context.analysisOptions, contextFolder); | 1711 AnalysisDriver driver = info.analysisDriver; |
| 1712 callbacks.updateContextPackageUriResolver(context); | 1712 SourceFactory sourceFactory = |
| 1713 _createSourceFactory(null, driver.analysisOptions, contextFolder); |
| 1714 driver.configure(sourceFactory: sourceFactory); |
| 1715 } else { |
| 1716 AnalysisContext context = folderMap[contextFolder]; |
| 1717 context.sourceFactory = |
| 1718 _createSourceFactory(context, context.analysisOptions, contextFolder); |
| 1719 callbacks.updateContextPackageUriResolver(context); |
| 1720 } |
| 1713 } | 1721 } |
| 1714 | 1722 |
| 1715 /** | 1723 /** |
| 1716 * Create and return a source representing the given [file] within the given | 1724 * Create and return a source representing the given [file] within the given |
| 1717 * [context]. | 1725 * [context]. |
| 1718 */ | 1726 */ |
| 1719 static Source createSourceInContext(AnalysisContext context, File file) { | 1727 static Source createSourceInContext(AnalysisContext context, File file) { |
| 1720 // TODO(brianwilkerson) Optimize this, by allowing support for source | 1728 // TODO(brianwilkerson) Optimize this, by allowing support for source |
| 1721 // factories to restore URI's from a file path rather than a source. | 1729 // factories to restore URI's from a file path rather than a source. |
| 1722 Source source = file.createSource(); | 1730 Source source = file.createSource(); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1967 } | 1975 } |
| 1968 return _embedderLocator; | 1976 return _embedderLocator; |
| 1969 } | 1977 } |
| 1970 | 1978 |
| 1971 @override | 1979 @override |
| 1972 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { | 1980 SdkExtensionFinder getSdkExtensionFinder(ResourceProvider resourceProvider) { |
| 1973 return _sdkExtensionFinder ??= | 1981 return _sdkExtensionFinder ??= |
| 1974 new SdkExtensionFinder(buildPackageMap(resourceProvider)); | 1982 new SdkExtensionFinder(buildPackageMap(resourceProvider)); |
| 1975 } | 1983 } |
| 1976 } | 1984 } |
| OLD | NEW |