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 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
10 import 'package:analyzer/plugin/options.dart'; | 10 import 'package:analyzer/plugin/options.dart'; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 static const String enableAssertInitializer = 'enableAssertInitializer'; | 56 static const String enableAssertInitializer = 'enableAssertInitializer'; |
57 static const String enableAsync = 'enableAsync'; | 57 static const String enableAsync = 'enableAsync'; |
58 static const String enableGenericMethods = 'enableGenericMethods'; | 58 static const String enableGenericMethods = 'enableGenericMethods'; |
59 static const String enableInitializingFormalAccess = | 59 static const String enableInitializingFormalAccess = |
60 'enableInitializingFormalAccess'; | 60 'enableInitializingFormalAccess'; |
61 static const String enableStrictCallChecks = 'enableStrictCallChecks'; | 61 static const String enableStrictCallChecks = 'enableStrictCallChecks'; |
62 static const String enableSuperMixins = 'enableSuperMixins'; | 62 static const String enableSuperMixins = 'enableSuperMixins'; |
63 | 63 |
64 static const String errors = 'errors'; | 64 static const String errors = 'errors'; |
65 static const String exclude = 'exclude'; | 65 static const String exclude = 'exclude'; |
| 66 static const String include = 'include'; |
66 static const String language = 'language'; | 67 static const String language = 'language'; |
67 static const String plugins = 'plugins'; | 68 static const String plugins = 'plugins'; |
68 static const String strong_mode = 'strong-mode'; | 69 static const String strong_mode = 'strong-mode'; |
69 | 70 |
70 // Strong mode options, see AnalysisOptionsImpl for documentation. | 71 // Strong mode options, see AnalysisOptionsImpl for documentation. |
71 static const String implicitCasts = 'implicit-casts'; | 72 static const String implicitCasts = 'implicit-casts'; |
72 static const String implicitDynamic = 'implicit-dynamic'; | 73 static const String implicitDynamic = 'implicit-dynamic'; |
73 | 74 |
74 /// Ways to say `ignore`. | 75 /// Ways to say `ignore`. |
75 static const List<String> ignoreSynonyms = const ['ignore', 'false']; | 76 static const List<String> ignoreSynonyms = const ['ignore', 'false']; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME'; | 222 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME'; |
222 | 223 |
223 /// The task descriptor describing this kind of task. | 224 /// The task descriptor describing this kind of task. |
224 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 225 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
225 'GenerateOptionsErrorsTask', | 226 'GenerateOptionsErrorsTask', |
226 createTask, | 227 createTask, |
227 buildInputs, | 228 buildInputs, |
228 <ResultDescriptor>[ANALYSIS_OPTIONS_ERRORS, LINE_INFO], | 229 <ResultDescriptor>[ANALYSIS_OPTIONS_ERRORS, LINE_INFO], |
229 suitabilityFor: suitabilityFor); | 230 suitabilityFor: suitabilityFor); |
230 | 231 |
231 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); | 232 AnalysisOptionsProvider optionsProvider; |
232 | 233 |
233 GenerateOptionsErrorsTask(AnalysisContext context, AnalysisTarget target) | 234 GenerateOptionsErrorsTask(AnalysisContext context, AnalysisTarget target) |
234 : super(context, target); | 235 : super(context, target) { |
| 236 optionsProvider = new AnalysisOptionsProvider(context?.sourceFactory); |
| 237 } |
235 | 238 |
236 @override | 239 @override |
237 TaskDescriptor get descriptor => DESCRIPTOR; | 240 TaskDescriptor get descriptor => DESCRIPTOR; |
238 | 241 |
239 Source get source => target.source; | 242 Source get source => target.source; |
240 | 243 |
241 @override | 244 @override |
242 void internalPerform() { | 245 void internalPerform() { |
243 String content = getRequiredInput(CONTENT_INPUT_NAME); | 246 String content = getRequiredInput(CONTENT_INPUT_NAME); |
244 | 247 |
245 List<AnalysisError> errors = <AnalysisError>[]; | 248 List<AnalysisError> errors = <AnalysisError>[]; |
| 249 Source initialSource = source; |
| 250 SourceSpan initialIncludeSpan; |
| 251 |
| 252 // Validate the specified options and any included option files |
| 253 void validate(Source source, Map<String, YamlNode> options) { |
| 254 List<AnalysisError> validationErrors = |
| 255 new OptionsFileValidator(source).validate(options); |
| 256 if (initialIncludeSpan != null && validationErrors.isNotEmpty) { |
| 257 for (AnalysisError error in validationErrors) { |
| 258 var args = [ |
| 259 source.fullName, |
| 260 error.offset.toString(), |
| 261 (error.offset + error.length - 1).toString(), |
| 262 error.message, |
| 263 ]; |
| 264 errors.add(new AnalysisError( |
| 265 initialSource, |
| 266 initialIncludeSpan.start.column + 1, |
| 267 initialIncludeSpan.length, |
| 268 AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING, |
| 269 args)); |
| 270 } |
| 271 } else { |
| 272 errors.addAll(validationErrors); |
| 273 } |
| 274 |
| 275 YamlNode node = options[AnalyzerOptions.include]; |
| 276 if (node == null) { |
| 277 return; |
| 278 } |
| 279 SourceSpan span = node.span; |
| 280 initialIncludeSpan ??= span; |
| 281 String includeUri = span.text; |
| 282 Source includedSource = |
| 283 context.sourceFactory.resolveUri(source, includeUri); |
| 284 if (!includedSource.exists()) { |
| 285 errors.add(new AnalysisError( |
| 286 initialSource, |
| 287 initialIncludeSpan.start.column + 1, |
| 288 initialIncludeSpan.length, |
| 289 AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND, |
| 290 [includeUri, source.fullName])); |
| 291 return; |
| 292 } |
| 293 try { |
| 294 Map<String, YamlNode> options = |
| 295 optionsProvider.getOptionsFromString(includedSource.contents.data); |
| 296 validate(includedSource, options); |
| 297 } on OptionsFormatException catch (e) { |
| 298 var args = [ |
| 299 includedSource.fullName, |
| 300 e.span.start.offset.toString(), |
| 301 e.span.end.offset.toString(), |
| 302 e.message, |
| 303 ]; |
| 304 // Report errors for included option files |
| 305 // on the include directive located in the initial options file. |
| 306 errors.add(new AnalysisError( |
| 307 initialSource, |
| 308 initialIncludeSpan.start.column + 1, |
| 309 initialIncludeSpan.length, |
| 310 AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR, |
| 311 args)); |
| 312 } |
| 313 } |
246 | 314 |
247 try { | 315 try { |
248 Map<String, YamlNode> options = | 316 Map<String, YamlNode> options = |
249 optionsProvider.getOptionsFromString(content); | 317 optionsProvider.getOptionsFromString(content); |
250 errors.addAll(_validate(options)); | 318 validate(source, options); |
251 } on OptionsFormatException catch (e) { | 319 } on OptionsFormatException catch (e) { |
252 SourceSpan span = e.span; | 320 SourceSpan span = e.span; |
253 var error = new AnalysisError(source, span.start.column + 1, span.length, | 321 errors.add(new AnalysisError(source, span.start.column + 1, span.length, |
254 AnalysisOptionsErrorCode.PARSE_ERROR, [e.message]); | 322 AnalysisOptionsErrorCode.PARSE_ERROR, [e.message])); |
255 errors.add(error); | |
256 } | 323 } |
257 | 324 |
258 // | 325 // |
259 // Record outputs. | 326 // Record outputs. |
260 // | 327 // |
261 outputs[ANALYSIS_OPTIONS_ERRORS] = errors; | 328 outputs[ANALYSIS_OPTIONS_ERRORS] = errors; |
262 outputs[LINE_INFO] = computeLineInfo(content); | 329 outputs[LINE_INFO] = computeLineInfo(content); |
263 } | 330 } |
264 | 331 |
265 List<AnalysisError> _validate(Map<String, YamlNode> options) => | |
266 new OptionsFileValidator(source).validate(options); | |
267 | |
268 /// Return a map from the names of the inputs of this kind of task to the | 332 /// Return a map from the names of the inputs of this kind of task to the |
269 /// task input descriptors describing those inputs for a task with the | 333 /// task input descriptors describing those inputs for a task with the |
270 /// given [target]. | 334 /// given [target]. |
271 static Map<String, TaskInput> buildInputs(AnalysisTarget source) => | 335 static Map<String, TaskInput> buildInputs(AnalysisTarget source) => |
272 <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)}; | 336 <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)}; |
273 | 337 |
274 /// Compute [LineInfo] for the given [content]. | 338 /// Compute [LineInfo] for the given [content]. |
275 static LineInfo computeLineInfo(String content) { | 339 static LineInfo computeLineInfo(String content) { |
276 List<int> lineStarts = StringUtilities.computeLineStarts(content); | 340 List<int> lineStarts = StringUtilities.computeLineStarts(content); |
277 return new LineInfo(lineStarts); | 341 return new LineInfo(lineStarts); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 } | 676 } |
613 }); | 677 }); |
614 } else if (config is Map) { | 678 } else if (config is Map) { |
615 options.strongMode = true; | 679 options.strongMode = true; |
616 config.forEach((k, v) => _applyStrongModeOption(options, k, v)); | 680 config.forEach((k, v) => _applyStrongModeOption(options, k, v)); |
617 } else { | 681 } else { |
618 options.strongMode = config is bool ? config : false; | 682 options.strongMode = config is bool ? config : false; |
619 } | 683 } |
620 } | 684 } |
621 } | 685 } |
OLD | NEW |