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

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

Issue 2947743002: Add support to pass the location of the analysis options file to plugins (Closed)
Patch Set: Created 3 years, 6 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
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 analyzer.source.analysis_options_provider; 5 library analyzer.source.analysis_options_provider;
6 6
7 import 'dart:core'; 7 import 'dart:core';
8 8
9 import 'package:analyzer/file_system/file_system.dart'; 9 import 'package:analyzer/file_system/file_system.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 12 matching lines...) Expand all
23 23
24 AnalysisOptionsProvider([this.sourceFactory]); 24 AnalysisOptionsProvider([this.sourceFactory]);
25 25
26 /// Provide the options found in either 26 /// Provide the options found in either
27 /// [root]/[AnalysisEngine.ANALYSIS_OPTIONS_FILE] or 27 /// [root]/[AnalysisEngine.ANALYSIS_OPTIONS_FILE] or
28 /// [root]/[AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE]. 28 /// [root]/[AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE].
29 /// Recursively merge options referenced by an include directive 29 /// Recursively merge options referenced by an include directive
30 /// and remove the include directive from the resulting options map. 30 /// and remove the include directive from the resulting options map.
31 /// Return an empty options map if the file does not exist. 31 /// Return an empty options map if the file does not exist.
32 Map<String, YamlNode> getOptions(Folder root, {bool crawlUp: false}) { 32 Map<String, YamlNode> getOptions(Folder root, {bool crawlUp: false}) {
33 Resource resource; 33 return getOptionsFromFile(getOptionsFile(root, crawlUp: crawlUp));
34 }
35
36 /// Return the analysis options file from which options should be read, or
37 /// `null` if there is no analysis options file for code in the given [root].
38 ///
39 /// The given [root] directory will be searched first. If no file is found and
40 /// if [crawlUp] is `true`, then enclosing directories will be searched.
41 File getOptionsFile(Folder root, {bool crawlUp: false}) {
42 Resource resource = null;
34 for (Folder folder = root; folder != null; folder = folder.parent) { 43 for (Folder folder = root; folder != null; folder = folder.parent) {
35 resource = folder.getChild(AnalysisEngine.ANALYSIS_OPTIONS_FILE); 44 resource = folder.getChild(AnalysisEngine.ANALYSIS_OPTIONS_FILE);
36 if (resource.exists) { 45 if (resource.exists) {
37 break; 46 break;
38 } 47 }
39 resource = folder.getChild(AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 48 resource = folder.getChild(AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
40 if (resource.exists || !crawlUp) { 49 if (resource.exists || !crawlUp) {
41 break; 50 break;
42 } 51 }
43 } 52 }
44 return getOptionsFromFile(resource); 53 return resource is File ? resource : null;
45 } 54 }
46 55
47 /// Provide the options found in [file]. 56 /// Provide the options found in [file].
48 /// Recursively merge options referenced by an include directive 57 /// Recursively merge options referenced by an include directive
49 /// and remove the include directive from the resulting options map. 58 /// and remove the include directive from the resulting options map.
50 /// Return an empty options map if the file does not exist. 59 /// Return an empty options map if the file does not exist.
51 Map<String, YamlNode> getOptionsFromFile(File file) { 60 Map<String, YamlNode> getOptionsFromFile(File file) {
52 return getOptionsFromSource(new FileSource(file)); 61 return getOptionsFromSource(new FileSource(file));
53 } 62 }
54 63
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 /// Thrown on options format exceptions. 165 /// Thrown on options format exceptions.
157 class OptionsFormatException implements Exception { 166 class OptionsFormatException implements Exception {
158 final String message; 167 final String message;
159 final SourceSpan span; 168 final SourceSpan span;
160 OptionsFormatException(this.message, [this.span]); 169 OptionsFormatException(this.message, [this.span]);
161 170
162 @override 171 @override
163 String toString() => 172 String toString() =>
164 'OptionsFormatException: ${message?.toString()}, ${span?.toString()}'; 173 'OptionsFormatException: ${message?.toString()}, ${span?.toString()}';
165 } 174 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/src/plugin/plugin_manager_test.dart ('k') | pkg/analyzer_plugin/doc/api.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698