Chromium Code Reviews| 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 |
| index cdd912cc3d5c41680c0ae3e3165b8fd8236a2619..808c8353301b80cd4f71b208f34dd16ef53fc598 100644 |
| --- a/pkg/analyzer/lib/source/analysis_options_provider.dart |
| +++ b/pkg/analyzer/lib/source/analysis_options_provider.dart |
| @@ -8,12 +8,20 @@ import 'dart:core'; |
| import 'package:analyzer/file_system/file_system.dart'; |
| import 'package:analyzer/src/generated/engine.dart'; |
| +import 'package:analyzer/src/generated/source.dart'; |
| +import 'package:analyzer/src/source/source_resource.dart'; |
| import 'package:analyzer/src/util/yaml.dart'; |
| import 'package:source_span/source_span.dart'; |
| import 'package:yaml/yaml.dart'; |
| /// Provide the options found in the analysis options file. |
| class AnalysisOptionsProvider { |
| + /// The source factory used to resolve include declarations |
| + /// in analysis options files or `null` if include is not supported. |
| + SourceFactory sourceFactory; |
| + |
| + AnalysisOptionsProvider([this.sourceFactory]); |
| + |
| /// Provide the options found in either |
| /// [root]/[AnalysisEngine.ANALYSIS_OPTIONS_FILE] or |
| /// [root]/[AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE]. |
| @@ -30,15 +38,29 @@ class AnalysisOptionsProvider { |
| break; |
| } |
| } |
| - String optionsText = _readAnalysisOptionsFile(resource); |
| - return getOptionsFromString(optionsText); |
| + return getOptionsFromFile(resource); |
| } |
| /// Provide the options found in [file]. |
| /// Return an empty options map if the file does not exist. |
| Map<String, YamlNode> getOptionsFromFile(File file) { |
| - var optionsSource = _readAnalysisOptionsFile(file); |
| - return getOptionsFromString(optionsSource); |
| + return getOptionsFromSource(new FileSource(file)); |
| + } |
| + |
| + /// Provide the options found in [source]. |
| + /// Return an empty options map if the file does not exist. |
| + Map<String, YamlNode> getOptionsFromSource(Source source) { |
| + Map<String, YamlNode> options = |
| + getOptionsFromString(_readAnalysisOptions(source)); |
| + YamlNode node = options.remove('include'); |
|
Brian Wilkerson
2016/11/11 19:37:47
Given that "participants" are able to look at the
danrubel
2016/11/14 20:39:33
I don't think the "include" directive makes sense
|
| + if (sourceFactory != null && node is YamlScalar) { |
| + var path = node.value; |
| + if (path is String) { |
| + Source parent = sourceFactory.resolveUri(source, path); |
| + options = merge(getOptionsFromSource(parent), options); |
| + } |
| + } |
| + return options; |
| } |
| /// Provide the options found in [optionsSource]. |
| @@ -110,13 +132,13 @@ class AnalysisOptionsProvider { |
| Map<String, YamlNode> defaults, Map<String, YamlNode> overrides) => |
| new Merger().merge(defaults, overrides) as Map<String, YamlNode>; |
| - /// Read the contents of [file] as a string. |
| - /// Returns null if file does not exist. |
| - String _readAnalysisOptionsFile(File file) { |
| + /// Read the contents of [source] as a string. |
| + /// Returns null if source is null or does not exist. |
| + String _readAnalysisOptions(Source source) { |
| try { |
| - return file.readAsStringSync(); |
| - } on FileSystemException { |
| - // File can't be read. |
| + return source.contents.data; |
| + } catch (e) { |
| + // Source can't be read. |
| return null; |
|
Brian Wilkerson
2016/11/11 19:37:47
There is linter support for linting options files.
danrubel
2016/11/14 20:39:33
Good idea. https://github.com/dart-lang/sdk/issues
|
| } |
| } |