Chromium Code Reviews| 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.options; | 5 library analyzer.src.task.options; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/plugin/options.dart'; | 8 import 'package:analyzer/plugin/options.dart'; |
| 9 import 'package:analyzer/source/analysis_options_provider.dart'; | 9 import 'package:analyzer/source/analysis_options_provider.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 /// A task that generates errors for an `.analysis_options` file. | 41 /// A task that generates errors for an `.analysis_options` file. |
| 42 class GenerateOptionsErrorsTask extends SourceBasedAnalysisTask { | 42 class GenerateOptionsErrorsTask extends SourceBasedAnalysisTask { |
| 43 /// The name of the input whose value is the content of the file. | 43 /// The name of the input whose value is the content of the file. |
| 44 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME'; | 44 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME'; |
| 45 | 45 |
| 46 /// The task descriptor describing this kind of task. | 46 /// The task descriptor describing this kind of task. |
| 47 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 47 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 48 'GenerateOptionsErrorsTask', | 48 'GenerateOptionsErrorsTask', |
| 49 createTask, | 49 createTask, |
| 50 buildInputs, | 50 buildInputs, |
| 51 <ResultDescriptor>[ANALYSIS_OPTIONS_ERRORS]); | 51 <ResultDescriptor>[ANALYSIS_OPTIONS_ERRORS, LINE_INFO]); |
| 52 | 52 |
| 53 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); | 53 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); |
| 54 | 54 |
| 55 GenerateOptionsErrorsTask(AnalysisContext context, AnalysisTarget target) | 55 GenerateOptionsErrorsTask(AnalysisContext context, AnalysisTarget target) |
| 56 : super(context, target); | 56 : super(context, target); |
| 57 | 57 |
| 58 @override | 58 @override |
| 59 TaskDescriptor get descriptor => DESCRIPTOR; | 59 TaskDescriptor get descriptor => DESCRIPTOR; |
| 60 | 60 |
| 61 Source get source => target.source; | 61 Source get source => target.source; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 74 SourceSpan span = e.span; | 74 SourceSpan span = e.span; |
| 75 var error = new AnalysisError(source, span.start.column + 1, span.length, | 75 var error = new AnalysisError(source, span.start.column + 1, span.length, |
| 76 AnalysisOptionsErrorCode.PARSE_ERROR, [e.message]); | 76 AnalysisOptionsErrorCode.PARSE_ERROR, [e.message]); |
| 77 errors.add(error); | 77 errors.add(error); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // | 80 // |
| 81 // Record outputs. | 81 // Record outputs. |
| 82 // | 82 // |
| 83 outputs[ANALYSIS_OPTIONS_ERRORS] = errors; | 83 outputs[ANALYSIS_OPTIONS_ERRORS] = errors; |
| 84 outputs[LINE_INFO] = _computeLineInfo(content); | |
| 84 } | 85 } |
| 85 | 86 |
| 86 List<AnalysisError> _validate(Map<String, YamlNode> options) => | 87 List<AnalysisError> _validate(Map<String, YamlNode> options) => |
| 87 new OptionsFileValidator(source).validate(options); | 88 new OptionsFileValidator(source).validate(options); |
| 88 | 89 |
| 89 /// Return a map from the names of the inputs of this kind of task to the | 90 /// Return a map from the names of the inputs of this kind of task to the |
| 90 /// task input descriptors describing those inputs for a task with the | 91 /// task input descriptors describing those inputs for a task with the |
| 91 /// given [target]. | 92 /// given [target]. |
| 92 static Map<String, TaskInput> buildInputs(Source source) => | 93 static Map<String, TaskInput> buildInputs(Source source) => |
| 93 <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)}; | 94 <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)}; |
| 94 | 95 |
| 95 /// Create a task based on the given [target] in the given [context]. | 96 /// Create a task based on the given [target] in the given [context]. |
| 96 static GenerateOptionsErrorsTask createTask( | 97 static GenerateOptionsErrorsTask createTask( |
| 97 AnalysisContext context, AnalysisTarget target) => | 98 AnalysisContext context, AnalysisTarget target) => |
| 98 new GenerateOptionsErrorsTask(context, target); | 99 new GenerateOptionsErrorsTask(context, target); |
| 100 | |
| 101 /// Compute [LineInfo] for the given [content]. | |
| 102 static LineInfo _computeLineInfo(String content) { | |
| 103 List<int> lineStarts = <int>[0]; | |
| 104 for (int index = 0; index < content.length; index++) { | |
| 105 if (content.codeUnitAt(index) == 0x0A) { | |
|
Brian Wilkerson
2015/10/27 13:18:29
For Dart files we accept either CR, CR/LF, or LF a
pquitslund
2015/10/27 15:31:44
I was folllowing HTML's suit but this is not a bad
Brian Wilkerson
2015/10/27 15:59:44
We compute line info while scanning, as part of th
| |
| 106 lineStarts.add(index + 1); | |
| 107 } | |
| 108 } | |
| 109 return new LineInfo(lineStarts); | |
| 110 } | |
| 99 } | 111 } |
| 100 | 112 |
| 101 /// Validates `linter` top-level options. | 113 /// Validates `linter` top-level options. |
| 102 /// TODO(pq): move into `linter` package and plugin. | 114 /// TODO(pq): move into `linter` package and plugin. |
| 103 class LinterOptionsValidator extends TopLevelOptionValidator { | 115 class LinterOptionsValidator extends TopLevelOptionValidator { |
| 104 LinterOptionsValidator() : super('linter', const ['rules']); | 116 LinterOptionsValidator() : super('linter', const ['rules']); |
| 105 } | 117 } |
| 106 | 118 |
| 107 /// Validates options defined in an `.analysis_options` file. | 119 /// Validates options defined in an `.analysis_options` file. |
| 108 class OptionsFileValidator { | 120 class OptionsFileValidator { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION, | 156 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION, |
| 145 k.span, | 157 k.span, |
| 146 [pluginName, k.value]); | 158 [pluginName, k.value]); |
| 147 } | 159 } |
| 148 } | 160 } |
| 149 //TODO(pq): consider an error if the node is not a Scalar. | 161 //TODO(pq): consider an error if the node is not a Scalar. |
| 150 }); | 162 }); |
| 151 } | 163 } |
| 152 } | 164 } |
| 153 } | 165 } |
| OLD | NEW |