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

Side by Side Diff: lib/src/analyzer/context.dart

Issue 2183603003: Working compiler in browser. (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Git merged master Created 4 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
« no previous file with comments | « no previous file | lib/src/compiler/compiler.dart » ('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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 2
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver; 6 import 'package:args/args.dart' show ArgParser, ArgResults;
7 import 'package:analyzer/file_system/file_system.dart'
8 show ResourceProvider, ResourceUriResolver;
7 import 'package:analyzer/file_system/physical_file_system.dart' 9 import 'package:analyzer/file_system/physical_file_system.dart'
8 show PhysicalResourceProvider; 10 show PhysicalResourceProvider;
9 import 'package:args/args.dart' show ArgParser, ArgResults;
10 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl; 11 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl;
11 import 'package:analyzer/src/generated/engine.dart' 12 import 'package:analyzer/src/generated/engine.dart'
12 show AnalysisContext, AnalysisEngine, AnalysisOptionsImpl; 13 show AnalysisContext, AnalysisEngine, AnalysisOptionsImpl;
13 import 'package:analyzer/src/generated/java_io.dart' show JavaFile; 14 import 'package:analyzer/src/generated/java_io.dart' show JavaFile;
14 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; 15 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk;
16 import 'package:analyzer/src/generated/source.dart';
15 import 'package:analyzer/src/generated/source_io.dart' 17 import 'package:analyzer/src/generated/source_io.dart'
16 show 18 show
17 CustomUriResolver, 19 CustomUriResolver,
18 DartUriResolver, 20 DartUriResolver,
19 PackageUriResolver, 21 PackageUriResolver,
20 SourceFactory, 22 SourceFactory,
21 UriResolver; 23 UriResolver;
22 import 'package:analyzer/src/summary/package_bundle_reader.dart' 24 import 'package:analyzer/src/summary/package_bundle_reader.dart'
23 show 25 show
24 InSummaryPackageUriResolver, 26 InSummaryPackageUriResolver,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 mappings[splitMapping[0]] = path.absolute(splitMapping[1]); 102 mappings[splitMapping[0]] = path.absolute(splitMapping[1]);
101 } 103 }
102 } 104 }
103 return mappings; 105 return mappings;
104 } 106 }
105 } 107 }
106 108
107 /// Creates an [AnalysisContext] with dev_compiler type rules and inference, 109 /// Creates an [AnalysisContext] with dev_compiler type rules and inference,
108 /// using [createSourceFactory] to set up its [SourceFactory]. 110 /// using [createSourceFactory] to set up its [SourceFactory].
109 AnalysisContext createAnalysisContextWithSources(AnalyzerOptions options, 111 AnalysisContext createAnalysisContextWithSources(AnalyzerOptions options,
110 {DartUriResolver sdkResolver, List<UriResolver> fileResolvers}) { 112 {DartUriResolver sdkResolver,
113 List<UriResolver> fileResolvers,
114 ResourceProvider resourceProvider}) {
111 AnalysisEngine.instance.processRequiredPlugins(); 115 AnalysisEngine.instance.processRequiredPlugins();
112 116
113 sdkResolver ??= 117 sdkResolver ??=
114 createSdkPathResolver(options.dartSdkSummaryPath, options.dartSdkPath); 118 createSdkPathResolver(options.dartSdkSummaryPath, options.dartSdkPath);
115 119
116 // Read the summaries. 120 // Read the summaries.
117 SummaryDataStore summaryData; 121 SummaryDataStore summaryData;
118 if (options.summaryPaths.isNotEmpty) { 122 if (options.summaryPaths.isNotEmpty) {
119 summaryData = new SummaryDataStore(options.summaryPaths); 123 summaryData = new SummaryDataStore(options.summaryPaths);
120 } 124 }
121 125
122 var srcFactory = _createSourceFactory(options, 126 var srcFactory = _createSourceFactory(options,
123 sdkResolver: sdkResolver, 127 sdkResolver: sdkResolver,
124 fileResolvers: fileResolvers, 128 fileResolvers: fileResolvers,
125 summaryData: summaryData); 129 summaryData: summaryData,
130 resourceProvider: resourceProvider);
126 131
127 var context = createAnalysisContext(); 132 var context = createAnalysisContext();
128 context.sourceFactory = srcFactory; 133 context.sourceFactory = srcFactory;
129 if (summaryData != null) { 134 if (summaryData != null) {
130 context.typeProvider = sdkResolver.dartSdk.context.typeProvider; 135 context.typeProvider = sdkResolver.dartSdk.context.typeProvider;
131 context.resultProvider = 136 context.resultProvider =
132 new InputPackagesResultProvider(context, summaryData); 137 new InputPackagesResultProvider(context, summaryData);
133 } 138 }
134 return context; 139 return context;
135 } 140 }
(...skipping 10 matching lines...) Expand all
146 /// Creates a SourceFactory configured by the [options]. 151 /// Creates a SourceFactory configured by the [options].
147 /// 152 ///
148 /// Use [options.useMockSdk] to specify the SDK mode, or use [sdkResolver] 153 /// Use [options.useMockSdk] to specify the SDK mode, or use [sdkResolver]
149 /// to entirely override the DartUriResolver. 154 /// to entirely override the DartUriResolver.
150 /// 155 ///
151 /// If supplied, [fileResolvers] will override the default `file:` and 156 /// If supplied, [fileResolvers] will override the default `file:` and
152 /// `package:` URI resolvers. 157 /// `package:` URI resolvers.
153 SourceFactory _createSourceFactory(AnalyzerOptions options, 158 SourceFactory _createSourceFactory(AnalyzerOptions options,
154 {DartUriResolver sdkResolver, 159 {DartUriResolver sdkResolver,
155 List<UriResolver> fileResolvers, 160 List<UriResolver> fileResolvers,
156 SummaryDataStore summaryData}) { 161 SummaryDataStore summaryData,
162 ResourceProvider resourceProvider}) {
157 var resolvers = <UriResolver>[]; 163 var resolvers = <UriResolver>[];
158 if (options.customUrlMappings.isNotEmpty) { 164 if (options.customUrlMappings.isNotEmpty) {
159 resolvers.add(new CustomUriResolver(options.customUrlMappings)); 165 resolvers.add(new CustomUriResolver(options.customUrlMappings));
160 } 166 }
161 resolvers.add(sdkResolver); 167 resolvers.add(sdkResolver);
162 if (summaryData != null) { 168 if (summaryData != null) {
163 resolvers.add(new InSummaryPackageUriResolver(summaryData)); 169 resolvers.add(new InSummaryPackageUriResolver(summaryData));
164 } 170 }
165 171
166 if (fileResolvers == null) fileResolvers = createFileResolvers(options); 172 if (fileResolvers == null) fileResolvers = createFileResolvers(options);
167 resolvers.addAll(fileResolvers); 173 resolvers.addAll(fileResolvers);
168 return new SourceFactory(resolvers); 174 return new SourceFactory(resolvers, null, resourceProvider);
169 } 175 }
170 176
171 List<UriResolver> createFileResolvers(AnalyzerOptions options) { 177 List<UriResolver> createFileResolvers(AnalyzerOptions options) {
172 return [ 178 return [
173 new ResourceUriResolver(PhysicalResourceProvider.INSTANCE), 179 new ResourceUriResolver(PhysicalResourceProvider.INSTANCE),
174 options.useMultiPackage 180 options.useMultiPackage
175 ? new MultiPackageResolver(options.packagePaths) 181 ? new MultiPackageResolver(options.packagePaths)
176 : new PackageUriResolver([new JavaFile(options.packageRoot)]) 182 : new PackageUriResolver([new JavaFile(options.packageRoot)])
177 ]; 183 ];
178 } 184 }
179 185
180 DirectoryBasedDartSdk _createDirectoryBasedDartSdk(String sdkPath) { 186 DirectoryBasedDartSdk _createDirectoryBasedDartSdk(String sdkPath) {
181 var sdk = new DirectoryBasedDartSdk( 187 var sdk = new DirectoryBasedDartSdk(
182 new JavaFile(sdkPath), /*useDart2jsPaths:*/ true); 188 new JavaFile(sdkPath), /*useDart2jsPaths:*/ true);
183 sdk.useSummary = true; 189 sdk.useSummary = true;
184 sdk.analysisOptions = new AnalysisOptionsImpl()..strongMode = true; 190 sdk.analysisOptions = new AnalysisOptionsImpl()..strongMode = true;
185 return sdk; 191 return sdk;
186 } 192 }
187 193
188 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. 194 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath].
189 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) { 195 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) {
190 var sdk = (sdkSummaryPath != null) 196 var sdk = (sdkSummaryPath != null)
191 ? new SummaryBasedDartSdk(sdkSummaryPath, true) 197 ? new SummaryBasedDartSdk(sdkSummaryPath, true)
192 : _createDirectoryBasedDartSdk(sdkPath); 198 : _createDirectoryBasedDartSdk(sdkPath);
193 return new DartUriResolver(sdk); 199 return new DartUriResolver(sdk);
194 } 200 }
OLDNEW
« no previous file with comments | « no previous file | lib/src/compiler/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698