Skip to content

Commit 5ce8de6

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate deprecated_consistency
Bug: https://github.com/dart-lang/linter/issues/5099 Change-Id: Ice1e43981098dee54483696ac79518ef6c752bf5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393481 Auto-Submit: Phil Quitslund <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent 9c9d838 commit 5ce8de6

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

pkg/linter/analyzer_use_new_elements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ lib/src/rules/constant_identifier_names.dart
6565
lib/src/rules/control_flow_in_finally.dart
6666
lib/src/rules/curly_braces_in_flow_control_structures.dart
6767
lib/src/rules/dangling_library_doc_comments.dart
68+
lib/src/rules/deprecated_consistency.dart
6869
lib/src/rules/diagnostic_describe_all_properties.dart
6970
lib/src/rules/directives_ordering.dart
7071
lib/src/rules/discarded_futures.dart
@@ -499,7 +500,6 @@ test_data/rules/require_trailing_commas.dart
499500
test_data/rules/type_init_formals.dart
500501
test_data/rules/unawaited_futures.dart
501502
test_data/rules/unmocked/unsafe_html.dart
502-
test_data/rules/unnecessary_parenthesis.dart
503503
test_data/rules/void_checks.dart
504504
tool/benchmark.dart
505505
tool/changelog.dart

pkg/linter/lib/src/rules/deprecated_consistency.dart

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/ast/visitor.dart';
7-
import 'package:analyzer/dart/element/element.dart';
7+
import 'package:analyzer/dart/element/element2.dart';
88

99
import '../analyzer.dart';
1010

@@ -40,9 +40,9 @@ class _Visitor extends SimpleAstVisitor<void> {
4040

4141
@override
4242
void visitConstructorDeclaration(ConstructorDeclaration node) {
43-
var constructorElement = node.declaredElement;
43+
var constructorElement = node.declaredFragment?.element;
4444
if (constructorElement != null &&
45-
constructorElement.enclosingElement3.hasDeprecated &&
45+
constructorElement.enclosingElement2.hasDeprecated &&
4646
!constructorElement.hasDeprecated) {
4747
var nodeToAnnotate = node.name ?? node.returnType;
4848
rule.reportLintForOffset(nodeToAnnotate.offset, nodeToAnnotate.length,
@@ -52,19 +52,28 @@ class _Visitor extends SimpleAstVisitor<void> {
5252

5353
@override
5454
void visitFieldFormalParameter(FieldFormalParameter node) {
55-
var declaredElement = node.declaredElement;
56-
if (declaredElement is! FieldFormalParameterElement) return;
55+
var declaredElement = node.declaredFragment?.element;
56+
if (declaredElement is! FieldFormalParameterElement2) return;
5757

58-
var field = declaredElement.field;
58+
var field = declaredElement.field2;
5959
if (field == null) return;
6060

6161
if (field.hasDeprecated && !declaredElement.hasDeprecated) {
6262
rule.reportLint(node,
6363
errorCode: LinterLintCode.deprecated_consistency_field);
6464
}
6565
if (!field.hasDeprecated && declaredElement.hasDeprecated) {
66-
rule.reportLintForOffset(field.nameOffset, field.nameLength,
66+
var fieldFragment = field.firstFragment;
67+
var nameOffset = fieldFragment.nameOffset2;
68+
if (nameOffset == null) return;
69+
var nameLength = fieldFragment.name2?.length;
70+
if (nameLength == null) return;
71+
rule.reportLintForOffset(nameOffset, nameLength,
6772
errorCode: LinterLintCode.deprecated_consistency_parameter);
6873
}
6974
}
7075
}
76+
77+
extension on Annotatable {
78+
bool get hasDeprecated => metadata2.hasDeprecated;
79+
}

0 commit comments

Comments
 (0)