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 12 matching lines...) Expand all Loading... |
23 | 23 |
24 /// The errors produced while parsing `.analysis_options` files. | 24 /// The errors produced while parsing `.analysis_options` files. |
25 /// | 25 /// |
26 /// The list will be empty if there were no errors, but will not be `null`. | 26 /// The list will be empty if there were no errors, but will not be `null`. |
27 final ListResultDescriptor<AnalysisError> ANALYSIS_OPTIONS_ERRORS = | 27 final ListResultDescriptor<AnalysisError> ANALYSIS_OPTIONS_ERRORS = |
28 new ListResultDescriptor<AnalysisError>( | 28 new ListResultDescriptor<AnalysisError>( |
29 'ANALYSIS_OPTIONS_ERRORS', AnalysisError.NO_ERRORS); | 29 'ANALYSIS_OPTIONS_ERRORS', AnalysisError.NO_ERRORS); |
30 | 30 |
31 final _OptionsProcessor _processor = new _OptionsProcessor(); | 31 final _OptionsProcessor _processor = new _OptionsProcessor(); |
32 | 32 |
| 33 void applyToAnalysisOptions( |
| 34 AnalysisOptionsImpl options, Map<String, Object> optionMap) { |
| 35 _processor.applyToAnalysisOptions(options, optionMap); |
| 36 } |
| 37 |
33 /// Configure this [context] based on configuration details specified in | 38 /// Configure this [context] based on configuration details specified in |
34 /// the given [options]. If [options] is `null`, default values are applied. | 39 /// the given [options]. If [options] is `null`, default values are applied. |
35 void configureContextOptions( | 40 void configureContextOptions( |
36 AnalysisContext context, Map<String, Object> options) => | 41 AnalysisContext context, Map<String, Object> options) => |
37 _processor.configure(context, options); | 42 _processor.configure(context, options); |
38 | 43 |
39 /// `analyzer` analysis options constants. | 44 /// `analyzer` analysis options constants. |
40 class AnalyzerOptions { | 45 class AnalyzerOptions { |
41 static const String analyzer = 'analyzer'; | 46 static const String analyzer = 'analyzer'; |
42 static const String enableAsync = 'enableAsync'; | 47 static const String enableAsync = 'enableAsync'; |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 class TrueOrFalseValueErrorBuilder extends ErrorBuilder { | 410 class TrueOrFalseValueErrorBuilder extends ErrorBuilder { |
406 TrueOrFalseValueErrorBuilder() : super(AnalyzerOptions.trueOrFalse); | 411 TrueOrFalseValueErrorBuilder() : super(AnalyzerOptions.trueOrFalse); |
407 @override | 412 @override |
408 AnalysisOptionsWarningCode get pluralProposalCode => | 413 AnalysisOptionsWarningCode get pluralProposalCode => |
409 AnalysisOptionsWarningCode.UNSUPPORTED_VALUE; | 414 AnalysisOptionsWarningCode.UNSUPPORTED_VALUE; |
410 } | 415 } |
411 | 416 |
412 class _OptionsProcessor { | 417 class _OptionsProcessor { |
413 static final Map<String, Object> defaults = {'analyzer': {}}; | 418 static final Map<String, Object> defaults = {'analyzer': {}}; |
414 | 419 |
| 420 /** |
| 421 * Apply the options in the given [optionMap] to the given analysis [options]. |
| 422 */ |
| 423 void applyToAnalysisOptions( |
| 424 AnalysisOptionsImpl options, Map<String, Object> optionMap) { |
| 425 if (optionMap == null) { |
| 426 return; |
| 427 } |
| 428 var analyzer = optionMap[AnalyzerOptions.analyzer]; |
| 429 if (analyzer is! Map) { |
| 430 return; |
| 431 } |
| 432 // Process strong mode option. |
| 433 var strongMode = analyzer[AnalyzerOptions.strong_mode]; |
| 434 if (strongMode is bool) { |
| 435 options.strongMode = strongMode; |
| 436 } |
| 437 // Process language options. |
| 438 var language = analyzer[AnalyzerOptions.language]; |
| 439 _applyLanguageOptions(options, language); |
| 440 } |
| 441 |
415 /// Configure [context] based on the given [options] (which can be `null` | 442 /// Configure [context] based on the given [options] (which can be `null` |
416 /// to restore [defaults]). | 443 /// to restore [defaults]). |
417 void configure(AnalysisContext context, Map<String, Object> options) { | 444 void configure(AnalysisContext context, Map<String, Object> options) { |
418 if (options == null) { | 445 if (options == null) { |
419 options = defaults; | 446 options = defaults; |
420 } | 447 } |
421 | 448 |
422 var analyzer = options[AnalyzerOptions.analyzer]; | 449 var analyzer = options[AnalyzerOptions.analyzer]; |
423 if (analyzer is! Map) { | 450 if (analyzer is! Map) { |
424 return; | 451 return; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 | 513 |
487 void setStrongMode(AnalysisContext context, Object strongMode) { | 514 void setStrongMode(AnalysisContext context, Object strongMode) { |
488 bool strong = strongMode is bool ? strongMode : false; | 515 bool strong = strongMode is bool ? strongMode : false; |
489 if (context.analysisOptions.strongMode != strong) { | 516 if (context.analysisOptions.strongMode != strong) { |
490 AnalysisOptionsImpl options = | 517 AnalysisOptionsImpl options = |
491 new AnalysisOptionsImpl.from(context.analysisOptions); | 518 new AnalysisOptionsImpl.from(context.analysisOptions); |
492 options.strongMode = strong; | 519 options.strongMode = strong; |
493 context.analysisOptions = options; | 520 context.analysisOptions = options; |
494 } | 521 } |
495 } | 522 } |
| 523 |
| 524 void _applyLanguageOption( |
| 525 AnalysisOptionsImpl options, Object feature, Object value) { |
| 526 bool boolValue = toBool(value); |
| 527 if (boolValue != null) { |
| 528 if (feature == AnalyzerOptions.enableAsync) { |
| 529 options.enableAsync = boolValue; |
| 530 } |
| 531 if (feature == AnalyzerOptions.enableSuperMixins) { |
| 532 options.enableSuperMixins = boolValue; |
| 533 } |
| 534 if (feature == AnalyzerOptions.enableGenericMethods) { |
| 535 options.enableGenericMethods = boolValue; |
| 536 } |
| 537 } |
| 538 } |
| 539 |
| 540 void _applyLanguageOptions(AnalysisOptionsImpl options, Object configs) { |
| 541 if (configs is YamlMap) { |
| 542 configs.nodes.forEach((key, value) { |
| 543 if (key is YamlScalar && value is YamlScalar) { |
| 544 String feature = key.value?.toString(); |
| 545 _applyLanguageOption(options, feature, value.value); |
| 546 } |
| 547 }); |
| 548 } else if (configs is Map) { |
| 549 configs |
| 550 .forEach((key, value) => _applyLanguageOption(options, key, value)); |
| 551 } |
| 552 } |
496 } | 553 } |
OLD | NEW |