Skip to content

Commit

Permalink
Require analyzer 5.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins committed Oct 26, 2022
1 parent 02ad6c7 commit 094d07c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 45 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.3.3-dev

Require analyzer 5.2.0.

## 5.3.2

* Support analyzer 5.0.0.
Expand Down
84 changes: 42 additions & 42 deletions lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bar>`, add the `Bar`.
type.typeArguments
.whereType<analyzer.InterfaceType>()
Expand Down Expand Up @@ -294,14 +294,14 @@ class _TypeVisitor extends RecursiveElementVisitor<void> {
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
Expand All @@ -310,7 +310,7 @@ class _TypeVisitor extends RecursiveElementVisitor<void> {
for (final parameter in toStringMethod.parameters) {
final parameterType = parameter.type;
if (parameterType is analyzer.InterfaceType) {
parameterType.element2.accept(this);
parameterType.element.accept(this);
}
}
}
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -578,7 +578,7 @@ class _MockTargetGatherer {
});
}
final mockName = mockSpec.getField('mockName')!.toSymbolValue() ??
'Mock${type.element2.name}';
'Mock${type.element.name}';
final mixins = <analyzer.InterfaceType>[];
for (final m in mockSpec.getField('mixins')!.toListValue()!) {
final typeToMixin = m.toTypeValue();
Expand Down Expand Up @@ -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}');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.');
Expand All @@ -970,7 +970,7 @@ class _MockTargetGatherer {
var errorMessages = <String>[];
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');
Expand All @@ -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 {
Expand Down Expand Up @@ -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));
}));
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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?
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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}'; "
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
);
}
}
Expand Down Expand Up @@ -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';
Expand All @@ -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 ||
Expand All @@ -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' ||
Expand Down
2 changes: 1 addition & 1 deletion lib/src/version.dart
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const packageVersion = '5.3.2';
const packageVersion = '5.3.3-dev';
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 094d07c

Please sign in to comment.