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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 outputs[LINE_INFO] = computeLineInfo(content); |
85 } | 85 } |
86 | 86 |
87 List<AnalysisError> _validate(Map<String, YamlNode> options) => | 87 List<AnalysisError> _validate(Map<String, YamlNode> options) => |
88 new OptionsFileValidator(source).validate(options); | 88 new OptionsFileValidator(source).validate(options); |
89 | 89 |
90 /// 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 |
91 /// task input descriptors describing those inputs for a task with the | 91 /// task input descriptors describing those inputs for a task with the |
92 /// given [target]. | 92 /// given [target]. |
93 static Map<String, TaskInput> buildInputs(Source source) => | 93 static Map<String, TaskInput> buildInputs(Source source) => |
94 <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)}; | 94 <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)}; |
95 | 95 |
| 96 /// Compute [LineInfo] for the given [content]. |
| 97 static LineInfo computeLineInfo(String content) { |
| 98 List<int> lineStarts = <int>[0]; |
| 99 int length = content.length; |
| 100 int unit; |
| 101 for (int index = 0; index < length; index++) { |
| 102 unit = content.codeUnitAt(index); |
| 103 // Special-case \r\n. |
| 104 if (unit == 0x0D /* \r */) { |
| 105 // Peek ahead to detect a following \n. |
| 106 if ((index + 1 < length) && content.codeUnitAt(index + 1) == 0x0A) { |
| 107 // Line start will get registered at next index at the \n. |
| 108 } else { |
| 109 lineStarts.add(index + 1); |
| 110 } |
| 111 } |
| 112 |
| 113 if (unit == 0x0A) { |
| 114 lineStarts.add(index + 1); |
| 115 } |
| 116 } |
| 117 return new LineInfo(lineStarts); |
| 118 } |
| 119 |
96 /// Create a task based on the given [target] in the given [context]. | 120 /// Create a task based on the given [target] in the given [context]. |
97 static GenerateOptionsErrorsTask createTask( | 121 static GenerateOptionsErrorsTask createTask( |
98 AnalysisContext context, AnalysisTarget target) => | 122 AnalysisContext context, AnalysisTarget target) => |
99 new GenerateOptionsErrorsTask(context, target); | 123 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) { | |
106 lineStarts.add(index + 1); | |
107 } | |
108 } | |
109 return new LineInfo(lineStarts); | |
110 } | |
111 } | 124 } |
112 | 125 |
113 /// Validates `linter` top-level options. | 126 /// Validates `linter` top-level options. |
114 /// TODO(pq): move into `linter` package and plugin. | 127 /// TODO(pq): move into `linter` package and plugin. |
115 class LinterOptionsValidator extends TopLevelOptionValidator { | 128 class LinterOptionsValidator extends TopLevelOptionValidator { |
116 LinterOptionsValidator() : super('linter', const ['rules']); | 129 LinterOptionsValidator() : super('linter', const ['rules']); |
117 } | 130 } |
118 | 131 |
119 /// Validates options defined in an `.analysis_options` file. | 132 /// Validates options defined in an `.analysis_options` file. |
120 class OptionsFileValidator { | 133 class OptionsFileValidator { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION, | 169 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION, |
157 k.span, | 170 k.span, |
158 [pluginName, k.value]); | 171 [pluginName, k.value]); |
159 } | 172 } |
160 } | 173 } |
161 //TODO(pq): consider an error if the node is not a Scalar. | 174 //TODO(pq): consider an error if the node is not a Scalar. |
162 }); | 175 }); |
163 } | 176 } |
164 } | 177 } |
165 } | 178 } |
OLD | NEW |