Skip to content

Commit

Permalink
element support for @reopen
Browse files Browse the repository at this point in the history
See: dart-lang/linter#3917

Change-Id: I9652fabcbac37644cfca89227b6830e32a79576d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279657
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Phil Quitslund <[email protected]>
  • Loading branch information
pq authored and Commit Queue committed Jan 25, 2023
1 parent f4ee873 commit 4a4bca6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/analyzer/lib/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,9 @@ abstract class Element implements AnalysisTarget {
/// Return `true` if this element has an annotation of the form `@protected`.
bool get hasProtected;

/// Return `true` if this element has an annotation of the form `@reopen`.
bool get hasReopen;

/// Return `true` if this element has an annotation of the form `@required`.
bool get hasRequired;

Expand Down Expand Up @@ -831,6 +834,10 @@ abstract class ElementAnnotation implements ConstantEvaluationTarget {
/// implementing a proxy object.
bool get isProxy;

/// Return `true` if this annotation marks the associated member as being
/// reopened.
bool get isReopen;

/// Return `true` if this annotation marks the associated member as being
/// required.
bool get isRequired;
Expand Down
22 changes: 22 additions & 0 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1983,6 +1983,10 @@ class ElementAnnotationImpl implements ElementAnnotation {
/// protected.
static const String _protectedVariableName = 'protected';

/// The name of the top-level variable used to mark a class or mixin as being
/// reopened.
static const String _reopenVariableName = 'reopen';

/// The name of the class used to mark a parameter as being required.
static const String _requiredClassName = 'Required';

Expand Down Expand Up @@ -2119,6 +2123,9 @@ class ElementAnnotationImpl implements ElementAnnotation {
@override
bool get isProxy => false;

@override
bool get isReopen => _isPackageMetaGetter(_reopenVariableName);

@override
bool get isRequired =>
_isConstructor(
Expand Down Expand Up @@ -2503,6 +2510,18 @@ abstract class ElementImpl implements Element {
return false;
}

@override
bool get hasReopen {
final metadata = this.metadata;
for (var i = 0; i < metadata.length; i++) {
var annotation = metadata[i];
if (annotation.isReopen) {
return true;
}
}
return false;
}

@override
bool get hasRequired {
final metadata = this.metadata;
Expand Down Expand Up @@ -5090,6 +5109,9 @@ class MultiplyDefinedElementImpl implements MultiplyDefinedElement {
@override
bool get hasProtected => false;

@override
bool get hasReopen => false;

@override
bool get hasRequired => false;

Expand Down
3 changes: 3 additions & 0 deletions pkg/analyzer/lib/src/dart/element/member.dart
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,9 @@ abstract class Member implements Element {
@override
bool get hasProtected => _declaration.hasProtected;

@override
bool get hasReopen => _declaration.hasReopen;

@override
bool get hasRequired => _declaration.hasRequired;

Expand Down
10 changes: 10 additions & 0 deletions pkg/analyzer/lib/src/test_utilities/mock_packages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ const _OptionalTypeArgs optionalTypeArgs = _OptionalTypeArgs();
const _Protected protected = _Protected();
const _Reopen reopen = _Reopen();
const Required required = Required();
const _Sealed sealed = _Sealed();
Expand All @@ -103,6 +105,14 @@ class Immutable {
const Immutable([this.reason = '']);
}
@Target({
TargetKind.classType,
TargetKind.mixinType,
})
class _Reopen {
const _Reopen();
}
class Required {
final String reason;
Expand Down

0 comments on commit 4a4bca6

Please sign in to comment.