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 'dart:core' hide Resource; | 7 import 'dart:core'; |
8 | 8 |
9 import 'package:analyzer/file_system/file_system.dart'; | 9 import 'package:analyzer/file_system/file_system.dart'; |
10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
11 import 'package:analyzer/src/util/yaml.dart'; | 11 import 'package:analyzer/src/util/yaml.dart'; |
12 import 'package:source_span/source_span.dart'; | 12 import 'package:source_span/source_span.dart'; |
13 import 'package:yaml/yaml.dart'; | 13 import 'package:yaml/yaml.dart'; |
14 | 14 |
15 /// Provide the options found in the analysis options file. | 15 /// Provide the options found in the analysis options file. |
16 class AnalysisOptionsProvider { | 16 class AnalysisOptionsProvider { |
17 /// Provide the options found in either | 17 /// Provide the options found in either |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 YamlNode safelyLoadYamlNode() { | 52 YamlNode safelyLoadYamlNode() { |
53 try { | 53 try { |
54 return loadYamlNode(optionsSource); | 54 return loadYamlNode(optionsSource); |
55 } on YamlException catch (e) { | 55 } on YamlException catch (e) { |
56 throw new OptionsFormatException(e.message, e.span); | 56 throw new OptionsFormatException(e.message, e.span); |
57 } catch (e) { | 57 } catch (e) { |
58 throw new OptionsFormatException('Unable to parse YAML document.'); | 58 throw new OptionsFormatException('Unable to parse YAML document.'); |
59 } | 59 } |
60 } | 60 } |
| 61 |
61 YamlNode doc = safelyLoadYamlNode(); | 62 YamlNode doc = safelyLoadYamlNode(); |
62 | 63 |
63 // Empty options. | 64 // Empty options. |
64 if (doc is YamlScalar && doc.value == null) { | 65 if (doc is YamlScalar && doc.value == null) { |
65 return options; | 66 return options; |
66 } | 67 } |
67 if ((doc != null) && (doc is! YamlMap)) { | 68 if ((doc != null) && (doc is! YamlMap)) { |
68 throw new OptionsFormatException( | 69 throw new OptionsFormatException( |
69 'Bad options file format (expected map, got ${doc.runtimeType})', | 70 'Bad options file format (expected map, got ${doc.runtimeType})', |
70 doc.span); | 71 doc.span); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 /// Thrown on options format exceptions. | 125 /// Thrown on options format exceptions. |
125 class OptionsFormatException implements Exception { | 126 class OptionsFormatException implements Exception { |
126 final String message; | 127 final String message; |
127 final SourceSpan span; | 128 final SourceSpan span; |
128 OptionsFormatException(this.message, [this.span]); | 129 OptionsFormatException(this.message, [this.span]); |
129 | 130 |
130 @override | 131 @override |
131 String toString() => | 132 String toString() => |
132 'OptionsFormatException: ${message?.toString()}, ${span?.toString()}'; | 133 'OptionsFormatException: ${message?.toString()}, ${span?.toString()}'; |
133 } | 134 } |
OLD | NEW |