| 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 | 8 |
| 9 import 'package:analyzer/src/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 import 'package:analyzer/src/generated/source.dart'; | 23 import 'package:analyzer/src/generated/source.dart'; |
| 24 import 'package:analyzer/src/generated/visitors.dart'; | 24 import 'package:analyzer/src/generated/visitors.dart'; |
| 25 import 'package:analyzer/src/plugin/engine_plugin.dart'; | 25 import 'package:analyzer/src/plugin/engine_plugin.dart'; |
| 26 import 'package:analyzer/src/services/lint.dart'; | 26 import 'package:analyzer/src/services/lint.dart'; |
| 27 import 'package:analyzer/src/task/driver.dart'; | 27 import 'package:analyzer/src/task/driver.dart'; |
| 28 import 'package:analyzer/src/task/general.dart'; | 28 import 'package:analyzer/src/task/general.dart'; |
| 29 import 'package:analyzer/src/task/html.dart'; | 29 import 'package:analyzer/src/task/html.dart'; |
| 30 import 'package:analyzer/src/task/inputs.dart'; | 30 import 'package:analyzer/src/task/inputs.dart'; |
| 31 import 'package:analyzer/src/task/model.dart'; | 31 import 'package:analyzer/src/task/model.dart'; |
| 32 import 'package:analyzer/src/task/strong_mode.dart'; | 32 import 'package:analyzer/src/task/strong_mode.dart'; |
| 33 import 'package:analyzer/src/task/strong/checker.dart'; |
| 34 import 'package:analyzer/src/task/strong/rules.dart'; |
| 33 import 'package:analyzer/task/dart.dart'; | 35 import 'package:analyzer/task/dart.dart'; |
| 34 import 'package:analyzer/task/general.dart'; | 36 import 'package:analyzer/task/general.dart'; |
| 35 import 'package:analyzer/task/model.dart'; | 37 import 'package:analyzer/task/model.dart'; |
| 36 | 38 |
| 37 /** | 39 /** |
| 38 * The [ResultCachingPolicy] for ASTs. | 40 * The [ResultCachingPolicy] for ASTs. |
| 39 */ | 41 */ |
| 40 const ResultCachingPolicy AST_CACHING_POLICY = | 42 const ResultCachingPolicy AST_CACHING_POLICY = |
| 41 const SimpleResultCachingPolicy(8192, 8192); | 43 const SimpleResultCachingPolicy(8192, 8192); |
| 42 | 44 |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 * The resolved [CompilationUnit] associated with a compilation unit, with | 456 * The resolved [CompilationUnit] associated with a compilation unit, with |
| 455 * constants not yet resolved. | 457 * constants not yet resolved. |
| 456 * | 458 * |
| 457 * The result is only available for [LibrarySpecificUnit]s. | 459 * The result is only available for [LibrarySpecificUnit]s. |
| 458 */ | 460 */ |
| 459 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT9 = | 461 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT9 = |
| 460 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT9', null, | 462 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT9', null, |
| 461 cachingPolicy: AST_CACHING_POLICY); | 463 cachingPolicy: AST_CACHING_POLICY); |
| 462 | 464 |
| 463 /** | 465 /** |
| 466 * The resolved [CompilationUnit] associated with a compilation unit, with |
| 467 * constants resolved. |
| 468 * |
| 469 * The result is only available for [LibrarySpecificUnit]s. |
| 470 */ |
| 471 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT10 = |
| 472 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT10', null, |
| 473 cachingPolicy: AST_CACHING_POLICY); |
| 474 |
| 475 /** |
| 464 * The errors produced while scanning a compilation unit. | 476 * The errors produced while scanning a compilation unit. |
| 465 * | 477 * |
| 466 * The list will be empty if there were no errors, but will not be `null`. | 478 * The list will be empty if there were no errors, but will not be `null`. |
| 467 * | 479 * |
| 468 * The result is only available for [Source]s representing a compilation unit. | 480 * The result is only available for [Source]s representing a compilation unit. |
| 469 */ | 481 */ |
| 470 final ListResultDescriptor<AnalysisError> SCAN_ERRORS = | 482 final ListResultDescriptor<AnalysisError> SCAN_ERRORS = |
| 471 new ListResultDescriptor<AnalysisError>( | 483 new ListResultDescriptor<AnalysisError>( |
| 472 'SCAN_ERRORS', AnalysisError.NO_ERRORS); | 484 'SCAN_ERRORS', AnalysisError.NO_ERRORS); |
| 473 | 485 |
| 474 /** | 486 /** |
| 487 * The additional strong mode errors produced while verifying a |
| 488 * compilation unit. |
| 489 * |
| 490 * The list will be empty if there were no errors, but will not be `null`. |
| 491 * |
| 492 * The result is only available for [LibrarySpecificUnits]s representing a |
| 493 * compilation unit. |
| 494 * |
| 495 */ |
| 496 final ListResultDescriptor<AnalysisError> STRONG_MODE_ERRORS = |
| 497 new ListResultDescriptor<AnalysisError>( |
| 498 'STRONG_MODE_ERRORS', AnalysisError.NO_ERRORS); |
| 499 |
| 500 /** |
| 475 * The [TypeProvider] of the [AnalysisContext]. | 501 * The [TypeProvider] of the [AnalysisContext]. |
| 476 */ | 502 */ |
| 477 final ResultDescriptor<TypeProvider> TYPE_PROVIDER = | 503 final ResultDescriptor<TypeProvider> TYPE_PROVIDER = |
| 478 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null); | 504 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null); |
| 479 | 505 |
| 480 /** | 506 /** |
| 481 * The [UsedImportedElements] of a [LibrarySpecificUnit]. | 507 * The [UsedImportedElements] of a [LibrarySpecificUnit]. |
| 482 */ | 508 */ |
| 483 final ResultDescriptor<UsedImportedElements> USED_IMPORTED_ELEMENTS = | 509 final ResultDescriptor<UsedImportedElements> USED_IMPORTED_ELEMENTS = |
| 484 new ResultDescriptor<UsedImportedElements>('USED_IMPORTED_ELEMENTS', null, | 510 new ResultDescriptor<UsedImportedElements>('USED_IMPORTED_ELEMENTS', null, |
| (...skipping 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2102 * Create a [DartErrorsTask] based on the given [target] in the given | 2128 * Create a [DartErrorsTask] based on the given [target] in the given |
| 2103 * [context]. | 2129 * [context]. |
| 2104 */ | 2130 */ |
| 2105 static DartErrorsTask createTask( | 2131 static DartErrorsTask createTask( |
| 2106 AnalysisContext context, AnalysisTarget target) { | 2132 AnalysisContext context, AnalysisTarget target) { |
| 2107 return new DartErrorsTask(context, target); | 2133 return new DartErrorsTask(context, target); |
| 2108 } | 2134 } |
| 2109 } | 2135 } |
| 2110 | 2136 |
| 2111 /** | 2137 /** |
| 2112 * A task that builds [RESOLVED_UNIT] for a unit. | 2138 * A task that builds [RESOLVED_UNIT10] for a unit. |
| 2113 */ | 2139 */ |
| 2114 class EvaluateUnitConstantsTask extends SourceBasedAnalysisTask { | 2140 class EvaluateUnitConstantsTask extends SourceBasedAnalysisTask { |
| 2115 /** | 2141 /** |
| 2116 * The name of the [RESOLVED_UNIT9] input. | 2142 * The name of the [RESOLVED_UNIT9] input. |
| 2117 */ | 2143 */ |
| 2118 static const String UNIT_INPUT = 'UNIT_INPUT'; | 2144 static const String UNIT_INPUT = 'UNIT_INPUT'; |
| 2119 | 2145 |
| 2120 /** | 2146 /** |
| 2121 * The name of the [CONSTANT_VALUE] input. | 2147 * The name of the [CONSTANT_VALUE] input. |
| 2122 */ | 2148 */ |
| 2123 static const String CONSTANT_VALUES = 'CONSTANT_VALUES'; | 2149 static const String CONSTANT_VALUES = 'CONSTANT_VALUES'; |
| 2124 | 2150 |
| 2125 /** | 2151 /** |
| 2126 * The task descriptor describing this kind of task. | 2152 * The task descriptor describing this kind of task. |
| 2127 */ | 2153 */ |
| 2128 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 2154 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 2129 'EvaluateUnitConstantsTask', | 2155 'EvaluateUnitConstantsTask', |
| 2130 createTask, | 2156 createTask, |
| 2131 buildInputs, | 2157 buildInputs, |
| 2132 <ResultDescriptor>[RESOLVED_UNIT]); | 2158 <ResultDescriptor>[RESOLVED_UNIT10]); |
| 2133 | 2159 |
| 2134 EvaluateUnitConstantsTask(AnalysisContext context, LibrarySpecificUnit target) | 2160 EvaluateUnitConstantsTask(AnalysisContext context, LibrarySpecificUnit target) |
| 2135 : super(context, target); | 2161 : super(context, target); |
| 2136 | 2162 |
| 2137 @override | 2163 @override |
| 2138 TaskDescriptor get descriptor => DESCRIPTOR; | 2164 TaskDescriptor get descriptor => DESCRIPTOR; |
| 2139 | 2165 |
| 2140 @override | 2166 @override |
| 2141 void internalPerform() { | 2167 void internalPerform() { |
| 2142 // No actual work needs to be performed; the task manager will ensure that | 2168 // No actual work needs to be performed; the task manager will ensure that |
| 2143 // all constants are evaluated before this method is called. | 2169 // all constants are evaluated before this method is called. |
| 2144 CompilationUnit unit = getRequiredInput(UNIT_INPUT); | 2170 CompilationUnit unit = getRequiredInput(UNIT_INPUT); |
| 2145 outputs[RESOLVED_UNIT] = unit; | 2171 outputs[RESOLVED_UNIT10] = unit; |
| 2146 } | 2172 } |
| 2147 | 2173 |
| 2148 /** | 2174 /** |
| 2149 * Return a map from the names of the inputs of this kind of task to the task | 2175 * Return a map from the names of the inputs of this kind of task to the task |
| 2150 * input descriptors describing those inputs for a task with the | 2176 * input descriptors describing those inputs for a task with the |
| 2151 * given [target]. | 2177 * given [target]. |
| 2152 */ | 2178 */ |
| 2153 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 2179 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 2154 LibrarySpecificUnit unit = target; | 2180 LibrarySpecificUnit unit = target; |
| 2155 return <String, TaskInput>{ | 2181 return <String, TaskInput>{ |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2528 AnalysisContext context, AnalysisTarget target) { | 2554 AnalysisContext context, AnalysisTarget target) { |
| 2529 return new GenerateHintsTask(context, target); | 2555 return new GenerateHintsTask(context, target); |
| 2530 } | 2556 } |
| 2531 } | 2557 } |
| 2532 | 2558 |
| 2533 /** | 2559 /** |
| 2534 * A task that generates [LINTS] for a unit. | 2560 * A task that generates [LINTS] for a unit. |
| 2535 */ | 2561 */ |
| 2536 class GenerateLintsTask extends SourceBasedAnalysisTask { | 2562 class GenerateLintsTask extends SourceBasedAnalysisTask { |
| 2537 /** | 2563 /** |
| 2538 * The name of the [RESOLVED_UNIT8] input. | 2564 * The name of the [RESOLVED_UNIT] input. |
| 2539 */ | 2565 */ |
| 2540 static const String RESOLVED_UNIT_INPUT = 'RESOLVED_UNIT'; | 2566 static const String RESOLVED_UNIT_INPUT = 'RESOLVED_UNIT'; |
| 2541 | 2567 |
| 2542 /** | 2568 /** |
| 2543 * The task descriptor describing this kind of task. | 2569 * The task descriptor describing this kind of task. |
| 2544 */ | 2570 */ |
| 2545 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 2571 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 2546 'GenerateLintsTask', createTask, buildInputs, <ResultDescriptor>[LINTS]); | 2572 'GenerateLintsTask', createTask, buildInputs, <ResultDescriptor>[LINTS]); |
| 2547 | 2573 |
| 2548 GenerateLintsTask(InternalAnalysisContext context, AnalysisTarget target) | 2574 GenerateLintsTask(InternalAnalysisContext context, AnalysisTarget target) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2567 // | 2593 // |
| 2568 // Prepare inputs. | 2594 // Prepare inputs. |
| 2569 // | 2595 // |
| 2570 CompilationUnit unit = getRequiredInput(RESOLVED_UNIT_INPUT); | 2596 CompilationUnit unit = getRequiredInput(RESOLVED_UNIT_INPUT); |
| 2571 | 2597 |
| 2572 // | 2598 // |
| 2573 // Generate lints. | 2599 // Generate lints. |
| 2574 // | 2600 // |
| 2575 List<Linter> linters = lintRegistry[context] ?? []; | 2601 List<Linter> linters = lintRegistry[context] ?? []; |
| 2576 linters.forEach((l) => l.reporter = errorReporter); | 2602 linters.forEach((l) => l.reporter = errorReporter); |
| 2577 Iterable<AstVisitor> visitors = | 2603 Iterable<AstVisitor> visitors = linters.map((l) => l.getVisitor()).toList(); |
| 2578 linters.map((l) => l.getVisitor()).toList(); | |
| 2579 unit.accept(new DelegatingAstVisitor(visitors.where((v) => v != null))); | 2604 unit.accept(new DelegatingAstVisitor(visitors.where((v) => v != null))); |
| 2580 | 2605 |
| 2581 // | 2606 // |
| 2582 // Record outputs. | 2607 // Record outputs. |
| 2583 // | 2608 // |
| 2584 outputs[LINTS] = errorListener.errors; | 2609 outputs[LINTS] = errorListener.errors; |
| 2585 } | 2610 } |
| 2586 | 2611 |
| 2587 /** | 2612 /** |
| 2588 * Return a map from the names of the inputs of this kind of task to the task | 2613 * Return a map from the names of the inputs of this kind of task to the task |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3117 * The name of the [HINTS] input. | 3142 * The name of the [HINTS] input. |
| 3118 */ | 3143 */ |
| 3119 static const String HINTS_INPUT = 'HINTS'; | 3144 static const String HINTS_INPUT = 'HINTS'; |
| 3120 | 3145 |
| 3121 /** | 3146 /** |
| 3122 * The name of the [LINTS] input. | 3147 * The name of the [LINTS] input. |
| 3123 */ | 3148 */ |
| 3124 static const String LINTS_INPUT = 'LINTS'; | 3149 static const String LINTS_INPUT = 'LINTS'; |
| 3125 | 3150 |
| 3126 /** | 3151 /** |
| 3152 * The name of the [STRONG_MODE_ERRORS] input. |
| 3153 */ |
| 3154 static const String STRONG_MODE_ERRORS_INPUT = 'STRONG_MODE_ERRORS'; |
| 3155 |
| 3156 /** |
| 3127 * The name of the [RESOLVE_TYPE_NAMES_ERRORS] input. | 3157 * The name of the [RESOLVE_TYPE_NAMES_ERRORS] input. |
| 3128 */ | 3158 */ |
| 3129 static const String RESOLVE_TYPE_NAMES_ERRORS_INPUT = | 3159 static const String RESOLVE_TYPE_NAMES_ERRORS_INPUT = |
| 3130 'RESOLVE_TYPE_NAMES_ERRORS'; | 3160 'RESOLVE_TYPE_NAMES_ERRORS'; |
| 3131 | 3161 |
| 3132 /** | 3162 /** |
| 3133 * The name of the [RESOLVE_UNIT_ERRORS] input. | 3163 * The name of the [RESOLVE_UNIT_ERRORS] input. |
| 3134 */ | 3164 */ |
| 3135 static const String RESOLVE_UNIT_ERRORS_INPUT = 'RESOLVE_UNIT_ERRORS'; | 3165 static const String RESOLVE_UNIT_ERRORS_INPUT = 'RESOLVE_UNIT_ERRORS'; |
| 3136 | 3166 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3165 // | 3195 // |
| 3166 // Prepare inputs. | 3196 // Prepare inputs. |
| 3167 // | 3197 // |
| 3168 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[]; | 3198 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[]; |
| 3169 errorLists.add(getRequiredInput(BUILD_DIRECTIVES_ERRORS_INPUT)); | 3199 errorLists.add(getRequiredInput(BUILD_DIRECTIVES_ERRORS_INPUT)); |
| 3170 errorLists.add(getRequiredInput(BUILD_LIBRARY_ERRORS_INPUT)); | 3200 errorLists.add(getRequiredInput(BUILD_LIBRARY_ERRORS_INPUT)); |
| 3171 errorLists.add(getRequiredInput(HINTS_INPUT)); | 3201 errorLists.add(getRequiredInput(HINTS_INPUT)); |
| 3172 errorLists.add(getRequiredInput(LINTS_INPUT)); | 3202 errorLists.add(getRequiredInput(LINTS_INPUT)); |
| 3173 errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT)); | 3203 errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT)); |
| 3174 errorLists.add(getRequiredInput(RESOLVE_UNIT_ERRORS_INPUT)); | 3204 errorLists.add(getRequiredInput(RESOLVE_UNIT_ERRORS_INPUT)); |
| 3205 errorLists.add(getRequiredInput(STRONG_MODE_ERRORS_INPUT)); |
| 3175 errorLists.add(getRequiredInput(VARIABLE_REFERENCE_ERRORS_INPUT)); | 3206 errorLists.add(getRequiredInput(VARIABLE_REFERENCE_ERRORS_INPUT)); |
| 3176 errorLists.add(getRequiredInput(VERIFY_ERRORS_INPUT)); | 3207 errorLists.add(getRequiredInput(VERIFY_ERRORS_INPUT)); |
| 3177 // | 3208 // |
| 3178 // Record outputs. | 3209 // Record outputs. |
| 3179 // | 3210 // |
| 3180 outputs[LIBRARY_UNIT_ERRORS] = AnalysisError.mergeLists(errorLists); | 3211 outputs[LIBRARY_UNIT_ERRORS] = AnalysisError.mergeLists(errorLists); |
| 3181 } | 3212 } |
| 3182 | 3213 |
| 3183 /** | 3214 /** |
| 3184 * Return a map from the names of the inputs of this kind of task to the task | 3215 * Return a map from the names of the inputs of this kind of task to the task |
| 3185 * input descriptors describing those inputs for a task with the | 3216 * input descriptors describing those inputs for a task with the |
| 3186 * given [unit]. | 3217 * given [unit]. |
| 3187 */ | 3218 */ |
| 3188 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 3219 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 3189 LibrarySpecificUnit unit = target; | 3220 LibrarySpecificUnit unit = target; |
| 3190 Map<String, TaskInput> inputs = <String, TaskInput>{ | 3221 Map<String, TaskInput> inputs = <String, TaskInput>{ |
| 3191 HINTS_INPUT: HINTS.of(unit), | 3222 HINTS_INPUT: HINTS.of(unit), |
| 3192 LINTS_INPUT: LINTS.of(unit), | 3223 LINTS_INPUT: LINTS.of(unit), |
| 3193 RESOLVE_TYPE_NAMES_ERRORS_INPUT: RESOLVE_TYPE_NAMES_ERRORS.of(unit), | 3224 RESOLVE_TYPE_NAMES_ERRORS_INPUT: RESOLVE_TYPE_NAMES_ERRORS.of(unit), |
| 3194 RESOLVE_UNIT_ERRORS_INPUT: RESOLVE_UNIT_ERRORS.of(unit), | 3225 RESOLVE_UNIT_ERRORS_INPUT: RESOLVE_UNIT_ERRORS.of(unit), |
| 3226 STRONG_MODE_ERRORS_INPUT: STRONG_MODE_ERRORS.of(unit), |
| 3195 VARIABLE_REFERENCE_ERRORS_INPUT: VARIABLE_REFERENCE_ERRORS.of(unit), | 3227 VARIABLE_REFERENCE_ERRORS_INPUT: VARIABLE_REFERENCE_ERRORS.of(unit), |
| 3196 VERIFY_ERRORS_INPUT: VERIFY_ERRORS.of(unit) | 3228 VERIFY_ERRORS_INPUT: VERIFY_ERRORS.of(unit) |
| 3197 }; | 3229 }; |
| 3198 Source source = unit.source; | 3230 Source source = unit.source; |
| 3199 if (unit.library == source) { | 3231 if (unit.library == source) { |
| 3200 inputs[BUILD_DIRECTIVES_ERRORS_INPUT] = | 3232 inputs[BUILD_DIRECTIVES_ERRORS_INPUT] = |
| 3201 BUILD_DIRECTIVES_ERRORS.of(source); | 3233 BUILD_DIRECTIVES_ERRORS.of(source); |
| 3202 inputs[BUILD_LIBRARY_ERRORS_INPUT] = BUILD_LIBRARY_ERRORS.of(source); | 3234 inputs[BUILD_LIBRARY_ERRORS_INPUT] = BUILD_LIBRARY_ERRORS.of(source); |
| 3203 } else { | 3235 } else { |
| 3204 inputs[BUILD_DIRECTIVES_ERRORS_INPUT] = | 3236 inputs[BUILD_DIRECTIVES_ERRORS_INPUT] = |
| (...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4145 /** | 4177 /** |
| 4146 * Create a [ScanDartTask] based on the given [target] in the given [context]. | 4178 * Create a [ScanDartTask] based on the given [target] in the given [context]. |
| 4147 */ | 4179 */ |
| 4148 static ScanDartTask createTask( | 4180 static ScanDartTask createTask( |
| 4149 AnalysisContext context, AnalysisTarget target) { | 4181 AnalysisContext context, AnalysisTarget target) { |
| 4150 return new ScanDartTask(context, target); | 4182 return new ScanDartTask(context, target); |
| 4151 } | 4183 } |
| 4152 } | 4184 } |
| 4153 | 4185 |
| 4154 /** | 4186 /** |
| 4187 * A task that builds [STRONG_MODE_ERRORS] for a unit. Also builds |
| 4188 * [RESOLVED_UNIT] for a unit. |
| 4189 */ |
| 4190 class StrongModeVerifyUnitTask extends SourceBasedAnalysisTask { |
| 4191 /** |
| 4192 * The name of the [RESOLVED_UNIT10] input. |
| 4193 */ |
| 4194 static const String UNIT_INPUT = 'UNIT_INPUT'; |
| 4195 |
| 4196 /** |
| 4197 * The name of the [TYPE_PROVIDER] input. |
| 4198 */ |
| 4199 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; |
| 4200 |
| 4201 /** |
| 4202 * The task descriptor describing this kind of task. |
| 4203 */ |
| 4204 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 4205 'StrongModeVerifyUnitTask', |
| 4206 createTask, |
| 4207 buildInputs, |
| 4208 <ResultDescriptor>[STRONG_MODE_ERRORS, RESOLVED_UNIT]); |
| 4209 |
| 4210 StrongModeVerifyUnitTask( |
| 4211 InternalAnalysisContext context, AnalysisTarget target) |
| 4212 : super(context, target); |
| 4213 |
| 4214 @override |
| 4215 TaskDescriptor get descriptor => DESCRIPTOR; |
| 4216 |
| 4217 @override |
| 4218 void internalPerform() { |
| 4219 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 4220 // |
| 4221 // Prepare inputs. |
| 4222 // |
| 4223 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); |
| 4224 CompilationUnit unit = getRequiredInput(UNIT_INPUT); |
| 4225 if (context.analysisOptions.strongMode) { |
| 4226 unit.accept(new CodeChecker(new TypeRules(typeProvider), errorListener)); |
| 4227 } |
| 4228 |
| 4229 // |
| 4230 // Record outputs. |
| 4231 // |
| 4232 outputs[STRONG_MODE_ERRORS] = removeDuplicateErrors(errorListener.errors); |
| 4233 outputs[RESOLVED_UNIT] = unit; |
| 4234 } |
| 4235 |
| 4236 /** |
| 4237 * Return a map from the names of the inputs of this kind of task to the task |
| 4238 * input descriptors describing those inputs for a task with the |
| 4239 * given [target]. |
| 4240 */ |
| 4241 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 4242 LibrarySpecificUnit unit = target; |
| 4243 return <String, TaskInput>{ |
| 4244 'resolvedUnits': IMPORT_EXPORT_SOURCE_CLOSURE |
| 4245 .of(unit.library) |
| 4246 .toMapOf(UNITS) |
| 4247 .toFlattenList((Source library, Source unit) => |
| 4248 RESOLVED_UNIT10.of(new LibrarySpecificUnit(library, unit))), |
| 4249 UNIT_INPUT: RESOLVED_UNIT10.of(unit), |
| 4250 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) |
| 4251 }; |
| 4252 } |
| 4253 |
| 4254 /** |
| 4255 * Create a [StrongModeVerifyUnitTask] based on the given [target] in |
| 4256 * the given [context]. |
| 4257 */ |
| 4258 static StrongModeVerifyUnitTask createTask( |
| 4259 AnalysisContext context, AnalysisTarget target) { |
| 4260 return new StrongModeVerifyUnitTask(context, target); |
| 4261 } |
| 4262 } |
| 4263 |
| 4264 /** |
| 4155 * A task that builds [VERIFY_ERRORS] for a unit. | 4265 * A task that builds [VERIFY_ERRORS] for a unit. |
| 4156 */ | 4266 */ |
| 4157 class VerifyUnitTask extends SourceBasedAnalysisTask { | 4267 class VerifyUnitTask extends SourceBasedAnalysisTask { |
| 4158 /** | 4268 /** |
| 4159 * The name of the [RESOLVED_UNIT] input. | 4269 * The name of the [RESOLVED_UNIT] input. |
| 4160 */ | 4270 */ |
| 4161 static const String UNIT_INPUT = 'UNIT_INPUT'; | 4271 static const String UNIT_INPUT = 'UNIT_INPUT'; |
| 4162 | 4272 |
| 4163 /** | 4273 /** |
| 4164 * The name of the [TYPE_PROVIDER] input. | 4274 * The name of the [TYPE_PROVIDER] input. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4207 // | 4317 // |
| 4208 // Use the ErrorVerifier to compute errors. | 4318 // Use the ErrorVerifier to compute errors. |
| 4209 // | 4319 // |
| 4210 ErrorVerifier errorVerifier = new ErrorVerifier( | 4320 ErrorVerifier errorVerifier = new ErrorVerifier( |
| 4211 errorReporter, | 4321 errorReporter, |
| 4212 libraryElement, | 4322 libraryElement, |
| 4213 typeProvider, | 4323 typeProvider, |
| 4214 new InheritanceManager(libraryElement), | 4324 new InheritanceManager(libraryElement), |
| 4215 context.analysisOptions.enableSuperMixins); | 4325 context.analysisOptions.enableSuperMixins); |
| 4216 unit.accept(errorVerifier); | 4326 unit.accept(errorVerifier); |
| 4327 |
| 4217 // | 4328 // |
| 4218 // Record outputs. | 4329 // Record outputs. |
| 4219 // | 4330 // |
| 4220 outputs[VERIFY_ERRORS] = removeDuplicateErrors(errorListener.errors); | 4331 outputs[VERIFY_ERRORS] = removeDuplicateErrors(errorListener.errors); |
| 4221 } | 4332 } |
| 4222 | 4333 |
| 4223 /** | 4334 /** |
| 4224 * Check each directive in the given [unit] to see if the referenced source | 4335 * Check each directive in the given [unit] to see if the referenced source |
| 4225 * exists and report an error if it does not. | 4336 * exists and report an error if it does not. |
| 4226 */ | 4337 */ |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4398 | 4509 |
| 4399 @override | 4510 @override |
| 4400 bool moveNext() { | 4511 bool moveNext() { |
| 4401 if (_newSources.isEmpty) { | 4512 if (_newSources.isEmpty) { |
| 4402 return false; | 4513 return false; |
| 4403 } | 4514 } |
| 4404 currentTarget = _newSources.removeLast(); | 4515 currentTarget = _newSources.removeLast(); |
| 4405 return true; | 4516 return true; |
| 4406 } | 4517 } |
| 4407 } | 4518 } |
| OLD | NEW |