| Index: pkg/analyzer/lib/src/task/dart.dart
|
| diff --git a/pkg/analyzer/lib/src/task/dart.dart b/pkg/analyzer/lib/src/task/dart.dart
|
| index 0ccb28d5502f22890d488e573e3326de47a5e4c8..699d965cb5a85b3c3965e67d412e899ec8a11a9f 100644
|
| --- a/pkg/analyzer/lib/src/task/dart.dart
|
| +++ b/pkg/analyzer/lib/src/task/dart.dart
|
| @@ -37,7 +37,7 @@ final ResultDescriptor<List<AnalysisError>> BUILD_DIRECTIVES_ERRORS =
|
| contributesTo: DART_ERRORS);
|
|
|
| /**
|
| - * The errors produced while builing a library element.
|
| + * The errors produced while building a library element.
|
| *
|
| * The list will be empty if there were no errors, but will not be `null`.
|
| *
|
| @@ -49,6 +49,18 @@ final ResultDescriptor<List<AnalysisError>> BUILD_LIBRARY_ERRORS =
|
| contributesTo: DART_ERRORS);
|
|
|
| /**
|
| + * The errors produced while building function type aliases.
|
| + *
|
| + * The list will be empty if there were no errors, but will not be `null`.
|
| + *
|
| + * The result is only available for targets representing a Dart library.
|
| + */
|
| +final ResultDescriptor<List<AnalysisError>> BUILD_FUNCTION_TYPE_ALIASES_ERRORS =
|
| + new ResultDescriptor<List<AnalysisError>>(
|
| + 'BUILD_FUNCTION_TYPE_ALIASES_ERRORS', AnalysisError.NO_ERRORS,
|
| + contributesTo: DART_ERRORS);
|
| +
|
| +/**
|
| * The export [Namespace] of a library.
|
| *
|
| * The result is only available for targets representing a Dart library.
|
| @@ -138,6 +150,16 @@ final ResultDescriptor<CompilationUnit> RESOLVED_UNIT4 =
|
| new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT4', null);
|
|
|
| /**
|
| + * The partially resolved [CompilationUnit] associated with a unit.
|
| + *
|
| + * All the function type aliases are resolved.
|
| + *
|
| + * The result is only available for targets representing a unit.
|
| + */
|
| +final ResultDescriptor<CompilationUnit> RESOLVED_UNIT5 =
|
| + new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT5', null);
|
| +
|
| +/**
|
| * The [TypeProvider] of the context.
|
| */
|
| final ResultDescriptor<TypeProvider> TYPE_PROVIDER =
|
| @@ -683,6 +705,102 @@ class BuildExportSourceClosureTask extends SourceBasedAnalysisTask {
|
| }
|
|
|
| /**
|
| + * A task that builds [RESOLVED_UNIT5] for a library.
|
| + */
|
| +class BuildFunctionTypeAliasesTask extends SourceBasedAnalysisTask {
|
| + /**
|
| + * The name of the [TYPE_PROVIDER] input.
|
| + */
|
| + static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
|
| +
|
| + /**
|
| + * The [EXPORT_NAMESPACE]s of imported libraries input.
|
| + */
|
| + static const String IMPORTS_EXPORT_NAMESPACE_INPUT =
|
| + 'IMPORTS_EXPORT_NAMESPACE_INPUT';
|
| +
|
| + /**
|
| + * The name of the [RESOLVED_UNIT3] input.
|
| + */
|
| + static const String UNIT_INPUT = 'UNIT_INPUT';
|
| +
|
| + /**
|
| + * The task descriptor describing this kind of task.
|
| + */
|
| + static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
|
| + 'BuildFunctionTypeAliasesTask', createTask, buildInputs,
|
| + <ResultDescriptor>[BUILD_FUNCTION_TYPE_ALIASES_ERRORS, RESOLVED_UNIT5]);
|
| +
|
| + BuildFunctionTypeAliasesTask(
|
| + InternalAnalysisContext context, AnalysisTarget target)
|
| + : super(context, target);
|
| +
|
| + @override
|
| + TaskDescriptor get descriptor => DESCRIPTOR;
|
| +
|
| + @override
|
| + void internalPerform() {
|
| + RecordingErrorListener errorListener = new RecordingErrorListener();
|
| + //
|
| + // Prepare inputs.
|
| + //
|
| + Source source = getRequiredSource();
|
| + TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
|
| + Map<Source, Namespace> exportNamespaces =
|
| + getRequiredInput(IMPORTS_EXPORT_NAMESPACE_INPUT);
|
| + CompilationUnit unit = getRequiredInput(UNIT_INPUT);
|
| + //
|
| + // Build scopes.
|
| + //
|
| + LibraryElement libraryElement = unit.element.library;
|
| + Scope importScope = new LibraryImportScopeNew(
|
| + libraryElement, exportNamespaces, errorListener);
|
| + LibraryScope libraryScope =
|
| + new LibraryScope(libraryElement, importScope, errorListener);
|
| + //
|
| + // Resolve FunctionTypeAlias declarations.
|
| + //
|
| + TypeResolverVisitor visitor = new TypeResolverVisitor.con2(
|
| + libraryElement, libraryScope, source, typeProvider, errorListener);
|
| + for (CompilationUnitMember member in unit.declarations) {
|
| + if (member is FunctionTypeAlias) {
|
| + member.accept(visitor);
|
| + }
|
| + }
|
| + //
|
| + // Record outputs.
|
| + //
|
| + outputs[BUILD_FUNCTION_TYPE_ALIASES_ERRORS] = errorListener.errors;
|
| + outputs[RESOLVED_UNIT5] = unit;
|
| + }
|
| +
|
| + /**
|
| + * Return a map from the names of the inputs of this kind of task to the task
|
| + * input descriptors describing those inputs for a task with the
|
| + * given [target].
|
| + */
|
| + static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) {
|
| + return <String, TaskInput>{
|
| + TYPE_PROVIDER_INPUT:
|
| + TYPE_PROVIDER.inputFor(AnalysisContextTarget.request),
|
| + IMPORTS_EXPORT_NAMESPACE_INPUT: new ListToMapTaskInput<Source, Namespace>(
|
| + IMPORTED_LIBRARIES.inputFor(target.library),
|
| + (Source importSource) => EXPORT_NAMESPACE.inputFor(importSource)),
|
| + UNIT_INPUT: RESOLVED_UNIT4.inputFor(target.unit)
|
| + };
|
| + }
|
| +
|
| + /**
|
| + * Create a [BuildFunctionTypeAliasesTask] based on the given [target] in
|
| + * the given [context].
|
| + */
|
| + static BuildFunctionTypeAliasesTask createTask(
|
| + AnalysisContext context, AnalysisTarget target) {
|
| + return new BuildFunctionTypeAliasesTask(context, target);
|
| + }
|
| +}
|
| +
|
| +/**
|
| * A task that builds a library element for a Dart library.
|
| */
|
| class BuildLibraryElementTask extends SourceBasedAnalysisTask {
|
| @@ -1173,11 +1291,68 @@ class ExportNamespaceBuilder {
|
| }
|
|
|
| /**
|
| + * The scope containing all of the names available from imported libraries.
|
| + */
|
| +class LibraryImportScopeNew extends LibraryImportScope {
|
| + final Map<Source, Namespace> exportNamespaces;
|
| +
|
| + LibraryImportScopeNew(LibraryElement definingLibrary, this.exportNamespaces,
|
| + AnalysisErrorListener errorListener)
|
| + : super(definingLibrary, errorListener);
|
| +
|
| + /**
|
| + * Create the import [Namespace] of the given [LibraryElement].
|
| + */
|
| + Namespace buildImportElementNamespace(ImportElement element) {
|
| + LibraryElement importedLibrary = element.importedLibrary;
|
| + // Check that the URI references a valid library.
|
| + if (importedLibrary == null) {
|
| + return Namespace.EMPTY;
|
| + }
|
| + // Prepare exported names.
|
| + Source importedSource = importedLibrary.source;
|
| + Namespace exportNamespace = exportNamespaces[importedSource];
|
| + HashMap<String, Element> definedNames = exportNamespace.definedNames;
|
| + // Apply the combinators and prefix.
|
| + definedNames = ExportNamespaceBuilder._applyCombinators(
|
| + definedNames, element.combinators);
|
| + definedNames = _applyPrefix(definedNames, element.prefix);
|
| + return new Namespace(definedNames);
|
| + }
|
| +
|
| + @override
|
| + void createImportedNamespaces() {
|
| + for (ImportElement import in definingLibrary.imports) {
|
| + Namespace namespace = buildImportElementNamespace(import);
|
| + importedNamespaces.add(namespace);
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * Apply the given [prefixElement] to all of the names in [definedNames].
|
| + */
|
| + static HashMap<String, Element> _applyPrefix(
|
| + HashMap<String, Element> definedNames, PrefixElement prefixElement) {
|
| + if (prefixElement != null) {
|
| + String prefix = prefixElement.name;
|
| + HashMap<String, Element> newNames = new HashMap<String, Element>();
|
| + definedNames.forEach((String name, Element element) {
|
| + newNames['$prefix.$name'] = element;
|
| + });
|
| + return newNames;
|
| + } else {
|
| + return definedNames;
|
| + }
|
| + }
|
| +}
|
| +
|
| +/**
|
| * A pair of a library [Source] and a unit [Source] in this library.
|
| */
|
| class LibraryUnitTarget implements AnalysisTarget {
|
| final Source library;
|
| final Source unit;
|
| +
|
| LibraryUnitTarget(this.library, this.unit);
|
|
|
| @override
|
|
|