| OLD | NEW |
| 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/context/cache.dart'; | 10 import 'package:analyzer/src/context/cache.dart'; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 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 [Source]s representing a library. | 44 * The result is only available for [Source]s representing a library. |
| 45 */ | 45 */ |
| 46 final ListResultDescriptor<AnalysisError> BUILD_DIRECTIVES_ERRORS = | 46 final ListResultDescriptor<AnalysisError> BUILD_DIRECTIVES_ERRORS = |
| 47 new ListResultDescriptor<AnalysisError>( | 47 new ListResultDescriptor<AnalysisError>( |
| 48 'BUILD_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS); | 48 'BUILD_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS); |
| 49 | 49 |
| 50 /** | 50 /** |
| 51 * The errors produced while building function type aliases. | |
| 52 * | |
| 53 * The list will be empty if there were no errors, but will not be `null`. | |
| 54 * | |
| 55 * The result is only available for [LibrarySpecificUnit]s. | |
| 56 */ | |
| 57 final ListResultDescriptor<AnalysisError> BUILD_FUNCTION_TYPE_ALIASES_ERRORS = | |
| 58 new ListResultDescriptor<AnalysisError>( | |
| 59 'BUILD_FUNCTION_TYPE_ALIASES_ERRORS', AnalysisError.NO_ERRORS); | |
| 60 | |
| 61 /** | |
| 62 * The errors produced while building a library element. | 51 * The errors produced while building a library element. |
| 63 * | 52 * |
| 64 * The list will be empty if there were no errors, but will not be `null`. | 53 * The list will be empty if there were no errors, but will not be `null`. |
| 65 * | 54 * |
| 66 * The result is only available for [Source]s representing a library. | 55 * The result is only available for [Source]s representing a library. |
| 67 */ | 56 */ |
| 68 final ListResultDescriptor<AnalysisError> BUILD_LIBRARY_ERRORS = | 57 final ListResultDescriptor<AnalysisError> BUILD_LIBRARY_ERRORS = |
| 69 new ListResultDescriptor<AnalysisError>( | 58 new ListResultDescriptor<AnalysisError>( |
| 70 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS); | 59 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS); |
| 71 | 60 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT2 = | 324 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT2 = |
| 336 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT2', null, | 325 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT2', null, |
| 337 cachingPolicy: AST_CACHING_POLICY); | 326 cachingPolicy: AST_CACHING_POLICY); |
| 338 | 327 |
| 339 /** | 328 /** |
| 340 * The partially resolved [CompilationUnit] associated with a unit. | 329 * The partially resolved [CompilationUnit] associated with a unit. |
| 341 * | 330 * |
| 342 * All the function type aliases are resolved. | 331 * All the function type aliases are resolved. |
| 343 * | 332 * |
| 344 * The result is only available for [LibrarySpecificUnit]s. | 333 * The result is only available for [LibrarySpecificUnit]s. |
| 334 * |
| 335 * TODO(paulberry): this is no longer used and should be deleted. However, it |
| 336 * can't be safely deleted yet because the analysis server is referring to it. |
| 345 */ | 337 */ |
| 338 @deprecated |
| 346 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT3 = | 339 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT3 = |
| 347 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT3', null, | 340 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT3', null, |
| 348 cachingPolicy: AST_CACHING_POLICY); | 341 cachingPolicy: AST_CACHING_POLICY); |
| 349 | 342 |
| 350 /** | 343 /** |
| 351 * The partially resolved [CompilationUnit] associated with a unit. | 344 * The partially resolved [CompilationUnit] associated with a unit. |
| 352 * | 345 * |
| 353 * [RESOLVED_UNIT3] with resolved type names. | 346 * [RESOLVED_UNIT2] with resolved type names. |
| 354 * | 347 * |
| 355 * The result is only available for [LibrarySpecificUnit]s. | 348 * The result is only available for [LibrarySpecificUnit]s. |
| 356 */ | 349 */ |
| 357 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT4 = | 350 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT4 = |
| 358 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT4', null, | 351 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT4', null, |
| 359 cachingPolicy: AST_CACHING_POLICY); | 352 cachingPolicy: AST_CACHING_POLICY); |
| 360 | 353 |
| 361 /** | 354 /** |
| 362 * The partially resolved [CompilationUnit] associated with a unit. | 355 * The partially resolved [CompilationUnit] associated with a unit. |
| 363 * | 356 * |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1144 * Create a [BuildExportNamespaceTask] based on the given [target] in | 1137 * Create a [BuildExportNamespaceTask] based on the given [target] in |
| 1145 * the given [context]. | 1138 * the given [context]. |
| 1146 */ | 1139 */ |
| 1147 static BuildExportNamespaceTask createTask( | 1140 static BuildExportNamespaceTask createTask( |
| 1148 AnalysisContext context, AnalysisTarget target) { | 1141 AnalysisContext context, AnalysisTarget target) { |
| 1149 return new BuildExportNamespaceTask(context, target); | 1142 return new BuildExportNamespaceTask(context, target); |
| 1150 } | 1143 } |
| 1151 } | 1144 } |
| 1152 | 1145 |
| 1153 /** | 1146 /** |
| 1154 * A task that builds [RESOLVED_UNIT3] for a unit. | |
| 1155 */ | |
| 1156 class BuildFunctionTypeAliasesTask extends SourceBasedAnalysisTask { | |
| 1157 /** | |
| 1158 * The name of the [TYPE_PROVIDER] input. | |
| 1159 */ | |
| 1160 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; | |
| 1161 | |
| 1162 /** | |
| 1163 * The name of the [LIBRARY_ELEMENT4] input. | |
| 1164 */ | |
| 1165 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; | |
| 1166 | |
| 1167 /** | |
| 1168 * The name of the [RESOLVED_UNIT2] input. | |
| 1169 */ | |
| 1170 static const String UNIT_INPUT = 'UNIT_INPUT'; | |
| 1171 | |
| 1172 /** | |
| 1173 * The task descriptor describing this kind of task. | |
| 1174 */ | |
| 1175 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | |
| 1176 'BuildFunctionTypeAliasesTask', createTask, buildInputs, | |
| 1177 <ResultDescriptor>[BUILD_FUNCTION_TYPE_ALIASES_ERRORS, RESOLVED_UNIT3]); | |
| 1178 | |
| 1179 BuildFunctionTypeAliasesTask( | |
| 1180 InternalAnalysisContext context, AnalysisTarget target) | |
| 1181 : super(context, target); | |
| 1182 | |
| 1183 @override | |
| 1184 TaskDescriptor get descriptor => DESCRIPTOR; | |
| 1185 | |
| 1186 @override | |
| 1187 void internalPerform() { | |
| 1188 RecordingErrorListener errorListener = new RecordingErrorListener(); | |
| 1189 // | |
| 1190 // Prepare inputs. | |
| 1191 // | |
| 1192 Source source = getRequiredSource(); | |
| 1193 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); | |
| 1194 CompilationUnit unit = getRequiredInput(UNIT_INPUT); | |
| 1195 LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT); | |
| 1196 // | |
| 1197 // Resolve FunctionTypeAlias declarations. | |
| 1198 // | |
| 1199 TypeResolverVisitor visitor = new TypeResolverVisitor.con2( | |
| 1200 libraryElement, source, typeProvider, errorListener); | |
| 1201 for (CompilationUnitMember member in unit.declarations) { | |
| 1202 if (member is FunctionTypeAlias) { | |
| 1203 member.accept(visitor); | |
| 1204 } | |
| 1205 } | |
| 1206 // | |
| 1207 // Record outputs. | |
| 1208 // | |
| 1209 outputs[BUILD_FUNCTION_TYPE_ALIASES_ERRORS] = | |
| 1210 removeDuplicateErrors(errorListener.errors); | |
| 1211 outputs[RESOLVED_UNIT3] = unit; | |
| 1212 } | |
| 1213 | |
| 1214 /** | |
| 1215 * Return a map from the names of the inputs of this kind of task to the task | |
| 1216 * input descriptors describing those inputs for a task with the | |
| 1217 * given [target]. | |
| 1218 */ | |
| 1219 static Map<String, TaskInput> buildInputs(LibrarySpecificUnit target) { | |
| 1220 LibrarySpecificUnit unit = target; | |
| 1221 return <String, TaskInput>{ | |
| 1222 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), | |
| 1223 'importsExportNamespace': | |
| 1224 IMPORTED_LIBRARIES.of(unit.library).toMapOf(LIBRARY_ELEMENT4), | |
| 1225 LIBRARY_INPUT: LIBRARY_ELEMENT4.of(unit.library), | |
| 1226 UNIT_INPUT: RESOLVED_UNIT2.of(unit) | |
| 1227 }; | |
| 1228 } | |
| 1229 | |
| 1230 /** | |
| 1231 * Create a [BuildFunctionTypeAliasesTask] based on the given [target] in | |
| 1232 * the given [context]. | |
| 1233 */ | |
| 1234 static BuildFunctionTypeAliasesTask createTask( | |
| 1235 AnalysisContext context, AnalysisTarget target) { | |
| 1236 return new BuildFunctionTypeAliasesTask(context, target); | |
| 1237 } | |
| 1238 } | |
| 1239 | |
| 1240 /** | |
| 1241 * This task builds [LIBRARY_ELEMENT6] by forcing building constructors for | 1147 * This task builds [LIBRARY_ELEMENT6] by forcing building constructors for |
| 1242 * all the classes of the defining and part units of a library. | 1148 * all the classes of the defining and part units of a library. |
| 1243 */ | 1149 */ |
| 1244 class BuildLibraryConstructorsTask extends SourceBasedAnalysisTask { | 1150 class BuildLibraryConstructorsTask extends SourceBasedAnalysisTask { |
| 1245 /** | 1151 /** |
| 1246 * The name of the [LIBRARY_ELEMENT5] input. | 1152 * The name of the [LIBRARY_ELEMENT5] input. |
| 1247 */ | 1153 */ |
| 1248 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; | 1154 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; |
| 1249 | 1155 |
| 1250 /** | 1156 /** |
| (...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2558 return new LibraryErrorsReadyTask(context, target); | 2464 return new LibraryErrorsReadyTask(context, target); |
| 2559 } | 2465 } |
| 2560 } | 2466 } |
| 2561 | 2467 |
| 2562 /** | 2468 /** |
| 2563 * A task that merges all of the errors for a single source into a single list | 2469 * A task that merges all of the errors for a single source into a single list |
| 2564 * of errors. | 2470 * of errors. |
| 2565 */ | 2471 */ |
| 2566 class LibraryUnitErrorsTask extends SourceBasedAnalysisTask { | 2472 class LibraryUnitErrorsTask extends SourceBasedAnalysisTask { |
| 2567 /** | 2473 /** |
| 2568 * The name of the [BUILD_FUNCTION_TYPE_ALIASES_ERRORS] input. | |
| 2569 */ | |
| 2570 static const String BUILD_FUNCTION_TYPE_ALIASES_ERRORS_INPUT = | |
| 2571 'BUILD_FUNCTION_TYPE_ALIASES_ERRORS'; | |
| 2572 | |
| 2573 /** | |
| 2574 * The name of the [HINTS] input. | 2474 * The name of the [HINTS] input. |
| 2575 */ | 2475 */ |
| 2576 static const String HINTS_INPUT = 'HINTS'; | 2476 static const String HINTS_INPUT = 'HINTS'; |
| 2577 | 2477 |
| 2578 /** | 2478 /** |
| 2579 * The name of the [RESOLVE_REFERENCES_ERRORS] input. | 2479 * The name of the [RESOLVE_REFERENCES_ERRORS] input. |
| 2580 */ | 2480 */ |
| 2581 static const String RESOLVE_REFERENCES_ERRORS_INPUT = | 2481 static const String RESOLVE_REFERENCES_ERRORS_INPUT = |
| 2582 'RESOLVE_REFERENCES_ERRORS'; | 2482 'RESOLVE_REFERENCES_ERRORS'; |
| 2583 | 2483 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2615 | 2515 |
| 2616 @override | 2516 @override |
| 2617 TaskDescriptor get descriptor => DESCRIPTOR; | 2517 TaskDescriptor get descriptor => DESCRIPTOR; |
| 2618 | 2518 |
| 2619 @override | 2519 @override |
| 2620 void internalPerform() { | 2520 void internalPerform() { |
| 2621 // | 2521 // |
| 2622 // Prepare inputs. | 2522 // Prepare inputs. |
| 2623 // | 2523 // |
| 2624 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[]; | 2524 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[]; |
| 2625 errorLists.add(getRequiredInput(BUILD_FUNCTION_TYPE_ALIASES_ERRORS_INPUT)); | |
| 2626 errorLists.addAll(getRequiredInput(CONSTRUCTORS_ERRORS_INPUT)); | 2525 errorLists.addAll(getRequiredInput(CONSTRUCTORS_ERRORS_INPUT)); |
| 2627 errorLists.add(getRequiredInput(HINTS_INPUT)); | 2526 errorLists.add(getRequiredInput(HINTS_INPUT)); |
| 2628 errorLists.add(getRequiredInput(RESOLVE_REFERENCES_ERRORS_INPUT)); | 2527 errorLists.add(getRequiredInput(RESOLVE_REFERENCES_ERRORS_INPUT)); |
| 2629 errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT)); | 2528 errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT)); |
| 2630 errorLists.add(getRequiredInput(VARIABLE_REFERENCE_ERRORS_INPUT)); | 2529 errorLists.add(getRequiredInput(VARIABLE_REFERENCE_ERRORS_INPUT)); |
| 2631 errorLists.add(getRequiredInput(VERIFY_ERRORS_INPUT)); | 2530 errorLists.add(getRequiredInput(VERIFY_ERRORS_INPUT)); |
| 2632 // | 2531 // |
| 2633 // Record outputs. | 2532 // Record outputs. |
| 2634 // | 2533 // |
| 2635 outputs[LIBRARY_UNIT_ERRORS] = AnalysisError.mergeLists(errorLists); | 2534 outputs[LIBRARY_UNIT_ERRORS] = AnalysisError.mergeLists(errorLists); |
| 2636 } | 2535 } |
| 2637 | 2536 |
| 2638 /** | 2537 /** |
| 2639 * Return a map from the names of the inputs of this kind of task to the task | 2538 * Return a map from the names of the inputs of this kind of task to the task |
| 2640 * input descriptors describing those inputs for a task with the | 2539 * input descriptors describing those inputs for a task with the |
| 2641 * given [unit]. | 2540 * given [unit]. |
| 2642 */ | 2541 */ |
| 2643 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 2542 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 2644 LibrarySpecificUnit unit = target; | 2543 LibrarySpecificUnit unit = target; |
| 2645 return <String, TaskInput>{ | 2544 return <String, TaskInput>{ |
| 2646 BUILD_FUNCTION_TYPE_ALIASES_ERRORS_INPUT: | |
| 2647 BUILD_FUNCTION_TYPE_ALIASES_ERRORS.of(unit), | |
| 2648 CONSTRUCTORS_ERRORS_INPUT: COMPILATION_UNIT_ELEMENT | 2545 CONSTRUCTORS_ERRORS_INPUT: COMPILATION_UNIT_ELEMENT |
| 2649 .of(unit) | 2546 .of(unit) |
| 2650 .mappedToList((CompilationUnitElement element) => element.types) | 2547 .mappedToList((CompilationUnitElement element) => element.types) |
| 2651 .toListOf(CONSTRUCTORS_ERRORS), | 2548 .toListOf(CONSTRUCTORS_ERRORS), |
| 2652 HINTS_INPUT: HINTS.of(unit), | 2549 HINTS_INPUT: HINTS.of(unit), |
| 2653 RESOLVE_REFERENCES_ERRORS_INPUT: RESOLVE_REFERENCES_ERRORS.of(unit), | 2550 RESOLVE_REFERENCES_ERRORS_INPUT: RESOLVE_REFERENCES_ERRORS.of(unit), |
| 2654 RESOLVE_TYPE_NAMES_ERRORS_INPUT: RESOLVE_TYPE_NAMES_ERRORS.of(unit), | 2551 RESOLVE_TYPE_NAMES_ERRORS_INPUT: RESOLVE_TYPE_NAMES_ERRORS.of(unit), |
| 2655 VARIABLE_REFERENCE_ERRORS_INPUT: VARIABLE_REFERENCE_ERRORS.of(unit), | 2552 VARIABLE_REFERENCE_ERRORS_INPUT: VARIABLE_REFERENCE_ERRORS.of(unit), |
| 2656 VERIFY_ERRORS_INPUT: VERIFY_ERRORS.of(unit) | 2553 VERIFY_ERRORS_INPUT: VERIFY_ERRORS.of(unit) |
| 2657 }; | 2554 }; |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3148 } | 3045 } |
| 3149 | 3046 |
| 3150 /** | 3047 /** |
| 3151 * Return a map from the names of the inputs of this kind of task to the task | 3048 * Return a map from the names of the inputs of this kind of task to the task |
| 3152 * input descriptors describing those inputs for a task with the | 3049 * input descriptors describing those inputs for a task with the |
| 3153 * given [target]. | 3050 * given [target]. |
| 3154 */ | 3051 */ |
| 3155 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 3052 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 3156 LibrarySpecificUnit unit = target; | 3053 LibrarySpecificUnit unit = target; |
| 3157 return <String, TaskInput>{ | 3054 return <String, TaskInput>{ |
| 3055 'importsExportNamespace': |
| 3056 IMPORTED_LIBRARIES.of(unit.library).toMapOf(LIBRARY_ELEMENT4), |
| 3158 LIBRARY_INPUT: LIBRARY_ELEMENT4.of(unit.library), | 3057 LIBRARY_INPUT: LIBRARY_ELEMENT4.of(unit.library), |
| 3159 UNIT_INPUT: RESOLVED_UNIT3.of(unit), | 3058 UNIT_INPUT: RESOLVED_UNIT2.of(unit), |
| 3160 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) | 3059 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) |
| 3161 }; | 3060 }; |
| 3162 } | 3061 } |
| 3163 | 3062 |
| 3164 /** | 3063 /** |
| 3165 * Create a [ResolveUnitTypeNamesTask] based on the given [target] in | 3064 * Create a [ResolveUnitTypeNamesTask] based on the given [target] in |
| 3166 * the given [context]. | 3065 * the given [context]. |
| 3167 */ | 3066 */ |
| 3168 static ResolveUnitTypeNamesTask createTask( | 3067 static ResolveUnitTypeNamesTask createTask( |
| 3169 AnalysisContext context, AnalysisTarget target) { | 3068 AnalysisContext context, AnalysisTarget target) { |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3582 | 3481 |
| 3583 @override | 3482 @override |
| 3584 bool moveNext() { | 3483 bool moveNext() { |
| 3585 if (_newSources.isEmpty) { | 3484 if (_newSources.isEmpty) { |
| 3586 return false; | 3485 return false; |
| 3587 } | 3486 } |
| 3588 currentTarget = _newSources.removeLast(); | 3487 currentTarget = _newSources.removeLast(); |
| 3589 return true; | 3488 return true; |
| 3590 } | 3489 } |
| 3591 } | 3490 } |
| OLD | NEW |