Skip to content

Commit 37c1da6

Browse files
pqcommit-bot@chromium.org
authored andcommitted
element model support for @doNotStore
Change-Id: Ic69dcee22de76540d7034a0a9265cb22ea325b4e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/159184 Commit-Queue: Phil Quitslund <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 690d04e commit 37c1da6

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

pkg/analyzer/lib/dart/element/element.dart

+7
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,9 @@ abstract class Element implements AnalysisTarget {
528528
/// or `@Deprecated('..')`.
529529
bool get hasDeprecated;
530530

531+
/// Return `true` if this element has an annotation of the form `@doNotStore`.
532+
bool get hasDoNotStore;
533+
531534
/// Return `true` if this element has an annotation of the form `@factory`.
532535
bool get hasFactory;
533536

@@ -702,6 +705,10 @@ abstract class ElementAnnotation implements ConstantEvaluationTarget {
702705
/// deprecated.
703706
bool get isDeprecated;
704707

708+
/// Return `true` if this annotation marks the associated element as not to be
709+
/// stored.
710+
bool get isDoNotStore;
711+
705712
/// Return `true` if this annotation marks the associated member as a factory.
706713
bool get isFactory;
707714

pkg/analyzer/lib/src/dart/element/element.dart

+25
Original file line numberDiff line numberDiff line change
@@ -2284,6 +2284,10 @@ class ElementAnnotationImpl implements ElementAnnotation {
22842284
/// deprecated.
22852285
static const String _DEPRECATED_VARIABLE_NAME = "deprecated";
22862286

2287+
/// The name of the top-level variable used to mark an element as not to be
2288+
/// stored.
2289+
static const String _DO_NOT_STORE_VARIABLE_NAME = "doNotStore";
2290+
22872291
/// The name of the top-level variable used to mark a method as being a
22882292
/// factory.
22892293
static const String _FACTORY_VARIABLE_NAME = "factory";
@@ -2411,6 +2415,12 @@ class ElementAnnotationImpl implements ElementAnnotation {
24112415
return false;
24122416
}
24132417

2418+
@override
2419+
bool get isDoNotStore =>
2420+
element is PropertyAccessorElement &&
2421+
element.name == _DO_NOT_STORE_VARIABLE_NAME &&
2422+
element.library?.name == _META_LIB_NAME;
2423+
24142424
@override
24152425
bool get isFactory =>
24162426
element is PropertyAccessorElement &&
@@ -2674,6 +2684,18 @@ abstract class ElementImpl implements Element {
26742684
return false;
26752685
}
26762686

2687+
@override
2688+
bool get hasDoNotStore {
2689+
var metadata = this.metadata;
2690+
for (var i = 0; i < metadata.length; i++) {
2691+
var annotation = metadata[i];
2692+
if (annotation.isDoNotStore) {
2693+
return true;
2694+
}
2695+
}
2696+
return false;
2697+
}
2698+
26772699
@override
26782700
bool get hasFactory {
26792701
var metadata = this.metadata;
@@ -5957,6 +5979,9 @@ class MultiplyDefinedElementImpl implements MultiplyDefinedElement {
59575979
@override
59585980
bool get hasDeprecated => false;
59595981

5982+
@override
5983+
bool get hasDoNotStore => false;
5984+
59605985
@override
59615986
bool get hasFactory => false;
59625987

pkg/analyzer/lib/src/dart/element/member.dart

+3
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,9 @@ abstract class Member implements Element {
450450
@override
451451
bool get hasDeprecated => _declaration.hasDeprecated;
452452

453+
@override
454+
bool get hasDoNotStore => _declaration.hasDoNotStore;
455+
453456
@override
454457
bool get hasFactory => _declaration.hasFactory;
455458

0 commit comments

Comments
 (0)