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

Unified 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 side-by-side diff with in-line comments
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')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/context/context.dart
diff --git a/pkg/analyzer/lib/src/context/context.dart b/pkg/analyzer/lib/src/context/context.dart
index 4714557e35a910b1a9a07d958b866ce1cca77006..1d8ce64d1e6c29cb0ed51b6493f922ff5a81d85f 100644
--- a/pkg/analyzer/lib/src/context/context.dart
+++ b/pkg/analyzer/lib/src/context/context.dart
@@ -8,12 +8,14 @@ import 'dart:async';
import 'dart:collection';
import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/instrumentation/instrumentation.dart';
import 'package:analyzer/plugin/task.dart';
import 'package:analyzer/source/embedder.dart';
import 'package:analyzer/src/cancelable_future.dart';
import 'package:analyzer/src/context/cache.dart';
import 'package:analyzer/src/dart/element/element.dart';
+import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/constant.dart';
import 'package:analyzer/src/generated/engine.dart';
@@ -24,6 +26,7 @@ import 'package:analyzer/src/generated/java_engine.dart';
import 'package:analyzer/src/generated/resolver.dart';
import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
import 'package:analyzer/src/generated/source.dart';
+import 'package:analyzer/src/generated/testing/ast_factory.dart';
import 'package:analyzer/src/generated/utilities_collection.dart';
import 'package:analyzer/src/task/dart.dart';
import 'package:analyzer/src/task/dart_work_manager.dart';
@@ -459,13 +462,19 @@ class AnalysisContextImpl implements InternalAnalysisContext {
if (coreElement == null) {
throw new AnalysisException("Could not create an element for dart:core");
}
- Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC);
- if (asyncSource == null) {
- throw new AnalysisException("Could not create a source for dart:async");
- }
- LibraryElement asyncElement = computeLibraryElement(asyncSource);
- if (asyncElement == null) {
- throw new AnalysisException("Could not create an element for dart:async");
+ LibraryElement asyncElement;
+ if (analysisOptions.enableAsync) {
+ Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC);
+ if (asyncSource == null) {
+ throw new AnalysisException("Could not create a source for dart:async");
+ }
+ asyncElement = computeLibraryElement(asyncSource);
+ if (asyncElement == null) {
+ throw new AnalysisException(
+ "Could not create an element for dart:async");
+ }
+ } else {
+ asyncElement = createMockAsyncLib(coreElement);
}
_typeProvider = new TypeProviderImpl(coreElement, asyncElement);
return _typeProvider;
@@ -675,6 +684,54 @@ class AnalysisContextImpl implements InternalAnalysisContext {
]);
}
+ /**
+ * Create a minimalistic mock dart:async library
+ * to stand in for a real one if one does not exist
+ * facilitating creation a type provider without dart:async.
+ */
+ LibraryElement createMockAsyncLib(LibraryElement coreLibrary) {
+ InterfaceType objType = coreLibrary.getType('Object').type;
+
+ ClassElement _classElement(String typeName, [List<String> parameterNames]) {
+ ClassElementImpl element =
+ new ClassElementImpl.forNode(AstFactory.identifier3(typeName));
+ element.supertype = objType;
+ InterfaceTypeImpl type = new InterfaceTypeImpl(element);
+ element.type = type;
+ if (parameterNames != null) {
+ int count = parameterNames.length;
+ if (count > 0) {
+ List<TypeParameterElementImpl> typeParameters =
+ new List<TypeParameterElementImpl>(count);
+ List<TypeParameterTypeImpl> typeArguments =
+ new List<TypeParameterTypeImpl>(count);
+ for (int i = 0; i < count; i++) {
+ TypeParameterElementImpl typeParameter =
+ new TypeParameterElementImpl.forNode(
+ AstFactory.identifier3(parameterNames[i]));
+ typeParameters[i] = typeParameter;
+ typeArguments[i] = new TypeParameterTypeImpl(typeParameter);
+ typeParameter.type = typeArguments[i];
+ }
+ element.typeParameters = typeParameters;
+ type.typeArguments = typeArguments;
+ }
+ }
+ return element;
+ }
+
+ InterfaceType futureType = _classElement('Future', ['T']).type;
+ InterfaceType streamType = _classElement('Stream', ['T']).type;
+ CompilationUnitElementImpl asyncUnit =
+ 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.
+ asyncUnit.types = <ClassElement>[futureType.element, streamType.element];
+ LibraryElementImpl mockLib = new LibraryElementImpl.forNode(
+ this, AstFactory.libraryIdentifier2(["dart.async"]));
+ mockLib.definingCompilationUnit = asyncUnit;
+ mockLib.publicNamespace = new PublicNamespaceBuilder().build(mockLib);
+ return mockLib;
+ }
+
@override
void dispose() {
_disposed = true;
« 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