Skip to content

Commit 726fc33

Browse files
scheglovCommit Queue
authored andcommitted
API. Deprecate 'ContextLocator' and 'ContextBuilder'.
Bug: #56102 Change-Id: Ia55b978571e412ea7b6b7c4b6cc482f731ecdc1a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375760 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Bob Nystrom <[email protected]>
1 parent 63f47bb commit 726fc33

File tree

8 files changed

+21
-10
lines changed

8 files changed

+21
-10
lines changed

pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ import 'package:analysis_server/src/server/performance.dart';
3131
import 'package:analysis_server/src/services/user_prompts/dart_fix_prompt_manager.dart';
3232
import 'package:analysis_server/src/utilities/extensions/flutter.dart';
3333
import 'package:analysis_server/src/utilities/process.dart';
34-
import 'package:analyzer/dart/analysis/context_locator.dart';
3534
import 'package:analyzer/dart/analysis/results.dart';
3635
import 'package:analyzer/dart/analysis/session.dart';
3736
import 'package:analyzer/error/error.dart';
3837
import 'package:analyzer/exception/exception.dart';
3938
import 'package:analyzer/file_system/file_system.dart';
4039
import 'package:analyzer/instrumentation/instrumentation.dart';
40+
import 'package:analyzer/src/dart/analysis/context_locator.dart';
4141
import 'package:analyzer/src/dart/analysis/status.dart' as analysis;
4242
import 'package:analyzer/src/generated/sdk.dart';
4343
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
@@ -984,7 +984,7 @@ class LspAnalysisServer extends AnalysisServer {
984984
/// This is used when there are no workspace folders open directly.
985985
List<String> _getRootsForOpenFiles() {
986986
var openFiles = priorityFiles.toList();
987-
var contextLocator = ContextLocator(resourceProvider: resourceProvider);
987+
var contextLocator = ContextLocatorImpl(resourceProvider: resourceProvider);
988988
var roots = contextLocator.locateRoots(includedPaths: openFiles);
989989

990990
var packages = <String>{};

pkg/analyzer/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## 6.8.0-dev
22
* Add `AnalysisContextCollection.dispose()`. It must be invoked at the end.
3+
* Deprecated `ContextLocator` and `ContextBuilder`.
4+
Use `AnalysisContextCollection` instead.
35

46
## 6.7.0
57
* Deprecated `File.createSource()`, it violates levels of abstraction.

pkg/analyzer/lib/dart/analysis/context_builder.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:analyzer/src/dart/analysis/context_builder.dart';
1111
/// A utility class used to build an analysis context based on a context root.
1212
///
1313
/// Clients may not extend, implement or mix-in this class.
14+
@Deprecated('Use AnalysisContextCollection instead')
1415
abstract class ContextBuilder {
1516
/// Initialize a newly created context builder. If a [resourceProvider] is
1617
/// given, then it will be used to access the file system, otherwise the

pkg/analyzer/lib/dart/analysis/context_locator.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:analyzer/src/dart/analysis/context_locator.dart';
1111
/// folders and a list of excluded files and folders.
1212
///
1313
/// Clients may not extend, implement or mix-in this class.
14+
@Deprecated('Use AnalysisContextCollection instead')
1415
abstract class ContextLocator {
1516
/// Initialize a newly created context locator. If a [resourceProvider] is
1617
/// supplied, it will be used to access the file system. Otherwise the default

pkg/analyzer/lib/src/dart/analysis/analysis_context_collection.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
6-
import 'package:analyzer/dart/analysis/context_locator.dart';
76
import 'package:analyzer/dart/analysis/context_root.dart';
87
import 'package:analyzer/dart/analysis/declared_variables.dart';
98
import 'package:analyzer/file_system/file_system.dart';
109
import 'package:analyzer/file_system/physical_file_system.dart';
1110
import 'package:analyzer/src/dart/analysis/byte_store.dart';
1211
import 'package:analyzer/src/dart/analysis/context_builder.dart';
12+
import 'package:analyzer/src/dart/analysis/context_locator.dart';
1313
import 'package:analyzer/src/dart/analysis/driver.dart';
1414
import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart';
1515
import 'package:analyzer/src/dart/analysis/file_content_cache.dart';
@@ -91,7 +91,7 @@ class AnalysisContextCollectionImpl implements AnalysisContextCollection {
9191
// ignore: prefer_initializing_formals
9292
this.macroSupportFactory = macroSupportFactory;
9393

94-
var contextLocator = ContextLocator(
94+
var contextLocator = ContextLocatorImpl(
9595
resourceProvider: this.resourceProvider,
9696
);
9797
var roots = contextLocator.locateRoots(

pkg/analyzer/lib/src/dart/analysis/context_builder.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import 'package:analyzer/src/util/sdk.dart';
4242
import 'package:analyzer/src/workspace/workspace.dart';
4343

4444
/// An implementation of a context builder.
45+
// ignore:deprecated_member_use_from_same_package
4546
class ContextBuilderImpl implements ContextBuilder {
4647
/// The resource provider used to access the file system.
4748
final ResourceProvider resourceProvider;

pkg/analyzer/lib/src/dart/analysis/context_locator.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import 'package:path/path.dart';
2626
import 'package:yaml/yaml.dart';
2727

2828
/// An implementation of a context locator.
29+
// ignore:deprecated_member_use_from_same_package
2930
class ContextLocatorImpl implements ContextLocator {
3031
/// A flag indicating if analysis contexts are limited to one corresponding
3132
/// analysis options file.

pkg/test_runner/tool/orphan_files.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ library;
1313
import 'dart:io';
1414

1515
import 'package:analyzer/dart/analysis/analysis_context.dart';
16-
import 'package:analyzer/dart/analysis/context_builder.dart';
17-
import 'package:analyzer/dart/analysis/context_locator.dart';
16+
import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
1817
import 'package:analyzer/dart/analysis/results.dart';
1918
import 'package:analyzer/dart/ast/ast.dart';
2019
import 'package:test_runner/src/path.dart';
@@ -65,12 +64,18 @@ void _checkTestDirectory(Directory directory) {
6564
}
6665

6766
void _initAnalysisContext() {
68-
var roots = ContextLocator().locateRoots(includedPaths: ['test']);
69-
if (roots.length != 1) {
70-
throw StateError('Expected to find exactly one context root, got $roots');
67+
var collection = AnalysisContextCollection(
68+
includedPaths: ['test'],
69+
);
70+
71+
if (collection.contexts.length != 1) {
72+
throw StateError(
73+
'Expected to find exactly one context root, '
74+
'got ${collection.contexts.length}',
75+
);
7176
}
7277

73-
_analysisContext = ContextBuilder().createContext(contextRoot: roots[0]);
78+
_analysisContext = collection.contexts.single;
7479
}
7580

7681
void _parseReferences(Set<String> importedPaths, String filePath) {

0 commit comments

Comments
 (0)