Skip to content

Commit 7089876

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate library_annotations
Bug: https://github.com/dart-lang/linter/issues/5099 Change-Id: I386be7cbd2768d031ab42cc47d5b007e1f6d8478 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389360 Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent efa95a8 commit 7089876

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

pkg/analyzer/lib/dart/element/element.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,16 @@ abstract class ElementAnnotation implements ConstantEvaluationTarget {
897897
/// other element.
898898
Element? get element;
899899

900+
/// Returns the element referenced by this annotation.
901+
///
902+
/// In valid code this element can be a [GetterElement] of a constant
903+
/// top-level variable, or a constant static field of a class; or a
904+
/// constant [ConstructorElement].
905+
///
906+
/// In invalid code this element can be `null`, or a reference to any
907+
/// other element.
908+
Element2? get element2;
909+
900910
/// Whether the annotation marks the associated function as always throwing.
901911
bool get isAlwaysThrows;
902912

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,6 +2078,11 @@ class ElementAnnotationImpl implements ElementAnnotation {
20782078
@override
20792079
AnalysisContext get context => compilationUnit.library.context;
20802080

2081+
@override
2082+
Element2? get element2 {
2083+
return element?.asElement2;
2084+
}
2085+
20812086
@override
20822087
bool get isAlwaysThrows => _isPackageMetaGetter(_alwaysThrowsVariableName);
20832088

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

Lines changed: 5 additions & 5 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
// ignore: implementation_imports
99
import 'package:analyzer/src/dart/element/extensions.dart';
1010
import 'package:meta/meta_meta.dart';
@@ -89,9 +89,9 @@ extension on ElementAnnotation {
8989
required String libraryName,
9090
required String className,
9191
}) {
92-
var element = this.element;
93-
return element is ConstructorElement &&
94-
element.enclosingElement3.name == className &&
95-
element.library.name == libraryName;
92+
var element = element2;
93+
return element is ConstructorElement2 &&
94+
element.enclosingElement2.name == className &&
95+
element.library2?.name == libraryName;
9696
}
9797
}

0 commit comments

Comments
 (0)