| 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:source_span/source_span.dart'; | 9 import 'package:source_span/source_span.dart'; |
| 10 import 'package:yaml/yaml.dart'; | 10 import 'package:yaml/yaml.dart'; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 return getOptionsFromString(optionsSource); | 26 return getOptionsFromString(optionsSource); |
| 27 } | 27 } |
| 28 | 28 |
| 29 /// Provide the options found in [optionsSource]. | 29 /// Provide the options found in [optionsSource]. |
| 30 /// Return an empty options map if the source is null. | 30 /// Return an empty options map if the source is null. |
| 31 Map<String, YamlNode> getOptionsFromString(String optionsSource) { | 31 Map<String, YamlNode> getOptionsFromString(String optionsSource) { |
| 32 var options = <String, YamlNode>{}; | 32 var options = <String, YamlNode>{}; |
| 33 if (optionsSource == null) { | 33 if (optionsSource == null) { |
| 34 return options; | 34 return options; |
| 35 } | 35 } |
| 36 var doc = loadYaml(optionsSource); | 36 YamlNode doc = loadYamlNode(optionsSource); |
| 37 // Empty options. |
| 38 if (doc is YamlScalar && doc.value == null) { |
| 39 return options; |
| 40 } |
| 37 if ((doc != null) && (doc is! YamlMap)) { | 41 if ((doc != null) && (doc is! YamlMap)) { |
| 38 throw new OptionsFormatException( | 42 throw new OptionsFormatException( |
| 39 'Bad options file format (expected map, got ${doc.runtimeType})\n' | 43 'Bad options file format (expected map, got ${doc.runtimeType})', |
| 40 'contents of options file:\n' | |
| 41 '$optionsSource\n', | |
| 42 doc.span); | 44 doc.span); |
| 43 } | 45 } |
| 44 if (doc is YamlMap) { | 46 if (doc is YamlMap) { |
| 45 doc.forEach((k, v) { | 47 doc.forEach((k, v) { |
| 46 if (k is! String) { | 48 if (k is! String) { |
| 47 throw new OptionsFormatException( | 49 throw new OptionsFormatException( |
| 48 'Bad options file format (expected String scope key, ' | 50 'Bad options file format (expected String scope key, ' |
| 49 'got ${k.runtimeType})', | 51 'got ${k.runtimeType})', |
| 50 k != null ? k.span : doc.span); | 52 k != null ? k.span : doc.span); |
| 51 } | 53 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 70 /// Thrown on options format exceptions. | 72 /// Thrown on options format exceptions. |
| 71 class OptionsFormatException implements Exception { | 73 class OptionsFormatException implements Exception { |
| 72 final String message; | 74 final String message; |
| 73 final SourceSpan span; | 75 final SourceSpan span; |
| 74 OptionsFormatException(this.message, [this.span]); | 76 OptionsFormatException(this.message, [this.span]); |
| 75 | 77 |
| 76 @override | 78 @override |
| 77 String toString() => | 79 String toString() => |
| 78 'OptionsFormatException: ${message?.toString()}, ${span?.toString()}'; | 80 'OptionsFormatException: ${message?.toString()}, ${span?.toString()}'; |
| 79 } | 81 } |
| OLD | NEW |