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'; |
11 import 'package:analyzer/source/analysis_options_provider.dart'; | 11 import 'package:analyzer/source/analysis_options_provider.dart'; |
| 12 import 'package:analyzer/source/error_processor.dart'; |
12 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
13 import 'package:analyzer/src/generated/java_engine.dart'; | 14 import 'package:analyzer/src/generated/java_engine.dart'; |
14 import 'package:analyzer/src/generated/source.dart'; | 15 import 'package:analyzer/src/generated/source.dart'; |
15 import 'package:analyzer/src/generated/utilities_general.dart'; | 16 import 'package:analyzer/src/generated/utilities_general.dart'; |
16 import 'package:analyzer/src/task/general.dart'; | 17 import 'package:analyzer/src/task/general.dart'; |
17 import 'package:analyzer/src/task/strong/info.dart'; | 18 import 'package:analyzer/src/task/strong/info.dart'; |
18 import 'package:analyzer/task/general.dart'; | 19 import 'package:analyzer/task/general.dart'; |
19 import 'package:analyzer/task/model.dart'; | 20 import 'package:analyzer/task/model.dart'; |
20 import 'package:source_span/source_span.dart'; | 21 import 'package:source_span/source_span.dart'; |
21 import 'package:yaml/yaml.dart'; | 22 import 'package:yaml/yaml.dart'; |
(...skipping 20 matching lines...) Expand all Loading... |
42 static const String enableSuperMixins = 'enableSuperMixins'; | 43 static const String enableSuperMixins = 'enableSuperMixins'; |
43 static const String errors = 'errors'; | 44 static const String errors = 'errors'; |
44 static const String exclude = 'exclude'; | 45 static const String exclude = 'exclude'; |
45 static const String language = 'language'; | 46 static const String language = 'language'; |
46 static const String plugins = 'plugins'; | 47 static const String plugins = 'plugins'; |
47 static const String strong_mode = 'strong-mode'; | 48 static const String strong_mode = 'strong-mode'; |
48 | 49 |
49 /// Ways to say `ignore`. | 50 /// Ways to say `ignore`. |
50 static const List<String> ignoreSynonyms = const ['ignore', 'false']; | 51 static const List<String> ignoreSynonyms = const ['ignore', 'false']; |
51 | 52 |
| 53 /// Valid error `severity`s. |
| 54 static final List<String> severities = |
| 55 ErrorSeverity.values.map((s) => s.name).toList(); |
| 56 |
52 /// Ways to say `include`. | 57 /// Ways to say `include`. |
53 static const List<String> includeSynonyms = const ['include', 'true']; | 58 static const List<String> includeSynonyms = const ['include', 'true']; |
54 | 59 |
55 /// Ways to say `true` or `false`. | 60 /// Ways to say `true` or `false`. |
56 static const List<String> trueOrFalse = const ['true', 'false']; | 61 static const List<String> trueOrFalse = const ['true', 'false']; |
57 | 62 |
58 /// Supported top-level `analyzer` options. | 63 /// Supported top-level `analyzer` options. |
59 static const List<String> topLevel = const [ | 64 static const List<String> topLevel = const [ |
60 errors, | 65 errors, |
61 exclude, | 66 exclude, |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 if (analyzer is! Map) { | 402 if (analyzer is! Map) { |
398 return; | 403 return; |
399 } | 404 } |
400 | 405 |
401 // Set strong mode (default is false). | 406 // Set strong mode (default is false). |
402 var strongMode = analyzer[AnalyzerOptions.strong_mode]; | 407 var strongMode = analyzer[AnalyzerOptions.strong_mode]; |
403 setStrongMode(context, strongMode); | 408 setStrongMode(context, strongMode); |
404 | 409 |
405 // Set filters. | 410 // Set filters. |
406 var filters = analyzer[AnalyzerOptions.errors]; | 411 var filters = analyzer[AnalyzerOptions.errors]; |
407 setFilters(context, filters); | 412 setProcessors(context, filters); |
408 | 413 |
409 // Process language options. | 414 // Process language options. |
410 var language = analyzer[AnalyzerOptions.language]; | 415 var language = analyzer[AnalyzerOptions.language]; |
411 setLanguageOptions(context, language); | 416 setLanguageOptions(context, language); |
412 } | 417 } |
413 | 418 |
414 ErrorFilter parseFilter(String code, Object enable) { | |
415 enable = toLowerCase(enable); | |
416 if (AnalyzerOptions.ignoreSynonyms.contains(enable)) { | |
417 // Case-insensitive. | |
418 code = toUpperCase(code); | |
419 return ((AnalysisError error) => error.errorCode.name == code); | |
420 } | |
421 } | |
422 | |
423 void setFilters(AnalysisContext context, Object codes) { | |
424 List<ErrorFilter> filters = <ErrorFilter>[]; | |
425 // If codes are enumerated, collect them as filters; else leave filters | |
426 // empty to overwrite previous value. | |
427 if (codes is YamlMap) { | |
428 String value; | |
429 // TODO(pq): stop traversing nodes and unify w/ standard map handling | |
430 codes.nodes.forEach((k, v) { | |
431 if (k is YamlScalar && v is YamlScalar) { | |
432 ErrorFilter filter = parseFilter(k.value, v.value); | |
433 if (filter != null) { | |
434 filters.add(filter); | |
435 } | |
436 } | |
437 }); | |
438 } else if (codes is Map) { | |
439 codes.forEach((k, v) { | |
440 if (k is String) { | |
441 ErrorFilter filter = parseFilter(k, v); | |
442 if (filter != null) { | |
443 filters.add(filter); | |
444 } | |
445 } | |
446 }); | |
447 } | |
448 context.setConfigurationData(CONFIGURED_ERROR_FILTERS, filters); | |
449 } | |
450 | |
451 void setLanguageOption( | 419 void setLanguageOption( |
452 AnalysisContext context, Object feature, Object value) { | 420 AnalysisContext context, Object feature, Object value) { |
453 if (feature == AnalyzerOptions.enableSuperMixins) { | 421 if (feature == AnalyzerOptions.enableSuperMixins) { |
454 if (isTrue(value)) { | 422 if (isTrue(value)) { |
455 AnalysisOptionsImpl options = | 423 AnalysisOptionsImpl options = |
456 new AnalysisOptionsImpl.from(context.analysisOptions); | 424 new AnalysisOptionsImpl.from(context.analysisOptions); |
457 options.enableSuperMixins = true; | 425 options.enableSuperMixins = true; |
458 context.analysisOptions = options; | 426 context.analysisOptions = options; |
459 } | 427 } |
460 } | 428 } |
(...skipping 13 matching lines...) Expand all Loading... |
474 if (k is YamlScalar && v is YamlScalar) { | 442 if (k is YamlScalar && v is YamlScalar) { |
475 String feature = k.value?.toString(); | 443 String feature = k.value?.toString(); |
476 setLanguageOption(context, feature, v.value); | 444 setLanguageOption(context, feature, v.value); |
477 } | 445 } |
478 }); | 446 }); |
479 } else if (configs is Map) { | 447 } else if (configs is Map) { |
480 configs.forEach((k, v) => setLanguageOption(context, k, v)); | 448 configs.forEach((k, v) => setLanguageOption(context, k, v)); |
481 } | 449 } |
482 } | 450 } |
483 | 451 |
| 452 void setProcessors(AnalysisContext context, Object codes) { |
| 453 ErrorConfig config = new ErrorConfig(codes); |
| 454 context.setConfigurationData(CONFIGURED_ERROR_PROCESSORS, config.processors)
; |
| 455 } |
| 456 |
484 void setStrongMode(AnalysisContext context, Object strongMode) { | 457 void setStrongMode(AnalysisContext context, Object strongMode) { |
485 bool strong = strongMode is bool ? strongMode : false; | 458 bool strong = strongMode is bool ? strongMode : false; |
486 if (context.analysisOptions.strongMode != strong) { | 459 if (context.analysisOptions.strongMode != strong) { |
487 AnalysisOptionsImpl options = | 460 AnalysisOptionsImpl options = |
488 new AnalysisOptionsImpl.from(context.analysisOptions); | 461 new AnalysisOptionsImpl.from(context.analysisOptions); |
489 options.strongMode = strong; | 462 options.strongMode = strong; |
490 context.analysisOptions = options; | 463 context.analysisOptions = options; |
491 } | 464 } |
492 } | 465 } |
493 } | 466 } |
OLD | NEW |