Skip to content

Commit

Permalink
[element model] migrate library_annotations
Browse files Browse the repository at this point in the history
Bug: dart-lang/linter#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]>
  • Loading branch information
pq authored and Commit Queue committed Oct 9, 2024
1 parent efa95a8 commit 7089876
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
10 changes: 10 additions & 0 deletions pkg/analyzer/lib/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,16 @@ abstract class ElementAnnotation implements ConstantEvaluationTarget {
/// other element.
Element? get element;

/// Returns the element referenced by this annotation.
///
/// In valid code this element can be a [GetterElement] of a constant
/// top-level variable, or a constant static field of a class; or a
/// constant [ConstructorElement].
///
/// In invalid code this element can be `null`, or a reference to any
/// other element.
Element2? get element2;

/// Whether the annotation marks the associated function as always throwing.
bool get isAlwaysThrows;

Expand Down
5 changes: 5 additions & 0 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2078,6 +2078,11 @@ class ElementAnnotationImpl implements ElementAnnotation {
@override
AnalysisContext get context => compilationUnit.library.context;

@override
Element2? get element2 {
return element?.asElement2;
}

@override
bool get isAlwaysThrows => _isPackageMetaGetter(_alwaysThrowsVariableName);

Expand Down
10 changes: 5 additions & 5 deletions pkg/linter/lib/src/rules/library_annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
// ignore: implementation_imports
import 'package:analyzer/src/dart/element/extensions.dart';
import 'package:meta/meta_meta.dart';
Expand Down Expand Up @@ -89,9 +89,9 @@ extension on ElementAnnotation {
required String libraryName,
required String className,
}) {
var element = this.element;
return element is ConstructorElement &&
element.enclosingElement3.name == className &&
element.library.name == libraryName;
var element = element2;
return element is ConstructorElement2 &&
element.enclosingElement2.name == className &&
element.library2?.name == libraryName;
}
}

0 comments on commit 7089876

Please sign in to comment.