| 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 source.analysis_options_provider; | 5 library 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 // Empty options. | 47 // Empty options. |
| 48 if (doc is YamlScalar && doc.value == null) { | 48 if (doc is YamlScalar && doc.value == null) { |
| 49 return options; | 49 return options; |
| 50 } | 50 } |
| 51 if ((doc != null) && (doc is! YamlMap)) { | 51 if ((doc != null) && (doc is! YamlMap)) { |
| 52 throw new OptionsFormatException( | 52 throw new OptionsFormatException( |
| 53 'Bad options file format (expected map, got ${doc.runtimeType})', | 53 'Bad options file format (expected map, got ${doc.runtimeType})', |
| 54 doc.span); | 54 doc.span); |
| 55 } | 55 } |
| 56 if (doc is YamlMap) { | 56 if (doc is YamlMap) { |
| 57 (doc as YamlMap).forEach((k, v) { | 57 (doc as YamlMap).nodes.forEach((k, v) { |
| 58 if (k is! String) { | 58 var key; |
| 59 if (k is YamlScalar) { |
| 60 key = k.value; |
| 61 } |
| 62 if (key is! String) { |
| 59 throw new OptionsFormatException( | 63 throw new OptionsFormatException( |
| 60 'Bad options file format (expected String scope key, ' | 64 'Bad options file format (expected String scope key, ' |
| 61 'got ${k.runtimeType})', | 65 'got ${k.runtimeType})', |
| 62 k != null ? k.span : doc.span); | 66 k != null ? k.span : doc.span); |
| 63 } | 67 } |
| 64 options[k] = v; | 68 if (v != null && v is! YamlNode) { |
| 69 throw new OptionsFormatException( |
| 70 'Bad options file format (expected Node value, ' |
| 71 'got ${v.runtimeType}: `${v.toString()}`)', |
| 72 doc.span); |
| 73 } |
| 74 options[key] = v; |
| 65 }); | 75 }); |
| 66 } | 76 } |
| 67 return options; | 77 return options; |
| 68 } | 78 } |
| 69 | 79 |
| 70 /// 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 |
| 71 /// overridden by [overrides]. | 81 /// overridden by [overrides]. |
| 72 /// | 82 /// |
| 73 /// Some notes about merge semantics: | 83 /// Some notes about merge semantics: |
| 74 /// | 84 /// |
| (...skipping 23 matching lines...) Expand all Loading... |
| 98 /// Thrown on options format exceptions. | 108 /// Thrown on options format exceptions. |
| 99 class OptionsFormatException implements Exception { | 109 class OptionsFormatException implements Exception { |
| 100 final String message; | 110 final String message; |
| 101 final SourceSpan span; | 111 final SourceSpan span; |
| 102 OptionsFormatException(this.message, [this.span]); | 112 OptionsFormatException(this.message, [this.span]); |
| 103 | 113 |
| 104 @override | 114 @override |
| 105 String toString() => | 115 String toString() => |
| 106 'OptionsFormatException: ${message?.toString()}, ${span?.toString()}'; | 116 'OptionsFormatException: ${message?.toString()}, ${span?.toString()}'; |
| 107 } | 117 } |
| OLD | NEW |