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

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

Issue 2981553002: AnalysisOptionsProvider.getOptionsFile() should return only existing files. (Closed)
Patch Set: Created 3 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 | « pkg/analysis_server/test/domain_diagnostic_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 return getOptionsFromFile(getOptionsFile(root, crawlUp: crawlUp)); 33 File optionsFile = getOptionsFile(root, crawlUp: crawlUp);
34 if (optionsFile == null) {
35 return const <String, YamlNode>{};
36 }
37 return getOptionsFromFile(optionsFile);
34 } 38 }
35 39
36 /// Return the analysis options file from which options should be read, or 40 /// 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]. 41 /// `null` if there is no analysis options file for code in the given [root].
38 /// 42 ///
39 /// The given [root] directory will be searched first. If no file is found and 43 /// 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. 44 /// if [crawlUp] is `true`, then enclosing directories will be searched.
41 File getOptionsFile(Folder root, {bool crawlUp: false}) { 45 File getOptionsFile(Folder root, {bool crawlUp: false}) {
42 Resource resource = null; 46 Resource resource = null;
43 for (Folder folder = root; folder != null; folder = folder.parent) { 47 for (Folder folder = root; folder != null; folder = folder.parent) {
44 resource = folder.getChild(AnalysisEngine.ANALYSIS_OPTIONS_FILE); 48 resource = folder.getChild(AnalysisEngine.ANALYSIS_OPTIONS_FILE);
45 if (resource.exists) { 49 if (resource.exists) {
46 break; 50 break;
47 } 51 }
48 resource = folder.getChild(AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 52 resource = folder.getChild(AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
49 if (resource.exists || !crawlUp) { 53 if (resource.exists || !crawlUp) {
50 break; 54 break;
51 } 55 }
52 } 56 }
53 return resource is File ? resource : null; 57 if (resource is File && resource.exists) {
58 return resource;
59 }
60 return null;
54 } 61 }
55 62
56 /// Provide the options found in [file]. 63 /// Provide the options found in [file].
57 /// Recursively merge options referenced by an include directive 64 /// Recursively merge options referenced by an include directive
58 /// and remove the include directive from the resulting options map. 65 /// and remove the include directive from the resulting options map.
59 /// Return an empty options map if the file does not exist. 66 /// Return an empty options map if the file does not exist.
60 Map<String, YamlNode> getOptionsFromFile(File file) { 67 Map<String, YamlNode> getOptionsFromFile(File file) {
61 return getOptionsFromSource(new FileSource(file)); 68 return getOptionsFromSource(new FileSource(file));
62 } 69 }
63 70
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 /// Thrown on options format exceptions. 172 /// Thrown on options format exceptions.
166 class OptionsFormatException implements Exception { 173 class OptionsFormatException implements Exception {
167 final String message; 174 final String message;
168 final SourceSpan span; 175 final SourceSpan span;
169 OptionsFormatException(this.message, [this.span]); 176 OptionsFormatException(this.message, [this.span]);
170 177
171 @override 178 @override
172 String toString() => 179 String toString() =>
173 'OptionsFormatException: ${message?.toString()}, ${span?.toString()}'; 180 'OptionsFormatException: ${message?.toString()}, ${span?.toString()}';
174 } 181 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/domain_diagnostic_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698