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

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

Issue 1591653003: plumb through enableAsync (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: remove work-in-progress Created 4 years, 11 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 | pkg/analyzer/lib/src/task/dart.dart » ('j') | pkg/analyzer/lib/src/task/dart.dart » ('J')
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.context.context; 5 library analyzer.src.context.context;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
11 import 'package:analyzer/dart/element/type.dart';
11 import 'package:analyzer/instrumentation/instrumentation.dart'; 12 import 'package:analyzer/instrumentation/instrumentation.dart';
12 import 'package:analyzer/plugin/task.dart'; 13 import 'package:analyzer/plugin/task.dart';
13 import 'package:analyzer/source/embedder.dart'; 14 import 'package:analyzer/source/embedder.dart';
14 import 'package:analyzer/src/cancelable_future.dart'; 15 import 'package:analyzer/src/cancelable_future.dart';
15 import 'package:analyzer/src/context/cache.dart'; 16 import 'package:analyzer/src/context/cache.dart';
16 import 'package:analyzer/src/dart/element/element.dart'; 17 import 'package:analyzer/src/dart/element/element.dart';
18 import 'package:analyzer/src/dart/element/type.dart';
17 import 'package:analyzer/src/generated/ast.dart'; 19 import 'package:analyzer/src/generated/ast.dart';
18 import 'package:analyzer/src/generated/constant.dart'; 20 import 'package:analyzer/src/generated/constant.dart';
19 import 'package:analyzer/src/generated/engine.dart'; 21 import 'package:analyzer/src/generated/engine.dart';
20 import 'package:analyzer/src/generated/error.dart'; 22 import 'package:analyzer/src/generated/error.dart';
21 import 'package:analyzer/src/generated/incremental_resolver.dart'; 23 import 'package:analyzer/src/generated/incremental_resolver.dart';
22 import 'package:analyzer/src/generated/java_core.dart'; 24 import 'package:analyzer/src/generated/java_core.dart';
23 import 'package:analyzer/src/generated/java_engine.dart'; 25 import 'package:analyzer/src/generated/java_engine.dart';
24 import 'package:analyzer/src/generated/resolver.dart'; 26 import 'package:analyzer/src/generated/resolver.dart';
25 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; 27 import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
26 import 'package:analyzer/src/generated/source.dart'; 28 import 'package:analyzer/src/generated/source.dart';
29 import 'package:analyzer/src/generated/testing/ast_factory.dart';
27 import 'package:analyzer/src/generated/utilities_collection.dart'; 30 import 'package:analyzer/src/generated/utilities_collection.dart';
28 import 'package:analyzer/src/task/dart.dart'; 31 import 'package:analyzer/src/task/dart.dart';
29 import 'package:analyzer/src/task/dart_work_manager.dart'; 32 import 'package:analyzer/src/task/dart_work_manager.dart';
30 import 'package:analyzer/src/task/driver.dart'; 33 import 'package:analyzer/src/task/driver.dart';
31 import 'package:analyzer/src/task/incremental_element_builder.dart'; 34 import 'package:analyzer/src/task/incremental_element_builder.dart';
32 import 'package:analyzer/src/task/manager.dart'; 35 import 'package:analyzer/src/task/manager.dart';
33 import 'package:analyzer/task/dart.dart'; 36 import 'package:analyzer/task/dart.dart';
34 import 'package:analyzer/task/general.dart'; 37 import 'package:analyzer/task/general.dart';
35 import 'package:analyzer/task/html.dart'; 38 import 'package:analyzer/task/html.dart';
36 import 'package:analyzer/task/model.dart'; 39 import 'package:analyzer/task/model.dart';
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 return _typeProvider; 455 return _typeProvider;
453 } 456 }
454 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE); 457 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE);
455 if (coreSource == null) { 458 if (coreSource == null) {
456 throw new AnalysisException("Could not create a source for dart:core"); 459 throw new AnalysisException("Could not create a source for dart:core");
457 } 460 }
458 LibraryElement coreElement = computeLibraryElement(coreSource); 461 LibraryElement coreElement = computeLibraryElement(coreSource);
459 if (coreElement == null) { 462 if (coreElement == null) {
460 throw new AnalysisException("Could not create an element for dart:core"); 463 throw new AnalysisException("Could not create an element for dart:core");
461 } 464 }
462 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); 465 LibraryElement asyncElement;
463 if (asyncSource == null) { 466 if (analysisOptions.enableAsync) {
464 throw new AnalysisException("Could not create a source for dart:async"); 467 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC);
465 } 468 if (asyncSource == null) {
466 LibraryElement asyncElement = computeLibraryElement(asyncSource); 469 throw new AnalysisException("Could not create a source for dart:async");
467 if (asyncElement == null) { 470 }
468 throw new AnalysisException("Could not create an element for dart:async"); 471 asyncElement = computeLibraryElement(asyncSource);
472 if (asyncElement == null) {
473 throw new AnalysisException(
474 "Could not create an element for dart:async");
475 }
476 } else {
477 asyncElement = createMockAsyncLib(coreElement);
469 } 478 }
470 _typeProvider = new TypeProviderImpl(coreElement, asyncElement); 479 _typeProvider = new TypeProviderImpl(coreElement, asyncElement);
471 return _typeProvider; 480 return _typeProvider;
472 } 481 }
473 482
474 /** 483 /**
475 * Sets the [TypeProvider] for this context. 484 * Sets the [TypeProvider] for this context.
476 */ 485 */
477 void set typeProvider(TypeProvider typeProvider) { 486 void set typeProvider(TypeProvider typeProvider) {
478 _typeProvider = typeProvider; 487 _typeProvider = typeProvider;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 DartSdk sdk = factory.dartSdk; 677 DartSdk sdk = factory.dartSdk;
669 if (sdk == null) { 678 if (sdk == null) {
670 return new AnalysisCache(<CachePartition>[_privatePartition]); 679 return new AnalysisCache(<CachePartition>[_privatePartition]);
671 } 680 }
672 return new AnalysisCache(<CachePartition>[ 681 return new AnalysisCache(<CachePartition>[
673 AnalysisEngine.instance.partitionManager.forSdk(sdk), 682 AnalysisEngine.instance.partitionManager.forSdk(sdk),
674 _privatePartition 683 _privatePartition
675 ]); 684 ]);
676 } 685 }
677 686
687 /**
688 * Create a minimalistic mock dart:async library
689 * to stand in for a real one if one does not exist
690 * facilitating creation a type provider without dart:async.
691 */
692 LibraryElement createMockAsyncLib(LibraryElement coreLibrary) {
693 InterfaceType objType = coreLibrary.getType('Object').type;
694
695 ClassElement _classElement(String typeName, [List<String> parameterNames]) {
696 ClassElementImpl element =
697 new ClassElementImpl.forNode(AstFactory.identifier3(typeName));
698 element.supertype = objType;
699 InterfaceTypeImpl type = new InterfaceTypeImpl(element);
700 element.type = type;
701 if (parameterNames != null) {
702 int count = parameterNames.length;
703 if (count > 0) {
704 List<TypeParameterElementImpl> typeParameters =
705 new List<TypeParameterElementImpl>(count);
706 List<TypeParameterTypeImpl> typeArguments =
707 new List<TypeParameterTypeImpl>(count);
708 for (int i = 0; i < count; i++) {
709 TypeParameterElementImpl typeParameter =
710 new TypeParameterElementImpl.forNode(
711 AstFactory.identifier3(parameterNames[i]));
712 typeParameters[i] = typeParameter;
713 typeArguments[i] = new TypeParameterTypeImpl(typeParameter);
714 typeParameter.type = typeArguments[i];
715 }
716 element.typeParameters = typeParameters;
717 type.typeArguments = typeArguments;
718 }
719 }
720 return element;
721 }
722
723 InterfaceType futureType = _classElement('Future', ['T']).type;
724 InterfaceType streamType = _classElement('Stream', ['T']).type;
725 CompilationUnitElementImpl asyncUnit =
726 new CompilationUnitElementImpl("async.dart");
Brian Wilkerson 2016/01/15 18:59:50 Do we ever use the file name to identify the libra
danrubel 2016/01/15 19:14:29 Good suggestion. Done.
727 asyncUnit.types = <ClassElement>[futureType.element, streamType.element];
728 LibraryElementImpl mockLib = new LibraryElementImpl.forNode(
729 this, AstFactory.libraryIdentifier2(["dart.async"]));
730 mockLib.definingCompilationUnit = asyncUnit;
731 mockLib.publicNamespace = new PublicNamespaceBuilder().build(mockLib);
732 return mockLib;
733 }
734
678 @override 735 @override
679 void dispose() { 736 void dispose() {
680 _disposed = true; 737 _disposed = true;
681 for (List<PendingFuture> pendingFutures in _pendingFutureTargets.values) { 738 for (List<PendingFuture> pendingFutures in _pendingFutureTargets.values) {
682 for (PendingFuture pendingFuture in pendingFutures) { 739 for (PendingFuture pendingFuture in pendingFutures) {
683 pendingFuture.forciblyComplete(); 740 pendingFuture.forciblyComplete();
684 } 741 }
685 } 742 }
686 _pendingFutureTargets.clear(); 743 _pendingFutureTargets.clear();
687 _privatePartition.dispose(); 744 _privatePartition.dispose();
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after
2033 } 2090 }
2034 DartSdk sdk = factory.dartSdk; 2091 DartSdk sdk = factory.dartSdk;
2035 if (sdk == null) { 2092 if (sdk == null) {
2036 throw new IllegalArgumentException( 2093 throw new IllegalArgumentException(
2037 "The source factory for an SDK analysis context must have a DartUriRes olver"); 2094 "The source factory for an SDK analysis context must have a DartUriRes olver");
2038 } 2095 }
2039 return new AnalysisCache( 2096 return new AnalysisCache(
2040 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); 2097 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]);
2041 } 2098 }
2042 } 2099 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/dart.dart » ('j') | pkg/analyzer/lib/src/task/dart.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698