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

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

Issue 1425393002: Map merging. (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:source_span/source_span.dart'; 10 import 'package:source_span/source_span.dart';
10 import 'package:yaml/yaml.dart'; 11 import 'package:yaml/yaml.dart';
11 12
12 /// Provide the options found in the `.analysis_options` file. 13 /// Provide the options found in the `.analysis_options` file.
13 class AnalysisOptionsProvider { 14 class AnalysisOptionsProvider {
14 /// Provide the options found in [root]/[ANALYSIS_OPTIONS_FILE]. 15 /// Provide the options found in [root]/[ANALYSIS_OPTIONS_FILE].
15 /// Return an empty options map if the file does not exist. 16 /// Return an empty options map if the file does not exist.
16 Map<String, YamlNode> getOptions(Folder root) { 17 Map<String, YamlNode> getOptions(Folder root) {
17 var optionsSource = _readAnalysisOptionsFile( 18 var optionsSource = _readAnalysisOptionsFile(
18 root.getChild(AnalysisEngine.ANALYSIS_OPTIONS_FILE)); 19 root.getChild(AnalysisEngine.ANALYSIS_OPTIONS_FILE));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 'Bad options file format (expected String scope key, ' 60 'Bad options file format (expected String scope key, '
60 'got ${k.runtimeType})', 61 'got ${k.runtimeType})',
61 k != null ? k.span : doc.span); 62 k != null ? k.span : doc.span);
62 } 63 }
63 options[k] = v; 64 options[k] = v;
64 }); 65 });
65 } 66 }
66 return options; 67 return options;
67 } 68 }
68 69
70 /// Merge the given options contents where the values in [defaults] may be
71 /// overridden by [overrides].
72 ///
73 /// Some notes about merge semantics:
74 ///
75 /// * lists are merged (without duplicates).
76 /// * lists of scalar values can be promoted to simple maps when merged with
77 /// maps of strings to booleans (e.g., ['opt1', 'opt2'] becomes
78 /// {'opt1': true, 'opt2': true}.
79 /// * maps are merged recursively.
80 /// * if map values cannot be merged, the overriding value is taken.
81 ///
82 Map<String, YamlNode> merge(
83 Map<String, YamlNode> defaults, Map<String, YamlNode> overrides) =>
84 new Merger().merge(defaults, overrides);
85
69 /// Read the contents of [file] as a string. 86 /// Read the contents of [file] as a string.
70 /// Returns null if file does not exist. 87 /// Returns null if file does not exist.
71 String _readAnalysisOptionsFile(File file) { 88 String _readAnalysisOptionsFile(File file) {
72 try { 89 try {
73 return file.readAsStringSync(); 90 return file.readAsStringSync();
74 } on FileSystemException { 91 } on FileSystemException {
75 // File can't be read. 92 // File can't be read.
76 return null; 93 return null;
77 } 94 }
78 } 95 }
79 } 96 }
80 97
81 /// Thrown on options format exceptions. 98 /// Thrown on options format exceptions.
82 class OptionsFormatException implements Exception { 99 class OptionsFormatException implements Exception {
83 final String message; 100 final String message;
84 final SourceSpan span; 101 final SourceSpan span;
85 OptionsFormatException(this.message, [this.span]); 102 OptionsFormatException(this.message, [this.span]);
86 103
87 @override 104 @override
88 String toString() => 105 String toString() =>
89 'OptionsFormatException: ${message?.toString()}, ${span?.toString()}'; 106 'OptionsFormatException: ${message?.toString()}, ${span?.toString()}';
90 } 107 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/util/yaml.dart » ('j') | pkg/analyzer/test/src/util/yaml_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698