Chromium Code Reviews| 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 code_transformers.src.resolvers; | 5 library code_transformers.src.resolvers; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'package:barback/barback.dart'; | 8 import 'package:barback/barback.dart'; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/engine.dart' show AnalysisOptions; | 10 import 'package:analyzer/src/generated/engine.dart' show AnalysisOptions; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 final Map<AssetId, Resolver> _resolvers = {}; | 30 final Map<AssetId, Resolver> _resolvers = {}; |
| 31 final DartSdk dartSdk; | 31 final DartSdk dartSdk; |
| 32 final DartUriResolver dartUriResolver; | 32 final DartUriResolver dartUriResolver; |
| 33 final AnalysisOptions options; | 33 final AnalysisOptions options; |
| 34 | 34 |
| 35 /// Null unless `useSharedSources` is true. This option should only be used if | 35 /// Null unless `useSharedSources` is true. This option should only be used if |
| 36 /// you know that files are always in a consistent state wherever this | 36 /// you know that files are always in a consistent state wherever this |
| 37 /// resolvers object is used. Any time that [Resolvers#get] or | 37 /// resolvers object is used. Any time that [Resolvers#get] or |
| 38 /// [Resolver#resolve] are called it will update the sources globally when | 38 /// [Resolver#resolve] are called it will update the sources globally when |
| 39 /// this option is in use. | 39 /// this option is in use. |
| 40 final Map<AssetId, dynamic> sharedSources; | 40 final Map<AssetId, AssetBasedSource> sharedSources; |
| 41 | 41 |
| 42 Resolvers.fromSdk(this.dartSdk, this.dartUriResolver, | 42 Resolvers.fromSdk(this.dartSdk, this.dartUriResolver, |
| 43 {this.options, bool useSharedSources}) | 43 {this.options, bool useSharedSources}) |
| 44 : sharedSources = useSharedSources == true ? <AssetId, dynamic>{} : null; | 44 : sharedSources = |
| 45 useSharedSources == true ? <AssetId, AssetBasedSource>{} : null; | |
| 45 | 46 |
| 46 factory Resolvers(dartSdkDirectory, | 47 factory Resolvers(dartSdkDirectory, |
| 47 {AnalysisOptions options, bool useSharedSources}) { | 48 {AnalysisOptions options, bool useSharedSources}) { |
| 48 _initAnalysisEngine(); | 49 _initAnalysisEngine(); |
| 49 var sdk = new DirectoryBasedDartSdkProxy(dartSdkDirectory); | 50 var sdk = new DirectoryBasedDartSdkProxy(dartSdkDirectory); |
| 50 var uriResolver = new DartUriResolverProxy(sdk); | 51 var uriResolver = new DartUriResolverProxy(sdk); |
| 51 return new Resolvers.fromSdk(sdk, uriResolver, | 52 return new Resolvers.fromSdk(sdk, uriResolver, |
| 52 options: options, useSharedSources: useSharedSources); | 53 options: options, useSharedSources: useSharedSources); |
| 53 } | 54 } |
| 54 | 55 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 /// | 87 /// |
| 87 /// To use mix this class in, set the resolvers field and override | 88 /// To use mix this class in, set the resolvers field and override |
| 88 /// [applyResolver]. | 89 /// [applyResolver]. |
| 89 abstract class ResolverTransformer implements Transformer { | 90 abstract class ResolverTransformer implements Transformer { |
| 90 /// The cache of resolvers- must be set from subclass. | 91 /// The cache of resolvers- must be set from subclass. |
| 91 Resolvers resolvers; | 92 Resolvers resolvers; |
| 92 | 93 |
| 93 /// See [Resolver#resolve] for more info - can be overridden by a subclass. | 94 /// See [Resolver#resolve] for more info - can be overridden by a subclass. |
| 94 bool get resolveAllLibraries => true; | 95 bool get resolveAllLibraries => true; |
| 95 | 96 |
| 96 /// By default only process prossible entry point assets. | 97 /// By default only process possible entry point assets. |
|
Siggi Cherem (dart-lang)
2016/03/25 00:20:59
wow, that's quite the strong mode! :)
Jennifer Messerly
2016/03/25 00:32:33
haha :)
| |
| 97 /// | 98 /// |
| 98 /// This is only a preliminary check based on the asset ID. | 99 /// This is only a preliminary check based on the asset ID. |
| 99 Future<bool> isPrimary(assetOrId) { | 100 Future<bool> isPrimary(assetOrId) { |
| 100 // assetOrId is to handle the transition from Asset to AssetID between | 101 // assetOrId is to handle the transition from Asset to AssetID between |
| 101 // pub 1.3 and 1.4. Once support for 1.3 is dropped this should only | 102 // pub 1.3 and 1.4. Once support for 1.3 is dropped this should only |
| 102 // support AssetId. | 103 // support AssetId. |
| 103 var id = assetOrId is AssetId ? assetOrId : assetOrId.id; | 104 var id = assetOrId is AssetId ? assetOrId : (assetOrId as Asset).id; |
| 104 return new Future.value(isPossibleDartEntryId(id)); | 105 return new Future.value(isPossibleDartEntryId(id)); |
| 105 } | 106 } |
| 106 | 107 |
| 107 /// Check to see if this should apply with the resolver on the provided asset. | 108 /// Check to see if this should apply with the resolver on the provided asset. |
| 108 /// | 109 /// |
| 109 /// By default this will only apply on possible Dart entry points (see | 110 /// By default this will only apply on possible Dart entry points (see |
| 110 /// [isPossibleDartEntry]). | 111 /// [isPossibleDartEntry]). |
| 111 Future<bool> shouldApplyResolver(Asset asset) => isPossibleDartEntry(asset); | 112 Future<bool> shouldApplyResolver(Asset asset) => isPossibleDartEntry(asset); |
| 112 | 113 |
| 113 /// This provides a default implementation of `Transformer.apply` that will | 114 /// This provides a default implementation of `Transformer.apply` that will |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 /// Return a Future to indicate when apply is completed. | 149 /// Return a Future to indicate when apply is completed. |
| 149 applyResolver(Transform transform, Resolver resolver); | 150 applyResolver(Transform transform, Resolver resolver); |
| 150 } | 151 } |
| 151 | 152 |
| 152 bool _analysisEngineInitialized = false; | 153 bool _analysisEngineInitialized = false; |
| 153 _initAnalysisEngine() { | 154 _initAnalysisEngine() { |
| 154 if (_analysisEngineInitialized) return; | 155 if (_analysisEngineInitialized) return; |
| 155 _analysisEngineInitialized = true; | 156 _analysisEngineInitialized = true; |
| 156 AnalysisEngine.instance.processRequiredPlugins(); | 157 AnalysisEngine.instance.processRequiredPlugins(); |
| 157 } | 158 } |
| OLD | NEW |