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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/source/analysis_options_provider.dart
diff --git a/pkg/analyzer/lib/source/analysis_options_provider.dart b/pkg/analyzer/lib/source/analysis_options_provider.dart
new file mode 100644
index 0000000000000000000000000000000000000000..e34812a988c227a0cfda3e424fb1f6dddddf65be
--- /dev/null
+++ b/pkg/analyzer/lib/source/analysis_options_provider.dart
@@ -0,0 +1,52 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library source.analysis_options_provider;
+
+import 'package:analyzer/file_system/file_system.dart';
+import 'package:yaml/yaml.dart';
+
+/// Provide the options found in the `.analysis_options` file.
+class AnalysisOptionsProvider {
+ /// The name of the analysis options source file.
+ static const String ANALYSIS_OPTIONS_NAME = '.analysis_options';
+
+ /// Provide the options found in the [ANALYSIS_OPTIONS_NAME] file located in
+ /// [folder]. Return an empty options map if the file does not exist.
+ Map<String, YamlNode> getOptions(Folder root) {
+ var options = <String, YamlNode>{};
+ var optionsSource = _readAnalysisOptionsFile(root);
+ if (optionsSource == null) {
+ return options;
+ }
+ var doc = loadYaml(optionsSource);
+ if (doc is! YamlMap) {
+ throw new Exception(
+ 'Bad options file format (expected map, got ${doc.runtimeType})');
+ }
+ if (doc is YamlMap) {
+ doc.forEach((k, v) {
+ if (k is! String) {
+ throw new Exception(
+ 'Bad options file format (expected String scope key, '
+ 'got ${k.runtimeType})');
+ }
+ options[k] = v;
+ });
+ }
+ return options;
+ }
+
+ /// Read the contents of [root]/[ANALYSIS_OPTIONS_NAME] as a string.
+ /// Returns null if file does not exist.
+ String _readAnalysisOptionsFile(Folder root) {
+ var file = root.getChild(ANALYSIS_OPTIONS_NAME);
+ try {
+ return file.readAsStringSync();
+ } on FileSystemException {
+ // File can't be read.
+ return null;
+ }
+ }
+}
« 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