Move more completion override tests to run on both protocols.

Change-Id: I082fdd06918cc6589314f9e3e0bab68ee52e28d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244726
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart b/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart
index 53e5e32..021701c 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart
@@ -974,7 +974,7 @@
         withNullability: _isNonNullableByDefault);
     _addSuggestion(
       suggestion,
-      textToMatchOverride: element.displayName,
+      textToMatchOverride: _textToMatchOverride(element),
     );
   }
 
@@ -1502,6 +1502,13 @@
       suggestion.docSummary = doc.summary;
     }
   }
+
+  static String _textToMatchOverride(ExecutableElement element) {
+    if (element.isOperator) {
+      return 'operator';
+    }
+    return element.displayName;
+  }
 }
 
 abstract class SuggestionListener {
diff --git a/pkg/analysis_server/test/services/completion/dart/location/class_body_test.dart b/pkg/analysis_server/test/services/completion/dart/location/class_body_test.dart
index ca3535f..c9003f8 100644
--- a/pkg/analysis_server/test/services/completion/dart/location/class_body_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/location/class_body_test.dart
@@ -312,6 +312,109 @@
 }
 
 mixin OverrideTestCases on AbstractCompletionDriverTest {
+  Future<void> test_class_inComment() async {
+    final response = await getTestCodeSuggestions('''
+class A {
+  void foo01() {}
+}
+
+class B extends A {
+  // foo^
+  void bar() {}
+}
+''');
+
+    check(response).suggestions.overrides.isEmpty;
+  }
+
+  Future<void> test_class_inComment_dartdoc() async {
+    final response = await getTestCodeSuggestions('''
+class A {
+  void foo01() {}
+}
+
+class B extends A {
+  /// foo^
+  void bar() {}
+}
+''');
+
+    check(response).suggestions.overrides.isEmpty;
+  }
+
+  Future<void> test_class_inComment_reference() async {
+    final response = await getTestCodeSuggestions('''
+class A {
+  void foo01() {}
+}
+
+class B extends A {
+  /// [foo^]
+  void bar() {}
+}
+''');
+
+    check(response).suggestions.overrides.isEmpty;
+  }
+
+  Future<void> test_class_method_alreadyOverridden() async {
+    final response = await getTestCodeSuggestions('''
+class A {
+  void foo01() {}
+  void foo02() {}
+}
+
+class B extends A {
+  void foo02() {}
+  foo^
+}
+''');
+
+    check(response).suggestions.overrides
+      ..includesAll([
+        _isOverrideWithSuper_foo01,
+      ])
+      ..excludesAll([
+        (suggestion) => suggestion.completion.contains('foo02'),
+      ]);
+  }
+
+  Future<void> test_class_method_beforeField() async {
+    final response = await getTestCodeSuggestions('''
+class A {
+  void foo01() {}
+}
+
+class B extends A {
+  foo^
+  
+  int bar = 0;
+}
+''');
+
+    check(response).suggestions.overrides.includesAll([
+      _isOverrideWithSuper_foo01,
+    ]);
+  }
+
+  Future<void> test_class_method_beforeMethod() async {
+    final response = await getTestCodeSuggestions('''
+class A {
+  void foo01() {}
+}
+
+class B extends A {
+  foo^
+  
+  void bar() {}
+}
+''');
+
+    check(response).suggestions.overrides.includesAll([
+      _isOverrideWithSuper_foo01,
+    ]);
+  }
+
   Future<void> test_class_method_fromExtends() async {
     final response = await getTestCodeSuggestions('''
 class A {
@@ -324,12 +427,115 @@
 ''');
 
     check(response).suggestions.overrides.includesAll([
+      _isOverrideWithSuper_foo01,
+    ]);
+  }
+
+  Future<void> test_class_method_fromExtends_fromPart() async {
+    newFile('$testPackageLibPath/a.dart', r'''
+part of 'test.dart';
+
+class A {
+  void foo01() {}
+}
+''');
+
+    final response = await getTestCodeSuggestions('''
+part 'a.dart';
+
+class B extends A {
+  foo^
+}
+''');
+
+    check(response).suggestions.overrides.includesAll([
+      _isOverrideWithSuper_foo01,
+    ]);
+  }
+
+  Future<void> test_class_method_fromExtends_multiple() async {
+    final response = await getTestCodeSuggestions('''
+class A {
+  void foo01() {}
+}
+
+class B extends A {
+  void foo02() {}
+}
+
+class C extends B {
+  foo^
+}
+''');
+
+    check(response).suggestions.overrides.includesAll([
+      _isOverrideWithSuper_foo01,
+      _isOverrideWithSuper_foo02,
+    ]);
+  }
+
+  Future<void> test_class_method_fromExtends_private_otherLibrary() async {
+    newFile('$testPackageLibPath/a.dart', r'''
+class A {
+  // ignore:unused_element
+  void _foo01() {}
+  void foo02() {}
+}
+''');
+
+    final response = await getTestCodeSuggestions('''
+import 'a.dart';
+
+class B extends A {
+  foo^
+}
+''');
+
+    check(response).suggestions.overrides
+      ..includesAll([
+        _isOverrideWithSuper_foo02,
+      ])
+      ..excludesAll([
+        _isOverrideWithSuper_private_foo01,
+      ]);
+  }
+
+  Future<void> test_class_method_fromExtends_private_thisLibrary() async {
+    final response = await getTestCodeSuggestions('''
+class A {
+  void _foo01() {}
+  void foo02() {}
+}
+
+class B extends A {
+  foo^
+}
+''');
+
+    check(response).suggestions.overrides.includesAll([
+      _isOverrideWithSuper_private_foo01,
+      _isOverrideWithSuper_foo02,
+    ]);
+  }
+
+  Future<void> test_class_method_fromExtends_withOverride() async {
+    final response = await getTestCodeSuggestions('''
+class A {
+  void foo01() {}
+}
+
+class B extends A {
+  @override
+  foo^
+}
+''');
+
+    check(response).suggestions.overrides.includesAll([
       (suggestion) => suggestion
         ..displayText.isEqualTo('foo01() { … }')
-        ..hasSelection(offset: 60, length: 14)
+        ..hasSelection(offset: 48, length: 14)
         ..completion.isEqualTo(r'''
-@override
-  void foo01() {
+void foo01() {
     // TODO: implement foo01
     super.foo01();
   }'''),
@@ -348,14 +554,7 @@
 ''');
 
     check(response).suggestions.overrides.includesAll([
-      (suggestion) => suggestion
-        ..displayText.isEqualTo('foo01() { … }')
-        ..hasSelection(offset: 55)
-        ..completion.isEqualTo(r'''
-@override
-  void foo01() {
-    // TODO: implement foo01
-  }'''),
+      _isOverrideWithoutSuper_foo01,
     ]);
   }
 
@@ -371,16 +570,175 @@
 ''');
 
     check(response).suggestions.overrides.includesAll([
+      _isOverrideWithSuper_foo01,
+    ]);
+  }
+
+  Future<void> test_class_operator_eqEq() async {
+    final response = await getTestCodeSuggestions('''
+class A {
+  opera^
+}
+''');
+
+    check(response).suggestions.overrides.includesAll([
       (suggestion) => suggestion
-        ..displayText.isEqualTo('foo01() { … }')
-        ..hasSelection(offset: 60, length: 14)
+        ..displayText.isEqualTo('==(Object other) { … }')
+        ..hasSelection(offset: 75, length: 22)
         ..completion.isEqualTo(r'''
 @override
+  bool operator ==(Object other) {
+    // TODO: implement ==
+    return super == other;
+  }'''),
+    ]);
+  }
+
+  Future<void> test_class_operator_plus() async {
+    final response = await getTestCodeSuggestions('''
+class A {
+  int operator +(int other) { }
+}
+
+class B extends A {
+  opera^
+}
+''');
+
+    check(response).suggestions.overrides.includesAll([
+      (suggestion) => suggestion
+        ..displayText.isEqualTo('+(int other) { … }')
+        ..hasSelection(offset: 69, length: 21)
+        ..completion.isEqualTo(r'''
+@override
+  int operator +(int other) {
+    // TODO: implement +
+    return super + other;
+  }'''),
+    ]);
+  }
+
+  Future<void> test_extension_method() async {
+    final response = await getTestCodeSuggestions('''
+class A {
+  void foo01() {}
+}
+
+extension E on A {
+  foo^
+}
+''');
+
+    check(response).suggestions.overrides.isEmpty;
+  }
+
+  Future<void> test_mixin_method_fromConstraints_alreadyOverridden() async {
+    final response = await getTestCodeSuggestions('''
+class A {
+  void foo01() {}
+  void foo02() {}
+}
+
+mixin M on A {
+  void foo02() {}
+  foo^
+}
+''');
+
+    check(response).suggestions.overrides
+      ..includesAll([
+        _isOverrideWithSuper_foo01,
+      ])
+      ..excludesAll([
+        (suggestion) => suggestion.completion.contains('foo02'),
+      ]);
+  }
+
+  Future<void> test_mixin_method_fromImplements() async {
+    final response = await getTestCodeSuggestions('''
+class A {
+  void foo01() {}
+}
+
+mixin M implements A {
+  foo^
+}
+''');
+
+    check(response).suggestions.overrides.includesAll([
+      _isOverrideWithoutSuper_foo01,
+    ]);
+  }
+
+  Future<void> test_mixin_method_fromSuperclassConstraint() async {
+    final response = await getTestCodeSuggestions('''
+class A {
+  void foo01() {}
+}
+
+mixin M on A {
+  foo^
+}
+''');
+
+    check(response).suggestions.overrides.includesAll([
+      _isOverrideWithSuper_foo01,
+    ]);
+  }
+
+  static void _isOverrideWithoutSuper_foo01(
+    CheckTarget<CompletionSuggestionForTesting> suggestion,
+  ) {
+    suggestion
+      ..displayText.isEqualTo('foo01() { … }')
+      ..hasSelection(offset: 55)
+      ..completion.isEqualTo(r'''
+@override
+  void foo01() {
+    // TODO: implement foo01
+  }''');
+  }
+
+  static void _isOverrideWithSuper_foo01(
+    CheckTarget<CompletionSuggestionForTesting> suggestion,
+  ) {
+    suggestion
+      ..displayText.isEqualTo('foo01() { … }')
+      ..hasSelection(offset: 60, length: 14)
+      ..completion.isEqualTo(r'''
+@override
   void foo01() {
     // TODO: implement foo01
     super.foo01();
-  }'''),
-    ]);
+  }''');
+  }
+
+  static void _isOverrideWithSuper_foo02(
+    CheckTarget<CompletionSuggestionForTesting> suggestion,
+  ) {
+    suggestion
+      ..displayText.isEqualTo('foo02() { … }')
+      ..hasSelection(offset: 60, length: 14)
+      ..completion.isEqualTo(r'''
+@override
+  void foo02() {
+    // TODO: implement foo02
+    super.foo02();
+  }''');
+  }
+
+  static void _isOverrideWithSuper_private_foo01(
+    CheckTarget<CompletionSuggestionForTesting> suggestion,
+  ) {
+    suggestion
+      ..displayText.isEqualTo('_foo01() { … }')
+      ..hasSelection(offset: 62, length: 15)
+      ..completion.isEqualTo(r'''
+@override
+  void _foo01() {
+    // TODO: implement _foo01
+    super._foo01();
+  }''');
   }
 }
 
diff --git a/pkg/analysis_server/test/services/completion/dart/override_contributor_test.dart b/pkg/analysis_server/test/services/completion/dart/override_contributor_test.dart
deleted file mode 100644
index 1b0ab51..0000000
--- a/pkg/analysis_server/test/services/completion/dart/override_contributor_test.dart
+++ /dev/null
@@ -1,599 +0,0 @@
-// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
-import 'package:analysis_server/src/services/completion/dart/completion_manager.dart';
-import 'package:analysis_server/src/services/completion/dart/override_contributor.dart';
-import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart';
-import 'package:analyzer_plugin/protocol/protocol_common.dart';
-import 'package:test/test.dart';
-import 'package:test_reflective_loader/test_reflective_loader.dart';
-
-import 'completion_contributor_util.dart';
-
-void main() {
-  defineReflectiveTests(OverrideContributorTest);
-}
-
-@reflectiveTest
-class OverrideContributorTest extends DartCompletionContributorTest {
-  @override
-  DartCompletionContributor createContributor(
-    DartCompletionRequest request,
-    SuggestionBuilder builder,
-  ) {
-    return OverrideContributor(request, builder);
-  }
-
-  Future<void> test_alreadyOverridden() async {
-    addTestSource('''
-class A {
-  void foo() {}
-  void bar() {}
-}
-
-class B implements A {
-  void bar() {}
-  f^
-}
-''');
-    await computeSuggestions();
-    _assertNoOverrideContaining('bar');
-  }
-
-  Future<void> test_beforeGetter() async {
-    addTestSource('''
-class A {
-  method() {}
-  int? age;
-}
-
-class B extends A {
-  m^
-
-  String value1 = '';
-}
-''');
-    await computeSuggestions();
-    _assertOverride('''
-@override
-  method() {
-    // TODO: implement method
-    return super.method();
-  }''',
-        displayText: 'method() { … }',
-        selectionOffset: 57,
-        selectionLength: 22);
-  }
-
-  Future<void> test_beforeMethod() async {
-    addTestSource('''
-class A {
-  method() {}
-  int? age;
-}
-
-class B extends A {
-  m^
-
-  void b() {}
-}
-''');
-    await computeSuggestions();
-    _assertOverride('''
-@override
-  method() {
-    // TODO: implement method
-    return super.method();
-  }''',
-        displayText: 'method() { … }',
-        selectionOffset: 57,
-        selectionLength: 22);
-  }
-
-  Future<void> test_customOperator() async {
-    addTestSource('''
-class A {
-  void operator &(A other) { }
-}
-class B extends A {
-  other^
-}
-''');
-    await computeSuggestions();
-    _assertOverride('''
-@override
-  void operator &(A other) {
-    // TODO: implement &
-    super & other;
-  }''',
-        displayText: '&(A other) { … }',
-        selectionOffset: 68,
-        selectionLength: 14);
-  }
-
-  Future<void> test_equalsOperator() async {
-    addTestSource('''
-class A {
-  other^
-}
-''');
-    await computeSuggestions();
-    _assertOverride('''
-@override
-  bool operator ==(Object other) {
-    // TODO: implement ==
-    return super == other;
-  }''',
-        displayText: '==(Object other) { … }',
-        selectionOffset: 75,
-        selectionLength: 22);
-  }
-
-  Future<void> test_fromMultipleSuperclasses() async {
-    addTestSource(r'''
-class A {
-  A suggested1(int x) => null;
-  B suggested2(String y) => null;
-}
-class B extends A {
-  B suggested2(String y) => null;
-  C suggested3([String z]) => null;
-  void suggested4() { }
-  int get suggested5 => null;
-}
-class C extends B {
-  sugg^
-}
-''');
-    await computeSuggestions();
-    _assertOverride('''
-@override
-  A suggested1(int x) {
-    // TODO: implement suggested1
-    return super.suggested1(x);
-  }''',
-        displayText: 'suggested1(int x) { … }',
-        selectionOffset: 72,
-        selectionLength: 27);
-    _assertOverride('''
-@override
-  A suggested1(int x) {
-    // TODO: implement suggested1
-    return super.suggested1(x);
-  }''',
-        displayText: 'suggested1(int x) { … }',
-        selectionOffset: 72,
-        selectionLength: 27);
-    _assertOverride('''
-@override
-  B suggested2(String y) {
-    // TODO: implement suggested2
-    return super.suggested2(y);
-  }''',
-        displayText: 'suggested2(String y) { … }',
-        selectionOffset: 75,
-        selectionLength: 27);
-    _assertOverride('''
-@override
-  C suggested3([String z]) {
-    // TODO: implement suggested3
-    return super.suggested3(z);
-  }''',
-        displayText: 'suggested3([String z]) { … }',
-        selectionOffset: 77,
-        selectionLength: 27);
-    _assertOverride('''
-@override
-  void suggested4() {
-    // TODO: implement suggested4
-    super.suggested4();
-  }''',
-        displayText: 'suggested4() { … }',
-        selectionOffset: 70,
-        selectionLength: 19);
-    _assertOverride('''
-@override
-  // TODO: implement suggested5
-  int get suggested5 => super.suggested5;''',
-        displayText: 'suggested5 => …',
-        selectionOffset: 66,
-        selectionLength: 16);
-  }
-
-  Future<void> test_fromPart() async {
-    addSource('$testPackageLibPath/myLib.dart', '''
-library myLib;
-part 'test.dart';
-part 'otherPart.dart';
-class A {
-  A suggested1(int x) => null;
-  B suggested2(String y) => null;
-}
-''');
-    addSource('$testPackageLibPath/otherPart.dart', '''
-part of myLib;
-class B extends A {
-  B suggested2(String y) => null;
-  C suggested3([String z]) => null;
-}
-''');
-    addTestSource(r'''
-part of myLib;
-class C extends B {
-  sugg^
-}
-''');
-    // assume information for context.getLibrariesContaining has been cached
-    await resolveFile('$testPackageLibPath/myLib.dart');
-    await computeSuggestions();
-    _assertOverride('''
-@override
-  A suggested1(int x) {
-    // TODO: implement suggested1
-    return super.suggested1(x);
-  }''', displayText: 'suggested1(int x) { … }');
-    _assertOverride('''
-@override
-  A suggested1(int x) {
-    // TODO: implement suggested1
-    return super.suggested1(x);
-  }''',
-        displayText: 'suggested1(int x) { … }',
-        selectionOffset: 72,
-        selectionLength: 27);
-    _assertOverride('''
-@override
-  B suggested2(String y) {
-    // TODO: implement suggested2
-    return super.suggested2(y);
-  }''',
-        displayText: 'suggested2(String y) { … }',
-        selectionOffset: 75,
-        selectionLength: 27);
-    _assertOverride('''
-@override
-  C suggested3([String z]) {
-    // TODO: implement suggested3
-    return super.suggested3(z);
-  }''',
-        displayText: 'suggested3([String z]) { … }',
-        selectionOffset: 77,
-        selectionLength: 27);
-  }
-
-  Future<void> test_inClass_of_interface() async {
-    addTestSource('''
-class A {
-  void foo() {}
-}
-
-class B implements A {
-  f^
-}
-''');
-    await computeSuggestions();
-    _assertOverride('''
-@override
-  void foo() {
-    // TODO: implement foo
-  }''', displayText: 'foo() { … }', selectionOffset: 51, selectionLength: 0);
-  }
-
-  Future<void> test_inComment() async {
-    addTestSource('''
-class A {
-  void foo() {}
-}
-
-class B implements A {
-  // comment^
-  void m() {}
-}
-''');
-    await computeSuggestions();
-    _assertNoOverrideContaining('foo');
-  }
-
-  Future<void> test_inComment_dartdoc() async {
-    addTestSource('''
-class A {
-  void foo() {}
-}
-
-class B implements A {
-  /// dartdoc^
-  void m() {}
-}
-''');
-    await computeSuggestions();
-    _assertNoOverrideContaining('foo');
-  }
-
-  Future<void> test_inComment_reference() async {
-    addTestSource('''
-class A {
-  void foo() {}
-}
-
-class B implements A {
-  /// Asdf [St^]
-  void m() {}
-}
-''');
-    await computeSuggestions();
-    _assertNoOverrideContaining('foo');
-  }
-
-  Future<void> test_inConstructor() async {
-    addTestSource('''
-class A {
-  void foo() {}
-}
-
-class B implements A {
-  var one;
-  B(this.^);
-}
-''');
-    await computeSuggestions();
-    _assertNoOverrideContaining('foo');
-  }
-
-  Future<void> test_inConstructor2() async {
-    addTestSource('''
-class A {
-  void foo() {}
-}
-
-class B implements A {
-  var one;
-  var two;
-  B(this.one, {this.^});
-}
-''');
-    await computeSuggestions();
-    _assertNoOverrideContaining('foo');
-  }
-
-  Future<void> test_inFieldDeclaration_name() async {
-    addTestSource('''
-class A {
-  void foo() {}
-}
-
-class B implements A {
-  final String ^type;
-}
-''');
-    await computeSuggestions();
-    _assertNoOverrideContaining('foo');
-  }
-
-  Future<void> test_inFieldDeclaration_value() async {
-    addTestSource('''
-class A {
-  void foo() {}
-}
-
-class B implements A {
-  final String type = '^';
-}
-''');
-    await computeSuggestions();
-    _assertNoOverrideContaining('foo');
-  }
-
-  Future<void> test_inMixin_of_interface() async {
-    addTestSource('''
-class A {
-  void foo() {}
-}
-
-mixin M implements A {
-  f^
-}
-''');
-    await computeSuggestions();
-    _assertOverride('''
-@override
-  void foo() {
-    // TODO: implement foo
-  }''', displayText: 'foo() { … }', selectionOffset: 51, selectionLength: 0);
-  }
-
-  Future<void> test_inMixin_of_superclassConstraint() async {
-    addTestSource('''
-class A {
-  void foo() {}
-}
-
-mixin M on A {
-  f^
-}
-''');
-    await computeSuggestions();
-    _assertOverride('''
-@override
-  void foo() {
-    // TODO: implement foo
-    super.foo();
-  }''', displayText: 'foo() { … }', selectionOffset: 56, selectionLength: 12);
-  }
-
-  @failingTest
-  Future<void> test_insideBareClass() async {
-    addTestSource('''
-class A {
-  method() {}
-  int age;
-}
-
-class B extends A {
-  ^
-}
-''');
-    await computeSuggestions();
-    _assertOverride('''
-@override
-  method() {
-    // TODO: implement method
-    return super.method();
-  }''',
-        displayText: 'method() { … }',
-        selectionOffset: 57,
-        selectionLength: 22);
-  }
-
-  Future<void> test_outsideOfWorkspace() async {
-    testFile = convertPath('/home/other/lib/a.dart');
-    addTestSource('''
-class A {
-  void foo() {}
-}
-
-class B extends A {
-  f^
-}
-''');
-    await computeSuggestions();
-    _assertNoOverrideContaining('foo');
-  }
-
-  Future<void> test_private_otherLibrary() async {
-    newFile('$testPackageLibPath/a.dart', '''
-class A {
-  void foo() {}
-  void _bar() {}
-}
-''');
-    addTestSource(r'''
-import 'a.dart';
-
-class B extends A {
-  f^
-}
-''');
-    await computeSuggestions();
-
-    _assertOverride('''
-@override
-  void foo() {
-    // TODO: implement foo
-    super.foo();
-  }''', displayText: 'foo() { … }', selectionOffset: 56, selectionLength: 12);
-
-    expect(suggestions, _notSuggestedPredicate((suggestion) {
-      return suggestion.completion.contains('void _bar()');
-    }));
-  }
-
-  Future<void> test_private_thisLibrary() async {
-    addTestSource(r'''
-class A {
-  void foo() {}
-  void _bar() {}
-}
-
-class B extends A {
-  f^
-}
-''');
-    await computeSuggestions();
-
-    _assertOverride('''
-@override
-  void foo() {
-    // TODO: implement foo
-    super.foo();
-  }''', displayText: 'foo() { … }', selectionOffset: 56, selectionLength: 12);
-
-    _assertOverride('''
-@override
-  void _bar() {
-    // TODO: implement _bar
-    super._bar();
-  }''', displayText: '_bar() { … }', selectionOffset: 58, selectionLength: 13);
-  }
-
-  Future<void> test_withExistingOverride() async {
-    addTestSource('''
-class A {
-  method() {}
-  int age;
-}
-
-class B extends A {
-  @override
-  meth^
-}
-''');
-    await computeSuggestions();
-    _assertOverride('''
-method() {
-    // TODO: implement method
-    return super.method();
-  }''',
-        displayText: 'method() { … }',
-        selectionOffset: 45,
-        selectionLength: 22);
-  }
-
-  @failingTest
-  Future<void> test_withOverrideAnnotation() async {
-    addTestSource('''
-class A {
-  method() {}
-  int age;
-}
-
-class B extends A {
-  @override
-  ^
-}
-''');
-    await computeSuggestions();
-    _assertOverride('''
-method() {
-    // TODO: implement method
-    return super.method();
-  }''',
-        displayText: 'method() { … }',
-        selectionOffset: 45,
-        selectionLength: 22);
-  }
-
-  void _assertNoOverrideContaining(String search) {
-    expect(
-        suggestions.where((c) =>
-            c.kind == CompletionSuggestionKind.OVERRIDE &&
-            c.completion.contains(search)),
-        isEmpty);
-  }
-
-  CompletionSuggestion _assertOverride(String completion,
-      {String? displayText, int? selectionOffset, int? selectionLength}) {
-    var cs = getSuggest(
-        completion: completion,
-        csKind: CompletionSuggestionKind.OVERRIDE,
-        elemKind: null);
-    if (cs == null) {
-      failedCompletion('expected $completion', suggestions);
-    }
-    expect(cs.kind, equals(CompletionSuggestionKind.OVERRIDE));
-    if (selectionOffset != null && selectionLength != null) {
-      expect(cs.selectionOffset, selectionOffset);
-      expect(cs.selectionLength, selectionLength);
-    }
-    expect(cs.isDeprecated, isFalse);
-    expect(cs.isPotential, isFalse);
-    expect(cs.element, isNotNull);
-    expect(cs.displayText, displayText);
-    return cs;
-  }
-
-  static Matcher _notSuggestedPredicate(bool Function(CompletionSuggestion) f) {
-    return isNot(contains(predicate(f)));
-  }
-}
diff --git a/pkg/analysis_server/test/services/completion/dart/test_all.dart b/pkg/analysis_server/test/services/completion/dart/test_all.dart
index 29e4a22..041b84c 100644
--- a/pkg/analysis_server/test/services/completion/dart/test_all.dart
+++ b/pkg/analysis_server/test/services/completion/dart/test_all.dart
@@ -19,7 +19,6 @@
 import 'local_reference_contributor_test.dart' as local_ref_test;
 import 'location/test_all.dart' as location;
 import 'named_constructor_contributor_test.dart' as named_contributor_test;
-import 'override_contributor_test.dart' as override_contributor_test;
 import 'relevance/test_all.dart' as relevance_tests;
 import 'static_member_contributor_test.dart' as static_contributor_test;
 import 'type_member_contributor_test.dart' as type_member_contributor_test;
@@ -43,7 +42,6 @@
     local_ref_test.main();
     location.main();
     named_contributor_test.main();
-    override_contributor_test.main();
     relevance_tests.main();
     static_contributor_test.main();
     type_member_contributor_test.main();
diff --git a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
index 1f4cdab..d089ded 100644
--- a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
@@ -962,8 +962,12 @@
       // The name of a NamedType does not provide any context.
       // So, we don't need to resolve anything.
       if (parent is NamedType) {
-        // `{foo^ print(0);}` looks as `foo print; (0);`.
         var parent3 = parent.parent?.parent;
+        // `class A {foo^ int bar = 0;}` looks as `class A {foo int; bar = 0;}`.
+        if (parent3 is FieldDeclaration) {
+          return false;
+        }
+        // `{foo^ print(0);}` looks as `foo print; (0);`.
         if (parent3 is VariableDeclarationStatement &&
             parent3.semicolon.isSynthetic) {
           return false;
diff --git a/pkg/analyzer/test/src/dart/analysis/resolve_for_completion_test.dart b/pkg/analyzer/test/src/dart/analysis/resolve_for_completion_test.dart
index f0f8f69..ac40815 100644
--- a/pkg/analyzer/test/src/dart/analysis/resolve_for_completion_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/resolve_for_completion_test.dart
@@ -28,12 +28,14 @@
     var result = await _resolveTestCode(r'''
 class A {
   var f1 = 0;
-  doub^ f2 = null;
+  dou^ f2 = null;
   var f3 = 1;
 }
 ''');
 
-    result.assertResolvedNodes([]);
+    result.assertResolvedNodes([
+      'dou f2 = null;',
+    ]);
   }
 
   test_class__fieldDeclaration_type_namedType_typeArgument_name() async {
@@ -48,6 +50,19 @@
     result.assertResolvedNodes([]);
   }
 
+  test_class_body_identifier_beforeFieldDeclaration() async {
+    var result = await _resolveTestCode(r'''
+class A {
+  foo^
+  int bar = 0;
+}
+''');
+
+    result.assertResolvedNodes([
+      'foo int;',
+    ]);
+  }
+
   test_class_extends_name() async {
     var result = await _resolveTestCode(r'''
 class A extends foo^ {}