Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Side by Side Diff: pkg/code_transformers/lib/src/resolvers.dart

Issue 431443003: Exposing code_transformer's Resolvers options (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/code_transformers/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/sdk.dart' show DartSdk; 11 import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
11 import 'package:analyzer/src/generated/source.dart' show DartUriResolver; 12 import 'package:analyzer/src/generated/source.dart' show DartUriResolver;
12 13
13 import 'entry_point.dart'; 14 import 'entry_point.dart';
14 import 'resolver.dart'; 15 import 'resolver.dart';
15 import 'resolver_impl.dart'; 16 import 'resolver_impl.dart';
16 import 'dart_sdk.dart' hide dartSdkDirectory; 17 import 'dart_sdk.dart' hide dartSdkDirectory;
17 18
18 /// Barback-based code resolvers which maintains up-to-date resolved ASTs for 19 /// Barback-based code resolvers which maintains up-to-date resolved ASTs for
19 /// the specified code entry points. 20 /// the specified code entry points.
20 /// 21 ///
21 /// This can used by transformers dependent on resolved ASTs to handle the 22 /// This can used by transformers dependent on resolved ASTs to handle the
22 /// resolution of the AST and cache the results between compilations. 23 /// resolution of the AST and cache the results between compilations.
23 /// 24 ///
24 /// If multiple transformers rely on a resolved AST they should (ideally) share 25 /// If multiple transformers rely on a resolved AST they should (ideally) share
25 /// the same Resolvers object to minimize re-parsing the AST. 26 /// the same Resolvers object to minimize re-parsing the AST.
26 class Resolvers { 27 class Resolvers {
27 final Map<AssetId, Resolver> _resolvers = {}; 28 final Map<AssetId, Resolver> _resolvers = {};
28 final DartSdk dartSdk; 29 final DartSdk dartSdk;
29 final DartUriResolver dartUriResolver; 30 final DartUriResolver dartUriResolver;
31 final AnalysisOptions options;
30 32
31 Resolvers.fromSdk(this.dartSdk, this.dartUriResolver); 33 Resolvers.fromSdk(this.dartSdk, this.dartUriResolver, {this.options});
32 34
33 factory Resolvers(dartSdkDirectory) { 35 factory Resolvers(dartSdkDirectory, {AnalysisOptions options}) {
34 var sdk = new DirectoryBasedDartSdkProxy(dartSdkDirectory); 36 var sdk = new DirectoryBasedDartSdkProxy(dartSdkDirectory);
35 var uriResolver = new DartUriResolverProxy(sdk); 37 var uriResolver = new DartUriResolverProxy(sdk);
36 return new Resolvers.fromSdk(sdk, uriResolver); 38 return new Resolvers.fromSdk(sdk, uriResolver, options: options);
37 } 39 }
38 40
39 factory Resolvers.fromMock(Map<String, String> sources, 41 factory Resolvers.fromMock(Map<String, String> sources,
40 {bool reportMissing: false}) { 42 {bool reportMissing: false, AnalysisOptions options}) {
41 var sdk = new MockDartSdk(sources, reportMissing: reportMissing); 43 var sdk = new MockDartSdk(sources, reportMissing: reportMissing);
42 return new Resolvers.fromSdk(sdk, sdk.resolver); 44 return new Resolvers.fromSdk(sdk, sdk.resolver, options: options);
43 } 45 }
44 46
45 /// Get a resolver for [transform]. If provided, this resolves the code 47 /// Get a resolver for [transform]. If provided, this resolves the code
46 /// starting from each of the assets in [entryPoints]. If not, this resolves 48 /// starting from each of the assets in [entryPoints]. If not, this resolves
47 /// the code starting from `transform.primaryInput.id` by default. 49 /// the code starting from `transform.primaryInput.id` by default.
48 /// 50 ///
49 /// [Resolver.release] must be called once it's done being used, or 51 /// [Resolver.release] must be called once it's done being used, or
50 /// [ResolverTransformer] should be used to automatically release the 52 /// [ResolverTransformer] should be used to automatically release the
51 /// resolver. 53 /// resolver.
52 Future<Resolver> get(Transform transform, [List<AssetId> entryPoints]) { 54 Future<Resolver> get(Transform transform, [List<AssetId> entryPoints]) {
53 var id = transform.primaryInput.id; 55 var id = transform.primaryInput.id;
54 var resolver = _resolvers.putIfAbsent(id, 56 var resolver = _resolvers.putIfAbsent(id,
55 () => new ResolverImpl(dartSdk, dartUriResolver)); 57 () => new ResolverImpl(dartSdk, dartUriResolver, options: options));
56 return resolver.resolve(transform, entryPoints); 58 return resolver.resolve(transform, entryPoints);
57 } 59 }
58 } 60 }
59 61
60 /// Transformer mixin which automatically gets and releases resolvers. 62 /// Transformer mixin which automatically gets and releases resolvers.
61 /// 63 ///
62 /// To use mix this class in, set the resolvers field and override 64 /// To use mix this class in, set the resolvers field and override
63 /// [applyResolver]. 65 /// [applyResolver].
64 abstract class ResolverTransformer implements Transformer { 66 abstract class ResolverTransformer implements Transformer {
65 /// The cache of resolvers- must be set from subclass. 67 /// The cache of resolvers- must be set from subclass.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 resolver.release(); 115 resolver.release();
114 }); 116 });
115 }); 117 });
116 } 118 }
117 119
118 /// Invoked when the resolver is ready to be processed. 120 /// Invoked when the resolver is ready to be processed.
119 /// 121 ///
120 /// Return a Future to indicate when apply is completed. 122 /// Return a Future to indicate when apply is completed.
121 applyResolver(Transform transform, Resolver resolver); 123 applyResolver(Transform transform, Resolver resolver);
122 } 124 }
OLDNEW
« no previous file with comments | « no previous file | pkg/code_transformers/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698