97871aeab5
In many cases, AnalysisOptions is sufficient. * ResolvedCorrectionProducer will be public API for someone writing an analyzer plugin; it should not expose an AnalysisOptionsImpl. Luckily the only need for the Impl, today, is in the "ignore diagnostic" fixes so we can cast in there. (We could also expose the `file` and the `unignorableNames` fields.) * Some other spots only cast in order to access one of the 'strict' fields, but all of those have been made public. * AnalysisOptionsImpl.enabledLegacyPluginNames can be made final. * Many other users don't need AnalysisOptionsImpl, or only need it to pass it to other code that _does_ need it. In many of those cases it makes sense to look at an object as an AnalysisOptions, and let the code that needs a field from Impl to do a cast. Change-Id: I3640934fb9d93c9b95f15a22457af604e420c7a9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392240 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Samuel Rawlins <srawlins@google.com>
97 lines
2.9 KiB
Dart
97 lines
2.9 KiB
Dart
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'package:analyzer/dart/analysis/analysis_options.dart';
|
|
import 'package:analyzer/source/source.dart';
|
|
import 'package:analyzer/src/dart/analysis/analysis_options.dart';
|
|
import 'package:analyzer/src/dart/analysis/session.dart';
|
|
import 'package:analyzer/src/dart/element/class_hierarchy.dart';
|
|
import 'package:analyzer/src/dart/element/element.dart';
|
|
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
|
|
import 'package:analyzer/src/dart/element/type_provider.dart';
|
|
import 'package:analyzer/src/dart/element/type_system.dart';
|
|
import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
|
|
import 'package:analyzer/src/generated/source.dart' show SourceFactory;
|
|
import 'package:analyzer/src/test_utilities/mock_sdk_elements.dart';
|
|
|
|
class TestAnalysisContext implements AnalysisContext {
|
|
@override
|
|
final SourceFactory sourceFactory = _MockSourceFactory();
|
|
|
|
final _MockAnalysisSession _analysisSession = _MockAnalysisSession();
|
|
final AnalysisOptions _analysisOptions = AnalysisOptionsImpl();
|
|
|
|
late TypeProviderImpl _typeProvider;
|
|
late TypeSystemImpl _typeSystem;
|
|
|
|
TestAnalysisContext() {
|
|
var sdkElements = MockSdkElements(this, _analysisSession);
|
|
|
|
_typeProvider = TypeProviderImpl(
|
|
coreLibrary: sdkElements.coreLibrary,
|
|
asyncLibrary: sdkElements.asyncLibrary,
|
|
);
|
|
|
|
_typeSystem = TypeSystemImpl(
|
|
typeProvider: _typeProvider,
|
|
);
|
|
|
|
_setLibraryTypeSystem(sdkElements.coreLibrary);
|
|
_setLibraryTypeSystem(sdkElements.asyncLibrary);
|
|
}
|
|
|
|
@override
|
|
AnalysisOptions get analysisOptions => _analysisOptions;
|
|
|
|
AnalysisSessionImpl get analysisSession => _analysisSession;
|
|
|
|
TypeProviderImpl get typeProvider {
|
|
return _typeProvider;
|
|
}
|
|
|
|
TypeSystemImpl get typeSystem {
|
|
return _typeSystem;
|
|
}
|
|
|
|
@override
|
|
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
|
|
|
void _setLibraryTypeSystem(LibraryElementImpl libraryElement) {
|
|
libraryElement.typeProvider = _typeProvider;
|
|
libraryElement.typeSystem = _typeSystem;
|
|
}
|
|
}
|
|
|
|
class _MockAnalysisSession implements AnalysisSessionImpl {
|
|
@override
|
|
final ClassHierarchy classHierarchy = ClassHierarchy();
|
|
|
|
@override
|
|
final InheritanceManager3 inheritanceManager = InheritanceManager3();
|
|
|
|
@override
|
|
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
|
}
|
|
|
|
class _MockSource implements Source {
|
|
@override
|
|
final Uri uri;
|
|
|
|
_MockSource(this.uri);
|
|
|
|
@override
|
|
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
|
}
|
|
|
|
class _MockSourceFactory implements SourceFactory {
|
|
@override
|
|
Source forUri(String uriStr) {
|
|
var uri = Uri.parse(uriStr);
|
|
return _MockSource(uri);
|
|
}
|
|
|
|
@override
|
|
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
|
}
|