Skip to content

Commit

Permalink
analyzer 5.2.0 (#3788)
Browse files Browse the repository at this point in the history
  • Loading branch information
pq authored Oct 26, 2022
1 parent aae094d commit 22cc957
Show file tree
Hide file tree
Showing 47 changed files with 107 additions and 107 deletions.
4 changes: 2 additions & 2 deletions lib/src/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ bool _checkForSimpleGetter(MethodDeclaration getter, Expression? expression) {
if (expression is SimpleIdentifier) {
var staticElement = expression.staticElement;
if (staticElement is PropertyAccessorElement) {
var enclosingElement = getter.declaredElement?.enclosingElement3;
var enclosingElement = getter.declaredElement?.enclosingElement;
// Skipping library level getters, test that the enclosing element is
// the same
if (staticElement.enclosingElement3 == enclosingElement) {
if (staticElement.enclosingElement == enclosingElement) {
return staticElement.isSynthetic && staticElement.variable.isPrivate;
}
}
Expand Down
28 changes: 14 additions & 14 deletions lib/src/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ extension ConstructorElementExtension on ConstructorElement {
required String constructorName,
}) =>
library.name == uri &&
enclosingElement3.name == className &&
enclosingElement.name == className &&
name == constructorName;
}

Expand All @@ -188,8 +188,8 @@ extension DartTypeExtension on DartType? {
var self = this;
if (self is InterfaceType) {
return isAnyInterface(self) ||
!self.element2.isSynthetic &&
self.element2.allSupertypes.any(isAnyInterface);
!self.element.isSynthetic &&
self.element.allSupertypes.any(isAnyInterface);
} else {
return false;
}
Expand All @@ -201,7 +201,7 @@ extension DartTypeExtension on DartType? {
return false;
}
bool predicate(InterfaceType i) => i.isSameAs(interface, library);
var element = self.element2;
var element = self.element;
return predicate(self) ||
!element.isSynthetic && element.allSupertypes.any(predicate);
}
Expand All @@ -211,8 +211,8 @@ extension DartTypeExtension on DartType? {
bool isSameAs(String? interface, String? library) {
var self = this;
return self is InterfaceType &&
self.element2.name == interface &&
self.element2.library.name == library;
self.element.name == interface &&
self.element.library.name == library;
}

static bool _extendsClass(
Expand All @@ -221,7 +221,7 @@ extension DartTypeExtension on DartType? {
String? className,
String? library) =>
type != null &&
seenElements.add(type.element2) &&
seenElements.add(type.element) &&
(type.isSameAs(className, library) ||
_extendsClass(type.superclass, seenElements, className, library));
}
Expand Down Expand Up @@ -268,7 +268,7 @@ extension InterfaceTypeExtension on InterfaceType {
InterfaceType? type,
Set<InterfaceElement> alreadyVisited,
List<InterfaceType> interfaceTypes) {
if (type == null || !alreadyVisited.add(type.element2)) {
if (type == null || !alreadyVisited.add(type.element)) {
return;
}
interfaceTypes.add(type);
Expand Down Expand Up @@ -296,7 +296,7 @@ extension MethodDeclarationExtension on MethodDeclaration {
if (name == null) {
return false;
}
var parentElement = declaredElement?.enclosingElement3;
var parentElement = declaredElement?.enclosingElement;
if (parentElement is! InterfaceElement) {
return false;
}
Expand All @@ -322,7 +322,7 @@ extension MethodDeclarationExtension on MethodDeclaration {
if (declaredElement == null) {
return null;
}
var parent = declaredElement.enclosingElement3;
var parent = declaredElement.enclosingElement;
if (parent is InterfaceElement) {
return parent.lookUpGetter(name.lexeme, declaredElement.library);
}
Expand All @@ -337,7 +337,7 @@ extension MethodDeclarationExtension on MethodDeclaration {
if (declaredElement == null) {
return null;
}
var parent = declaredElement.enclosingElement3;
var parent = declaredElement.enclosingElement;
if (parent is InterfaceElement) {
return parent.lookUpInheritedConcreteGetter(
name.lexeme, declaredElement.library);
Expand All @@ -349,7 +349,7 @@ extension MethodDeclarationExtension on MethodDeclaration {
MethodElement? lookUpInheritedConcreteMethod() {
var declaredElement = this.declaredElement;
if (declaredElement != null) {
var parent = declaredElement.enclosingElement3;
var parent = declaredElement.enclosingElement;
if (parent is InterfaceElement) {
return parent.lookUpInheritedConcreteMethod(
name.lexeme, declaredElement.library);
Expand All @@ -362,7 +362,7 @@ extension MethodDeclarationExtension on MethodDeclaration {
PropertyAccessorElement? lookUpInheritedConcreteSetter() {
var declaredElement = this.declaredElement;
if (declaredElement != null) {
var parent = declaredElement.enclosingElement3;
var parent = declaredElement.enclosingElement;
if (parent is InterfaceElement) {
return parent.lookUpInheritedConcreteSetter(
name.lexeme, declaredElement.library);
Expand All @@ -375,7 +375,7 @@ extension MethodDeclarationExtension on MethodDeclaration {
MethodElement? lookUpInheritedMethod() {
var declaredElement = this.declaredElement;
if (declaredElement != null) {
var parent = declaredElement.enclosingElement3;
var parent = declaredElement.enclosingElement;
if (parent is InterfaceElement) {
return parent.lookUpInheritedMethod(
name.lexeme, declaredElement.library);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/rules/avoid_classes_with_only_static_members.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class _Visitor extends SimpleAstVisitor<void> {
var interface = context.inheritanceManager.getInterface(declaredElement);
var map = interface.map;
for (var member in map.values) {
var enclosingElement = member.enclosingElement3;
var enclosingElement = member.enclosingElement;
if (enclosingElement is ClassElement &&
!enclosingElement.isDartCoreObject) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class _Visitor extends SimpleAstVisitor<void> {

bool _hasImmutableAnnotation(ClassElement clazz) {
var inheritedAndSelfElements = <InterfaceElement>[
...clazz.allSupertypes.map((t) => t.element2),
...clazz.allSupertypes.map((t) => t.element),
clazz,
];
var inheritedAndSelfAnnotations = inheritedAndSelfElements
Expand Down
4 changes: 2 additions & 2 deletions lib/src/rules/avoid_implementing_value_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ class _Visitor extends SimpleAstVisitor<void> {
for (var interface in implementsClause.interfaces) {
var interfaceType = interface.type;
if (interfaceType is InterfaceType &&
_overridesEquals(interfaceType.element2)) {
_overridesEquals(interfaceType.element)) {
rule.reportLint(interface);
}
}
}

static bool _overridesEquals(InterfaceElement element) {
var method = element.lookUpConcreteMethod('==', element.library);
var enclosing = method?.enclosingElement3;
var enclosing = method?.enclosingElement;
return enclosing is ClassElement && !enclosing.isDartCoreObject;
}
}
2 changes: 1 addition & 1 deletion lib/src/rules/avoid_returning_this.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class _Visitor extends SimpleAstVisitor<void> {
var returnType = node.declaredElement?.returnType;
if (returnType is InterfaceType &&
// ignore: cast_nullable_to_non_nullable
returnType.element2 == (parent as Declaration).declaredElement) {
returnType.element == (parent as Declaration).declaredElement) {
} else {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/rules/avoid_type_to_string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class _Visitor extends SimpleAstVisitor {
typeSystem.isSubtypeOf(targetType, typeType);

bool _isSimpleIdDeclByCoreObj(SimpleIdentifier simpleIdentifier) {
var encloser = simpleIdentifier.staticElement?.enclosingElement3;
var encloser = simpleIdentifier.staticElement?.enclosingElement;
return encloser is ClassElement && encloser.isDartCoreObject;
}
}
2 changes: 1 addition & 1 deletion lib/src/rules/avoid_types_as_parameter_names.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class _Visitor extends SimpleAstVisitor<void> {

@override
void visitCatchClause(CatchClause node) {
var parameter = node.exceptionParameter2;
var parameter = node.exceptionParameter;
if (parameter != null && _isTypeName(node, parameter.name)) {
rule.reportLint(parameter, arguments: [parameter.name.lexeme]);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/rules/deprecated_consistency.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class _Visitor extends SimpleAstVisitor<void> {
void visitConstructorDeclaration(ConstructorDeclaration node) {
var constructorElement = node.declaredElement;
if (constructorElement != null &&
constructorElement.enclosingElement3.hasDeprecated &&
constructorElement.enclosingElement.hasDeprecated &&
!constructorElement.hasDeprecated) {
rule.reportLint(node);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/rules/empty_catches.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class _Visitor extends SimpleAstVisitor<void> {
@override
void visitCatchClause(CatchClause node) {
// Skip exceptions named with underscores.
var exceptionParameter = node.exceptionParameter2;
var exceptionParameter = node.exceptionParameter;
if (exceptionParameter != null &&
exceptionParameter.name.lexeme.isJustUnderscores) {
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/rules/exhaustive_cases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class _Visitor extends SimpleAstVisitor {
void visitSwitchStatement(SwitchStatement statement) {
var expressionType = statement.expression.staticType;
if (expressionType is InterfaceType) {
var interfaceElement = expressionType.element2;
var interfaceElement = expressionType.element;
// Handled in analyzer.
if (interfaceElement is! ClassElement) {
return;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/rules/implementation_imports.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class _Visitor extends SimpleAstVisitor<void> {

@override
void visitImportDirective(ImportDirective node) {
var importUri = node.element2?.importedLibrary?.source.uri;
var sourceUri = node.element2?.source.uri;
var importUri = node.element?.importedLibrary?.source.uri;
var sourceUri = node.element?.source.uri;

// Test for 'package:*/src/'.
if (!isImplementation(importUri)) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/rules/library_private_types_in_public_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Validator extends SimpleAstVisitor<void> {
var element = node.declaredElement;
if (element is FieldFormalParameterElement) {
var type = element.type;
if (type is InterfaceType && isPrivateName(type.element2.name)) {
if (type is InterfaceType && isPrivateName(type.element.name)) {
rule.reportLintForToken(node.name);
}
}
Expand Down Expand Up @@ -258,7 +258,7 @@ class Validator extends SimpleAstVisitor<void> {
var element = node.declaredElement;
if (element is SuperFormalParameterElement) {
var type = element.type;
if (type is InterfaceType && isPrivateName(type.element2.name)) {
if (type is InterfaceType && isPrivateName(type.element.name)) {
rule.reportLintForToken(node.name);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class _Visitor extends SimpleAstVisitor<void> {
static bool _isRegExpInstanceCreation(AstNode? node) {
if (node is InstanceCreationExpression) {
var constructorElement = node.constructorName.staticElement;
return constructorElement?.enclosingElement3.name == 'RegExp';
return constructorElement?.enclosingElement.name == 'RegExp';
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/rules/no_default_cases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class _Visitor extends SimpleAstVisitor {
if (expressionType is InterfaceType) {
for (var member in statement.members) {
if (member is SwitchDefault) {
var interfaceElement = expressionType.element2;
var interfaceElement = expressionType.element;
if (interfaceElement is EnumElement ||
interfaceElement is ClassElement &&
interfaceElement.isEnumLikeClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class _Visitor extends SimpleAstVisitor<void> {

@override
void visitCatchClause(CatchClause node) {
checkIdentifier(node.exceptionParameter2?.name);
checkIdentifier(node.stackTraceParameter2?.name);
checkIdentifier(node.exceptionParameter?.name);
checkIdentifier(node.stackTraceParameter?.name);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/src/rules/no_runtimeType_toString.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class _Visitor extends SimpleAstVisitor<void> {
if (declaredElement != null) {
var extendedType = declaredElement.extendedType;
if (extendedType is InterfaceType) {
var extendedElement = extendedType.element2;
var extendedElement = extendedType.element;
return !(extendedElement is ClassElement &&
!extendedElement.isAbstract);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/rules/non_constant_identifier_names.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class _Visitor extends SimpleAstVisitor<void> {

@override
void visitCatchClause(CatchClause node) {
checkIdentifier(node.exceptionParameter2?.name, underscoresOk: true);
checkIdentifier(node.exceptionParameter?.name, underscoresOk: true);
}

@override
Expand Down
4 changes: 2 additions & 2 deletions lib/src/rules/null_closures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class _Visitor extends SimpleAstVisitor<void> {
possibleMethods
.lookup(NonNullableFunction(library, className, methodName));

var element = type.element2;
var element = type.element;
if (element.isSynthetic) {
return null;
}
Expand All @@ -318,7 +318,7 @@ class _Visitor extends SimpleAstVisitor<void> {
}

for (var supertype in element.allSupertypes) {
var superElement = supertype.element2;
var superElement = supertype.element;
method = getMethod(superElement.library.name, superElement.name);
if (method != null) {
return method;
Expand Down
6 changes: 3 additions & 3 deletions lib/src/rules/overridden_fields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Iterable<InterfaceType> _findAllSupertypesAndMixins(
interfaces.add(superclass);
}
interfaces
..addAll(interface.element2.mixins)
..addAll(interface.element.mixins)
..addAll(_findAllSupertypesAndMixins(superclass, accumulator));
return interfaces.where((i) => i != interface);
}
Expand Down Expand Up @@ -138,7 +138,7 @@ class _Visitor extends SimpleAstVisitor<void> {
var overriddenField = _getOverriddenMember(declaredField);
if (overriddenField != null && !overriddenField.isAbstract) {
rule.reportLintForToken(variable.name,
arguments: [overriddenField.enclosingElement3.displayName]);
arguments: [overriddenField.enclosingElement.displayName]);
}
}
}
Expand All @@ -163,7 +163,7 @@ class _Visitor extends SimpleAstVisitor<void> {

bool containsOverriddenMember(InterfaceType i) =>
i.accessors.any(isOverriddenMember);
var enclosingElement = member.enclosingElement3;
var enclosingElement = member.enclosingElement;
if (enclosingElement is! InterfaceElement) {
return null;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/rules/prefer_asserts_in_initializer_lists.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ class _AssertVisitor extends RecursiveAstVisitor {

bool _hasAccessor(PropertyAccessorElement element) {
var classes = classAndSuperClasses?.classes;
return classes != null && classes.contains(element.enclosingElement3);
return classes != null && classes.contains(element.enclosingElement);
}

bool _hasMethod(MethodElement element) {
var classes = classAndSuperClasses?.classes;
return classes != null && classes.contains(element.enclosingElement3);
return classes != null && classes.contains(element.enclosingElement);
}

bool _paramMatchesField(
Expand Down Expand Up @@ -118,9 +118,9 @@ class _ClassAndSuperClasses {
void addRecursively(InterfaceElement? element) {
if (element != null && _classes.add(element)) {
for (var t in element.mixins) {
addRecursively(t.element2);
addRecursively(t.element);
}
addRecursively(element.supertype?.element2);
addRecursively(element.supertype?.element);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/rules/prefer_const_constructors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class _Visitor extends SimpleAstVisitor<void> {
// Handled by analyzer hint.
if (element.hasLiteral) return;

var enclosingElement = element.enclosingElement3;
var enclosingElement = element.enclosingElement;
if (enclosingElement is ClassElement &&
enclosingElement.isDartCoreObject) {
// Skip lint for `new Object()`, because it can be used for Id creation.
Expand Down
Loading

0 comments on commit 22cc957

Please sign in to comment.