diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fb41519..ba5ee6d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.3.3-dev + +Require analyzer 5.2.0. + ## 5.3.2 * Support analyzer 5.0.0. diff --git a/lib/src/builder.dart b/lib/src/builder.dart index 2935c434..dcfb6278 100644 --- a/lib/src/builder.dart +++ b/lib/src/builder.dart @@ -153,8 +153,8 @@ $rawOutput return; } seenTypes.add(type); - librariesWithTypes.add(type.element2.library); - type.element2.accept(typeVisitor); + librariesWithTypes.add(type.element.library); + type.element.accept(typeVisitor); // For a type like `Foo`, add the `Bar`. type.typeArguments .whereType() @@ -294,14 +294,14 @@ class _TypeVisitor extends RecursiveElementVisitor { if (type == null) return; if (type is analyzer.InterfaceType) { - final alreadyVisitedElement = _elements.contains(type.element2); - _elements.add(type.element2); + final alreadyVisitedElement = _elements.contains(type.element); + _elements.add(type.element); type.typeArguments.forEach(_addType); if (!alreadyVisitedElement) { - type.element2.typeParameters.forEach(visitTypeParameterElement); + type.element.typeParameters.forEach(visitTypeParameterElement); final toStringMethod = - type.element2.lookUpMethod('toString', type.element2.library); + type.element.lookUpMethod('toString', type.element.library); if (toStringMethod != null && toStringMethod.parameters.isNotEmpty) { // In a Fake class which implements a class which overrides `toString` // with additional (optional) parameters, we must also override @@ -310,7 +310,7 @@ class _TypeVisitor extends RecursiveElementVisitor { for (final parameter in toStringMethod.parameters) { final parameterType = parameter.type; if (parameterType is analyzer.InterfaceType) { - parameterType.element2.accept(this); + parameterType.element.accept(this); } } } @@ -403,7 +403,7 @@ class _MockTarget { this.hasExplicitTypeArguments = false, }); - InterfaceElement get interfaceElement => classType.element2; + InterfaceElement get interfaceElement => classType.element; } /// This class gathers and verifies mock targets referenced in `GenerateMocks` @@ -440,7 +440,7 @@ class _MockTargetGatherer { // annotations, on one element or even on different elements in a library. for (final annotation in element.metadata) { if (annotation.element is! ConstructorElement) continue; - final annotationClass = annotation.element!.enclosingElement3!.name; + final annotationClass = annotation.element!.enclosingElement!.name; switch (annotationClass) { case 'GenerateMocks': mockTargets @@ -503,8 +503,8 @@ class _MockTargetGatherer { // `type` have been instantiated to bounds here. Switch to the // declaration, which will be an uninstantiated type. final declarationType = - (type.element2.declaration as InterfaceElement).thisType; - final mockName = 'Mock${declarationType.element2.name}'; + (type.element.declaration as InterfaceElement).thisType; + final mockName = 'Mock${declarationType.element.name}'; mockTargets.add(_MockTarget( declarationType, mockName, @@ -557,7 +557,7 @@ class _MockTargetGatherer { // this case the type argument(s) on `type` have been instantiated to // bounds. Switch to the declaration, which will be an uninstantiated // type. - type = (type.element2.declaration as InterfaceElement).thisType; + type = (type.element.declaration as InterfaceElement).thisType; } else { // Check explicit type arguments for unknown types that were // turned into `dynamic` by the analyzer. @@ -578,7 +578,7 @@ class _MockTargetGatherer { }); } final mockName = mockSpec.getField('mockName')!.toSymbolValue() ?? - 'Mock${type.element2.name}'; + 'Mock${type.element.name}'; final mixins = []; for (final m in mockSpec.getField('mixins')!.toListValue()!) { final typeToMixin = m.toTypeValue(); @@ -702,7 +702,7 @@ class _MockTargetGatherer { static analyzer.InterfaceType _determineDartType( analyzer.DartType typeToMock, TypeProvider typeProvider) { if (typeToMock is analyzer.InterfaceType) { - final elementToMock = typeToMock.element2; + final elementToMock = typeToMock.element; if (elementToMock is EnumElement) { throw InvalidMockitoAnnotationException( 'Mockito cannot mock an enum: ${elementToMock.displayName}'); @@ -775,7 +775,7 @@ class _MockTargetGatherer { var preexistingMock = classesInEntryLib.firstWhereOrNull((c) => c.interfaces - .map((type) => type.element2) + .map((type) => type.element) .contains(mockTarget.interfaceElement) && _isMockClass(c.supertype!)); if (preexistingMock != null) { @@ -899,7 +899,7 @@ class _MockTargetGatherer { for (var parameter in function.parameters) { var parameterType = parameter.type; if (parameterType is analyzer.InterfaceType) { - var parameterTypeElement = parameterType.element2; + var parameterTypeElement = parameterType.element; if (parameterTypeElement.isPrivate) { // Technically, we can expand the type in the mock to something like // `Object?`. However, until there is a decent use case, we will not @@ -946,7 +946,7 @@ class _MockTargetGatherer { if (typeParameter is analyzer.InterfaceType) { // TODO(srawlins): Check for private names in bound; could be // `List<_Bar>`. - if (typeParameter.element2.isPrivate) { + if (typeParameter.element.isPrivate) { errorMessages.add( '${enclosingElement.fullName} features a private type parameter ' 'bound, and cannot be stubbed.'); @@ -970,7 +970,7 @@ class _MockTargetGatherer { var errorMessages = []; for (var typeArgument in typeArguments) { if (typeArgument is analyzer.InterfaceType) { - if (typeArgument.element2.isPrivate && !allowUnsupportedMember) { + if (typeArgument.element.isPrivate && !allowUnsupportedMember) { errorMessages.add( '${enclosingElement.fullName} features a private type argument, ' 'and cannot be stubbed. $_tryUnsupportedMembersMessage'); @@ -989,8 +989,8 @@ class _MockTargetGatherer { /// Return whether [type] is the Mock class declared by mockito. bool _isMockClass(analyzer.InterfaceType type) => - type.element2.name == 'Mock' && - type.element2.source.fullName.endsWith('lib/src/mock.dart'); + type.element.name == 'Mock' && + type.element.source.fullName.endsWith('lib/src/mock.dart'); } class _MockLibraryInfo { @@ -1128,8 +1128,8 @@ class _MockClassInfo { for (final mixin in mockTarget.mixins) { cBuilder.mixins.add(TypeReference((b) { b - ..symbol = mixin.element2.name - ..url = _typeImport(mixin.element2) + ..symbol = mixin.element.name + ..url = _typeImport(mixin.element) ..types.addAll(mixin.typeArguments.map(_typeReference)); })); } @@ -1443,7 +1443,7 @@ class _MockClassInfo { assert(typeArguments.length == 1); final elementType = _typeReference(typeArguments[0]); return literalSet({}, elementType); - } else if (type.element2.declaration == typeProvider.streamElement) { + } else if (type.element.declaration == typeProvider.streamElement) { assert(typeArguments.length == 1); final elementType = _typeReference(typeArguments[0]); return TypeReference((b) { @@ -1458,7 +1458,7 @@ class _MockClassInfo { // These "List" types from dart:typed_data are "non-subtypeable", but they // have predicatble constructors; each has an unnamed constructor which // takes a single int argument. - return referImported(type.element2.name, 'dart:typed_data') + return referImported(type.element.name, 'dart:typed_data') .call([literalNum(0)]); // TODO(srawlins): Do other types from typed_data have a "non-subtypeable" // restriction as well? @@ -1518,7 +1518,7 @@ class _MockClassInfo { Expression _dummyValueImplementing( analyzer.InterfaceType dartType, Expression invocation) { - final elementToFake = dartType.element2; + final elementToFake = dartType.element; if (elementToFake is EnumElement) { return _typeReference(dartType).property( elementToFake.fields.firstWhere((f) => f.isEnumConstant).name); @@ -1612,7 +1612,7 @@ class _MockClassInfo { parameter.computeConstantValue()!, parameter) .code; } on _ReviveException catch (e) { - final method = parameter.enclosingElement3!; + final method = parameter.enclosingElement!; throw InvalidMockitoAnnotationException( 'Mockito cannot generate a valid override for method ' "'${mockTarget.interfaceElement.displayName}.${method.displayName}'; " @@ -1643,8 +1643,8 @@ class _MockClassInfo { if (!parameter.isCovariant) { return type; } - final method = parameter.enclosingElement3 as MethodElement; - final class_ = method.enclosingElement3 as InterfaceElement; + final method = parameter.enclosingElement as MethodElement; + final class_ = method.enclosingElement as InterfaceElement; final name = Name(method.librarySource.uri, method.name); final overriddenMethods = inheritanceManager.getOverridden2(class_, name); if (overriddenMethods == null) { @@ -1654,7 +1654,7 @@ class _MockClassInfo { while (allOverriddenMethods.isNotEmpty) { final overriddenMethod = allOverriddenMethods.removeFirst(); final secondaryOverrides = inheritanceManager.getOverridden2( - overriddenMethod.enclosingElement3 as InterfaceElement, name); + overriddenMethod.enclosingElement as InterfaceElement, name); if (secondaryOverrides != null) { allOverriddenMethods.addAll(secondaryOverrides); } @@ -1745,7 +1745,7 @@ class _MockClassInfo { // We can create this invocation by referring to a const field or // top-level variable. return referImported( - revivable.accessor, _typeImport(object.type!.element2)); + revivable.accessor, _typeImport(object.type!.element)); } final name = revivable.source.fragment; @@ -1757,9 +1757,9 @@ class _MockClassInfo { for (var pair in revivable.namedArguments.entries) pair.key: _expressionFromDartObject(pair.value) }; - final element = parameter != null && name != object.type!.element2!.name - ? parameter.type.element2 - : object.type!.element2; + final element = parameter != null && name != object.type!.element!.name + ? parameter.type.element + : object.type!.element; final type = referImported(name, _typeImport(element)); if (revivable.accessor.isNotEmpty) { return type.constInstanceNamed( @@ -1920,10 +1920,10 @@ class _MockClassInfo { if (type is analyzer.InterfaceType) { return TypeReference((b) { b - ..symbol = type.element2.name + ..symbol = type.element.name ..isNullable = forceNullable || type.nullabilitySuffix == NullabilitySuffix.question - ..url = _typeImport(type.element2) + ..url = _typeImport(type.element) ..types.addAll(type.typeArguments.map(_typeReference)); }); } else if (type is analyzer.FunctionType) { @@ -1964,13 +1964,13 @@ class _MockClassInfo { } else if (type is analyzer.TypeParameterType) { return TypeReference((b) { b - ..symbol = type.element2.name + ..symbol = type.element.name ..isNullable = forceNullable || typeSystem.isNullable(type); }); } else { return referImported( type.getDisplayString(withNullability: false), - _typeImport(type.element2), + _typeImport(type.element), ); } } @@ -2086,12 +2086,12 @@ extension on Element { } else if (this is EnumElement) { return "The enum '$name'"; } else if (this is MethodElement) { - var className = enclosingElement3!.name; + var className = enclosingElement!.name; return "The method '$className.$name'"; } else if (this is MixinElement) { return "The mixin '$name'"; } else if (this is PropertyAccessorElement) { - var className = enclosingElement3!.name; + var className = enclosingElement!.name; return "The property accessor '$className.$name'"; } else { return 'unknown element'; @@ -2107,7 +2107,7 @@ extension on analyzer.DartType { if (self is analyzer.DynamicType) { return false; } else if (self is analyzer.InterfaceType) { - return self.element2.isPrivate || + return self.element.isPrivate || self.typeArguments.any((t) => t.containsPrivateName); } else if (self is analyzer.FunctionType) { return self.returnType.containsPrivateName || @@ -2132,10 +2132,10 @@ extension on analyzer.DartType { /// Returns whether this type is a "List" type from the dart:typed_data /// library. bool get isDartTypedDataList { - if (element2!.library!.name != 'dart.typed_data') { + if (element!.library!.name != 'dart.typed_data') { return false; } - final name = element2!.name; + final name = element!.name; return name == 'Float32List' || name == 'Float64List' || name == 'Int8List' || diff --git a/lib/src/version.dart b/lib/src/version.dart index cc93276f..453ec3a4 100644 --- a/lib/src/version.dart +++ b/lib/src/version.dart @@ -1 +1 @@ -const packageVersion = '5.3.2'; +const packageVersion = '5.3.3-dev'; diff --git a/pubspec.yaml b/pubspec.yaml index df104683..c1b73c58 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: mockito -version: 5.3.2 +version: 5.3.3-dev description: >- A mock framework inspired by Mockito with APIs for Fakes, Mocks, behavior verification, and stubbing. @@ -9,7 +9,7 @@ environment: sdk: '>=2.17.0-0 <3.0.0' dependencies: - analyzer: '>=4.7.0 <6.0.0' + analyzer: '>=5.2.0 <6.0.0' build: '>=1.3.0 <3.0.0' code_builder: ^4.3.0 collection: ^1.15.0