Skip to content

Commit

Permalink
API. Deprecate 'ContextLocator' and 'ContextBuilder'.
Browse files Browse the repository at this point in the history
Bug: #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>
  • Loading branch information
scheglov authored and Commit Queue committed Jul 15, 2024
1 parent 63f47bb commit 726fc33
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>{};
Expand Down
2 changes: 2 additions & 0 deletions pkg/analyzer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions pkg/analyzer/lib/dart/analysis/context_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/analyzer/lib/dart/analysis/context_locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions pkg/analyzer/lib/src/dart/analysis/context_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions pkg/analyzer/lib/src/dart/analysis/context_locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 11 additions & 6 deletions pkg/test_runner/tool/orphan_files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 726fc33

Please sign in to comment.