Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Unified Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 2336503003: fix #25578, implement @covariant parameter overrides (Closed)
Patch Set: fix comments, format Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/dart/element/element.dart ('k') | pkg/analyzer/lib/src/dart/element/handle.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « pkg/analyzer/lib/dart/element/element.dart ('k') | pkg/analyzer/lib/src/dart/element/handle.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698