Index: pkg/analyzer/lib/src/dart/element/element.dart |
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart |
index 735219389d8249403764c1f1a87bb4058ffd5423..ecd52b53c217e0281b376cda614058e67ba77ad2 100644 |
--- a/pkg/analyzer/lib/src/dart/element/element.dart |
+++ b/pkg/analyzer/lib/src/dart/element/element.dart |
@@ -2458,6 +2458,12 @@ class DynamicElementImpl extends ElementImpl implements TypeDefiningElement { |
*/ |
class ElementAnnotationImpl implements ElementAnnotation { |
/** |
+ * The name of the top-level variable used to mark a method parameter as |
+ * covariant. |
+ */ |
+ static String _COVARIANT_VARIABLE_NAME = "checked"; |
+ |
+ /** |
* The name of the class used to mark an element as being deprecated. |
*/ |
static String _DEPRECATED_CLASS_NAME = "Deprecated"; |
@@ -2560,6 +2566,15 @@ class ElementAnnotationImpl implements ElementAnnotation { |
@override |
AnalysisContext get context => compilationUnit.library.context; |
+ /** |
+ * Return `true` if this annotation marks the associated parameter as being |
+ * covariant, meaning it is allowed to have a narrower type in an override. |
+ */ |
+ bool get isCovariant => |
+ element is PropertyAccessorElement && |
+ element.name == _COVARIANT_VARIABLE_NAME && |
+ element.library?.name == _META_LIB_NAME; |
+ |
@override |
bool get isDeprecated { |
if (element?.library?.isDartCore == true) { |
@@ -6941,6 +6956,13 @@ class ParameterElementImpl extends VariableElementImpl |
int _visibleRangeLength = -1; |
/** |
+ * True if this parameter inherits from a covariant parameter. This happens |
+ * when it overrides a method in a supertype that has a corresponding |
+ * covariant parameter. |
+ */ |
+ bool inheritsCovariant = false; |
+ |
+ /** |
* Initialize a newly created parameter element to have the given [name] and |
* [nameOffset]. |
*/ |
@@ -7095,6 +7117,19 @@ class ParameterElementImpl extends VariableElementImpl |
} |
@override |
+ bool get isCovariant { |
+ if (inheritsCovariant) { |
+ return true; |
+ } |
+ for (ElementAnnotationImpl annotation in metadata) { |
+ if (annotation.isCovariant) { |
+ return true; |
+ } |
+ } |
+ return false; |
+ } |
+ |
+ @override |
bool get isFinal { |
if (_unlinkedParam != null) { |
return false; |