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

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

Issue 1231633011: Add an AnalysisOptionsProvider to analyzer (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 months 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
« no previous file with comments | « no previous file | pkg/analyzer/test/source/analysis_options_provider_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library source.analysis_options_provider;
6
7 import 'package:analyzer/file_system/file_system.dart';
8 import 'package:yaml/yaml.dart';
9
10 /// Provide the options found in the `.analysis_options` file.
11 class AnalysisOptionsProvider {
12 /// The name of the analysis options source file.
13 static const String ANALYSIS_OPTIONS_NAME = '.analysis_options';
14
15 /// Provide the options found in the [ANALYSIS_OPTIONS_NAME] file located in
16 /// [folder]. Return an empty options map if the file does not exist.
17 Map<String, YamlNode> getOptions(Folder root) {
18 var options = <String, YamlNode>{};
19 var optionsSource = _readAnalysisOptionsFile(root);
20 if (optionsSource == null) {
21 return options;
22 }
23 var doc = loadYaml(optionsSource);
24 if (doc is! YamlMap) {
25 throw new Exception(
26 'Bad options file format (expected map, got ${doc.runtimeType})');
27 }
28 if (doc is YamlMap) {
29 doc.forEach((k, v) {
30 if (k is! String) {
31 throw new Exception(
32 'Bad options file format (expected String scope key, '
33 'got ${k.runtimeType})');
34 }
35 options[k] = v;
36 });
37 }
38 return options;
39 }
40
41 /// Read the contents of [root]/[ANALYSIS_OPTIONS_NAME] as a string.
42 /// Returns null if file does not exist.
43 String _readAnalysisOptionsFile(Folder root) {
44 var file = root.getChild(ANALYSIS_OPTIONS_NAME);
45 try {
46 return file.readAsStringSync();
47 } on FileSystemException {
48 // File can't be read.
49 return null;
50 }
51 }
52 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/source/analysis_options_provider_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698