Move remaining of file_paths from ContextLocatorImpl.
Change-Id: I7f2362494af731657e59f1189d68790f71d0fc2f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/187200
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/analysis/context_locator.dart b/pkg/analyzer/lib/src/dart/analysis/context_locator.dart
index b05e502..7198e6b 100644
--- a/pkg/analyzer/lib/src/dart/analysis/context_locator.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/context_locator.dart
@@ -15,6 +15,7 @@
import 'package:analyzer/src/context/packages.dart';
import 'package:analyzer/src/dart/analysis/context_root.dart';
import 'package:analyzer/src/task/options.dart';
+import 'package:analyzer/src/util/file_paths.dart' as file_paths;
import 'package:analyzer/src/util/yaml.dart';
import 'package:analyzer/src/workspace/workspace.dart';
import 'package:glob/glob.dart';
@@ -23,18 +24,6 @@
/// An implementation of a context locator.
class ContextLocatorImpl implements ContextLocator {
- /// The name of the analysis options file.
- static const String ANALYSIS_OPTIONS_NAME = 'analysis_options.yaml';
-
- /// The name of the `.dart_tool` directory.
- static const String DOT_DART_TOOL_NAME = '.dart_tool';
-
- /// The name of the packages file.
- static const String PACKAGE_CONFIG_JSON_NAME = 'package_config.json';
-
- /// The name of the packages file.
- static const String DOT_PACKAGES_NAME = '.packages';
-
/// The resource provider used to access the file system.
final ResourceProvider resourceProvider;
@@ -348,19 +337,19 @@
/// Return the analysis options file in the given [folder], or `null` if the
/// folder does not contain an analysis options file.
File? _getOptionsFile(Folder folder) =>
- _getFile(folder, ANALYSIS_OPTIONS_NAME);
+ _getFile(folder, file_paths.analysisOptionsYaml);
/// Return the packages file in the given [folder], or `null` if the folder
/// does not contain a packages file.
File? _getPackagesFile(Folder folder) {
var file = folder
- .getChildAssumingFolder(DOT_DART_TOOL_NAME)
- .getChildAssumingFile(PACKAGE_CONFIG_JSON_NAME);
+ .getChildAssumingFolder(file_paths.dotDartTool)
+ .getChildAssumingFile(file_paths.packageConfigJson);
if (file.exists) {
return file;
}
- return _getFile(folder, DOT_PACKAGES_NAME);
+ return _getFile(folder, file_paths.dotPackages);
}
/// Add to the given lists of [folders] and [files] all of the resources in
diff --git a/pkg/analyzer/lib/src/test_utilities/resource_provider_mixin.dart b/pkg/analyzer/lib/src/test_utilities/resource_provider_mixin.dart
index bf332b0..ea5e130 100644
--- a/pkg/analyzer/lib/src/test_utilities/resource_provider_mixin.dart
+++ b/pkg/analyzer/lib/src/test_utilities/resource_provider_mixin.dart
@@ -4,7 +4,6 @@
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/memory_file_system.dart';
-import 'package:analyzer/src/dart/analysis/context_locator.dart';
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
/// A mixin for test classes that adds a [ResourceProvider] and utility methods
@@ -62,12 +61,12 @@
}
File newOptionsFile(String directoryPath, {String content = ''}) {
- String path = join(directoryPath, ContextLocatorImpl.ANALYSIS_OPTIONS_NAME);
+ String path = join(directoryPath, file_paths.analysisOptionsYaml);
return newFile(path, content: content);
}
File newPackagesFile(String directoryPath) {
- String path = join(directoryPath, ContextLocatorImpl.DOT_PACKAGES_NAME);
+ String path = join(directoryPath, file_paths.dotPackages);
return newFile(path);
}
diff --git a/pkg/analyzer/lib/src/util/file_paths.dart b/pkg/analyzer/lib/src/util/file_paths.dart
index 46e450f..2a6318c 100644
--- a/pkg/analyzer/lib/src/util/file_paths.dart
+++ b/pkg/analyzer/lib/src/util/file_paths.dart
@@ -13,12 +13,18 @@
/// File name of Android manifest files.
const String androidManifestXml = 'AndroidManifest.xml';
+/// The name of the `.dart_tool` directory.
+const String dotDartTool = '.dart_tool';
+
/// File name of package spec files.
const String dotPackages = '.packages';
/// The name of the data file used to specify data-driven fixes.
const String fixDataYaml = 'fix_data.yaml';
+/// The name of the package config files.
+const String packageConfigJson = 'package_config.json';
+
/// File name of pubspec files.
const String pubspecYaml = 'pubspec.yaml';
@@ -52,8 +58,8 @@
bool isPackageConfigJson(p.Context pathContext, String path) {
var components = pathContext.split(path);
return components.length > 2 &&
- components[components.length - 1] == 'package_config.json' &&
- components[components.length - 2] == '.dart_tool';
+ components[components.length - 1] == packageConfigJson &&
+ components[components.length - 2] == dotDartTool;
}
/// Return `true` if [path] is a `pubspec.yaml` file.
diff --git a/pkg/analyzer/test/src/dart/analysis/context_locator_test.dart b/pkg/analyzer/test/src/dart/analysis/context_locator_test.dart
index 116c6f1..e7df093 100644
--- a/pkg/analyzer/test/src/dart/analysis/context_locator_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/context_locator_test.dart
@@ -6,6 +6,7 @@
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/analysis/context_locator.dart';
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
+import 'package:analyzer/src/util/file_paths.dart' as file_paths;
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -573,9 +574,7 @@
void test_locateRoots_options_withExclude_wholeFolder_includedOptions() {
Folder rootFolder = newFolder('/test/root');
- File optionsFile = newFile(
- '/test/root/${ContextLocatorImpl.ANALYSIS_OPTIONS_NAME}',
- content: '''
+ File optionsFile = newOptionsFile('/test/root', content: '''
include: has_excludes.yaml
''');
newFile('/test/root/has_excludes.yaml', content: '''
@@ -609,9 +608,7 @@
void test_locateRoots_options_withExclude_wholeFolder_includedOptionsMerge() {
Folder rootFolder = newFolder('/test/root');
- File optionsFile = newFile(
- '/test/root/${ContextLocatorImpl.ANALYSIS_OPTIONS_NAME}',
- content: '''
+ File optionsFile = newOptionsFile('/test/root', content: '''
include: has_excludes.yaml
analyzer:
exclude:
@@ -802,8 +799,8 @@
File _newPackageConfigFile(String directoryPath) {
String path = join(
directoryPath,
- ContextLocatorImpl.DOT_DART_TOOL_NAME,
- ContextLocatorImpl.PACKAGE_CONFIG_JSON_NAME,
+ file_paths.dotDartTool,
+ file_paths.packageConfigJson,
);
return newFile(path);
}