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

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

Issue 2644543005: Element model support for covariant (Closed)
Patch Set: Created 3 years, 11 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
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 408d4e54e5dc2356fb73ada799945081a4c2c999..c01d7d8a0ce6b91403548743ce22486b73e9dd1d 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -4218,6 +4218,24 @@ class FieldElementImpl extends PropertyInducingElementImpl
@override
ClassElement get enclosingElement => super.enclosingElement as ClassElement;
+ /**
+ * Return `true` if this field was explicitly marked as being covariant.
+ */
+ bool get isCovariant {
+ if (_unlinkedVariable != null) {
+ return _unlinkedVariable.isCovariant;
+ }
+ return hasModifier(Modifier.COVARIANT);
+ }
+
+ /**
+ * Set whether this field is explicitly marked as being covariant.
+ */
+ void set isCovariant(bool isCovariant) {
+ _assertNotResynthesized(_unlinkedVariable);
+ setModifier(Modifier.COVARIANT, isCovariant);
+ }
+
@override
bool get isEnumConstant =>
enclosingElement != null ? enclosingElement.isEnum : false;
@@ -6291,76 +6309,81 @@ class Modifier implements Comparable<Modifier> {
static const Modifier CONST = const Modifier('CONST', 2);
/**
+ * Indicates that the modifier 'covariant' was applied to the element.
+ */
+ static const Modifier COVARIANT = const Modifier('COVARIANT', 3);
+
+ /**
* Indicates that the import element represents a deferred library.
*/
- static const Modifier DEFERRED = const Modifier('DEFERRED', 3);
+ static const Modifier DEFERRED = const Modifier('DEFERRED', 4);
/**
* Indicates that a class element was defined by an enum declaration.
*/
- static const Modifier ENUM = const Modifier('ENUM', 4);
+ static const Modifier ENUM = const Modifier('ENUM', 5);
/**
* Indicates that a class element was defined by an enum declaration.
*/
- static const Modifier EXTERNAL = const Modifier('EXTERNAL', 5);
+ static const Modifier EXTERNAL = const Modifier('EXTERNAL', 6);
/**
* Indicates that the modifier 'factory' was applied to the element.
*/
- static const Modifier FACTORY = const Modifier('FACTORY', 6);
+ static const Modifier FACTORY = const Modifier('FACTORY', 7);
/**
* Indicates that the modifier 'final' was applied to the element.
*/
- static const Modifier FINAL = const Modifier('FINAL', 7);
+ static const Modifier FINAL = const Modifier('FINAL', 8);
/**
* Indicates that an executable element has a body marked as being a
* generator.
*/
- static const Modifier GENERATOR = const Modifier('GENERATOR', 8);
+ static const Modifier GENERATOR = const Modifier('GENERATOR', 9);
/**
* Indicates that the pseudo-modifier 'get' was applied to the element.
*/
- static const Modifier GETTER = const Modifier('GETTER', 9);
+ static const Modifier GETTER = const Modifier('GETTER', 10);
/**
* A flag used for libraries indicating that the defining compilation unit
* contains at least one import directive whose URI uses the "dart-ext"
* scheme.
*/
- static const Modifier HAS_EXT_URI = const Modifier('HAS_EXT_URI', 10);
+ static const Modifier HAS_EXT_URI = const Modifier('HAS_EXT_URI', 11);
/**
* Indicates that the associated element did not have an explicit type
* associated with it. If the element is an [ExecutableElement], then the
* type being referred to is the return type.
*/
- static const Modifier IMPLICIT_TYPE = const Modifier('IMPLICIT_TYPE', 11);
+ static const Modifier IMPLICIT_TYPE = const Modifier('IMPLICIT_TYPE', 12);
/**
* Indicates that a class is a mixin application.
*/
static const Modifier MIXIN_APPLICATION =
- const Modifier('MIXIN_APPLICATION', 12);
+ const Modifier('MIXIN_APPLICATION', 13);
/**
* Indicates that a class contains an explicit reference to 'super'.
*/
static const Modifier REFERENCES_SUPER =
- const Modifier('REFERENCES_SUPER', 13);
+ const Modifier('REFERENCES_SUPER', 14);
/**
* Indicates that the pseudo-modifier 'set' was applied to the element.
*/
- static const Modifier SETTER = const Modifier('SETTER', 14);
+ static const Modifier SETTER = const Modifier('SETTER', 15);
/**
* Indicates that the modifier 'static' was applied to the element.
*/
- static const Modifier STATIC = const Modifier('STATIC', 15);
+ static const Modifier STATIC = const Modifier('STATIC', 16);
/**
* Indicates that the element does not appear in the source code but was
@@ -6368,12 +6391,13 @@ class Modifier implements Comparable<Modifier> {
* constructors, an implicit zero-argument constructor will be created and it
* will be marked as being synthetic.
*/
- static const Modifier SYNTHETIC = const Modifier('SYNTHETIC', 16);
+ static const Modifier SYNTHETIC = const Modifier('SYNTHETIC', 17);
static const List<Modifier> values = const [
ABSTRACT,
ASYNCHRONOUS,
CONST,
+ COVARIANT,
DEFERRED,
ENUM,
EXTERNAL,
@@ -7091,7 +7115,7 @@ class ParameterElementImpl extends VariableElementImpl
@override
bool get isCovariant {
- if (inheritsCovariant) {
+ if (isExplicitlyCovariant || inheritsCovariant) {
return true;
}
for (ElementAnnotationImpl annotation in metadata) {
@@ -7102,6 +7126,24 @@ class ParameterElementImpl extends VariableElementImpl
return false;
}
+ /**
+ * Return true if this parameter is explicitly marked as being covariant.
+ */
+ bool get isExplicitlyCovariant {
+ if (_unlinkedParam != null) {
+ return _unlinkedParam.isExplicitlyCovariant;
+ }
+ return hasModifier(Modifier.COVARIANT);
+ }
+
+ /**
+ * Set whether this variable parameter is explicitly marked as being covariant.
+ */
+ void set isExplicitlyCovariant(bool isCovariant) {
+ _assertNotResynthesized(_unlinkedParam);
+ setModifier(Modifier.COVARIANT, isCovariant);
+ }
+
@override
bool get isFinal {
if (_unlinkedParam != null) {
@@ -7368,7 +7410,7 @@ class ParameterElementImpl_ofImplicitSetter extends ParameterElementImpl {
@override
bool get isCovariant {
- if (inheritsCovariant) {
+ if (isExplicitlyCovariant || inheritsCovariant) {
return true;
}
for (ElementAnnotationImpl annotation in setter.variable.metadata) {
@@ -7380,6 +7422,15 @@ class ParameterElementImpl_ofImplicitSetter extends ParameterElementImpl {
}
@override
+ bool get isExplicitlyCovariant {
+ PropertyInducingElement variable = setter.variable;
+ if (variable is FieldElementImpl) {
+ return variable.isCovariant;
+ }
+ return false;
+ }
+
+ @override
DartType get type => setter.variable.type;
@override

Powered by Google App Engine
This is Rietveld 408576698