Remove DartSdk.analysisContext

Change-Id: I6a67344d928e6182a851741bbbc862284af710c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162623
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2020-09-13 00:56:36 +00:00 committed by commit-bot@chromium.org
parent ce6a95c15d
commit ba78db411a
7 changed files with 11 additions and 74 deletions

View file

@ -500,16 +500,6 @@ class ContextsPage extends DiagnosticPageWithNav {
buf.writeln('</div>');
buf.writeln('<div class="column one-half">');
var sdk = driver?.sourceFactory?.dartSdk;
AnalysisOptionsImpl sdkOptions = sdk?.context?.analysisOptions;
if (sdkOptions != null) {
h3('SDK analysis options');
p(describe(sdkOptions), raw: true);
}
buf.writeln('</div>');
buf.writeln('</div>');
h3('Lints');

View file

@ -5,11 +5,13 @@
import 'dart:typed_data';
import 'package:_fe_analyzer_shared/src/sdk/allowed_experiments.dart';
import 'package:analyzer/dart/analysis/declared_variables.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/analysis/utilities.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/context/context.dart';
import 'package:analyzer/src/dart/analysis/experiments.dart';
import 'package:analyzer/src/dart/analysis/session.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
@ -61,8 +63,13 @@ Uint8List buildSdkSummary({
return sdk.mapDartUri(e.shortName);
}).toList();
var analysisContext = AnalysisContextImpl(
SynchronousSession(AnalysisOptionsImpl(), DeclaredVariables()),
SourceFactory([DartUriResolver(sdk)]),
);
return _Builder(
sdk.context,
analysisContext,
sdk.allowedExperimentsJson,
sdk.languageVersion,
librarySources,
@ -70,7 +77,7 @@ Uint8List buildSdkSummary({
}
class _Builder {
final AnalysisContext context;
final AnalysisContextImpl context;
final String allowedExperimentsJson;
final Iterable<Source> librarySources;

View file

@ -70,12 +70,3 @@ class AnalysisContextImpl implements AnalysisContext {
);
}
}
/// An [AnalysisContext] that only contains sources for a Dart SDK.
class SdkAnalysisContext extends AnalysisContextImpl {
/// Initialize a newly created SDK analysis context with the given [options].
/// Analysis options cannot be changed afterwards. If the given [options] are
/// `null`, then default options are used.
SdkAnalysisContext(AnalysisOptions options, SourceFactory sourceFactory)
: super(SynchronousSession(options, DeclaredVariables()), sourceFactory);
}

View file

@ -10,7 +10,6 @@ import 'package:analyzer/dart/analysis/utilities.dart';
import 'package:analyzer/exception/exception.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/memory_file_system.dart';
import 'package:analyzer/src/context/context.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/java_engine_io.dart';
import 'package:analyzer/src/generated/sdk.dart';
@ -35,22 +34,9 @@ abstract class AbstractDartSdk implements DartSdk {
/// A mapping from Dart library URI's to the library represented by that URI.
LibraryMap libraryMap = LibraryMap();
/// The [AnalysisContext] which is used for all of the sources in this SDK.
SdkAnalysisContext _analysisContext;
/// The mapping from Dart URI's to the corresponding sources.
final Map<String, Source> _uriToSourceMap = HashMap<String, Source>();
@override
AnalysisContext get context {
if (_analysisContext == null) {
var factory = SourceFactory([DartUriResolver(this)]);
var analysisOptions = AnalysisOptionsImpl();
_analysisContext = SdkAnalysisContext(analysisOptions, factory);
}
return _analysisContext;
}
@override
List<SdkLibrary> get sdkLibraries => libraryMap.sdkLibraries;

View file

@ -6,7 +6,6 @@ import 'dart:collection';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
import 'package:analyzer/src/generated/source.dart' show Source;
import 'package:pub_semver/pub_semver.dart';
@ -32,9 +31,6 @@ abstract class DartSdk {
/// if the file cannot be read, e.g. does not exist.
String get allowedExperimentsJson;
/// Return the analysis context used for all of the sources in this [DartSdk].
AnalysisContext get context;
/// Return the language version of this SDK, or throws an exception.
///
/// The language version has only major/minor components, the patch number

View file

@ -3,11 +3,8 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/file_system/file_system.dart' show ResourceProvider;
import 'package:analyzer/src/context/context.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source.dart'
show DartUriResolver, Source, SourceFactory;
import 'package:analyzer/src/generated/source.dart' show Source;
import 'package:analyzer/src/summary/idl.dart';
import 'package:analyzer/src/summary/package_bundle_reader.dart';
import 'package:pub_semver/pub_semver.dart';
@ -22,9 +19,6 @@ class SummaryBasedDartSdk implements DartSdk {
PackageBundle _bundle;
ResourceProvider resourceProvider;
/// The [AnalysisContext] which is used for all of the sources in this sdk.
SdkAnalysisContext _analysisContext;
SummaryBasedDartSdk(String summaryPath, bool _, {this.resourceProvider}) {
_dataStore = SummaryDataStore(<String>[summaryPath],
resourceProvider: resourceProvider);
@ -48,16 +42,6 @@ class SummaryBasedDartSdk implements DartSdk {
/// Return the [PackageBundle] for this SDK, not `null`.
PackageBundle get bundle => _bundle;
@override
AnalysisContext get context {
if (_analysisContext == null) {
var analysisOptions = AnalysisOptionsImpl();
var factory = SourceFactory([DartUriResolver(this)]);
_analysisContext = SdkAnalysisContext(analysisOptions, factory);
}
return _analysisContext;
}
@override
Version get languageVersion {
var version = _bundle.sdk.languageVersion;

View file

@ -4,9 +4,7 @@
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/memory_file_system.dart';
import 'package:analyzer/src/context/context.dart';
import 'package:analyzer/src/dart/sdk/sdk.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:meta/meta.dart';
@ -1081,11 +1079,6 @@ class MockSdk implements DartSdk {
final Map<String, String> uriMap = {};
final AnalysisOptionsImpl _analysisOptions;
/// The [AnalysisContextImpl] which is used for all of the sources.
AnalysisContextImpl _analysisContext;
@override
final List<SdkLibrary> sdkLibraries = [];
@ -1095,9 +1088,8 @@ class MockSdk implements DartSdk {
/// their units are relative (will be put into `sdkRoot/lib`).
MockSdk({
@required this.resourceProvider,
AnalysisOptionsImpl analysisOptions,
List<MockSdkLibrary> additionalLibraries = const [],
}) : _analysisOptions = analysisOptions ?? AnalysisOptionsImpl() {
}) {
_versionFile = resourceProvider
.getFolder(resourceProvider.convertPath(sdkRoot))
.getChildAssumingFile('version');
@ -1189,15 +1181,6 @@ class MockSdk implements DartSdk {
}
}
@override
AnalysisContextImpl get context {
if (_analysisContext == null) {
var factory = SourceFactory([DartUriResolver(this)]);
_analysisContext = SdkAnalysisContext(_analysisOptions, factory);
}
return _analysisContext;
}
@override
Version get languageVersion {
var sdkVersionStr = _versionFile.readAsStringSync();