| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 analyzer.src.context.context_builder; | 5 library analyzer.src.context.context_builder; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:core'; | 8 import 'dart:core'; |
| 9 | 9 |
| 10 import 'package:analyzer/context/declared_variables.dart'; | 10 import 'package:analyzer/context/declared_variables.dart'; |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 return findPackagesFromFile(rootDirectoryPath); | 245 return findPackagesFromFile(rootDirectoryPath); |
| 246 } | 246 } |
| 247 | 247 |
| 248 SourceFactory createSourceFactory(String rootPath, AnalysisOptions options) { | 248 SourceFactory createSourceFactory(String rootPath, AnalysisOptions options) { |
| 249 Workspace workspace = createWorkspace(rootPath); | 249 Workspace workspace = createWorkspace(rootPath); |
| 250 DartSdk sdk = findSdk(workspace.packageMap, options); | 250 DartSdk sdk = findSdk(workspace.packageMap, options); |
| 251 return workspace.createSourceFactory(sdk); | 251 return workspace.createSourceFactory(sdk); |
| 252 } | 252 } |
| 253 | 253 |
| 254 Workspace createWorkspace(String rootPath) { | 254 Workspace createWorkspace(String rootPath) { |
| 255 if (_hasPackageFileInPath(rootPath)) { |
| 256 // Bazel workspaces that include package files are treated like normal |
| 257 // (non-Bazel) directories. |
| 258 return _BasicWorkspace.find(resourceProvider, rootPath, this); |
| 259 } |
| 255 Workspace workspace = BazelWorkspace.find(resourceProvider, rootPath); | 260 Workspace workspace = BazelWorkspace.find(resourceProvider, rootPath); |
| 256 workspace ??= GnWorkspace.find(resourceProvider, rootPath); | 261 workspace ??= GnWorkspace.find(resourceProvider, rootPath); |
| 257 return workspace ?? _BasicWorkspace.find(resourceProvider, rootPath, this); | 262 return workspace ?? _BasicWorkspace.find(resourceProvider, rootPath, this); |
| 258 } | 263 } |
| 259 | 264 |
| 260 /** | 265 /** |
| 261 * Add any [declaredVariables] to the list of declared variables used by the | 266 * Add any [declaredVariables] to the list of declared variables used by the |
| 262 * given [context]. | 267 * given [context]. |
| 263 */ | 268 */ |
| 264 void declareVariables(InternalAnalysisContext context) { | 269 void declareVariables(InternalAnalysisContext context) { |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 Folder parentDir = folder.parent; | 551 Folder parentDir = folder.parent; |
| 547 while (parentDir != null) { | 552 while (parentDir != null) { |
| 548 packagesCfgFile = checkForConfigFile(parentDir); | 553 packagesCfgFile = checkForConfigFile(parentDir); |
| 549 if (packagesCfgFile != null) { | 554 if (packagesCfgFile != null) { |
| 550 return packagesCfgFile; | 555 return packagesCfgFile; |
| 551 } | 556 } |
| 552 parentDir = parentDir.parent; | 557 parentDir = parentDir.parent; |
| 553 } | 558 } |
| 554 return null; | 559 return null; |
| 555 } | 560 } |
| 561 |
| 562 /** |
| 563 * Return `true` if either the directory at [rootPath] or a parent of that |
| 564 * directory contains a `.packages` file. |
| 565 */ |
| 566 bool _hasPackageFileInPath(String rootPath) { |
| 567 Folder folder = resourceProvider.getFolder(rootPath); |
| 568 while (folder != null) { |
| 569 File file = folder.getChildAssumingFile('.packages'); |
| 570 if (file.exists) { |
| 571 return true; |
| 572 } |
| 573 folder = folder.parent; |
| 574 } |
| 575 return false; |
| 576 } |
| 556 } | 577 } |
| 557 | 578 |
| 558 /** | 579 /** |
| 559 * Options used by a [ContextBuilder]. | 580 * Options used by a [ContextBuilder]. |
| 560 */ | 581 */ |
| 561 class ContextBuilderOptions { | 582 class ContextBuilderOptions { |
| 562 /** | 583 /** |
| 563 * The results of parsing the command line arguments as defined by | 584 * The results of parsing the command line arguments as defined by |
| 564 * [defineAnalysisArguments] or `null` if none. | 585 * [defineAnalysisArguments] or `null` if none. |
| 565 */ | 586 */ |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 | 750 |
| 730 final ContextBuilder _builder; | 751 final ContextBuilder _builder; |
| 731 | 752 |
| 732 Map<String, List<Folder>> _packageMap; | 753 Map<String, List<Folder>> _packageMap; |
| 733 | 754 |
| 734 Packages _packages; | 755 Packages _packages; |
| 735 | 756 |
| 736 _BasicWorkspace._(this.provider, this.root, this._builder); | 757 _BasicWorkspace._(this.provider, this.root, this._builder); |
| 737 | 758 |
| 738 @override | 759 @override |
| 760 // Alternately, we could check the pubspec for "sdk: flutter" |
| 761 bool get hasFlutterDependency => packageMap.containsKey('flutter'); |
| 762 |
| 763 @override |
| 739 Map<String, List<Folder>> get packageMap { | 764 Map<String, List<Folder>> get packageMap { |
| 740 _packageMap ??= _builder.convertPackagesToMap(packages); | 765 _packageMap ??= _builder.convertPackagesToMap(packages); |
| 741 return _packageMap; | 766 return _packageMap; |
| 742 } | 767 } |
| 743 | 768 |
| 744 @override | |
| 745 // Alternately, we could check the pubspec for "sdk: flutter" | |
| 746 bool get hasFlutterDependency => packageMap.containsKey('flutter'); | |
| 747 | |
| 748 Packages get packages { | 769 Packages get packages { |
| 749 _packages ??= _builder.createPackageMap(root); | 770 _packages ??= _builder.createPackageMap(root); |
| 750 return _packages; | 771 return _packages; |
| 751 } | 772 } |
| 752 | 773 |
| 753 @override | 774 @override |
| 754 UriResolver get packageUriResolver => | 775 UriResolver get packageUriResolver => |
| 755 new PackageMapUriResolver(provider, packageMap); | 776 new PackageMapUriResolver(provider, packageMap); |
| 756 | 777 |
| 757 @override | 778 @override |
| 758 SourceFactory createSourceFactory(DartSdk sdk) { | 779 SourceFactory createSourceFactory(DartSdk sdk) { |
| 759 List<UriResolver> resolvers = <UriResolver>[]; | 780 List<UriResolver> resolvers = <UriResolver>[]; |
| 760 if (sdk != null) { | 781 if (sdk != null) { |
| 761 resolvers.add(new DartUriResolver(sdk)); | 782 resolvers.add(new DartUriResolver(sdk)); |
| 762 } | 783 } |
| 763 resolvers.add(packageUriResolver); | 784 resolvers.add(packageUriResolver); |
| 764 resolvers.add(new ResourceUriResolver(provider)); | 785 resolvers.add(new ResourceUriResolver(provider)); |
| 765 return new SourceFactory(resolvers, packages, provider); | 786 return new SourceFactory(resolvers, packages, provider); |
| 766 } | 787 } |
| 767 | 788 |
| 768 /** | 789 /** |
| 769 * Find the basic workspace that contains the given [path]. | 790 * Find the basic workspace that contains the given [path]. |
| 770 */ | 791 */ |
| 771 static _BasicWorkspace find( | 792 static _BasicWorkspace find( |
| 772 ResourceProvider resourceProvider, String path, ContextBuilder builder) { | 793 ResourceProvider resourceProvider, String path, ContextBuilder builder) { |
| 773 return new _BasicWorkspace._(resourceProvider, path, builder); | 794 return new _BasicWorkspace._(resourceProvider, path, builder); |
| 774 } | 795 } |
| 775 } | 796 } |
| OLD | NEW |