|
5 | 5 | import 'package:analyzer/dart/analysis/features.dart'; |
6 | 6 | import 'package:analyzer/dart/ast/token.dart'; |
7 | 7 | import 'package:analyzer/dart/constant/value.dart'; |
8 | | -import 'package:analyzer/dart/element/element.dart'; |
9 | 8 | import 'package:analyzer/dart/element/element2.dart'; |
10 | 9 | import 'package:analyzer/dart/element/type.dart'; |
11 | 10 | import 'package:analyzer/file_system/physical_file_system.dart'; |
12 | 11 | import 'package:analyzer/src/dart/ast/ast.dart'; // ignore: implementation_imports |
13 | | -import 'package:analyzer/src/dart/element/member.dart'; // ignore: implementation_imports |
14 | 12 | import 'package:analyzer/src/dart/element/type.dart' // ignore: implementation_imports |
15 | 13 | show |
16 | 14 | InvalidTypeImpl; |
@@ -236,12 +234,6 @@ extension ClassElement2Extension on ClassElement2 { |
236 | 234 | bool isEnumLikeClass() => asEnumLikeClass() != null; |
237 | 235 | } |
238 | 236 |
|
239 | | -// TODO(pq): remove when internal migration is complete. |
240 | | -extension ClassElementExtension on ClassElement { |
241 | | - /// Get all constructors, including merged augmentations. |
242 | | - List<ConstructorElement> get allConstructors => augmented.constructors; |
243 | | -} |
244 | | - |
245 | 237 | extension ClassMemberListExtension on List<ClassMember> { |
246 | 238 | MethodDeclaration? getMethod(String name) => whereType<MethodDeclaration>() |
247 | 239 | .firstWhereOrNull((node) => node.name.lexeme == name); |
@@ -317,28 +309,6 @@ extension DartTypeExtension on DartType? { |
317 | 309 | _extendsClass(type.superclass, seenElements, className, library)); |
318 | 310 | } |
319 | 311 |
|
320 | | -extension ElementExtension on Element { |
321 | | - Element get canonicalElement { |
322 | | - var self = this; |
323 | | - if (self is PropertyAccessorElement) { |
324 | | - var variable = self.variable2; |
325 | | - if (variable is FieldMember) { |
326 | | - // A field element defined in a parameterized type where the values of |
327 | | - // the type parameters are known. |
328 | | - // |
329 | | - // This concept should be invisible when comparing FieldElements, but a |
330 | | - // bug in the analyzer causes FieldElements to not evaluate as |
331 | | - // equivalent to equivalent FieldMembers. See |
332 | | - // https://github.com/dart-lang/sdk/issues/35343. |
333 | | - return variable.declaration; |
334 | | - } else if (variable != null) { |
335 | | - return variable; |
336 | | - } |
337 | | - } |
338 | | - return self; |
339 | | - } |
340 | | -} |
341 | | - |
342 | 312 | extension ElementExtension2 on Element2? { |
343 | 313 | Element2? get canonicalElement2 => switch (this) { |
344 | 314 | PropertyAccessorElement2(:var variable3?) => variable3, |
@@ -569,42 +539,46 @@ extension LinterContextExtension on LinterContext { |
569 | 539 | } |
570 | 540 |
|
571 | 541 | extension MethodDeclarationExtension on MethodDeclaration { |
572 | | - bool get hasInheritedMethod => lookUpInheritedMethod() != null; |
573 | | - |
574 | 542 | /// Returns whether this method is an override of a method in any supertype. |
575 | 543 | bool get isOverride { |
576 | | - var name = declaredElement?.name; |
577 | | - if (name == null) { |
578 | | - return false; |
579 | | - } |
580 | | - var parentElement = declaredElement?.enclosingElement3; |
581 | | - if (parentElement is! InterfaceElement) { |
582 | | - return false; |
583 | | - } |
584 | | - var parentLibrary = parentElement.library; |
| 544 | + var element = declaredFragment?.element; |
| 545 | + |
| 546 | + var name = element?.name3; |
| 547 | + if (name == null) return false; |
| 548 | + |
| 549 | + var parentElement = element?.enclosingElement2; |
| 550 | + if (parentElement is! InterfaceElement2) return false; |
| 551 | + |
| 552 | + var parentLibrary = parentElement.library2; |
585 | 553 |
|
586 | 554 | if (isGetter) { |
587 | 555 | // Search supertypes for a getter of the same name. |
588 | 556 | return parentElement.allSupertypes |
589 | | - .any((t) => t.lookUpGetter2(name, parentLibrary) != null); |
| 557 | + .any((t) => t.lookUpGetter3(name, parentLibrary) != null); |
590 | 558 | } else if (isSetter) { |
591 | 559 | // Search supertypes for a setter of the same name. |
592 | 560 | return parentElement.allSupertypes |
593 | | - .any((t) => t.lookUpSetter2(name, parentLibrary) != null); |
| 561 | + .any((t) => t.lookUpSetter3(name, parentLibrary) != null); |
594 | 562 | } else { |
595 | 563 | // Search supertypes for a method of the same name. |
596 | 564 | return parentElement.allSupertypes |
597 | | - .any((t) => t.lookUpMethod2(name, parentLibrary) != null); |
| 565 | + .any((t) => t.lookUpMethod3(name, parentLibrary) != null); |
598 | 566 | } |
599 | 567 | } |
600 | 568 |
|
601 | | - MethodElement? lookUpInheritedMethod() { |
602 | | - var declaredElement = this.declaredElement; |
| 569 | + bool hasInheritedMethod(InheritanceManager3 inheritanceManager) => |
| 570 | + lookUpInheritedMethod(inheritanceManager) != null; |
| 571 | + |
| 572 | + MethodElement2? lookUpInheritedMethod( |
| 573 | + InheritanceManager3 inheritanceManager) { |
| 574 | + var declaredElement = declaredFragment?.element; |
603 | 575 | if (declaredElement != null) { |
604 | | - var parent = declaredElement.enclosingElement3; |
605 | | - if (parent is InterfaceElement) { |
606 | | - return parent.lookUpInheritedMethod( |
607 | | - name.lexeme, declaredElement.library); |
| 576 | + var parent = declaredElement.enclosingElement2; |
| 577 | + if (parent is InterfaceElement2) { |
| 578 | + var methodName = Name.forElement(declaredElement); |
| 579 | + if (methodName == null) return null; |
| 580 | + var inherited = inheritanceManager.getInherited4(parent, methodName); |
| 581 | + if (inherited is MethodElement2) return inherited; |
608 | 582 | } |
609 | 583 | } |
610 | 584 | return null; |
|
0 commit comments