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

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

Issue 2044383003: Issue 26639. Set source for mock 'dart:async' library. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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') | 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.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/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 assert(!driver.isTaskRunning); 480 assert(!driver.isTaskRunning);
481 481
482 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE); 482 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE);
483 if (coreSource == null) { 483 if (coreSource == null) {
484 throw new AnalysisException("Could not create a source for dart:core"); 484 throw new AnalysisException("Could not create a source for dart:core");
485 } 485 }
486 LibraryElement coreElement = computeLibraryElement(coreSource); 486 LibraryElement coreElement = computeLibraryElement(coreSource);
487 if (coreElement == null) { 487 if (coreElement == null) {
488 throw new AnalysisException("Could not create an element for dart:core"); 488 throw new AnalysisException("Could not create an element for dart:core");
489 } 489 }
490
490 LibraryElement asyncElement; 491 LibraryElement asyncElement;
491 if (analysisOptions.enableAsync) { 492 if (analysisOptions.enableAsync) {
492 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); 493 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC);
493 if (asyncSource == null) { 494 if (asyncSource == null) {
494 throw new AnalysisException("Could not create a source for dart:async"); 495 throw new AnalysisException("Could not create a source for dart:async");
495 } 496 }
496 asyncElement = computeLibraryElement(asyncSource); 497 asyncElement = computeLibraryElement(asyncSource);
497 if (asyncElement == null) { 498 if (asyncElement == null) {
498 throw new AnalysisException( 499 throw new AnalysisException(
499 "Could not create an element for dart:async"); 500 "Could not create an element for dart:async");
500 } 501 }
501 } else { 502 } else {
502 asyncElement = createMockAsyncLib(coreElement); 503 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC);
504 asyncElement = createMockAsyncLib(coreElement, asyncSource);
503 } 505 }
506
504 _typeProvider = new TypeProviderImpl(coreElement, asyncElement); 507 _typeProvider = new TypeProviderImpl(coreElement, asyncElement);
505 return _typeProvider; 508 return _typeProvider;
506 } 509 }
507 510
508 /** 511 /**
509 * Sets the [TypeProvider] for this context. 512 * Sets the [TypeProvider] for this context.
510 */ 513 */
511 @override 514 @override
512 void set typeProvider(TypeProvider typeProvider) { 515 void set typeProvider(TypeProvider typeProvider) {
513 _typeProvider = typeProvider; 516 _typeProvider = typeProvider;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 } 721 }
719 }); 722 });
720 return cache; 723 return cache;
721 } 724 }
722 725
723 /** 726 /**
724 * Create a minimalistic mock dart:async library 727 * Create a minimalistic mock dart:async library
725 * to stand in for a real one if one does not exist 728 * to stand in for a real one if one does not exist
726 * facilitating creation a type provider without dart:async. 729 * facilitating creation a type provider without dart:async.
727 */ 730 */
728 LibraryElement createMockAsyncLib(LibraryElement coreLibrary) { 731 LibraryElement createMockAsyncLib(LibraryElement coreLibrary, Source asyncSour ce) {
729 InterfaceType objType = coreLibrary.getType('Object').type; 732 InterfaceType objType = coreLibrary.getType('Object').type;
730 733
731 ClassElement _classElement(String typeName, [List<String> parameterNames]) { 734 ClassElement _classElement(String typeName, [List<String> parameterNames]) {
732 ClassElementImpl element = 735 ClassElementImpl element =
733 new ClassElementImpl.forNode(AstFactory.identifier3(typeName)); 736 new ClassElementImpl.forNode(AstFactory.identifier3(typeName));
734 element.supertype = objType; 737 element.supertype = objType;
735 if (parameterNames != null) { 738 if (parameterNames != null) {
736 int count = parameterNames.length; 739 int count = parameterNames.length;
737 if (count > 0) { 740 if (count > 0) {
738 List<TypeParameterElementImpl> typeParameters = 741 List<TypeParameterElementImpl> typeParameters =
(...skipping 14 matching lines...) Expand all
753 return element; 756 return element;
754 } 757 }
755 758
756 InterfaceType futureType = _classElement('Future', ['T']).type; 759 InterfaceType futureType = _classElement('Future', ['T']).type;
757 InterfaceType streamType = _classElement('Stream', ['T']).type; 760 InterfaceType streamType = _classElement('Stream', ['T']).type;
758 CompilationUnitElementImpl asyncUnit = 761 CompilationUnitElementImpl asyncUnit =
759 new CompilationUnitElementImpl("mock_async.dart"); 762 new CompilationUnitElementImpl("mock_async.dart");
760 asyncUnit.types = <ClassElement>[futureType.element, streamType.element]; 763 asyncUnit.types = <ClassElement>[futureType.element, streamType.element];
761 LibraryElementImpl mockLib = new LibraryElementImpl.forNode( 764 LibraryElementImpl mockLib = new LibraryElementImpl.forNode(
762 this, AstFactory.libraryIdentifier2(["dart.async"])); 765 this, AstFactory.libraryIdentifier2(["dart.async"]));
766 asyncUnit.librarySource = asyncSource;
767 asyncUnit.source = asyncSource;
763 mockLib.definingCompilationUnit = asyncUnit; 768 mockLib.definingCompilationUnit = asyncUnit;
764 mockLib.publicNamespace = 769 mockLib.publicNamespace =
765 new NamespaceBuilder().createPublicNamespaceForLibrary(mockLib); 770 new NamespaceBuilder().createPublicNamespaceForLibrary(mockLib);
766 return mockLib; 771 return mockLib;
767 } 772 }
768 773
769 @override 774 @override
770 void dispose() { 775 void dispose() {
771 _disposed = true; 776 _disposed = true;
772 for (List<PendingFuture> pendingFutures in _pendingFutureTargets.values) { 777 for (List<PendingFuture> pendingFutures in _pendingFutureTargets.values) {
(...skipping 1443 matching lines...) Expand 10 before | Expand all | Expand 10 after
2216 } 2221 }
2217 DartSdk sdk = factory.dartSdk; 2222 DartSdk sdk = factory.dartSdk;
2218 if (sdk == null) { 2223 if (sdk == null) {
2219 throw new IllegalArgumentException( 2224 throw new IllegalArgumentException(
2220 "The source factory for an SDK analysis context must have a DartUriRes olver"); 2225 "The source factory for an SDK analysis context must have a DartUriRes olver");
2221 } 2226 }
2222 return new AnalysisCache( 2227 return new AnalysisCache(
2223 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); 2228 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]);
2224 } 2229 }
2225 } 2230 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698