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

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

Issue 1385293002: Lint support for the new task model. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
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/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
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
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';
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 if (LintGenerator.LINTERS.isNotEmpty) {
2497 print(LintGenerator.LINTERS);
2498 print(errorListener.errors);
2499 }
2500
2501 //
2502 // Record outputs.
2503 //
2504 outputs[LINTS] = errorListener.errors;
2505 }
2506
2507 /**
2508 * Return a map from the names of the inputs of this kind of task to the task
2509 * input descriptors describing those inputs for a task with the
2510 * given [target].
2511 */
2512 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2513 LibrarySpecificUnit unit = target;
2514 Source libSource = unit.library;
2515 return <String, TaskInput>{
2516 RESOLVED_UNIT_INPUT: RESOLVED_UNIT.of(unit),
2517 USED_LOCAL_ELEMENTS_INPUT: UNITS.of(libSource).toList((unit) {
2518 LibrarySpecificUnit target = new LibrarySpecificUnit(libSource, unit);
2519 return USED_LOCAL_ELEMENTS.of(target);
2520 }),
2521 USED_IMPORTED_ELEMENTS_INPUT: UNITS.of(libSource).toList((unit) {
2522 LibrarySpecificUnit target = new LibrarySpecificUnit(libSource, unit);
2523 return USED_IMPORTED_ELEMENTS.of(target);
2524 }),
2525 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
pquitslund 2015/10/06 22:18:12 OK: I'm sure this can be pruned... Advise?
Brian Wilkerson 2015/10/06 22:40:53 Yes. The only input you use is RESOLVED_UNIT_INPUT
2526 };
2527 }
2528
2529 /**
2530 * Create a [GenerateLintsTask] based on the given [target] in
2531 * the given [context].
2532 */
2533 static GenerateLintsTask createTask(
2534 AnalysisContext context, AnalysisTarget target) {
2535 return new GenerateLintsTask(context, target);
2536 }
2537 }
2538
2539 /**
2422 * A task that ensures that all of the inferrable instance members in a 2540 * A task that ensures that all of the inferrable instance members in a
2423 * compilation unit have had their type inferred. 2541 * compilation unit have had their type inferred.
2424 */ 2542 */
2425 class InferInstanceMembersInUnitTask extends SourceBasedAnalysisTask { 2543 class InferInstanceMembersInUnitTask extends SourceBasedAnalysisTask {
2426 /** 2544 /**
2427 * The name of the [TYPE_PROVIDER] input. 2545 * The name of the [TYPE_PROVIDER] input.
2428 */ 2546 */
2429 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 2547 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
2430 2548
2431 /** 2549 /**
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
2812 * The name of the [BUILD_LIBRARY_ERRORS] input. 2930 * The name of the [BUILD_LIBRARY_ERRORS] input.
2813 */ 2931 */
2814 static const String BUILD_LIBRARY_ERRORS_INPUT = 'BUILD_LIBRARY_ERRORS'; 2932 static const String BUILD_LIBRARY_ERRORS_INPUT = 'BUILD_LIBRARY_ERRORS';
2815 2933
2816 /** 2934 /**
2817 * The name of the [HINTS] input. 2935 * The name of the [HINTS] input.
2818 */ 2936 */
2819 static const String HINTS_INPUT = 'HINTS'; 2937 static const String HINTS_INPUT = 'HINTS';
2820 2938
2821 /** 2939 /**
2940 * The name of the [LINTS] input.
2941 */
2942 static const String LINTS_INPUT = 'LINTS';
2943
2944 /**
2822 * The name of the [INFER_STATIC_VARIABLE_TYPES_ERRORS] input. 2945 * The name of the [INFER_STATIC_VARIABLE_TYPES_ERRORS] input.
2823 */ 2946 */
2824 static const String INFER_STATIC_VARIABLE_TYPES_ERRORS_INPUT = 2947 static const String INFER_STATIC_VARIABLE_TYPES_ERRORS_INPUT =
2825 'INFER_STATIC_VARIABLE_TYPES_ERRORS'; 2948 'INFER_STATIC_VARIABLE_TYPES_ERRORS';
2826 2949
2827 /** 2950 /**
2828 * The name of the [PARTIALLY_RESOLVE_REFERENCES_ERRORS] input. 2951 * The name of the [PARTIALLY_RESOLVE_REFERENCES_ERRORS] input.
2829 */ 2952 */
2830 static const String PARTIALLY_RESOLVE_REFERENCES_ERRORS_INPUT = 2953 static const String PARTIALLY_RESOLVE_REFERENCES_ERRORS_INPUT =
2831 'PARTIALLY_RESOLVE_REFERENCES_ERRORS'; 2954 'PARTIALLY_RESOLVE_REFERENCES_ERRORS';
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2870 2993
2871 @override 2994 @override
2872 void internalPerform() { 2995 void internalPerform() {
2873 // 2996 //
2874 // Prepare inputs. 2997 // Prepare inputs.
2875 // 2998 //
2876 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[]; 2999 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[];
2877 errorLists.add(getRequiredInput(BUILD_DIRECTIVES_ERRORS_INPUT)); 3000 errorLists.add(getRequiredInput(BUILD_DIRECTIVES_ERRORS_INPUT));
2878 errorLists.add(getRequiredInput(BUILD_LIBRARY_ERRORS_INPUT)); 3001 errorLists.add(getRequiredInput(BUILD_LIBRARY_ERRORS_INPUT));
2879 errorLists.add(getRequiredInput(HINTS_INPUT)); 3002 errorLists.add(getRequiredInput(HINTS_INPUT));
3003 errorLists.add(getRequiredInput(LINTS_INPUT));
2880 errorLists.add(getRequiredInput(INFER_STATIC_VARIABLE_TYPES_ERRORS_INPUT)); 3004 errorLists.add(getRequiredInput(INFER_STATIC_VARIABLE_TYPES_ERRORS_INPUT));
2881 errorLists.add(getRequiredInput(PARTIALLY_RESOLVE_REFERENCES_ERRORS_INPUT)); 3005 errorLists.add(getRequiredInput(PARTIALLY_RESOLVE_REFERENCES_ERRORS_INPUT));
2882 errorLists.add(getRequiredInput(RESOLVE_FUNCTION_BODIES_ERRORS_INPUT)); 3006 errorLists.add(getRequiredInput(RESOLVE_FUNCTION_BODIES_ERRORS_INPUT));
2883 errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT)); 3007 errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT));
2884 errorLists.add(getRequiredInput(VARIABLE_REFERENCE_ERRORS_INPUT)); 3008 errorLists.add(getRequiredInput(VARIABLE_REFERENCE_ERRORS_INPUT));
2885 errorLists.add(getRequiredInput(VERIFY_ERRORS_INPUT)); 3009 errorLists.add(getRequiredInput(VERIFY_ERRORS_INPUT));
2886 // 3010 //
2887 // Record outputs. 3011 // Record outputs.
2888 // 3012 //
2889 outputs[LIBRARY_UNIT_ERRORS] = AnalysisError.mergeLists(errorLists); 3013 outputs[LIBRARY_UNIT_ERRORS] = AnalysisError.mergeLists(errorLists);
2890 } 3014 }
2891 3015
2892 /** 3016 /**
2893 * Return a map from the names of the inputs of this kind of task to the task 3017 * 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 3018 * input descriptors describing those inputs for a task with the
2895 * given [unit]. 3019 * given [unit].
2896 */ 3020 */
2897 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 3021 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2898 LibrarySpecificUnit unit = target; 3022 LibrarySpecificUnit unit = target;
2899 Map<String, TaskInput> inputs = <String, TaskInput>{ 3023 Map<String, TaskInput> inputs = <String, TaskInput>{
2900 HINTS_INPUT: HINTS.of(unit), 3024 HINTS_INPUT: HINTS.of(unit),
3025 LINTS_INPUT: LINTS.of(unit),
2901 INFER_STATIC_VARIABLE_TYPES_ERRORS_INPUT: 3026 INFER_STATIC_VARIABLE_TYPES_ERRORS_INPUT:
2902 INFER_STATIC_VARIABLE_TYPES_ERRORS.of(unit), 3027 INFER_STATIC_VARIABLE_TYPES_ERRORS.of(unit),
2903 PARTIALLY_RESOLVE_REFERENCES_ERRORS_INPUT: 3028 PARTIALLY_RESOLVE_REFERENCES_ERRORS_INPUT:
2904 PARTIALLY_RESOLVE_REFERENCES_ERRORS.of(unit), 3029 PARTIALLY_RESOLVE_REFERENCES_ERRORS.of(unit),
2905 RESOLVE_FUNCTION_BODIES_ERRORS_INPUT: 3030 RESOLVE_FUNCTION_BODIES_ERRORS_INPUT:
2906 RESOLVE_FUNCTION_BODIES_ERRORS.of(unit), 3031 RESOLVE_FUNCTION_BODIES_ERRORS.of(unit),
2907 RESOLVE_TYPE_NAMES_ERRORS_INPUT: RESOLVE_TYPE_NAMES_ERRORS.of(unit), 3032 RESOLVE_TYPE_NAMES_ERRORS_INPUT: RESOLVE_TYPE_NAMES_ERRORS.of(unit),
2908 VARIABLE_REFERENCE_ERRORS_INPUT: VARIABLE_REFERENCE_ERRORS.of(unit), 3033 VARIABLE_REFERENCE_ERRORS_INPUT: VARIABLE_REFERENCE_ERRORS.of(unit),
2909 VERIFY_ERRORS_INPUT: VERIFY_ERRORS.of(unit) 3034 VERIFY_ERRORS_INPUT: VERIFY_ERRORS.of(unit)
2910 }; 3035 };
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after
4128 4253
4129 @override 4254 @override
4130 bool moveNext() { 4255 bool moveNext() {
4131 if (_newSources.isEmpty) { 4256 if (_newSources.isEmpty) {
4132 return false; 4257 return false;
4133 } 4258 }
4134 currentTarget = _newSources.removeLast(); 4259 currentTarget = _newSources.removeLast();
4135 return true; 4260 return true;
4136 } 4261 }
4137 } 4262 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/plugin/engine_plugin.dart ('k') | pkg/analyzer/lib/src/task/dart_work_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698