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

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

Issue 2668473002: Allow SDKs to be analyzed that lack a definition of FutureOr<T>. (Closed)
Patch Set: Created 3 years, 10 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 | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | 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 // 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/file_system/file_system.dart' show ResourceProvider; 9 import 'package:analyzer/file_system/file_system.dart' show ResourceProvider;
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/generated/testing/element_factory.dart';
18 import 'package:analyzer/src/summary/idl.dart'; 19 import 'package:analyzer/src/summary/idl.dart';
19 import 'package:analyzer/src/summary/package_bundle_reader.dart'; 20 import 'package:analyzer/src/summary/package_bundle_reader.dart';
20 21
21 /** 22 /**
22 * An implementation of [DartSdk] which provides analysis results for `dart:` 23 * An implementation of [DartSdk] which provides analysis results for `dart:`
23 * libraries from the given summary file. This implementation is limited and 24 * libraries from the given summary file. This implementation is limited and
24 * suitable only for command-line tools, but not for IDEs - it does not 25 * suitable only for command-line tools, but not for IDEs - it does not
25 * implement [sdkLibraries], [sdkVersion], [uris] and [fromFileUri]. 26 * implement [sdkLibraries], [sdkVersion], [uris] and [fromFileUri].
26 */ 27 */
27 class SummaryBasedDartSdk implements DartSdk { 28 class SummaryBasedDartSdk implements DartSdk {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 @override 186 @override
186 InterfaceType get futureNullType { 187 InterfaceType get futureNullType {
187 assert(_asyncLibrary != null); 188 assert(_asyncLibrary != null);
188 _futureNullType ??= futureType.instantiate(<DartType>[nullType]); 189 _futureNullType ??= futureType.instantiate(<DartType>[nullType]);
189 return _futureNullType; 190 return _futureNullType;
190 } 191 }
191 192
192 @override 193 @override
193 InterfaceType get futureOrType { 194 InterfaceType get futureOrType {
194 assert(_asyncLibrary != null); 195 assert(_asyncLibrary != null);
195 _futureOrType ??= _getType(_asyncLibrary, "FutureOr"); 196 try {
197 _futureOrType ??= _getType(_asyncLibrary, "FutureOr");
198 } on StateError {
199 // FutureOr<T> is still fairly new, so if we're analyzing an SDK that
200 // doesn't have it yet, create an element for it.
201 _futureOrType =
202 TypeProviderImpl.createPlaceholderFutureOr(futureType, objectType);
203 }
196 return _futureOrType; 204 return _futureOrType;
197 } 205 }
198 206
199 @override 207 @override
200 InterfaceType get futureType { 208 InterfaceType get futureType {
201 assert(_asyncLibrary != null); 209 assert(_asyncLibrary != null);
202 _futureType ??= _getType(_asyncLibrary, "Future"); 210 _futureType ??= _getType(_asyncLibrary, "Future");
203 return _futureType; 211 return _futureType;
204 } 212 }
205 213
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 * throw a [StateError] if there is no class with the given name. 343 * throw a [StateError] if there is no class with the given name.
336 */ 344 */
337 InterfaceType _getType(LibraryElement library, String name) { 345 InterfaceType _getType(LibraryElement library, String name) {
338 Element element = library.getType(name); 346 Element element = library.getType(name);
339 if (element == null) { 347 if (element == null) {
340 throw new StateError("No definition of type $name"); 348 throw new StateError("No definition of type $name");
341 } 349 }
342 return (element as ClassElement).type; 350 return (element as ClassElement).type;
343 } 351 }
344 } 352 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698