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'; |
11 import 'package:analyzer/src/generated/constant.dart'; | 11 import 'package:analyzer/src/generated/constant.dart'; |
12 import 'package:analyzer/src/generated/element.dart'; | 12 import 'package:analyzer/src/generated/element.dart'; |
13 import 'package:analyzer/src/generated/engine.dart' | 13 import 'package:analyzer/src/generated/engine.dart' |
14 hide AnalysisCache, AnalysisTask; | 14 hide AnalysisCache, AnalysisTask; |
15 import 'package:analyzer/src/generated/error.dart'; | 15 import 'package:analyzer/src/generated/error.dart'; |
16 import 'package:analyzer/src/generated/error_verifier.dart'; | 16 import 'package:analyzer/src/generated/error_verifier.dart'; |
17 import 'package:analyzer/src/generated/incremental_resolver.dart'; | 17 import 'package:analyzer/src/generated/incremental_resolver.dart'; |
18 import 'package:analyzer/src/generated/java_engine.dart'; | 18 import 'package:analyzer/src/generated/java_engine.dart'; |
19 import 'package:analyzer/src/generated/parser.dart'; | 19 import 'package:analyzer/src/generated/parser.dart'; |
20 import 'package:analyzer/src/generated/resolver.dart'; | 20 import 'package:analyzer/src/generated/resolver.dart'; |
21 import 'package:analyzer/src/generated/scanner.dart'; | 21 import 'package:analyzer/src/generated/scanner.dart'; |
22 import 'package:analyzer/src/generated/sdk.dart'; | 22 import 'package:analyzer/src/generated/sdk.dart'; |
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/plugin/engine_plugin.dart'; | 25 import 'package:analyzer/src/plugin/engine_plugin.dart'; |
26 import 'package:analyzer/src/services/lint.dart'; | |
25 import 'package:analyzer/src/task/driver.dart'; | 27 import 'package:analyzer/src/task/driver.dart'; |
26 import 'package:analyzer/src/task/general.dart'; | 28 import 'package:analyzer/src/task/general.dart'; |
27 import 'package:analyzer/src/task/html.dart'; | 29 import 'package:analyzer/src/task/html.dart'; |
28 import 'package:analyzer/src/task/inputs.dart'; | 30 import 'package:analyzer/src/task/inputs.dart'; |
29 import 'package:analyzer/src/task/model.dart'; | 31 import 'package:analyzer/src/task/model.dart'; |
30 import 'package:analyzer/src/task/strong_mode.dart'; | 32 import 'package:analyzer/src/task/strong_mode.dart'; |
31 import 'package:analyzer/task/dart.dart'; | 33 import 'package:analyzer/task/dart.dart'; |
32 import 'package:analyzer/task/general.dart'; | 34 import 'package:analyzer/task/general.dart'; |
33 import 'package:analyzer/task/model.dart'; | 35 import 'package:analyzer/task/model.dart'; |
34 | 36 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 /** | 286 /** |
285 * The analysis errors associated with a compilation unit in a specific library. | 287 * The analysis errors associated with a compilation unit in a specific library. |
286 * | 288 * |
287 * The result is only available for [LibrarySpecificUnit]s. | 289 * The result is only available for [LibrarySpecificUnit]s. |
288 */ | 290 */ |
289 final ListResultDescriptor<AnalysisError> LIBRARY_UNIT_ERRORS = | 291 final ListResultDescriptor<AnalysisError> LIBRARY_UNIT_ERRORS = |
290 new ListResultDescriptor<AnalysisError>( | 292 new ListResultDescriptor<AnalysisError>( |
291 'LIBRARY_UNIT_ERRORS', AnalysisError.NO_ERRORS); | 293 'LIBRARY_UNIT_ERRORS', AnalysisError.NO_ERRORS); |
292 | 294 |
293 /** | 295 /** |
296 * The errors produced while generating lints for a compilation unit. | |
297 * | |
298 * The list will be empty if there were no errors, but will not be `null`. | |
299 * | |
300 * The result is only available for [LibrarySpecificUnit]s. | |
301 */ | |
302 final ListResultDescriptor<AnalysisError> LINTS = | |
303 new ListResultDescriptor<AnalysisError>( | |
304 'LINT_ERRORS', AnalysisError.NO_ERRORS); | |
305 | |
306 /** | |
294 * The errors produced while parsing a compilation unit. | 307 * The errors produced while parsing a compilation unit. |
295 * | 308 * |
296 * The list will be empty if there were no errors, but will not be `null`. | 309 * The list will be empty if there were no errors, but will not be `null`. |
297 * | 310 * |
298 * The result is only available for [Source]s representing a compilation unit. | 311 * The result is only available for [Source]s representing a compilation unit. |
299 */ | 312 */ |
300 final ListResultDescriptor<AnalysisError> PARSE_ERRORS = | 313 final ListResultDescriptor<AnalysisError> PARSE_ERRORS = |
301 new ListResultDescriptor<AnalysisError>( | 314 new ListResultDescriptor<AnalysisError>( |
302 'PARSE_ERRORS', AnalysisError.NO_ERRORS); | 315 'PARSE_ERRORS', AnalysisError.NO_ERRORS); |
303 | 316 |
(...skipping 2108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2412 * Create a [GenerateHintsTask] based on the given [target] in | 2425 * Create a [GenerateHintsTask] based on the given [target] in |
2413 * the given [context]. | 2426 * the given [context]. |
2414 */ | 2427 */ |
2415 static GenerateHintsTask createTask( | 2428 static GenerateHintsTask createTask( |
2416 AnalysisContext context, AnalysisTarget target) { | 2429 AnalysisContext context, AnalysisTarget target) { |
2417 return new GenerateHintsTask(context, target); | 2430 return new GenerateHintsTask(context, target); |
2418 } | 2431 } |
2419 } | 2432 } |
2420 | 2433 |
2421 /** | 2434 /** |
2435 * A task that generates [LINTS] for a unit. | |
2436 */ | |
2437 class GenerateLintsTask extends SourceBasedAnalysisTask { | |
2438 /** | |
2439 * The name of the [RESOLVED_UNIT8] input. | |
2440 */ | |
2441 static const String RESOLVED_UNIT_INPUT = 'RESOLVED_UNIT'; | |
2442 | |
2443 /** | |
2444 * The name of a list of [USED_LOCAL_ELEMENTS] for each library unit input. | |
2445 */ | |
2446 static const String USED_LOCAL_ELEMENTS_INPUT = 'USED_LOCAL_ELEMENTS'; | |
scheglov
2015/10/09 03:45:10
It seems that this and the next two input names ar
pquitslund
2015/10/09 15:25:36
Good catch!
https://codereview.chromium.org/13863
| |
2447 | |
2448 /** | |
2449 * The name of a list of [USED_IMPORTED_ELEMENTS] for each library unit input. | |
2450 */ | |
2451 static const String USED_IMPORTED_ELEMENTS_INPUT = 'USED_IMPORTED_ELEMENTS'; | |
2452 | |
2453 /** | |
2454 * The name of the [TYPE_PROVIDER] input. | |
2455 */ | |
2456 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; | |
2457 | |
2458 /** | |
2459 * The task descriptor describing this kind of task. | |
2460 */ | |
2461 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | |
2462 'GenerateLintsTask', createTask, buildInputs, <ResultDescriptor>[LINTS]); | |
2463 | |
2464 GenerateLintsTask(InternalAnalysisContext context, AnalysisTarget target) | |
2465 : super(context, target); | |
2466 | |
2467 @override | |
2468 TaskDescriptor get descriptor => DESCRIPTOR; | |
2469 | |
2470 @override | |
2471 void internalPerform() { | |
2472 AnalysisOptions analysisOptions = context.analysisOptions; | |
2473 if (!analysisOptions.lint) { | |
2474 outputs[LINTS] = AnalysisError.NO_ERRORS; | |
2475 return; | |
2476 } | |
2477 // | |
2478 // Prepare collectors. | |
2479 // | |
2480 RecordingErrorListener errorListener = new RecordingErrorListener(); | |
2481 Source source = getRequiredSource(); | |
2482 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); | |
2483 // | |
2484 // Prepare inputs. | |
2485 // | |
2486 CompilationUnit unit = getRequiredInput(RESOLVED_UNIT_INPUT); | |
2487 | |
2488 // | |
2489 // Generate lints. | |
2490 // | |
2491 LintGenerator.LINTERS.forEach((l) => l.reporter = errorReporter); | |
2492 Iterable<AstVisitor> visitors = | |
2493 LintGenerator.LINTERS.map((l) => l.getVisitor()).toList(); | |
2494 unit.accept(new DelegatingAstVisitor(visitors.where((v) => v != null))); | |
2495 | |
2496 // | |
2497 // Record outputs. | |
2498 // | |
2499 outputs[LINTS] = errorListener.errors; | |
2500 } | |
2501 | |
2502 /** | |
2503 * Return a map from the names of the inputs of this kind of task to the task | |
2504 * input descriptors describing those inputs for a task with the | |
2505 * given [target]. | |
2506 */ | |
2507 static Map<String, TaskInput> buildInputs(AnalysisTarget target) => | |
2508 <String, TaskInput>{RESOLVED_UNIT_INPUT: RESOLVED_UNIT.of(target)}; | |
2509 | |
2510 /** | |
2511 * Create a [GenerateLintsTask] based on the given [target] in | |
2512 * the given [context]. | |
2513 */ | |
2514 static GenerateLintsTask createTask( | |
2515 AnalysisContext context, AnalysisTarget target) { | |
2516 return new GenerateLintsTask(context, target); | |
2517 } | |
2518 } | |
2519 | |
2520 /** | |
2422 * A task that ensures that all of the inferrable instance members in a | 2521 * A task that ensures that all of the inferrable instance members in a |
2423 * compilation unit have had their type inferred. | 2522 * compilation unit have had their type inferred. |
2424 */ | 2523 */ |
2425 class InferInstanceMembersInUnitTask extends SourceBasedAnalysisTask { | 2524 class InferInstanceMembersInUnitTask extends SourceBasedAnalysisTask { |
2426 /** | 2525 /** |
2427 * The name of the [TYPE_PROVIDER] input. | 2526 * The name of the [TYPE_PROVIDER] input. |
2428 */ | 2527 */ |
2429 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; | 2528 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; |
2430 | 2529 |
2431 /** | 2530 /** |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2812 * The name of the [BUILD_LIBRARY_ERRORS] input. | 2911 * The name of the [BUILD_LIBRARY_ERRORS] input. |
2813 */ | 2912 */ |
2814 static const String BUILD_LIBRARY_ERRORS_INPUT = 'BUILD_LIBRARY_ERRORS'; | 2913 static const String BUILD_LIBRARY_ERRORS_INPUT = 'BUILD_LIBRARY_ERRORS'; |
2815 | 2914 |
2816 /** | 2915 /** |
2817 * The name of the [HINTS] input. | 2916 * The name of the [HINTS] input. |
2818 */ | 2917 */ |
2819 static const String HINTS_INPUT = 'HINTS'; | 2918 static const String HINTS_INPUT = 'HINTS'; |
2820 | 2919 |
2821 /** | 2920 /** |
2921 * The name of the [LINTS] input. | |
2922 */ | |
2923 static const String LINTS_INPUT = 'LINTS'; | |
2924 | |
2925 /** | |
2822 * The name of the [INFER_STATIC_VARIABLE_TYPES_ERRORS] input. | 2926 * The name of the [INFER_STATIC_VARIABLE_TYPES_ERRORS] input. |
2823 */ | 2927 */ |
2824 static const String INFER_STATIC_VARIABLE_TYPES_ERRORS_INPUT = | 2928 static const String INFER_STATIC_VARIABLE_TYPES_ERRORS_INPUT = |
2825 'INFER_STATIC_VARIABLE_TYPES_ERRORS'; | 2929 'INFER_STATIC_VARIABLE_TYPES_ERRORS'; |
2826 | 2930 |
2827 /** | 2931 /** |
2828 * The name of the [PARTIALLY_RESOLVE_REFERENCES_ERRORS] input. | 2932 * The name of the [PARTIALLY_RESOLVE_REFERENCES_ERRORS] input. |
2829 */ | 2933 */ |
2830 static const String PARTIALLY_RESOLVE_REFERENCES_ERRORS_INPUT = | 2934 static const String PARTIALLY_RESOLVE_REFERENCES_ERRORS_INPUT = |
2831 'PARTIALLY_RESOLVE_REFERENCES_ERRORS'; | 2935 'PARTIALLY_RESOLVE_REFERENCES_ERRORS'; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2870 | 2974 |
2871 @override | 2975 @override |
2872 void internalPerform() { | 2976 void internalPerform() { |
2873 // | 2977 // |
2874 // Prepare inputs. | 2978 // Prepare inputs. |
2875 // | 2979 // |
2876 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[]; | 2980 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[]; |
2877 errorLists.add(getRequiredInput(BUILD_DIRECTIVES_ERRORS_INPUT)); | 2981 errorLists.add(getRequiredInput(BUILD_DIRECTIVES_ERRORS_INPUT)); |
2878 errorLists.add(getRequiredInput(BUILD_LIBRARY_ERRORS_INPUT)); | 2982 errorLists.add(getRequiredInput(BUILD_LIBRARY_ERRORS_INPUT)); |
2879 errorLists.add(getRequiredInput(HINTS_INPUT)); | 2983 errorLists.add(getRequiredInput(HINTS_INPUT)); |
2984 errorLists.add(getRequiredInput(LINTS_INPUT)); | |
2880 errorLists.add(getRequiredInput(INFER_STATIC_VARIABLE_TYPES_ERRORS_INPUT)); | 2985 errorLists.add(getRequiredInput(INFER_STATIC_VARIABLE_TYPES_ERRORS_INPUT)); |
2881 errorLists.add(getRequiredInput(PARTIALLY_RESOLVE_REFERENCES_ERRORS_INPUT)); | 2986 errorLists.add(getRequiredInput(PARTIALLY_RESOLVE_REFERENCES_ERRORS_INPUT)); |
2882 errorLists.add(getRequiredInput(RESOLVE_FUNCTION_BODIES_ERRORS_INPUT)); | 2987 errorLists.add(getRequiredInput(RESOLVE_FUNCTION_BODIES_ERRORS_INPUT)); |
2883 errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT)); | 2988 errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT)); |
2884 errorLists.add(getRequiredInput(VARIABLE_REFERENCE_ERRORS_INPUT)); | 2989 errorLists.add(getRequiredInput(VARIABLE_REFERENCE_ERRORS_INPUT)); |
2885 errorLists.add(getRequiredInput(VERIFY_ERRORS_INPUT)); | 2990 errorLists.add(getRequiredInput(VERIFY_ERRORS_INPUT)); |
2886 // | 2991 // |
2887 // Record outputs. | 2992 // Record outputs. |
2888 // | 2993 // |
2889 outputs[LIBRARY_UNIT_ERRORS] = AnalysisError.mergeLists(errorLists); | 2994 outputs[LIBRARY_UNIT_ERRORS] = AnalysisError.mergeLists(errorLists); |
2890 } | 2995 } |
2891 | 2996 |
2892 /** | 2997 /** |
2893 * Return a map from the names of the inputs of this kind of task to the task | 2998 * Return a map from the names of the inputs of this kind of task to the task |
2894 * input descriptors describing those inputs for a task with the | 2999 * input descriptors describing those inputs for a task with the |
2895 * given [unit]. | 3000 * given [unit]. |
2896 */ | 3001 */ |
2897 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 3002 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
2898 LibrarySpecificUnit unit = target; | 3003 LibrarySpecificUnit unit = target; |
2899 Map<String, TaskInput> inputs = <String, TaskInput>{ | 3004 Map<String, TaskInput> inputs = <String, TaskInput>{ |
2900 HINTS_INPUT: HINTS.of(unit), | 3005 HINTS_INPUT: HINTS.of(unit), |
3006 LINTS_INPUT: LINTS.of(unit), | |
scheglov
2015/10/09 03:45:10
Would be nice to keep these sorted.
pquitslund
2015/10/09 15:25:36
I think this has been fixed already.
| |
2901 INFER_STATIC_VARIABLE_TYPES_ERRORS_INPUT: | 3007 INFER_STATIC_VARIABLE_TYPES_ERRORS_INPUT: |
2902 INFER_STATIC_VARIABLE_TYPES_ERRORS.of(unit), | 3008 INFER_STATIC_VARIABLE_TYPES_ERRORS.of(unit), |
2903 PARTIALLY_RESOLVE_REFERENCES_ERRORS_INPUT: | 3009 PARTIALLY_RESOLVE_REFERENCES_ERRORS_INPUT: |
2904 PARTIALLY_RESOLVE_REFERENCES_ERRORS.of(unit), | 3010 PARTIALLY_RESOLVE_REFERENCES_ERRORS.of(unit), |
2905 RESOLVE_FUNCTION_BODIES_ERRORS_INPUT: | 3011 RESOLVE_FUNCTION_BODIES_ERRORS_INPUT: |
2906 RESOLVE_FUNCTION_BODIES_ERRORS.of(unit), | 3012 RESOLVE_FUNCTION_BODIES_ERRORS.of(unit), |
2907 RESOLVE_TYPE_NAMES_ERRORS_INPUT: RESOLVE_TYPE_NAMES_ERRORS.of(unit), | 3013 RESOLVE_TYPE_NAMES_ERRORS_INPUT: RESOLVE_TYPE_NAMES_ERRORS.of(unit), |
2908 VARIABLE_REFERENCE_ERRORS_INPUT: VARIABLE_REFERENCE_ERRORS.of(unit), | 3014 VARIABLE_REFERENCE_ERRORS_INPUT: VARIABLE_REFERENCE_ERRORS.of(unit), |
2909 VERIFY_ERRORS_INPUT: VERIFY_ERRORS.of(unit) | 3015 VERIFY_ERRORS_INPUT: VERIFY_ERRORS.of(unit) |
2910 }; | 3016 }; |
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4128 | 4234 |
4129 @override | 4235 @override |
4130 bool moveNext() { | 4236 bool moveNext() { |
4131 if (_newSources.isEmpty) { | 4237 if (_newSources.isEmpty) { |
4132 return false; | 4238 return false; |
4133 } | 4239 } |
4134 currentTarget = _newSources.removeLast(); | 4240 currentTarget = _newSources.removeLast(); |
4135 return true; | 4241 return true; |
4136 } | 4242 } |
4137 } | 4243 } |
OLD | NEW |