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

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

Issue 1012403002: Task: Build Type Aliases. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Simplify import scope computation for the new task model. Created 5 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/src/task/dart_test.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.task.dart; 5 library analyzer.src.task.dart;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 19 matching lines...) Expand all
30 * The list will be empty if there were no errors, but will not be `null`. 30 * The list will be empty if there were no errors, but will not be `null`.
31 * 31 *
32 * The result is only available for targets representing a Dart library. 32 * The result is only available for targets representing a Dart library.
33 */ 33 */
34 final ResultDescriptor<List<AnalysisError>> BUILD_DIRECTIVES_ERRORS = 34 final ResultDescriptor<List<AnalysisError>> BUILD_DIRECTIVES_ERRORS =
35 new ResultDescriptor<List<AnalysisError>>( 35 new ResultDescriptor<List<AnalysisError>>(
36 'BUILD_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS, 36 'BUILD_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS,
37 contributesTo: DART_ERRORS); 37 contributesTo: DART_ERRORS);
38 38
39 /** 39 /**
40 * The errors produced while builing a library element. 40 * The errors produced while building function type aliases.
41 * 41 *
42 * The list will be empty if there were no errors, but will not be `null`. 42 * The list will be empty if there were no errors, but will not be `null`.
43 * 43 *
44 * The result is only available for targets representing a Dart library.
45 */
46 final ResultDescriptor<List<AnalysisError>> BUILD_FUNCTION_TYPE_ALIASES_ERRORS =
47 new ResultDescriptor<List<AnalysisError>>(
48 'BUILD_FUNCTION_TYPE_ALIASES_ERRORS', AnalysisError.NO_ERRORS,
49 contributesTo: DART_ERRORS);
50
51 /**
52 * The errors produced while building a library element.
53 *
54 * The list will be empty if there were no errors, but will not be `null`.
55 *
44 * The result is only available for targets representing a Dart library. 56 * The result is only available for targets representing a Dart library.
45 */ 57 */
46 final ResultDescriptor<List<AnalysisError>> BUILD_LIBRARY_ERRORS = 58 final ResultDescriptor<List<AnalysisError>> BUILD_LIBRARY_ERRORS =
47 new ResultDescriptor<List<AnalysisError>>( 59 new ResultDescriptor<List<AnalysisError>>(
48 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS, 60 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS,
49 contributesTo: DART_ERRORS); 61 contributesTo: DART_ERRORS);
50 62
51 /** 63 /**
52 * The sources representing the export closure of a library. 64 * The sources representing the export closure of a library.
53 * 65 *
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 * The partially resolved [CompilationUnit] associated with a unit. 148 * The partially resolved [CompilationUnit] associated with a unit.
137 * 149 *
138 * All the enum member elements are built. 150 * All the enum member elements are built.
139 * 151 *
140 * The result is only available for targets representing a unit. 152 * The result is only available for targets representing a unit.
141 */ 153 */
142 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT4 = 154 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT4 =
143 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT4', null); 155 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT4', null);
144 156
145 /** 157 /**
158 * The partially resolved [CompilationUnit] associated with a unit.
159 *
160 * All the function type aliases are resolved.
161 *
162 * The result is only available for targets representing a unit.
163 */
164 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT5 =
165 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT5', null);
166
167 /**
146 * The [TypeProvider] of the context. 168 * The [TypeProvider] of the context.
147 */ 169 */
148 final ResultDescriptor<TypeProvider> TYPE_PROVIDER = 170 final ResultDescriptor<TypeProvider> TYPE_PROVIDER =
149 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null); 171 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null);
150 172
151 /** 173 /**
152 * A task that builds a compilation unit element for a single compilation unit. 174 * A task that builds a compilation unit element for a single compilation unit.
153 */ 175 */
154 class BuildCompilationUnitElementTask extends SourceBasedAnalysisTask { 176 class BuildCompilationUnitElementTask extends SourceBasedAnalysisTask {
155 /** 177 /**
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 Set<LibraryElement> libraries, LibraryElement library) { 694 Set<LibraryElement> libraries, LibraryElement library) {
673 if (library != null && libraries.add(library)) { 695 if (library != null && libraries.add(library)) {
674 for (ExportElement exportElement in library.exports) { 696 for (ExportElement exportElement in library.exports) {
675 _buildExportClosure(libraries, exportElement.exportedLibrary); 697 _buildExportClosure(libraries, exportElement.exportedLibrary);
676 } 698 }
677 } 699 }
678 } 700 }
679 } 701 }
680 702
681 /** 703 /**
704 * A task that builds [RESOLVED_UNIT5] for a library.
705 */
706 class BuildFunctionTypeAliasesTask extends SourceBasedAnalysisTask {
707 /**
708 * The name of the [TYPE_PROVIDER] input.
709 */
710 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
711
712 /**
713 * The name of the [RESOLVED_UNIT3] input.
714 */
715 static const String UNIT_INPUT = 'UNIT_INPUT';
716
717 /**
718 * The task descriptor describing this kind of task.
719 */
720 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
721 'BuildFunctionTypeAliasesTask', createTask, buildInputs,
722 <ResultDescriptor>[BUILD_FUNCTION_TYPE_ALIASES_ERRORS, RESOLVED_UNIT5]);
723
724 BuildFunctionTypeAliasesTask(
725 InternalAnalysisContext context, AnalysisTarget target)
726 : super(context, target);
727
728 @override
729 TaskDescriptor get descriptor => DESCRIPTOR;
730
731 @override
732 void internalPerform() {
733 RecordingErrorListener errorListener = new RecordingErrorListener();
734 //
735 // Prepare inputs.
736 //
737 Source source = getRequiredSource();
738 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
739 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
740 LibraryElement libraryElement = unit.element.library;
741 //
742 // Resolve FunctionTypeAlias declarations.
743 //
744 TypeResolverVisitor visitor = new TypeResolverVisitor.con2(
745 libraryElement, source, typeProvider, errorListener);
746 for (CompilationUnitMember member in unit.declarations) {
747 if (member is FunctionTypeAlias) {
748 member.accept(visitor);
749 }
750 }
751 //
752 // Record outputs.
753 //
754 outputs[BUILD_FUNCTION_TYPE_ALIASES_ERRORS] = errorListener.errors;
755 outputs[RESOLVED_UNIT5] = unit;
756 }
757
758 /**
759 * Return a map from the names of the inputs of this kind of task to the task
760 * input descriptors describing those inputs for a task with the
761 * given [target].
762 */
763 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) {
764 return <String, TaskInput>{
765 TYPE_PROVIDER_INPUT:
766 TYPE_PROVIDER.inputFor(AnalysisContextTarget.request),
767 'importsExportNamespace': new ListToMapTaskInput<Source, LibraryElement>(
768 IMPORTED_LIBRARIES.inputFor(target.library),
769 (Source importSource) => LIBRARY_ELEMENT4.inputFor(importSource)),
770 UNIT_INPUT: RESOLVED_UNIT4.inputFor(target.unit)
771 };
772 }
773
774 /**
775 * Create a [BuildFunctionTypeAliasesTask] based on the given [target] in
776 * the given [context].
777 */
778 static BuildFunctionTypeAliasesTask createTask(
779 AnalysisContext context, AnalysisTarget target) {
780 return new BuildFunctionTypeAliasesTask(context, target);
781 }
782 }
783
784 /**
682 * A task that builds a library element for a Dart library. 785 * A task that builds a library element for a Dart library.
683 */ 786 */
684 class BuildLibraryElementTask extends SourceBasedAnalysisTask { 787 class BuildLibraryElementTask extends SourceBasedAnalysisTask {
685 /** 788 /**
686 * The name of the input whose value is the defining [RESOLVED_UNIT1]. 789 * The name of the input whose value is the defining [RESOLVED_UNIT1].
687 */ 790 */
688 static const String DEFINING_RESOLVER_UNIT1_INPUT_NAME = 791 static const String DEFINING_RESOLVER_UNIT1_INPUT_NAME =
689 'DEFINING_RESOLVER_UNIT1_INPUT_NAME'; 792 'DEFINING_RESOLVER_UNIT1_INPUT_NAME';
690 793
691 /** 794 /**
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 return newNames; 1267 return newNames;
1165 } 1268 }
1166 } 1269 }
1167 1270
1168 /** 1271 /**
1169 * A pair of a library [Source] and a unit [Source] in this library. 1272 * A pair of a library [Source] and a unit [Source] in this library.
1170 */ 1273 */
1171 class LibraryUnitTarget implements AnalysisTarget { 1274 class LibraryUnitTarget implements AnalysisTarget {
1172 final Source library; 1275 final Source library;
1173 final Source unit; 1276 final Source unit;
1277
1174 LibraryUnitTarget(this.library, this.unit); 1278 LibraryUnitTarget(this.library, this.unit);
1175 1279
1176 @override 1280 @override
1177 int get hashCode { 1281 int get hashCode {
1178 return JenkinsSmiHash.combine(library.hashCode, unit.hashCode); 1282 return JenkinsSmiHash.combine(library.hashCode, unit.hashCode);
1179 } 1283 }
1180 1284
1181 @override 1285 @override
1182 Source get source => unit; 1286 Source get source => unit;
1183 1287
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 } 1552 }
1449 1553
1450 /** 1554 /**
1451 * Create a [ScanDartTask] based on the given [target] in the given [context]. 1555 * Create a [ScanDartTask] based on the given [target] in the given [context].
1452 */ 1556 */
1453 static ScanDartTask createTask( 1557 static ScanDartTask createTask(
1454 AnalysisContext context, AnalysisTarget target) { 1558 AnalysisContext context, AnalysisTarget target) {
1455 return new ScanDartTask(context, target); 1559 return new ScanDartTask(context, target);
1456 } 1560 }
1457 } 1561 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698