Skip to content

Commit 2946328

Browse files
scheglovCommit Queue
authored andcommitted
Element. Build mock SDK from declarative specifications.
The previous implementation of `MockSdkElements` was manually constructed, resulting in over 1000 lines of code that was difficult to maintain and extend. This change refactors the mock SDK element creation by introducing a generic, spec-based library builder. This builder uses declarative specifications (`LibrarySpec`, `ClassSpec`, etc.) to construct the corresponding element models. `MockSdkElements` now defines the `dart:core` and `dart:async` libraries as a simple, readable spec constant and uses the new builder to construct them. This significantly reduces boilerplate and improves the maintainability of the testing infrastructure. The new mock SDK does not include everything that was there before, because we don't need it, we need almost exclusively type hierarchies, with a few exceptions. Change-Id: I508e6c9d89be4766db0e0298bb4c52597deba1cd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445120 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent a9ad870 commit 2946328

File tree

5 files changed

+867
-1275
lines changed

5 files changed

+867
-1275
lines changed

pkg/analyzer/lib/src/generated/testing/test_type_provider.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:analyzer/src/dart/element/element.dart';
99
import 'package:analyzer/src/dart/element/type_provider.dart';
1010
import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
1111
import 'package:analyzer/src/generated/source.dart' show SourceFactory;
12+
import 'package:analyzer/src/summary2/reference.dart';
1213
import 'package:analyzer/src/test_utilities/mock_sdk_elements.dart';
1314
import 'package:analyzer/src/utilities/uri_cache.dart';
1415

@@ -18,7 +19,11 @@ class TestTypeProvider extends TypeProviderImpl {
1819
factory TestTypeProvider() {
1920
var analysisContext = _MockAnalysisContext();
2021
var analysisSession = _MockAnalysisSession();
21-
var sdkElements = MockSdkElements(analysisContext, analysisSession);
22+
var sdkElements = MockSdkElements(
23+
analysisContext,
24+
Reference.root(),
25+
analysisSession,
26+
);
2227
return TestTypeProvider._(
2328
sdkElements.coreLibrary,
2429
sdkElements.asyncLibrary,

0 commit comments

Comments
 (0)