| 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.source.analysis_options_provider; | 5 library analyzer.source.analysis_options_provider; |
| 6 | 6 |
| 7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/src/generated/engine.dart'; | 8 import 'package:analyzer/src/generated/engine.dart'; |
| 9 import 'package:analyzer/src/util/yaml.dart'; | 9 import 'package:analyzer/src/util/yaml.dart'; |
| 10 import 'package:source_span/source_span.dart'; | 10 import 'package:source_span/source_span.dart'; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 if (key is! String) { | 62 if (key is! String) { |
| 63 throw new OptionsFormatException( | 63 throw new OptionsFormatException( |
| 64 'Bad options file format (expected String scope key, ' | 64 'Bad options file format (expected String scope key, ' |
| 65 'got ${k.runtimeType})', | 65 'got ${k.runtimeType})', |
| 66 k != null ? k.span : doc.span); | 66 k != null ? k.span : doc.span); |
| 67 } | 67 } |
| 68 if (v != null && v is! YamlNode) { | 68 if (v != null && v is! YamlNode) { |
| 69 throw new OptionsFormatException( | 69 throw new OptionsFormatException( |
| 70 'Bad options file format (expected Node value, ' | 70 'Bad options file format (expected Node value, ' |
| 71 'got ${v.runtimeType}: `${v.toString()}`)', | 71 'got ${v.runtimeType}: `${v.toString()}`)', |
| 72 doc.span); | 72 doc.span); |
| 73 } | 73 } |
| 74 options[key] = v; | 74 options[key] = v; |
| 75 }); | 75 }); |
| 76 } | 76 } |
| 77 return options; | 77 return options; |
| 78 } | 78 } |
| 79 | 79 |
| 80 /// Merge the given options contents where the values in [defaults] may be | 80 /// Merge the given options contents where the values in [defaults] may be |
| 81 /// overridden by [overrides]. | 81 /// overridden by [overrides]. |
| 82 /// | 82 /// |
| 83 /// Some notes about merge semantics: | 83 /// Some notes about merge semantics: |
| 84 /// | 84 /// |
| 85 /// * lists are merged (without duplicates). | 85 /// * lists are merged (without duplicates). |
| 86 /// * lists of scalar values can be promoted to simple maps when merged with | 86 /// * lists of scalar values can be promoted to simple maps when merged with |
| 87 /// maps of strings to booleans (e.g., ['opt1', 'opt2'] becomes | 87 /// maps of strings to booleans (e.g., ['opt1', 'opt2'] becomes |
| 88 /// {'opt1': true, 'opt2': true}. | 88 /// {'opt1': true, 'opt2': true}. |
| 89 /// * maps are merged recursively. | 89 /// * maps are merged recursively. |
| 90 /// * if map values cannot be merged, the overriding value is taken. | 90 /// * if map values cannot be merged, the overriding value is taken. |
| 91 /// | 91 /// |
| 92 Map<String, YamlNode> merge( | 92 Map<String, YamlNode> merge( |
| 93 Map<String, YamlNode> defaults, Map<String, YamlNode> overrides) => | 93 Map<String, YamlNode> defaults, Map<String, YamlNode> overrides) => |
| 94 new Merger().merge(defaults, overrides); | 94 new Merger().merge(defaults, overrides) as Map<String, YamlNode>; |
| 95 | 95 |
| 96 /// Read the contents of [file] as a string. | 96 /// Read the contents of [file] as a string. |
| 97 /// Returns null if file does not exist. | 97 /// Returns null if file does not exist. |
| 98 String _readAnalysisOptionsFile(File file) { | 98 String _readAnalysisOptionsFile(File file) { |
| 99 try { | 99 try { |
| 100 return file.readAsStringSync(); | 100 return file.readAsStringSync(); |
| 101 } on FileSystemException { | 101 } on FileSystemException { |
| 102 // File can't be read. | 102 // File can't be read. |
| 103 return null; | 103 return null; |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 /// Thrown on options format exceptions. | 108 /// Thrown on options format exceptions. |
| 109 class OptionsFormatException implements Exception { | 109 class OptionsFormatException implements Exception { |
| 110 final String message; | 110 final String message; |
| 111 final SourceSpan span; | 111 final SourceSpan span; |
| 112 OptionsFormatException(this.message, [this.span]); | 112 OptionsFormatException(this.message, [this.span]); |
| 113 | 113 |
| 114 @override | 114 @override |
| 115 String toString() => | 115 String toString() => |
| 116 'OptionsFormatException: ${message?.toString()}, ${span?.toString()}'; | 116 'OptionsFormatException: ${message?.toString()}, ${span?.toString()}'; |
| 117 } | 117 } |
| OLD | NEW |