@@ -250,6 +250,12 @@ class _TypeVisitor extends RecursiveElementVisitor<void> {
250
250
super .visitClassElement (element);
251
251
}
252
252
253
+ @override
254
+ void visitEnumElement (EnumElement element) {
255
+ _elements.add (element);
256
+ super .visitEnumElement (element);
257
+ }
258
+
253
259
@override
254
260
void visitFieldElement (FieldElement element) {
255
261
_addType (element.type);
@@ -262,6 +268,12 @@ class _TypeVisitor extends RecursiveElementVisitor<void> {
262
268
super .visitMethodElement (element);
263
269
}
264
270
271
+ @override
272
+ void visitMixinElement (MixinElement element) {
273
+ _elements.add (element);
274
+ super .visitMixinElement (element);
275
+ }
276
+
265
277
@override
266
278
void visitParameterElement (ParameterElement element) {
267
279
_addType (element.type);
@@ -391,7 +403,7 @@ class _MockTarget {
391
403
this .hasExplicitTypeArguments = false ,
392
404
});
393
405
394
- InterfaceElement get classElement => classType.element2;
406
+ InterfaceElement get interfaceElement => classType.element2;
395
407
}
396
408
397
409
/// This class gathers and verifies mock targets referenced in `GenerateMocks`
@@ -491,7 +503,7 @@ class _MockTargetGatherer {
491
503
// `type` have been instantiated to bounds here. Switch to the
492
504
// declaration, which will be an uninstantiated type.
493
505
final declarationType =
494
- (type.element2.declaration as ClassElement ).thisType;
506
+ (type.element2.declaration as InterfaceElement ).thisType;
495
507
final mockName = 'Mock${declarationType .element2 .name }' ;
496
508
mockTargets.add (_MockTarget (
497
509
declarationType,
@@ -545,7 +557,7 @@ class _MockTargetGatherer {
545
557
// this case the type argument(s) on `type` have been instantiated to
546
558
// bounds. Switch to the declaration, which will be an uninstantiated
547
559
// type.
548
- type = (type.element2.declaration as ClassElement ).thisType;
560
+ type = (type.element2.declaration as InterfaceElement ).thisType;
549
561
} else {
550
562
// Check explicit type arguments for unknown types that were
551
563
// turned into `dynamic` by the analyzer.
@@ -731,21 +743,21 @@ class _MockTargetGatherer {
731
743
732
744
void _checkClassesToMockAreValid () {
733
745
final classesInEntryLib =
734
- _entryLib.topLevelElements.whereType <ClassElement >();
746
+ _entryLib.topLevelElements.whereType <InterfaceElement >();
735
747
final classNamesToMock = < String , _MockTarget > {};
736
748
final uniqueNameSuggestion =
737
749
"use the 'customMocks' argument in @GenerateMocks to specify a unique "
738
750
'name' ;
739
751
for (final mockTarget in _mockTargets) {
740
752
final name = mockTarget.mockName;
741
753
if (classNamesToMock.containsKey (name)) {
742
- final firstClass = classNamesToMock[name]! .classElement ;
754
+ final firstClass = classNamesToMock[name]! .interfaceElement ;
743
755
final firstSource = firstClass.source.fullName;
744
- final secondSource = mockTarget.classElement .source.fullName;
756
+ final secondSource = mockTarget.interfaceElement .source.fullName;
745
757
throw InvalidMockitoAnnotationException (
746
758
'Mockito cannot generate two mocks with the same name: $name (for '
747
759
'${firstClass .name } declared in $firstSource , and for '
748
- '${mockTarget .classElement .name } declared in $secondSource ); '
760
+ '${mockTarget .interfaceElement .name } declared in $secondSource ); '
749
761
'$uniqueNameSuggestion .' );
750
762
}
751
763
classNamesToMock[name] = mockTarget;
@@ -764,7 +776,7 @@ class _MockTargetGatherer {
764
776
var preexistingMock = classesInEntryLib.firstWhereOrNull ((c) =>
765
777
c.interfaces
766
778
.map ((type) => type.element2)
767
- .contains (mockTarget.classElement ) &&
779
+ .contains (mockTarget.interfaceElement ) &&
768
780
_isMockClass (c.supertype! ));
769
781
if (preexistingMock != null ) {
770
782
throw InvalidMockitoAnnotationException (
@@ -787,11 +799,11 @@ class _MockTargetGatherer {
787
799
/// and no corresponding dummy generator. Mockito cannot generate its own
788
800
/// dummy return values for unknown types.
789
801
void _checkMethodsToStubAreValid (_MockTarget mockTarget) {
790
- final classElement = mockTarget.classElement ;
791
- final className = classElement .name;
802
+ final interfaceElement = mockTarget.interfaceElement ;
803
+ final className = interfaceElement .name;
792
804
final substitution = Substitution .fromInterfaceType (mockTarget.classType);
793
805
final relevantMembers = _inheritanceManager
794
- .getInterface (classElement )
806
+ .getInterface (interfaceElement )
795
807
.map
796
808
.values
797
809
.where ((m) => ! m.isPrivate && ! m.isStatic)
@@ -968,9 +980,9 @@ class _MockLibraryInfo {
968
980
/// values.
969
981
final fakeClasses = < Class > [];
970
982
971
- /// [ClassElement ] s which are used in non-nullable return types, for which
983
+ /// [InterfaceElement ] s which are used in non-nullable return types, for which
972
984
/// fake classes are added to the generated library.
973
- final fakedClassElements = < InterfaceElement > [];
985
+ final fakedInterfaceElements = < InterfaceElement > [];
974
986
975
987
/// A mapping of each necessary [Element] to a URI from which it can be
976
988
/// imported.
@@ -1051,7 +1063,7 @@ class _MockClassInfo {
1051
1063
1052
1064
Class _buildMockClass () {
1053
1065
final typeToMock = mockTarget.classType;
1054
- final classToMock = mockTarget.classElement ;
1066
+ final classToMock = mockTarget.interfaceElement ;
1055
1067
final classIsImmutable = classToMock.metadata.any ((it) => it.isImmutable);
1056
1068
final className = classToMock.name;
1057
1069
@@ -1101,7 +1113,7 @@ class _MockClassInfo {
1101
1113
cBuilder.implements .add (TypeReference ((b) {
1102
1114
b
1103
1115
..symbol = classToMock.name
1104
- ..url = _typeImport (mockTarget.classElement )
1116
+ ..url = _typeImport (mockTarget.interfaceElement )
1105
1117
..types.addAll (typeArguments);
1106
1118
}));
1107
1119
if (mockTarget.onMissingStub == OnMissingStub .throwException) {
@@ -1471,7 +1483,7 @@ class _MockClassInfo {
1471
1483
} else {
1472
1484
final fakeName = mockLibraryInfo._fakeNameFor (elementToFake);
1473
1485
// Only make one fake class for each class that needs to be faked.
1474
- if (! mockLibraryInfo.fakedClassElements .contains (elementToFake)) {
1486
+ if (! mockLibraryInfo.fakedInterfaceElements .contains (elementToFake)) {
1475
1487
_addFakeClass (fakeName, elementToFake);
1476
1488
}
1477
1489
final typeArguments = dartType.typeArguments;
@@ -1524,7 +1536,7 @@ class _MockClassInfo {
1524
1536
(mBuilder) => _buildOverridingMethod (mBuilder, toStringMethod)));
1525
1537
}
1526
1538
}));
1527
- mockLibraryInfo.fakedClassElements .add (elementToFake);
1539
+ mockLibraryInfo.fakedInterfaceElements .add (elementToFake);
1528
1540
}
1529
1541
1530
1542
/// Returns a [Parameter] which matches [parameter] .
@@ -1559,7 +1571,7 @@ class _MockClassInfo {
1559
1571
final method = parameter.enclosingElement3! ;
1560
1572
throw InvalidMockitoAnnotationException (
1561
1573
'Mockito cannot generate a valid override for method '
1562
- "'${mockTarget .classElement .displayName }.${method .displayName }'; "
1574
+ "'${mockTarget .interfaceElement .displayName }.${method .displayName }'; "
1563
1575
"parameter '${parameter .displayName }' causes a problem: "
1564
1576
'${e .message }' );
1565
1577
}
@@ -1588,7 +1600,7 @@ class _MockClassInfo {
1588
1600
return type;
1589
1601
}
1590
1602
final method = parameter.enclosingElement3 as MethodElement ;
1591
- final class_ = method.enclosingElement3 as ClassElement ;
1603
+ final class_ = method.enclosingElement3 as InterfaceElement ;
1592
1604
final name = Name (method.librarySource.uri, method.name);
1593
1605
final overriddenMethods = inheritanceManager.getOverridden2 (class_, name);
1594
1606
if (overriddenMethods == null ) {
@@ -1598,7 +1610,7 @@ class _MockClassInfo {
1598
1610
while (allOverriddenMethods.isNotEmpty) {
1599
1611
final overriddenMethod = allOverriddenMethods.removeFirst ();
1600
1612
final secondaryOverrides = inheritanceManager.getOverridden2 (
1601
- overriddenMethod.enclosingElement3 as ClassElement , name);
1613
+ overriddenMethod.enclosingElement3 as InterfaceElement , name);
1602
1614
if (secondaryOverrides != null ) {
1603
1615
allOverriddenMethods.addAll (secondaryOverrides);
1604
1616
}
@@ -1996,9 +2008,13 @@ extension on Element {
1996
2008
String get fullName {
1997
2009
if (this is ClassElement ) {
1998
2010
return "The class '$name '" ;
2011
+ } else if (this is EnumElement ) {
2012
+ return "The enum '$name '" ;
1999
2013
} else if (this is MethodElement ) {
2000
2014
var className = enclosingElement3! .name;
2001
2015
return "The method '$className .$name '" ;
2016
+ } else if (this is MixinElement ) {
2017
+ return "The mixin '$name '" ;
2002
2018
} else if (this is PropertyAccessorElement ) {
2003
2019
var className = enclosingElement3! .name;
2004
2020
return "The property accessor '$className .$name '" ;
0 commit comments