Skip to content

Commit 2302814

Browse files
Googlercopybara-github
authored andcommitted
Stop using deprecated LibraryElement.isNonNullableByDefault
Prepare for https://dart-review.googlesource.com/c/sdk/+/366700 PiperOrigin-RevId: 634807230
1 parent 4be52e1 commit 2302814

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

lib/src/builder.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class MockBuilder implements Builder {
7474
Future<void> build(BuildStep buildStep) async {
7575
if (!await buildStep.resolver.isLibrary(buildStep.inputId)) return;
7676
final entryLib = await buildStep.inputLibrary;
77-
final sourceLibIsNonNullable = entryLib.isNonNullableByDefault;
77+
final sourceLibIsNonNullable = true;
7878

7979
final mockLibraryAsset = buildStep.allowedOutputs.singleOrNull;
8080
if (mockLibraryAsset == null) {
@@ -144,13 +144,11 @@ class MockBuilder implements Builder {
144144
// The source lib may be pre-null-safety because of an explicit opt-out
145145
// (`// @dart=2.9`), as opposed to living in a pre-null-safety package. To
146146
// allow for this situation, we must also add an opt-out comment here.
147-
final dartVersionComment = sourceLibIsNonNullable ? '' : '// @dart=2.9';
148147
final mockLibraryContent = DartFormatter().format('''
149148
// Mocks generated by Mockito $packageVersion from annotations
150149
// in ${entryLib.definingCompilationUnit.source.uri.path}.
151150
// Do not manually edit this file.
152151
153-
$dartVersionComment
154152
155153
$rawOutput
156154
''');
@@ -1051,7 +1049,7 @@ class _MockLibraryInfo {
10511049
final fallbackGenerators = mockTarget.fallbackGenerators;
10521050
mockClasses.add(_MockClassInfo(
10531051
mockTarget: mockTarget,
1054-
sourceLibIsNonNullable: entryLib.isNonNullableByDefault,
1052+
sourceLibIsNonNullable: true,
10551053
typeProvider: entryLib.typeProvider,
10561054
typeSystem: entryLib.typeSystem,
10571055
mockLibraryInfo: this,
@@ -1175,9 +1173,8 @@ class _MockClassInfo {
11751173
// The test can be pre-null-safety but if the class
11761174
// we want to mock is defined in a null safe library,
11771175
// we still need to override methods to get nice mocks.
1178-
final isNiceMockOfNullSafeClass = mockTarget.onMissingStub ==
1179-
OnMissingStub.returnDefault &&
1180-
typeToMock.element.enclosingElement.library.isNonNullableByDefault;
1176+
final isNiceMockOfNullSafeClass =
1177+
mockTarget.onMissingStub == OnMissingStub.returnDefault;
11811178

11821179
if (sourceLibIsNonNullable || isNiceMockOfNullSafeClass) {
11831180
cBuilder.methods.addAll(

0 commit comments

Comments
 (0)