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

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

Issue 2352433002: support `@virtual` fields, fix #27384 (Closed)
Patch Set: 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 d465b405556fad6a281fb6302d3840935c2c43ba..58c2169dcea689d5b1113b8d6ec94148c7b5cd7b 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -2514,6 +2514,12 @@ class ElementAnnotationImpl implements ElementAnnotation {
static String _REQUIRED_VARIABLE_NAME = "required";
/**
+ * The name of the top-level variable used to mark a member as intended to be
+ * overridden.
+ */
+ static String _VIRTUAL_VARIABLE_NAME = "virtual";
+
+ /**
* The element representing the field, variable, or constructor being used as
* an annotation.
*/
@@ -2616,6 +2622,18 @@ class ElementAnnotationImpl implements ElementAnnotation {
element.library?.name == _META_LIB_NAME;
/**
+ * Return `true` if this annotation marks the associated member as supporting
+ * overrides.
+ *
+ * This is currently used by fields in Strong Mode, as other members are
+ * already virtual-by-default.
+ */
+ bool get isVirtual =>
+ element is PropertyAccessorElement &&
+ element.name == _VIRTUAL_VARIABLE_NAME &&
+ element.library?.name == _META_LIB_NAME;
+
+ /**
* Get the library containing this annotation.
*/
Source get librarySource => compilationUnit.librarySource;
@@ -4182,6 +4200,16 @@ class FieldElementImpl extends PropertyInducingElementImpl
}
@override
+ bool get isVirtual {
+ for (ElementAnnotationImpl annotation in metadata) {
+ if (annotation.isVirtual) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @override
ElementKind get kind => ElementKind.FIELD;
/**
« 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