Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: pkg/analyzer/lib/source/analysis_options_provider.dart

Issue 1437703003: Improves options validation type safety (#24885). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/context_manager.dart ('k') | pkg/analyzer/lib/src/task/options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698