| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 /// Validates `analyzer` error filter options. | 120 /// Validates `analyzer` error filter options. |
| 121 class ErrorFilterOptionValidator extends OptionsValidator { | 121 class ErrorFilterOptionValidator extends OptionsValidator { |
| 122 /// Pretty list of legal includes. | 122 /// Pretty list of legal includes. |
| 123 static final String legalIncludes = StringUtilities.printListOfQuotedNames( | 123 static final String legalIncludes = StringUtilities.printListOfQuotedNames( |
| 124 new List.from(AnalyzerOptions.ignoreSynonyms) | 124 new List.from(AnalyzerOptions.ignoreSynonyms) |
| 125 ..addAll(AnalyzerOptions.includeSynonyms)); | 125 ..addAll(AnalyzerOptions.includeSynonyms)); |
| 126 | 126 |
| 127 @override | 127 @override |
| 128 void validate(ErrorReporter reporter, Map<String, YamlNode> options) { | 128 void validate(ErrorReporter reporter, Map<String, YamlNode> options) { |
| 129 YamlMap analyzer = options[AnalyzerOptions.analyzer]; | 129 YamlNode analyzer = options[AnalyzerOptions.analyzer]; |
| 130 if (analyzer == null) { | 130 if (analyzer is! YamlMap) { |
| 131 return; | 131 return; |
| 132 } | 132 } |
| 133 | 133 |
| 134 YamlNode filters = analyzer[AnalyzerOptions.errors]; | 134 YamlNode filters = analyzer[AnalyzerOptions.errors]; |
| 135 if (filters is YamlMap) { | 135 if (filters is YamlMap) { |
| 136 String value; | 136 String value; |
| 137 filters.nodes.forEach((k, v) { | 137 filters.nodes.forEach((k, v) { |
| 138 if (k is YamlScalar) { | 138 if (k is YamlScalar) { |
| 139 value = toUpperCase(k.value); | 139 value = toUpperCase(k.value); |
| 140 if (!ErrorCode.values.any((ErrorCode code) => code.name == value)) { | 140 if (!ErrorCode.values.any((ErrorCode code) => code.name == value)) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 new GenerateOptionsErrorsTask(context, target); | 226 new GenerateOptionsErrorsTask(context, target); |
| 227 } | 227 } |
| 228 | 228 |
| 229 /// Validates `analyzer` language configuration options. | 229 /// Validates `analyzer` language configuration options. |
| 230 class LanguageOptionValidator extends OptionsValidator { | 230 class LanguageOptionValidator extends OptionsValidator { |
| 231 ErrorBuilder builder = new ErrorBuilder(AnalyzerOptions.languageOptions); | 231 ErrorBuilder builder = new ErrorBuilder(AnalyzerOptions.languageOptions); |
| 232 ErrorBuilder trueOrFalseBuilder = new TrueOrFalseValueErrorBuilder(); | 232 ErrorBuilder trueOrFalseBuilder = new TrueOrFalseValueErrorBuilder(); |
| 233 | 233 |
| 234 @override | 234 @override |
| 235 void validate(ErrorReporter reporter, Map<String, YamlNode> options) { | 235 void validate(ErrorReporter reporter, Map<String, YamlNode> options) { |
| 236 YamlMap analyzer = options[AnalyzerOptions.analyzer]; | 236 YamlNode analyzer = options[AnalyzerOptions.analyzer]; |
| 237 if (analyzer == null) { | 237 if (analyzer is! YamlMap) { |
| 238 return; | 238 return; |
| 239 } | 239 } |
| 240 | 240 |
| 241 YamlNode language = analyzer[AnalyzerOptions.language]; | 241 YamlNode language = analyzer[AnalyzerOptions.language]; |
| 242 if (language is YamlMap) { | 242 if (language is YamlMap) { |
| 243 language.nodes.forEach((k, v) { | 243 language.nodes.forEach((k, v) { |
| 244 String key, value; | 244 String key, value; |
| 245 bool validKey = false; | 245 bool validKey = false; |
| 246 if (k is YamlScalar) { | 246 if (k is YamlScalar) { |
| 247 key = k.value?.toString(); | 247 key = k.value?.toString(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 AnalysisOptionsWarningCode get pluralProposalCode => | 341 AnalysisOptionsWarningCode get pluralProposalCode => |
| 342 AnalysisOptionsWarningCode.UNSUPPORTED_VALUE; | 342 AnalysisOptionsWarningCode.UNSUPPORTED_VALUE; |
| 343 } | 343 } |
| 344 | 344 |
| 345 class _OptionsProcessor { | 345 class _OptionsProcessor { |
| 346 void configure(AnalysisContext context, Map<String, YamlNode> options) { | 346 void configure(AnalysisContext context, Map<String, YamlNode> options) { |
| 347 if (options == null) { | 347 if (options == null) { |
| 348 return; | 348 return; |
| 349 } | 349 } |
| 350 | 350 |
| 351 YamlMap analyzer = options[AnalyzerOptions.analyzer]; | 351 var analyzer = options[AnalyzerOptions.analyzer]; |
| 352 if (analyzer == null) { | 352 if (analyzer is! YamlMap) { |
| 353 return; | 353 return; |
| 354 } | 354 } |
| 355 | 355 |
| 356 // Set strong mode (default is false). | 356 // Set strong mode (default is false). |
| 357 bool strongMode = analyzer[AnalyzerOptions.strong_mode] ?? false; | 357 var strongMode = analyzer[AnalyzerOptions.strong_mode]; |
| 358 setStrongMode(context, strongMode); | 358 setStrongMode(context, strongMode); |
| 359 | 359 |
| 360 // Set filters. | 360 // Set filters. |
| 361 YamlNode filters = analyzer[AnalyzerOptions.errors]; | 361 var filters = analyzer[AnalyzerOptions.errors]; |
| 362 setFilters(context, filters); | 362 setFilters(context, filters); |
| 363 | 363 |
| 364 // Process language options. | 364 // Process language options. |
| 365 YamlNode language = analyzer[AnalyzerOptions.language]; | 365 var language = analyzer[AnalyzerOptions.language]; |
| 366 setLanguageOptions(context, language); | 366 setLanguageOptions(context, language); |
| 367 } | 367 } |
| 368 | 368 |
| 369 void setFilters(AnalysisContext context, YamlNode codes) { | 369 void setFilters(AnalysisContext context, Object codes) { |
| 370 List<ErrorFilter> filters = <ErrorFilter>[]; | 370 List<ErrorFilter> filters = <ErrorFilter>[]; |
| 371 // If codes are enumerated, collect them as filters; else leave filters | 371 // If codes are enumerated, collect them as filters; else leave filters |
| 372 // empty to overwrite previous value. | 372 // empty to overwrite previous value. |
| 373 if (codes is YamlMap) { | 373 if (codes is YamlMap) { |
| 374 String value; | 374 String value; |
| 375 codes.nodes.forEach((k, v) { | 375 codes.nodes.forEach((k, v) { |
| 376 if (k is YamlScalar && v is YamlScalar) { | 376 if (k is YamlScalar && v is YamlScalar) { |
| 377 value = toLowerCase(v.value); | 377 value = toLowerCase(v.value); |
| 378 if (AnalyzerOptions.ignoreSynonyms.contains(value)) { | 378 if (AnalyzerOptions.ignoreSynonyms.contains(value)) { |
| 379 // Case-insensitive. | 379 // Case-insensitive. |
| 380 String code = toUpperCase(k.value); | 380 String code = toUpperCase(k.value); |
| 381 filters.add((AnalysisError error) => error.errorCode.name == code); | 381 filters.add((AnalysisError error) => error.errorCode.name == code); |
| 382 } | 382 } |
| 383 } | 383 } |
| 384 }); | 384 }); |
| 385 } | 385 } |
| 386 context.setConfigurationData(CONFIGURED_ERROR_FILTERS, filters); | 386 context.setConfigurationData(CONFIGURED_ERROR_FILTERS, filters); |
| 387 } | 387 } |
| 388 | 388 |
| 389 void setLanguageOptions(AnalysisContext context, YamlNode configs) { | 389 void setLanguageOptions(AnalysisContext context, Object configs) { |
| 390 if (configs is YamlMap) { | 390 if (configs is YamlMap) { |
| 391 configs.nodes.forEach((k, v) { | 391 configs.nodes.forEach((k, v) { |
| 392 String feature; | 392 String feature; |
| 393 if (k is YamlScalar && v is YamlScalar) { | 393 if (k is YamlScalar && v is YamlScalar) { |
| 394 feature = k.value?.toString(); | 394 feature = k.value?.toString(); |
| 395 if (feature == AnalyzerOptions.enableSuperMixins) { | 395 if (feature == AnalyzerOptions.enableSuperMixins) { |
| 396 if (isTrue(v.value)) { | 396 if (isTrue(v.value)) { |
| 397 AnalysisOptionsImpl options = | 397 AnalysisOptionsImpl options = |
| 398 new AnalysisOptionsImpl.from(context.analysisOptions); | 398 new AnalysisOptionsImpl.from(context.analysisOptions); |
| 399 options.enableSuperMixins = true; | 399 options.enableSuperMixins = true; |
| 400 context.analysisOptions = options; | 400 context.analysisOptions = options; |
| 401 } | 401 } |
| 402 } | 402 } |
| 403 if (feature == AnalyzerOptions.enableGenericMethods) { | 403 if (feature == AnalyzerOptions.enableGenericMethods) { |
| 404 if (isTrue(v.value)) { | 404 if (isTrue(v.value)) { |
| 405 AnalysisOptionsImpl options = | 405 AnalysisOptionsImpl options = |
| 406 new AnalysisOptionsImpl.from(context.analysisOptions); | 406 new AnalysisOptionsImpl.from(context.analysisOptions); |
| 407 options.enableGenericMethods = true; | 407 options.enableGenericMethods = true; |
| 408 context.analysisOptions = options; | 408 context.analysisOptions = options; |
| 409 } | 409 } |
| 410 } | 410 } |
| 411 } | 411 } |
| 412 }); | 412 }); |
| 413 } | 413 } |
| 414 } | 414 } |
| 415 | 415 |
| 416 void setStrongMode(AnalysisContext context, bool strongMode) { | 416 void setStrongMode(AnalysisContext context, Object strongMode) { |
| 417 if (context.analysisOptions.strongMode != strongMode) { | 417 bool strong = strongMode is bool ? strongMode : false; |
| 418 if (context.analysisOptions.strongMode != strong) { |
| 418 AnalysisOptionsImpl options = | 419 AnalysisOptionsImpl options = |
| 419 new AnalysisOptionsImpl.from(context.analysisOptions); | 420 new AnalysisOptionsImpl.from(context.analysisOptions); |
| 420 options.strongMode = strongMode; | 421 options.strongMode = strong; |
| 421 context.analysisOptions = options; | 422 context.analysisOptions = options; |
| 422 } | 423 } |
| 423 } | 424 } |
| 424 } | 425 } |
| OLD | NEW |