| 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 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:yaml/yaml.dart'; | 9 import 'package:yaml/yaml.dart'; |
| 9 | 10 |
| 10 /// Provide the options found in the `.analysis_options` file. | 11 /// Provide the options found in the `.analysis_options` file. |
| 11 class AnalysisOptionsProvider { | 12 class AnalysisOptionsProvider { |
| 12 /// The name of the analysis options source file. | 13 /// Provide the options found in [root]/[ANALYSIS_OPTIONS_FILE]. |
| 13 static const String ANALYSIS_OPTIONS_NAME = '.analysis_options'; | |
| 14 | |
| 15 /// Provide the options found in [root]/[ANALYSIS_OPTIONS_NAME]. | |
| 16 /// Return an empty options map if the file does not exist. | 14 /// Return an empty options map if the file does not exist. |
| 17 Map<String, YamlNode> getOptions(Folder root) { | 15 Map<String, YamlNode> getOptions(Folder root) { |
| 18 var optionsSource = | 16 var optionsSource = _readAnalysisOptionsFile( |
| 19 _readAnalysisOptionsFile(root.getChild(ANALYSIS_OPTIONS_NAME)); | 17 root.getChild(AnalysisEngine.ANALYSIS_OPTIONS_FILE)); |
| 20 return getOptionsFromString(optionsSource); | 18 return getOptionsFromString(optionsSource); |
| 21 } | 19 } |
| 22 | 20 |
| 23 /// Provide the options found in [file]. | 21 /// Provide the options found in [file]. |
| 24 /// Return an empty options map if the file does not exist. | 22 /// Return an empty options map if the file does not exist. |
| 25 Map<String, YamlNode> getOptionsFromFile(File file) { | 23 Map<String, YamlNode> getOptionsFromFile(File file) { |
| 26 var optionsSource = _readAnalysisOptionsFile(file); | 24 var optionsSource = _readAnalysisOptionsFile(file); |
| 27 return getOptionsFromString(optionsSource); | 25 return getOptionsFromString(optionsSource); |
| 28 } | 26 } |
| 29 | 27 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 58 /// Returns null if file does not exist. | 56 /// Returns null if file does not exist. |
| 59 String _readAnalysisOptionsFile(File file) { | 57 String _readAnalysisOptionsFile(File file) { |
| 60 try { | 58 try { |
| 61 return file.readAsStringSync(); | 59 return file.readAsStringSync(); |
| 62 } on FileSystemException { | 60 } on FileSystemException { |
| 63 // File can't be read. | 61 // File can't be read. |
| 64 return null; | 62 return null; |
| 65 } | 63 } |
| 66 } | 64 } |
| 67 } | 65 } |
| OLD | NEW |