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

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

Issue 1031283002: BuildLibraryConstructorsTask to build all constructors of all library classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | « no previous file | pkg/analyzer/lib/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.task.dart; 5 library analyzer.src.task.dart;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' as math; 8 import 'dart:math' as math;
9 9
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 * The result is only available for targets representing a Dart library. 56 * The result is only available for targets representing a Dart library.
57 */ 57 */
58 final ResultDescriptor<List<AnalysisError>> BUILD_LIBRARY_ERRORS = 58 final ResultDescriptor<List<AnalysisError>> BUILD_LIBRARY_ERRORS =
59 new ResultDescriptor<List<AnalysisError>>( 59 new ResultDescriptor<List<AnalysisError>>(
60 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS, 60 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS,
61 contributesTo: DART_ERRORS); 61 contributesTo: DART_ERRORS);
62 62
63 /** 63 /**
64 * The [ClassElement]s of a [LibraryUnitTarget]. 64 * The [ClassElement]s of a [LibraryUnitTarget].
65 */ 65 */
66 final ResultDescriptor<List<ClassElement>> CLASS_ELEMENTS = 66 final ListResultDescriptor<ClassElement> CLASS_ELEMENTS =
67 new ResultDescriptor<List<ClassElement>>('CLASS_ELEMENTS', null); 67 new ListResultDescriptor<ClassElement>('CLASS_ELEMENTS', null);
68 68
69 /** 69 /**
70 * The [ConstructorElement]s of a [ClassElement]. 70 * The [ConstructorElement]s of a [ClassElement].
71 */ 71 */
72 final ResultDescriptor<List<ConstructorElement>> CONSTRUCTORS = 72 final ResultDescriptor<List<ConstructorElement>> CONSTRUCTORS =
73 new ResultDescriptor<List<ConstructorElement>>('CONSTRUCTORS', null); 73 new ResultDescriptor<List<ConstructorElement>>('CONSTRUCTORS', null);
74 74
75 /** 75 /**
76 * The errors produced while building a [ClassElement] constructors. 76 * The errors produced while building a [ClassElement] constructors.
77 * 77 *
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 * The partial [LibraryElement] associated with a library. 141 * The partial [LibraryElement] associated with a library.
142 * 142 *
143 * [LIBRARY_ELEMENT4] plus [RESOLVED_UNIT4] for every unit. 143 * [LIBRARY_ELEMENT4] plus [RESOLVED_UNIT4] for every unit.
144 * 144 *
145 * The result is only available for targets representing a Dart library. 145 * The result is only available for targets representing a Dart library.
146 */ 146 */
147 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT5 = 147 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT5 =
148 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT5', null); 148 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT5', null);
149 149
150 /** 150 /**
151 * The partial [LibraryElement] associated with a library.
152 *
153 * Implicit constructors are built for every [ClassElement] requiring them.
154 *
155 * The result is only available for targets representing a Dart library.
156 */
157 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT6 =
158 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT6', null);
159
160 /**
151 * The errors produced while resolving type names. 161 * The errors produced while resolving type names.
152 * 162 *
153 * The list will be empty if there were no errors, but will not be `null`. 163 * The list will be empty if there were no errors, but will not be `null`.
154 * 164 *
155 * The result is only available for targets representing a Dart library. 165 * The result is only available for targets representing a Dart library.
156 */ 166 */
157 final ResultDescriptor<List<AnalysisError>> RESOLVE_TYPE_NAMES_ERRORS = 167 final ResultDescriptor<List<AnalysisError>> RESOLVE_TYPE_NAMES_ERRORS =
158 new ResultDescriptor<List<AnalysisError>>( 168 new ResultDescriptor<List<AnalysisError>>(
159 'RESOLVE_TYPE_NAMES_ERRORS', AnalysisError.NO_ERRORS, 169 'RESOLVE_TYPE_NAMES_ERRORS', AnalysisError.NO_ERRORS,
160 contributesTo: DART_ERRORS); 170 contributesTo: DART_ERRORS);
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 * Create a [BuildFunctionTypeAliasesTask] based on the given [target] in 1038 * Create a [BuildFunctionTypeAliasesTask] based on the given [target] in
1029 * the given [context]. 1039 * the given [context].
1030 */ 1040 */
1031 static BuildFunctionTypeAliasesTask createTask( 1041 static BuildFunctionTypeAliasesTask createTask(
1032 AnalysisContext context, AnalysisTarget target) { 1042 AnalysisContext context, AnalysisTarget target) {
1033 return new BuildFunctionTypeAliasesTask(context, target); 1043 return new BuildFunctionTypeAliasesTask(context, target);
1034 } 1044 }
1035 } 1045 }
1036 1046
1037 /** 1047 /**
1048 * An artifitial task that does nothing except to force building constructors
1049 * for for the defining and part units of a library.
1050 */
1051 class BuildLibraryConstructorsTask extends SourceBasedAnalysisTask {
1052 /**
1053 * The name of the [LIBRARY_ELEMENT5] input.
1054 */
1055 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
1056
1057 /**
1058 * The task descriptor describing this kind of task.
1059 */
1060 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1061 'BuildLibraryConstructorsTask', createTask, buildInputs,
1062 <ResultDescriptor>[LIBRARY_ELEMENT6]);
1063
1064 BuildLibraryConstructorsTask(
1065 InternalAnalysisContext context, AnalysisTarget target)
1066 : super(context, target);
1067
1068 @override
1069 TaskDescriptor get descriptor => DESCRIPTOR;
1070
1071 @override
1072 void internalPerform() {
1073 LibraryElement library = getRequiredInput(LIBRARY_INPUT);
1074 outputs[LIBRARY_ELEMENT6] = library;
1075 }
1076
1077 /**
1078 * Return a map from the names of the inputs of this kind of task to the task
1079 * input descriptors describing those inputs for a task with the
1080 * given [target].
1081 */
1082 static Map<String, TaskInput> buildInputs(Source libSource) {
1083 return <String, TaskInput>{
1084 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(libSource),
1085 'resolvedConstructors':
1086 CLASS_ELEMENTS.of(libSource).toListOf(CONSTRUCTORS),
1087 };
1088 }
1089
1090 /**
1091 * Create a [BuildLibraryConstructorsTask] based on the given [target] in
1092 * the given [context].
1093 */
1094 static BuildLibraryConstructorsTask createTask(
1095 AnalysisContext context, AnalysisTarget target) {
1096 return new BuildLibraryConstructorsTask(context, target);
1097 }
1098 }
1099
1100 /**
1038 * A task that builds a library element for a Dart library. 1101 * A task that builds a library element for a Dart library.
1039 */ 1102 */
1040 class BuildLibraryElementTask extends SourceBasedAnalysisTask { 1103 class BuildLibraryElementTask extends SourceBasedAnalysisTask {
1041 /** 1104 /**
1042 * The name of the input whose value is the defining [RESOLVED_UNIT1]. 1105 * The name of the input whose value is the defining [RESOLVED_UNIT1].
1043 */ 1106 */
1044 static const String DEFINING_UNIT_INPUT = 'DEFINING_UNIT_INPUT'; 1107 static const String DEFINING_UNIT_INPUT = 'DEFINING_UNIT_INPUT';
1045 1108
1046 /** 1109 /**
1047 * The name of the input whose value is a list of built [RESOLVED_UNIT1]s 1110 * The name of the input whose value is a list of built [RESOLVED_UNIT1]s
1048 * of the parts sourced by a library. 1111 * of the parts sourced by a library.
1049 */ 1112 */
1050 static const String PARTS_UNIT_INPUT = 'PARTS_UNIT_INPUT'; 1113 static const String PARTS_UNIT_INPUT = 'PARTS_UNIT_INPUT';
1051 1114
1052 /** 1115 /**
1053 * The task descriptor describing this kind of task. 1116 * The task descriptor describing this kind of task.
1054 */ 1117 */
1055 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1118 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1056 'BuildLibraryElementTask', createTask, buildInputs, <ResultDescriptor>[ 1119 'BuildLibraryElementTask', createTask, buildInputs, <ResultDescriptor>[
1057 BUILD_LIBRARY_ERRORS, 1120 BUILD_LIBRARY_ERRORS,
1121 CLASS_ELEMENTS,
1058 LIBRARY_ELEMENT1, 1122 LIBRARY_ELEMENT1,
1059 IS_LAUNCHABLE, 1123 IS_LAUNCHABLE,
1060 HAS_HTML_IMPORT 1124 HAS_HTML_IMPORT
1061 ]); 1125 ]);
1062 1126
1063 /** 1127 /**
1064 * The constant used as an unknown common library name in parts. 1128 * The constant used as an unknown common library name in parts.
1065 */ 1129 */
1066 static const String _UNKNOWN_LIBRARY_NAME = 'unknown-library-name'; 1130 static const String _UNKNOWN_LIBRARY_NAME = 'unknown-library-name';
1067 1131
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 libraryElement.definingCompilationUnit = definingCompilationUnitElement; 1245 libraryElement.definingCompilationUnit = definingCompilationUnitElement;
1182 libraryElement.entryPoint = entryPoint; 1246 libraryElement.entryPoint = entryPoint;
1183 libraryElement.parts = sourcedCompilationUnits; 1247 libraryElement.parts = sourcedCompilationUnits;
1184 for (Directive directive in directivesToResolve) { 1248 for (Directive directive in directivesToResolve) {
1185 directive.element = libraryElement; 1249 directive.element = libraryElement;
1186 } 1250 }
1187 if (sourcedCompilationUnits.isNotEmpty) { 1251 if (sourcedCompilationUnits.isNotEmpty) {
1188 _patchTopLevelAccessors(libraryElement); 1252 _patchTopLevelAccessors(libraryElement);
1189 } 1253 }
1190 // 1254 //
1255 // Prepare all class elements.
1256 //
1257 List<ClassElement> classElements = libraryElement.units
1258 .map((CompilationUnitElement unitElement) => unitElement.types)
1259 .expand((List<ClassElement> unitClassElements) => unitClassElements)
1260 .toList();
1261 //
1191 // Record outputs. 1262 // Record outputs.
1192 // 1263 //
1193 outputs[BUILD_LIBRARY_ERRORS] = errors; 1264 outputs[BUILD_LIBRARY_ERRORS] = errors;
1265 outputs[CLASS_ELEMENTS] = classElements;
1194 outputs[LIBRARY_ELEMENT1] = libraryElement; 1266 outputs[LIBRARY_ELEMENT1] = libraryElement;
1195 outputs[IS_LAUNCHABLE] = entryPoint != null; 1267 outputs[IS_LAUNCHABLE] = entryPoint != null;
1196 outputs[HAS_HTML_IMPORT] = hasHtmlImport; 1268 outputs[HAS_HTML_IMPORT] = hasHtmlImport;
1197 } 1269 }
1198 1270
1199 /** 1271 /**
1200 * Add all of the non-synthetic [getters] and [setters] defined in the given 1272 * Add all of the non-synthetic [getters] and [setters] defined in the given
1201 * [unit] that have no corresponding accessor to one of the given collections. 1273 * [unit] that have no corresponding accessor to one of the given collections.
1202 */ 1274 */
1203 void _collectAccessors(Map<String, PropertyAccessorElement> getters, 1275 void _collectAccessors(Map<String, PropertyAccessorElement> getters,
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1777 } 1849 }
1778 1850
1779 /** 1851 /**
1780 * Return a map from the names of the inputs of this kind of task to the task 1852 * Return a map from the names of the inputs of this kind of task to the task
1781 * input descriptors describing those inputs for a task with the 1853 * input descriptors describing those inputs for a task with the
1782 * given [target]. 1854 * given [target].
1783 */ 1855 */
1784 static Map<String, TaskInput> buildInputs(Source libSource) { 1856 static Map<String, TaskInput> buildInputs(Source libSource) {
1785 return <String, TaskInput>{ 1857 return <String, TaskInput>{
1786 LIBRARY_INPUT: LIBRARY_ELEMENT4.of(libSource), 1858 LIBRARY_INPUT: LIBRARY_ELEMENT4.of(libSource),
1787 'resolvedDefiningUnit': 1859 'resolvedUnits': UNITS.of(libSource).toMap((Source source) =>
1788 RESOLVED_UNIT4.of(new LibraryUnitTarget(libSource, libSource)),
1789 'resolvedPartsUnit': INCLUDED_PARTS.of(libSource).toMap((Source source) =>
1790 RESOLVED_UNIT4.of(new LibraryUnitTarget(libSource, source))) 1860 RESOLVED_UNIT4.of(new LibraryUnitTarget(libSource, source)))
1791 }; 1861 };
1792 } 1862 }
1793 1863
1794 /** 1864 /**
1795 * Create a [ResolveLibraryTypeNamesTask] based on the given [target] in 1865 * Create a [ResolveLibraryTypeNamesTask] based on the given [target] in
1796 * the given [context]. 1866 * the given [context].
1797 */ 1867 */
1798 static ResolveLibraryTypeNamesTask createTask( 1868 static ResolveLibraryTypeNamesTask createTask(
1799 AnalysisContext context, AnalysisTarget target) { 1869 AnalysisContext context, AnalysisTarget target) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 } 1990 }
1921 1991
1922 /** 1992 /**
1923 * Create a [ScanDartTask] based on the given [target] in the given [context]. 1993 * Create a [ScanDartTask] based on the given [target] in the given [context].
1924 */ 1994 */
1925 static ScanDartTask createTask( 1995 static ScanDartTask createTask(
1926 AnalysisContext context, AnalysisTarget target) { 1996 AnalysisContext context, AnalysisTarget target) {
1927 return new ScanDartTask(context, target); 1997 return new ScanDartTask(context, target);
1928 } 1998 }
1929 } 1999 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/task/dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698