OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library analyzer.src.task.options; |
| 6 |
| 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/source/analysis_options_provider.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/source.dart'; |
| 11 import 'package:analyzer/src/task/general.dart'; |
| 12 import 'package:analyzer/task/general.dart'; |
| 13 import 'package:analyzer/task/model.dart'; |
| 14 import 'package:source_span/source_span.dart'; |
| 15 |
| 16 /// The errors produced while parsing `.analysis_options` files. |
| 17 /// |
| 18 /// The list will be empty if there were no errors, but will not be `null`. |
| 19 final ListResultDescriptor<AnalysisError> ANALYSIS_OPTIONS_ERRORS = |
| 20 new ListResultDescriptor<AnalysisError>( |
| 21 'ANALYSIS_OPTIONS_ERRORS', AnalysisError.NO_ERRORS); |
| 22 |
| 23 /// A task that generates errors for an `.analysis_options` file. |
| 24 class GenerateOptionsErrorsTask extends SourceBasedAnalysisTask { |
| 25 /// The name of the input whose value is the content of the file. |
| 26 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME'; |
| 27 |
| 28 /// The task descriptor describing this kind of task. |
| 29 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 30 'GenerateOptionsErrorsTask', |
| 31 createTask, |
| 32 buildInputs, |
| 33 <ResultDescriptor>[ANALYSIS_OPTIONS_ERRORS]); |
| 34 |
| 35 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); |
| 36 |
| 37 GenerateOptionsErrorsTask(AnalysisContext context, AnalysisTarget target) |
| 38 : super(context, target); |
| 39 |
| 40 @override |
| 41 TaskDescriptor get descriptor => DESCRIPTOR; |
| 42 |
| 43 Source get source => target.source; |
| 44 |
| 45 @override |
| 46 void internalPerform() { |
| 47 String content = getRequiredInput(CONTENT_INPUT_NAME); |
| 48 |
| 49 List<AnalysisError> errors = <AnalysisError>[]; |
| 50 |
| 51 try { |
| 52 optionsProvider.getOptionsFromString(content); |
| 53 } on OptionsFormatException catch (e) { |
| 54 SourceSpan span = e.span; |
| 55 var error = new AnalysisError(source, span.start.column + 1, span.length, |
| 56 AnalysisOptionsErrorCode.PARSE_ERROR, [e.message]); |
| 57 errors.add(error); |
| 58 } |
| 59 |
| 60 // |
| 61 // Record outputs. |
| 62 // |
| 63 outputs[ANALYSIS_OPTIONS_ERRORS] = errors; |
| 64 } |
| 65 |
| 66 /// Return a map from the names of the inputs of this kind of task to the |
| 67 /// task input descriptors describing those inputs for a task with the |
| 68 /// given [target]. |
| 69 static Map<String, TaskInput> buildInputs(Source source) => |
| 70 <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)}; |
| 71 |
| 72 /// Create a task based on the given [target] in the given [context]. |
| 73 static GenerateOptionsErrorsTask createTask( |
| 74 AnalysisContext context, AnalysisTarget target) => |
| 75 new GenerateOptionsErrorsTask(context, target); |
| 76 } |
OLD | NEW |