Remove support for "@checked" annotations.

Dart now has a "covariant" keyword that serves the same purpose.

Fixes #28797

Note that this is a breaking change, not to the analyzer API but to
the language semantics implemented by the analyzer; client code that
wants the "@checked" behavior will now have to use the "covariant"
keyword instead.  Since the front end implementation of the type
system only supports the "covariant" keyword, the impact on user code
should be low; any user code that would be broken by this change is
already broken under the front end.  Google internal code has already
been migrated to use "covariant".

Change-Id: Ida052bd5449d3ba703bacf98143bece650f53b53
Reviewed-on: https://dart-review.googlesource.com/c/88225
Commit-Queue: Paul Berry <paulberry@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md
index 43477d5..5a574ca 100644
--- a/pkg/analyzer/CHANGELOG.md
+++ b/pkg/analyzer/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.34.2
+* Removed support for the `@checked` annotation.  Please use the `covariant`
+  keyword instead.
+
 ## 0.34.1
 * Added logic to report a hint if a deprecated lint is specified in the user's
   analysis_options.yaml file, or if a lint is specified twice.
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 5490be9..f23c65a 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -2418,10 +2418,6 @@
   /// throws, for dead code purposes.
   static String _ALWAYS_THROWS_VARIABLE_NAME = "alwaysThrows";
 
-  /// 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";
 
@@ -2535,13 +2531,6 @@
   @override
   bool get isConstantEvaluated => evaluationResult != null;
 
-  /// 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) {
@@ -6959,11 +6948,6 @@
     if (isExplicitlyCovariant || inheritsCovariant) {
       return true;
     }
-    for (ElementAnnotationImpl annotation in metadata) {
-      if (annotation.isCovariant) {
-        return true;
-      }
-    }
     return false;
   }
 
@@ -7227,11 +7211,6 @@
     if (isExplicitlyCovariant || inheritsCovariant) {
       return true;
     }
-    for (ElementAnnotationImpl annotation in setter.variable.metadata) {
-      if (annotation.isCovariant) {
-        return true;
-      }
-    }
     return false;
   }
 
diff --git a/pkg/analyzer/lib/src/summary/link.dart b/pkg/analyzer/lib/src/summary/link.dart
index 4ce08a6..5a9b656 100644
--- a/pkg/analyzer/lib/src/summary/link.dart
+++ b/pkg/analyzer/lib/src/summary/link.dart
@@ -4257,18 +4257,6 @@
     if (isExplicitlyCovariant || inheritsCovariant) {
       return true;
     }
-    for (UnlinkedExpr annotation in unlinkedParam.annotations) {
-      if (annotation.operations.length == 1 &&
-          annotation.operations[0] == UnlinkedExprOperation.pushReference) {
-        ReferenceableElementForLink element =
-            this.compilationUnit.resolveRef(annotation.references[0].reference);
-        if (element is PropertyAccessorElementForLink &&
-            element.name == 'checked' &&
-            element.library.name == 'meta') {
-          return true;
-        }
-      }
-    }
     return false;
   }
 
diff --git a/pkg/analyzer/pubspec.yaml b/pkg/analyzer/pubspec.yaml
index fde4314..33c10f2 100644
--- a/pkg/analyzer/pubspec.yaml
+++ b/pkg/analyzer/pubspec.yaml
@@ -1,5 +1,5 @@
 name: analyzer
-version: 0.34.1
+version: 0.34.2-dev
 author: Dart Team <misc@dartlang.org>
 description: Static analyzer for Dart.
 homepage: https://github.com/dart-lang/sdk/tree/master/pkg/analyzer
diff --git a/pkg/analyzer/test/src/summary/linker_test.dart b/pkg/analyzer/test/src/summary/linker_test.dart
index 96d7b4d..e406c24 100644
--- a/pkg/analyzer/test/src/summary/linker_test.dart
+++ b/pkg/analyzer/test/src/summary/linker_test.dart
@@ -165,14 +165,9 @@
   }
 
   void test_covariance() {
-    // Note: due to dartbug.com/27393, the keyword "checked" is identified by
-    // its presence in a library called "meta".  If that bug is fixed, this test
-    // may need to be changed.
     createLinker('''
-library meta;
-const checked = null;
 class A<T> {
-  void f(@checked T t) {}
+  void f(covariant T t) {}
 }
 class B<T> extends A<T> {
   void f(T t) {}
diff --git a/pkg/analyzer/test/src/summary/resynthesize_common.dart b/pkg/analyzer/test/src/summary/resynthesize_common.dart
index 4995afb..9267132 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_common.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_common.dart
@@ -7256,54 +7256,6 @@
         withOffsets: true);
   }
 
-  test_parameter_checked() async {
-    // Note: due to dartbug.com/27393, the keyword "checked" is identified by
-    // its presence in a library called "meta".  If that bug is fixed, this test
-    // my need to be changed.
-    var library = await checkLibrary(r'''
-library meta;
-const checked = null;
-class A<T> {
-  void f(@checked T t) {}
-}
-''');
-    checkElementText(library, r'''
-library meta;
-class A<T> {
-  void f(@
-        checked/*location: test.dart;checked?*/ covariant T t) {}
-}
-const dynamic checked = null;
-''');
-  }
-
-  test_parameter_checked_inherited() async {
-    // Note: due to dartbug.com/27393, the keyword "checked" is identified by
-    // its presence in a library called "meta".  If that bug is fixed, this test
-    // my need to be changed.
-    var library = await checkLibrary(r'''
-library meta;
-const checked = null;
-class A<T> {
-  void f(@checked T t) {}
-}
-class B<T> extends A<T> {
-  void f(T t) {}
-}
-''');
-    checkElementText(library, r'''
-library meta;
-class A<T> {
-  void f(@
-        checked/*location: test.dart;checked?*/ covariant T t) {}
-}
-class B<T> extends A<T> {
-  void f(covariant T t) {}
-}
-const dynamic checked = null;
-''');
-  }
-
   test_parameter_covariant() async {
     var library = await checkLibrary('class C { void m(covariant C c) {} }');
     checkElementText(library, r'''
diff --git a/pkg/analyzer/test/src/task/strong/checker_test.dart b/pkg/analyzer/test/src/task/strong/checker_test.dart
index 4194a0a..981b10e 100644
--- a/pkg/analyzer/test/src/task/strong/checker_test.dart
+++ b/pkg/analyzer/test/src/task/strong/checker_test.dart
@@ -523,20 +523,18 @@
   }
 
   test_covariantOverride() async {
-    _addMetaLibrary();
     await checkFile(r'''
-import 'meta.dart';
 class C {
   num f(num x) => x;
 }
 class D extends C {
-  int f(@checked int x) => x;
+  int f(covariant int x) => x;
 }
 class E extends D {
   int f(Object x) => /*info:DOWN_CAST_IMPLICIT*/x;
 }
 class F extends E {
-  int f(@checked int x) => x;
+  int f(covariant int x) => x;
 }
 class G extends E implements D {}
 
@@ -544,32 +542,30 @@
   /*error:INVALID_OVERRIDE*/int f(int x) => x;
 }
 class E_error extends D {
-  /*error:INVALID_OVERRIDE*/int f(@checked double x) => 0;
+  /*error:INVALID_OVERRIDE*/int f(covariant double x) => 0;
 }
 class F_error extends E {
-  /*error:INVALID_OVERRIDE*/int f(@checked double x) => 0;
+  /*error:INVALID_OVERRIDE*/int f(covariant double x) => 0;
 }
 class G_error extends E implements D {
-  /*error:INVALID_OVERRIDE*/int f(@checked double x) => 0;
+  /*error:INVALID_OVERRIDE*/int f(covariant double x) => 0;
 }
     ''');
   }
 
   @failingTest
   test_covariantOverride_fields() async {
-    _addMetaLibrary();
     await checkFile(r'''
-import 'meta.dart';
 class A {
   get foo => '';
   set foo(_) {}
 }
 
 class B extends A {
-  @checked num foo;
+  covariant num foo;
 }
 class C extends A {
-  @checked @virtual num foo;
+  covariant @virtual num foo;
 }
 class D extends C {
   @virtual int foo;
@@ -581,9 +577,7 @@
   }
 
   test_covariantOverride_leastUpperBound() async {
-    _addMetaLibrary();
     await checkFile(r'''
-import "meta.dart";
 abstract class Top {}
 abstract class Left implements Top {}
 abstract class Right implements Top {}
@@ -600,17 +594,15 @@
 }
 abstract class TakesBottom implements TakesLeft, TakesRight {
   // LUB(Left, Right) == Top, so this is an implicit cast from Top to Bottom.
-  m(@checked Bottom x);
+  m(covariant Bottom x);
 }
     ''');
   }
 
   test_covariantOverride_markerIsInherited() async {
-    _addMetaLibrary();
     await checkFile(r'''
-import 'meta.dart';
 class C {
-  num f(@checked num x) => x;
+  num f(covariant num x) => x;
 }
 class D extends C {
   int f(int x) => x;
@@ -3401,11 +3393,9 @@
 
   test_overrideNarrowsType_legalWithChecked() async {
     // Regression test for https://github.com/dart-lang/sdk/issues/25232
-    _addMetaLibrary();
     await checkFile(r'''
-import 'meta.dart';
 abstract class A { void test(A arg) { } }
-abstract class B extends A { void test(@checked B arg) { } }
+abstract class B extends A { void test(covariant B arg) { } }
 abstract class X implements A { }
 class C extends B with X { }
 class D extends B implements A { }