Skip to content

Commit 6810733

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate override_verifier
Change-Id: Iecbdd76990da0dbb25a4263dea5d3ecac7be4d71 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/410442 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Phil Quitslund <[email protected]> Auto-Submit: Phil Quitslund <[email protected]>
1 parent 1511cbe commit 6810733

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@ class LibraryAnalyzer {
510510

511511
unit.accept(OverrideVerifier(
512512
_inheritance,
513-
_libraryElement,
514513
errorReporter,
515514
));
516515

pkg/analyzer/lib/src/error/override_verifier.dart

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: analyzer_use_new_elements
6-
75
import 'package:analyzer/dart/ast/ast.dart';
86
import 'package:analyzer/dart/ast/visitor.dart';
9-
import 'package:analyzer/dart/element/element.dart';
7+
import 'package:analyzer/dart/element/element2.dart';
108
import 'package:analyzer/error/listener.dart';
119
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
1210
import 'package:analyzer/src/error/codes.dart';
@@ -18,42 +16,37 @@ class OverrideVerifier extends RecursiveAstVisitor<void> {
1816
/// The inheritance manager used to find overridden methods.
1917
final InheritanceManager3 _inheritance;
2018

21-
/// The URI of the library being verified.
22-
final Uri _libraryUri;
23-
2419
/// The error reporter used to report errors.
2520
final ErrorReporter _errorReporter;
2621

2722
/// The current class or mixin.
28-
InterfaceElement? _currentClass;
23+
InterfaceElement2? _currentClass;
2924

30-
OverrideVerifier(
31-
this._inheritance, LibraryElement library, this._errorReporter)
32-
: _libraryUri = library.source.uri;
25+
OverrideVerifier(this._inheritance, this._errorReporter);
3326

3427
@override
3528
void visitClassDeclaration(ClassDeclaration node) {
36-
_currentClass = node.declaredElement;
29+
_currentClass = node.declaredFragment?.element;
3730
super.visitClassDeclaration(node);
3831
_currentClass = null;
3932
}
4033

4134
@override
4235
void visitEnumDeclaration(EnumDeclaration node) {
43-
_currentClass = node.declaredElement;
36+
_currentClass = node.declaredFragment?.element;
4437
super.visitEnumDeclaration(node);
4538
_currentClass = null;
4639
}
4740

4841
@override
4942
void visitFieldDeclaration(FieldDeclaration node) {
5043
for (VariableDeclaration field in node.fields.variables) {
51-
var fieldElement = field.declaredElement as FieldElement;
52-
if (fieldElement.hasOverride) {
53-
var getter = fieldElement.getter;
44+
var fieldElement = field.declaredFragment?.element as FieldElement2;
45+
if (fieldElement.metadata2.hasOverride) {
46+
var getter = fieldElement.getter2;
5447
if (getter != null && _isOverride(getter)) continue;
5548

56-
var setter = fieldElement.setter;
49+
var setter = fieldElement.setter2;
5750
if (setter != null && _isOverride(setter)) continue;
5851

5952
_errorReporter.atToken(
@@ -66,15 +59,15 @@ class OverrideVerifier extends RecursiveAstVisitor<void> {
6659

6760
@override
6861
void visitMethodDeclaration(MethodDeclaration node) {
69-
var element = node.declaredElement!;
70-
if (element.hasOverride && !_isOverride(element)) {
71-
if (element is MethodElement) {
62+
var element = node.declaredFragment!.element;
63+
if (element.metadata2.hasOverride && !_isOverride(element)) {
64+
if (element is MethodElement2) {
7265
_errorReporter.atToken(
7366
node.name,
7467
WarningCode.OVERRIDE_ON_NON_OVERRIDING_METHOD,
7568
);
76-
} else if (element is PropertyAccessorElement) {
77-
if (element.isGetter) {
69+
} else if (element is PropertyAccessorElement2) {
70+
if (element is GetterElement) {
7871
_errorReporter.atToken(
7972
node.name,
8073
WarningCode.OVERRIDE_ON_NON_OVERRIDING_GETTER,
@@ -91,17 +84,17 @@ class OverrideVerifier extends RecursiveAstVisitor<void> {
9184

9285
@override
9386
void visitMixinDeclaration(MixinDeclaration node) {
94-
_currentClass = node.declaredElement;
87+
_currentClass = node.declaredFragment?.element;
9588
super.visitMixinDeclaration(node);
9689
_currentClass = null;
9790
}
9891

9992
/// Return `true` if the [member] overrides a member from a superinterface.
100-
bool _isOverride(ExecutableElement member) {
101-
var currentClass = _currentClass?.augmented.firstFragment;
93+
bool _isOverride(ExecutableElement2 member) {
94+
var currentClass = _currentClass?.firstFragment;
10295
if (currentClass != null) {
103-
var name = Name(_libraryUri, member.name);
104-
return _inheritance.getOverridden2(currentClass, name) != null;
96+
var name = Name.forElement(member)!;
97+
return _inheritance.getOverridden4(currentClass.element, name) != null;
10598
} else {
10699
return false;
107100
}

0 commit comments

Comments
 (0)