meta: Support @doNotStore on constructors and mixins

There were no tests of this component of the annotation's description:

> The annotation can also be applied to a class to implicitly
> annotate all of the valid members of the class

So I add those as well.

Bug: https://github.com/dart-lang/sdk/issues/48476
Change-Id: If5f0f4c6057f57b4dfd01d8f648110d69fbc5eb4
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367880
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
diff --git a/pkg/analyzer/lib/src/test_utilities/mock_packages.dart b/pkg/analyzer/lib/src/test_utilities/mock_packages.dart
index f248814..8ec3329 100644
--- a/pkg/analyzer/lib/src/test_utilities/mock_packages.dart
+++ b/pkg/analyzer/lib/src/test_utilities/mock_packages.dart
@@ -194,10 +194,12 @@
 
 @Target({
   TargetKind.classType,
+  TargetKind.constructor,
   TargetKind.function,
   TargetKind.getter,
   TargetKind.library,
   TargetKind.method,
+  TargetKind.mixinType,
 })
 class _DoNotStore {
   const _DoNotStore();
diff --git a/pkg/analyzer/test/src/diagnostics/assignment_of_do_not_store_test.dart b/pkg/analyzer/test/src/diagnostics/assignment_of_do_not_store_test.dart
index 138d538..bb6dd94 100644
--- a/pkg/analyzer/test/src/diagnostics/assignment_of_do_not_store_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/assignment_of_do_not_store_test.dart
@@ -55,6 +55,62 @@
     writeTestPackageConfigWithMeta();
   }
 
+  test_class_containingInstanceGetter() async {
+    await assertErrorsInCode('''
+import 'package:meta/meta.dart';
+@doNotStore
+class A {
+  String get v => '';
+}
+
+String f = A().v;
+''', [
+      error(WarningCode.ASSIGNMENT_OF_DO_NOT_STORE, 91, 5),
+    ]);
+  }
+
+  test_class_containingInstanceMethod() async {
+    await assertErrorsInCode('''
+import 'package:meta/meta.dart';
+@doNotStore
+class A {
+  String v() => '';
+}
+
+String f = A().v();
+''', [
+      error(WarningCode.ASSIGNMENT_OF_DO_NOT_STORE, 89, 7),
+    ]);
+  }
+
+  test_class_containingStaticGetter() async {
+    await assertErrorsInCode('''
+import 'package:meta/meta.dart';
+@doNotStore
+class A {
+  static String get v => '';
+}
+
+String f = A.v;
+''', [
+      error(WarningCode.ASSIGNMENT_OF_DO_NOT_STORE, 98, 3),
+    ]);
+  }
+
+  test_class_containingStaticMethod() async {
+    await assertErrorsInCode('''
+import 'package:meta/meta.dart';
+@doNotStore
+class A {
+  static String v() => '';
+}
+
+String f = A.v();
+''', [
+      error(WarningCode.ASSIGNMENT_OF_DO_NOT_STORE, 96, 5),
+    ]);
+  }
+
   test_classMemberGetter() async {
     await assertErrorsInCode('''
 import 'package:meta/meta.dart';
@@ -171,6 +227,23 @@
     ]);
   }
 
+  test_mixin_containingInstanceMethod() async {
+    await assertErrorsInCode('''
+import 'package:meta/meta.dart';
+@doNotStore
+mixin M {
+  String v() => '';
+}
+
+abstract class A {
+  M get m;
+  late String f = m.v();
+}
+''', [
+      error(WarningCode.ASSIGNMENT_OF_DO_NOT_STORE, 126, 5),
+    ]);
+  }
+
   test_tearOff() async {
     await assertNoErrorsInCode('''
 import 'package:meta/meta.dart';
diff --git a/pkg/analyzer/test/src/diagnostics/return_of_do_not_store_test.dart b/pkg/analyzer/test/src/diagnostics/return_of_do_not_store_test.dart
index 9c85f4f..58a4b8c 100644
--- a/pkg/analyzer/test/src/diagnostics/return_of_do_not_store_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/return_of_do_not_store_test.dart
@@ -59,6 +59,23 @@
     writeTestPackageConfigWithMeta();
   }
 
+  test_constructor() async {
+    await assertErrorsInCode('''
+import 'package:meta/meta.dart';
+
+class A {
+  @doNotStore
+  A();
+
+  String getA() {
+    return A();
+  }
+}
+''', [
+      error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_METHOD, 95, 3),
+    ]);
+  }
+
   @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/48476')
   test_returnFromClosureInFunction() async {
     await assertErrorsInCode('''
diff --git a/pkg/analyzer_utilities/lib/test/mock_packages/package_content/meta/lib/meta.dart b/pkg/analyzer_utilities/lib/test/mock_packages/package_content/meta/lib/meta.dart
index f7fe16a..025a639 100644
--- a/pkg/analyzer_utilities/lib/test/mock_packages/package_content/meta/lib/meta.dart
+++ b/pkg/analyzer_utilities/lib/test/mock_packages/package_content/meta/lib/meta.dart
@@ -71,14 +71,14 @@
 @Deprecated('Use the `covariant` modifier instead')
 const _Checked checked = _Checked();
 
-/// Used to annotate a method, getter or top-level getter or function to
-/// indicate that the value obtained by invoking it should not be stored in a
+/// Used to annotate a method, getter, top-level function, or top-level getter
+/// to indicate that the value obtained by invoking it should not be stored in a
 /// field or top-level variable. The annotation can also be applied to a class
 /// to implicitly annotate all of the valid members of the class, or applied to
 /// a library to annotate all of the valid members of the library, including
-/// classes. If a value returned by an element marked as `doNotStore` is returned
-/// from a function or getter, that function or getter should be similarly
-/// annotated.
+/// classes. If a value returned by an element marked as `doNotStore` is
+/// returned from a function or getter, that function or getter should be
+/// similarly annotated.
 ///
 /// Tools, such as the analyzer, can provide feedback if
 ///
@@ -90,9 +90,9 @@
 ///   or top-level variable.
 const _DoNotStore doNotStore = _DoNotStore();
 
-/// Used to annotate a method, getter or top-level getter or function that is
-/// not intended to be accessed in checked-in code, but might be ephemerally
-/// used during development or local testing.
+/// Used to annotate a method, getter, top-level function, or top-level getter
+/// that is not intended to be accessed in checked-in code, but might be
+/// ephemerally used during development or local testing.
 ///
 /// The intention of this annotation is to signify an API is available for
 /// temporary or ephemeral use (such as debugging or local testing), but should
@@ -610,12 +610,12 @@
 
 @Target({
   TargetKind.classType,
-  // TODO(srawlins): Add `TargetKind.constructor` when this annotation has
-  // functional tests. See https://github.com/dart-lang/sdk/issues/48476.
+  TargetKind.constructor,
   TargetKind.function,
   TargetKind.getter,
   TargetKind.library,
   TargetKind.method,
+  TargetKind.mixinType,
 })
 class _DoNotStore {
   const _DoNotStore();
diff --git a/pkg/meta/lib/meta.dart b/pkg/meta/lib/meta.dart
index e3292b7..385eefd 100644
--- a/pkg/meta/lib/meta.dart
+++ b/pkg/meta/lib/meta.dart
@@ -71,14 +71,14 @@
 @Deprecated('Use the `covariant` modifier instead')
 const _Checked checked = _Checked();
 
-/// Used to annotate a method, getter or top-level getter or function to
-/// indicate that the value obtained by invoking it should not be stored in a
+/// Used to annotate a method, getter, top-level function, or top-level getter
+/// to indicate that the value obtained by invoking it should not be stored in a
 /// field or top-level variable. The annotation can also be applied to a class
 /// to implicitly annotate all of the valid members of the class, or applied to
 /// a library to annotate all of the valid members of the library, including
-/// classes. If a value returned by an element marked as `doNotStore` is returned
-/// from a function or getter, that function or getter should be similarly
-/// annotated.
+/// classes. If a value returned by an element marked as `doNotStore` is
+/// returned from a function or getter, that function or getter should be
+/// similarly annotated.
 ///
 /// Tools, such as the analyzer, can provide feedback if
 ///
@@ -90,9 +90,9 @@
 ///   or top-level variable.
 const _DoNotStore doNotStore = _DoNotStore();
 
-/// Used to annotate a method, getter or top-level getter or function that is
-/// not intended to be accessed in checked-in code, but might be ephemerally
-/// used during development or local testing.
+/// Used to annotate a method, getter, top-level function, or top-level getter
+/// that is not intended to be accessed in checked-in code, but might be
+/// ephemerally used during development or local testing.
 ///
 /// The intention of this annotation is to signify an API is available for
 /// temporary or ephemeral use (such as debugging or local testing), but should
@@ -641,12 +641,12 @@
 
 @Target({
   TargetKind.classType,
-  // TODO(srawlins): Add `TargetKind.constructor` when this annotation has
-  // functional tests. See https://github.com/dart-lang/sdk/issues/48476.
+  TargetKind.constructor,
   TargetKind.function,
   TargetKind.getter,
   TargetKind.library,
   TargetKind.method,
+  TargetKind.mixinType,
 })
 class _DoNotStore {
   const _DoNotStore();