Skip to content

Commit

Permalink
Stop using deprecated LibraryElement.isNonNullableByDefault
Browse files Browse the repository at this point in the history
Prepare for https://dart-review.googlesource.com/c/sdk/+/366700

PiperOrigin-RevId: 634787005
  • Loading branch information
Googler authored and copybara-github committed May 17, 2024
1 parent 4be52e1 commit 16d0f96
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MockBuilder implements Builder {
Future<void> build(BuildStep buildStep) async {
if (!await buildStep.resolver.isLibrary(buildStep.inputId)) return;
final entryLib = await buildStep.inputLibrary;
final sourceLibIsNonNullable = entryLib.isNonNullableByDefault;
final sourceLibIsNonNullable = true;

final mockLibraryAsset = buildStep.allowedOutputs.singleOrNull;
if (mockLibraryAsset == null) {
Expand Down Expand Up @@ -144,13 +144,11 @@ class MockBuilder implements Builder {
// The source lib may be pre-null-safety because of an explicit opt-out
// (`// @dart=2.9`), as opposed to living in a pre-null-safety package. To
// allow for this situation, we must also add an opt-out comment here.
final dartVersionComment = sourceLibIsNonNullable ? '' : '// @dart=2.9';
final mockLibraryContent = DartFormatter().format('''
// Mocks generated by Mockito $packageVersion from annotations
// in ${entryLib.definingCompilationUnit.source.uri.path}.
// Do not manually edit this file.
$dartVersionComment
$rawOutput
''');
Expand Down Expand Up @@ -1051,7 +1049,7 @@ class _MockLibraryInfo {
final fallbackGenerators = mockTarget.fallbackGenerators;
mockClasses.add(_MockClassInfo(
mockTarget: mockTarget,
sourceLibIsNonNullable: entryLib.isNonNullableByDefault,
sourceLibIsNonNullable: true,
typeProvider: entryLib.typeProvider,
typeSystem: entryLib.typeSystem,
mockLibraryInfo: this,
Expand Down Expand Up @@ -1175,9 +1173,8 @@ class _MockClassInfo {
// The test can be pre-null-safety but if the class
// we want to mock is defined in a null safe library,
// we still need to override methods to get nice mocks.
final isNiceMockOfNullSafeClass = mockTarget.onMissingStub ==
OnMissingStub.returnDefault &&
typeToMock.element.enclosingElement.library.isNonNullableByDefault;
final isNiceMockOfNullSafeClass =
mockTarget.onMissingStub == OnMissingStub.returnDefault;

if (sourceLibIsNonNullable || isNiceMockOfNullSafeClass) {
cBuilder.methods.addAll(
Expand Down

0 comments on commit 16d0f96

Please sign in to comment.