API. Deprecate 'ContextLocator' and 'ContextBuilder'.

Bug: https://github.com/dart-lang/sdk/issues/56102
Change-Id: Ia55b978571e412ea7b6b7c4b6cc482f731ecdc1a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375760
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
Konstantin Shcheglov
2024-07-15 20:31:19 +00:00
committed by Commit Queue
parent 63f47bbb5a
commit 726fc33e0a
8 changed files with 21 additions and 10 deletions
@@ -31,13 +31,13 @@ import 'package:analysis_server/src/server/performance.dart';
import 'package:analysis_server/src/services/user_prompts/dart_fix_prompt_manager.dart';
import 'package:analysis_server/src/utilities/extensions/flutter.dart';
import 'package:analysis_server/src/utilities/process.dart';
import 'package:analyzer/dart/analysis/context_locator.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/exception/exception.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/instrumentation/instrumentation.dart';
import 'package:analyzer/src/dart/analysis/context_locator.dart';
import 'package:analyzer/src/dart/analysis/status.dart' as analysis;
import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
@@ -984,7 +984,7 @@ class LspAnalysisServer extends AnalysisServer {
/// This is used when there are no workspace folders open directly.
List<String> _getRootsForOpenFiles() {
var openFiles = priorityFiles.toList();
var contextLocator = ContextLocator(resourceProvider: resourceProvider);
var contextLocator = ContextLocatorImpl(resourceProvider: resourceProvider);
var roots = contextLocator.locateRoots(includedPaths: openFiles);
var packages = <String>{};
+2
View File
@@ -1,5 +1,7 @@
## 6.8.0-dev
* Add `AnalysisContextCollection.dispose()`. It must be invoked at the end.
* Deprecated `ContextLocator` and `ContextBuilder`.
Use `AnalysisContextCollection` instead.
## 6.7.0
* Deprecated `File.createSource()`, it violates levels of abstraction.
@@ -11,6 +11,7 @@ import 'package:analyzer/src/dart/analysis/context_builder.dart';
/// A utility class used to build an analysis context based on a context root.
///
/// Clients may not extend, implement or mix-in this class.
@Deprecated('Use AnalysisContextCollection instead')
abstract class ContextBuilder {
/// Initialize a newly created context builder. If a [resourceProvider] is
/// given, then it will be used to access the file system, otherwise the
@@ -11,6 +11,7 @@ import 'package:analyzer/src/dart/analysis/context_locator.dart';
/// folders and a list of excluded files and folders.
///
/// Clients may not extend, implement or mix-in this class.
@Deprecated('Use AnalysisContextCollection instead')
abstract class ContextLocator {
/// Initialize a newly created context locator. If a [resourceProvider] is
/// supplied, it will be used to access the file system. Otherwise the default
@@ -3,13 +3,13 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
import 'package:analyzer/dart/analysis/context_locator.dart';
import 'package:analyzer/dart/analysis/context_root.dart';
import 'package:analyzer/dart/analysis/declared_variables.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer/src/dart/analysis/byte_store.dart';
import 'package:analyzer/src/dart/analysis/context_builder.dart';
import 'package:analyzer/src/dart/analysis/context_locator.dart';
import 'package:analyzer/src/dart/analysis/driver.dart';
import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart';
import 'package:analyzer/src/dart/analysis/file_content_cache.dart';
@@ -91,7 +91,7 @@ class AnalysisContextCollectionImpl implements AnalysisContextCollection {
// ignore: prefer_initializing_formals
this.macroSupportFactory = macroSupportFactory;
var contextLocator = ContextLocator(
var contextLocator = ContextLocatorImpl(
resourceProvider: this.resourceProvider,
);
var roots = contextLocator.locateRoots(
@@ -42,6 +42,7 @@ import 'package:analyzer/src/util/sdk.dart';
import 'package:analyzer/src/workspace/workspace.dart';
/// An implementation of a context builder.
// ignore:deprecated_member_use_from_same_package
class ContextBuilderImpl implements ContextBuilder {
/// The resource provider used to access the file system.
final ResourceProvider resourceProvider;
@@ -26,6 +26,7 @@ import 'package:path/path.dart';
import 'package:yaml/yaml.dart';
/// An implementation of a context locator.
// ignore:deprecated_member_use_from_same_package
class ContextLocatorImpl implements ContextLocator {
/// A flag indicating if analysis contexts are limited to one corresponding
/// analysis options file.
+11 -6
View File
@@ -13,8 +13,7 @@ library;
import 'dart:io';
import 'package:analyzer/dart/analysis/analysis_context.dart';
import 'package:analyzer/dart/analysis/context_builder.dart';
import 'package:analyzer/dart/analysis/context_locator.dart';
import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:test_runner/src/path.dart';
@@ -65,12 +64,18 @@ void _checkTestDirectory(Directory directory) {
}
void _initAnalysisContext() {
var roots = ContextLocator().locateRoots(includedPaths: ['test']);
if (roots.length != 1) {
throw StateError('Expected to find exactly one context root, got $roots');
var collection = AnalysisContextCollection(
includedPaths: ['test'],
);
if (collection.contexts.length != 1) {
throw StateError(
'Expected to find exactly one context root, '
'got ${collection.contexts.length}',
);
}
_analysisContext = ContextBuilder().createContext(contextRoot: roots[0]);
_analysisContext = collection.contexts.single;
}
void _parseReferences(Set<String> importedPaths, String filePath) {