| 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' hide Resource; | 8 import 'dart:core' hide Resource; |
| 9 import 'dart:io' as io; | 9 import 'dart:io' as io; |
| 10 | 10 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 */ | 68 */ |
| 69 final ContentCache contentCache; | 69 final ContentCache contentCache; |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * The resolver provider used to create a package: URI resolver, or `null` if | 72 * The resolver provider used to create a package: URI resolver, or `null` if |
| 73 * the normal (Package Specification DEP) lookup mechanism is to be used. | 73 * the normal (Package Specification DEP) lookup mechanism is to be used. |
| 74 */ | 74 */ |
| 75 ResolverProvider packageResolverProvider; | 75 ResolverProvider packageResolverProvider; |
| 76 | 76 |
| 77 /** | 77 /** |
| 78 * The resolver provider used to create a file: URI resolver, or `null` if |
| 79 * the normal file URI resolver is to be used. |
| 80 */ |
| 81 ResolverProvider fileResolverProvider; |
| 82 |
| 83 /** |
| 78 * The file path of the .packages file that should be used in place of any | 84 * The file path of the .packages file that should be used in place of any |
| 79 * file found using the normal (Package Specification DEP) lookup mechanism, | 85 * file found using the normal (Package Specification DEP) lookup mechanism, |
| 80 * or `null` if the normal lookup mechanism should be used. | 86 * or `null` if the normal lookup mechanism should be used. |
| 81 */ | 87 */ |
| 82 String defaultPackageFilePath; | 88 String defaultPackageFilePath; |
| 83 | 89 |
| 84 /** | 90 /** |
| 85 * The file path of the packages directory that should be used in place of any | 91 * The file path of the packages directory that should be used in place of any |
| 86 * file found using the normal (Package Specification DEP) lookup mechanism, | 92 * file found using the normal (Package Specification DEP) lookup mechanism, |
| 87 * or `null` if the normal lookup mechanism should be used. | 93 * or `null` if the normal lookup mechanism should be used. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 return new MapPackages(map); | 196 return new MapPackages(map); |
| 191 } else if (defaultPackagesDirectoryPath != null) { | 197 } else if (defaultPackagesDirectoryPath != null) { |
| 192 return getPackagesDirectory( | 198 return getPackagesDirectory( |
| 193 new Uri.directory(defaultPackagesDirectoryPath)); | 199 new Uri.directory(defaultPackagesDirectoryPath)); |
| 194 } | 200 } |
| 195 return findPackagesFromFile(new Uri.directory(rootDirectoryPath)); | 201 return findPackagesFromFile(new Uri.directory(rootDirectoryPath)); |
| 196 } | 202 } |
| 197 | 203 |
| 198 SourceFactory createSourceFactory( | 204 SourceFactory createSourceFactory( |
| 199 String rootDirectoryPath, AnalysisOptions options) { | 205 String rootDirectoryPath, AnalysisOptions options) { |
| 206 Folder _folder = null; |
| 207 Folder folder() { |
| 208 return _folder ??= resourceProvider.getResource('.'); |
| 209 } |
| 210 UriResolver fileResolver = fileResolverProvider == null |
| 211 ? new ResourceUriResolver(resourceProvider) |
| 212 : fileResolverProvider(folder()); |
| 200 if (packageResolverProvider != null) { | 213 if (packageResolverProvider != null) { |
| 201 Folder folder = resourceProvider.getResource('.'); | 214 UriResolver packageResolver = packageResolverProvider(folder()); |
| 202 UriResolver resolver = packageResolverProvider(folder); | 215 if (packageResolver != null) { |
| 203 if (resolver != null) { | |
| 204 // TODO(brianwilkerson) This doesn't support either embedder files or | 216 // TODO(brianwilkerson) This doesn't support either embedder files or |
| 205 // sdk extensions because we don't have a way to get the package map | 217 // sdk extensions because we don't have a way to get the package map |
| 206 // from the resolver. | 218 // from the resolver. |
| 207 List<UriResolver> resolvers = <UriResolver>[ | 219 List<UriResolver> resolvers = <UriResolver>[ |
| 208 new DartUriResolver(findSdk(null, options)), | 220 new DartUriResolver(findSdk(null, options)), |
| 209 resolver, | 221 packageResolver, |
| 210 new ResourceUriResolver(resourceProvider) | 222 fileResolver |
| 211 ]; | 223 ]; |
| 212 return new SourceFactory(resolvers); | 224 return new SourceFactory(resolvers); |
| 213 } | 225 } |
| 214 } | 226 } |
| 215 Map<String, List<Folder>> packageMap = | 227 Map<String, List<Folder>> packageMap = |
| 216 convertPackagesToMap(createPackageMap(rootDirectoryPath)); | 228 convertPackagesToMap(createPackageMap(rootDirectoryPath)); |
| 217 List<UriResolver> resolvers = <UriResolver>[]; | 229 List<UriResolver> resolvers = <UriResolver>[]; |
| 218 resolvers.add(new DartUriResolver(findSdk(packageMap, options))); | 230 resolvers.add(new DartUriResolver(findSdk(packageMap, options))); |
| 219 if (packageMap != null) { | 231 if (packageMap != null) { |
| 220 resolvers.add(new PackageMapUriResolver(resourceProvider, packageMap)); | 232 resolvers.add(new PackageMapUriResolver(resourceProvider, packageMap)); |
| 221 } | 233 } |
| 222 resolvers.add(new ResourceUriResolver(resourceProvider)); | 234 resolvers.add(fileResolver); |
| 223 return new SourceFactory(resolvers); | 235 return new SourceFactory(resolvers); |
| 224 } | 236 } |
| 225 | 237 |
| 226 /** | 238 /** |
| 227 * Add any [declaredVariables] to the list of declared variables used by the | 239 * Add any [declaredVariables] to the list of declared variables used by the |
| 228 * given [context]. | 240 * given [context]. |
| 229 */ | 241 */ |
| 230 void declareVariables(InternalAnalysisContext context) { | 242 void declareVariables(InternalAnalysisContext context) { |
| 231 if (declaredVariables != null && declaredVariables.isNotEmpty) { | 243 if (declaredVariables != null && declaredVariables.isNotEmpty) { |
| 232 DeclaredVariables contextVariables = context.declaredVariables; | 244 DeclaredVariables contextVariables = context.declaredVariables; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 } | 347 } |
| 336 file = folder | 348 file = folder |
| 337 .getChildAssumingFile(AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); | 349 .getChildAssumingFile(AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); |
| 338 if (file.exists) { | 350 if (file.exists) { |
| 339 return file; | 351 return file; |
| 340 } | 352 } |
| 341 } | 353 } |
| 342 return null; | 354 return null; |
| 343 } | 355 } |
| 344 } | 356 } |
| OLD | NEW |