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

Side by Side Diff: pkg/analyzer/lib/src/summary/summary_sdk.dart

Issue 2176363002: Removed io dependencies in analyzer to allow compiler to run in the browser (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Refactored summary_sdk 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
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 // 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.summary.summary_sdk; 5 library analyzer.src.summary.summary_sdk;
6 6
7 import 'package:analyzer/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/dart/element/type.dart'; 8 import 'package:analyzer/dart/element/type.dart';
9 import 'package:analyzer/src/context/cache.dart' show CacheEntry; 9 import 'package:analyzer/src/context/cache.dart' show CacheEntry;
10 import 'package:analyzer/src/context/context.dart'; 10 import 'package:analyzer/src/context/context.dart';
11 import 'package:analyzer/src/dart/element/type.dart'; 11 import 'package:analyzer/src/dart/element/type.dart';
12 import 'package:analyzer/src/generated/constant.dart'; 12 import 'package:analyzer/src/generated/constant.dart';
13 import 'package:analyzer/src/generated/engine.dart'; 13 import 'package:analyzer/src/generated/engine.dart';
14 import 'package:analyzer/src/generated/resolver.dart'; 14 import 'package:analyzer/src/generated/resolver.dart';
15 import 'package:analyzer/src/generated/sdk.dart'; 15 import 'package:analyzer/src/generated/sdk.dart';
16 import 'package:analyzer/src/generated/source.dart' 16 import 'package:analyzer/src/generated/source.dart'
17 show DartUriResolver, Source, SourceFactory; 17 show DartUriResolver, Source, SourceFactory;
18 import 'package:analyzer/src/summary/idl.dart'; 18 import 'package:analyzer/src/summary/idl.dart';
19 import 'package:analyzer/src/summary/package_bundle_reader.dart'; 19 import 'package:analyzer/src/summary/package_bundle_reader.dart';
20 import 'package:analyzer/src/summary/resynthesize.dart'; 20 import 'package:analyzer/src/summary/resynthesize.dart';
21 import 'package:analyzer/src/task/dart.dart'; 21 import 'package:analyzer/src/task/dart.dart';
22 import 'package:analyzer/task/model.dart' show ResultDescriptor, TargetedResult; 22 import 'package:analyzer/task/model.dart' show ResultDescriptor, TargetedResult;
23 import 'package:analyzer/file_system/file_system.dart' show ResourceProvider;
23 24
24 class SdkSummaryResultProvider extends ResynthesizerResultProvider { 25 class SdkSummaryResultProvider extends ResynthesizerResultProvider {
25 final SummaryTypeProvider typeProvider = new SummaryTypeProvider(); 26 final SummaryTypeProvider typeProvider = new SummaryTypeProvider();
26 27
27 SdkSummaryResultProvider( 28 SdkSummaryResultProvider(
28 InternalAnalysisContext context, PackageBundle bundle, bool strongMode) 29 InternalAnalysisContext context, PackageBundle bundle, bool strongMode)
29 : super(context, new SummaryDataStore(const <String>[])) { 30 : super(context, new SummaryDataStore(const <String>[])) {
30 addBundle(null, bundle); 31 addBundle(null, bundle);
31 createResynthesizer(null, typeProvider); 32 createResynthesizer(null, typeProvider);
32 _buildCoreLibrary(); 33 _buildCoreLibrary();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 * An implementation of [DartSdk] which provides analysis results for `dart:` 100 * An implementation of [DartSdk] which provides analysis results for `dart:`
100 * libraries from the given summary file. This implementation is limited and 101 * libraries from the given summary file. This implementation is limited and
101 * suitable only for command-line tools, but not for IDEs - it does not 102 * suitable only for command-line tools, but not for IDEs - it does not
102 * implement [sdkLibraries], [sdkVersion], [uris] and [fromFileUri]. 103 * implement [sdkLibraries], [sdkVersion], [uris] and [fromFileUri].
103 */ 104 */
104 class SummaryBasedDartSdk implements DartSdk { 105 class SummaryBasedDartSdk implements DartSdk {
105 final bool strongMode; 106 final bool strongMode;
106 SummaryDataStore _dataStore; 107 SummaryDataStore _dataStore;
107 InSummaryPackageUriResolver _uriResolver; 108 InSummaryPackageUriResolver _uriResolver;
108 PackageBundle _bundle; 109 PackageBundle _bundle;
110 ResourceProvider resourceProvider;
109 111
110 /** 112 /**
111 * The [AnalysisContext] which is used for all of the sources in this sdk. 113 * The [AnalysisContext] which is used for all of the sources in this sdk.
112 */ 114 */
113 InternalAnalysisContext _analysisContext; 115 InternalAnalysisContext _analysisContext;
114 116
115 SummaryBasedDartSdk(String summaryPath, this.strongMode) { 117 SummaryBasedDartSdk(String summaryPath, this.strongMode,
Paul Berry 2016/07/26 21:16:22 Rather than have one constructor with two differen
priscillalee 2016/07/26 21:32:48 Done.
116 _dataStore = new SummaryDataStore(<String>[summaryPath]); 118 [PackageBundle bundle, this.resourceProvider]) {
119 if (summaryPath != null) {
120 _dataStore = new SummaryDataStore(<String>[summaryPath]);
121 } else {
122 _dataStore = new SummaryDataStore([], bundle);
123 }
117 _uriResolver = new InSummaryPackageUriResolver(_dataStore); 124 _uriResolver = new InSummaryPackageUriResolver(_dataStore);
118 _bundle = _dataStore.bundles.single; 125 _bundle = _dataStore.bundles.single;
119 } 126 }
120 127
121 /** 128 /**
122 * Return the [PackageBundle] for this SDK, not `null`. 129 * Return the [PackageBundle] for this SDK, not `null`.
123 */ 130 */
124 PackageBundle get bundle => _bundle; 131 PackageBundle get bundle => _bundle;
125 132
126 @override 133 @override
127 AnalysisContext get context { 134 AnalysisContext get context {
128 if (_analysisContext == null) { 135 if (_analysisContext == null) {
129 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl() 136 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl()
130 ..strongMode = strongMode; 137 ..strongMode = strongMode;
131 _analysisContext = new SdkAnalysisContext(analysisOptions); 138 _analysisContext = new SdkAnalysisContext(analysisOptions);
132 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); 139 SourceFactory factory = new SourceFactory(
140 [new DartUriResolver(this)], null, resourceProvider);
133 _analysisContext.sourceFactory = factory; 141 _analysisContext.sourceFactory = factory;
134 _analysisContext.resultProvider = 142 _analysisContext.resultProvider =
135 new SdkSummaryResultProvider(_analysisContext, _bundle, strongMode); 143 new SdkSummaryResultProvider(_analysisContext, _bundle, strongMode);
136 } 144 }
137 return _analysisContext; 145 return _analysisContext;
138 } 146 }
139 147
140 @override 148 @override
141 List<SdkLibrary> get sdkLibraries { 149 List<SdkLibrary> get sdkLibraries {
142 throw new UnimplementedError(); 150 throw new UnimplementedError();
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 * throw a [StateError] if there is no class with the given name. 407 * throw a [StateError] if there is no class with the given name.
400 */ 408 */
401 InterfaceType _getType(LibraryElement library, String name) { 409 InterfaceType _getType(LibraryElement library, String name) {
402 Element element = library.getType(name); 410 Element element = library.getType(name);
403 if (element == null) { 411 if (element == null) {
404 throw new StateError("No definition of type $name"); 412 throw new StateError("No definition of type $name");
405 } 413 }
406 return (element as ClassElement).type; 414 return (element as ClassElement).type;
407 } 415 }
408 } 416 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698