Prepare for NamedType breaking change in the analyzer.
https://dart-review.googlesource.com/c/sdk/+/303280
PiperOrigin-RevId: 537071619
diff --git a/lib/src/builder.dart b/lib/src/builder.dart
index 288e7de..48cea6b 100644
--- a/lib/src/builder.dart
+++ b/lib/src/builder.dart
@@ -564,7 +564,7 @@
final mockType = _mockType(mockSpecAsts[index]);
final typeToMock = mockSpecType.typeArguments.single;
if (typeToMock.isDynamic) {
- final mockTypeName = mockType?.name.name;
+ final mockTypeName = mockType?.qualifiedName;
if (mockTypeName == null) {
throw InvalidMockitoAnnotationException(
'MockSpec requires a type argument to determine the class to mock. '
@@ -596,7 +596,7 @@
'${(typeArgIdx + 1).ordinal} type argument for mocked '
'$typeName.');
}
- if (typeArgAst.name.name == 'dynamic') return;
+ if (typeArgAst.qualifiedName == 'dynamic') return;
throw InvalidMockitoAnnotationException(
'Undefined type $typeArgAst passed as the '
'${(typeArgIdx + 1).ordinal} type argument for mocked $typeName. Are '
@@ -2387,3 +2387,13 @@
ast.Annotation get annotationAst =>
(this as ElementAnnotationImpl).annotationAst;
}
+
+extension NamedTypeExtension on ast.NamedType {
+ String get qualifiedName {
+ final importPrefix = this.importPrefix;
+ if (importPrefix != null) {
+ return '${importPrefix.name.lexeme}.${name2.lexeme}';
+ }
+ return name2.lexeme;
+ }
+}