Improve the highlight range for invalid_super_invocation

Change-Id: I8be664802f04def78304b7cc0e8481d734d295e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170040
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/lib/src/task/strong/checker.dart b/pkg/analyzer/lib/src/task/strong/checker.dart
index fa3349b..7db1cf7 100644
--- a/pkg/analyzer/lib/src/task/strong/checker.dart
+++ b/pkg/analyzer/lib/src/task/strong/checker.dart
@@ -258,14 +258,16 @@
 
     final init = node.initializers;
     for (int i = 0, last = init.length - 1; i < last; i++) {
-      final node = init[i];
-      if (node is SuperConstructorInvocation) {
+      final initializer = init[i];
+      if (initializer is SuperConstructorInvocation) {
         // TODO(srawlins): Don't report this when
         //  [CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR] or
         //  [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS] is reported for
         //  this constructor.
-        _recordMessage(
-            node, CompileTimeErrorCode.INVALID_SUPER_INVOCATION, [node]);
+        var source = (node.root as CompilationUnit).declaredElement.source;
+        var token = initializer.superKeyword;
+        reporter.onError(AnalysisError(source, token.offset, token.length,
+            CompileTimeErrorCode.INVALID_SUPER_INVOCATION, [initializer]));
       }
     }
   }
@@ -927,6 +929,8 @@
   }
 
   void _recordMessage(AstNode node, ErrorCode errorCode, List arguments) {
+    // TODO(brianwilkerson) Convert this class to use an ErrorReporter so that
+    //  the logic for converting types is in one place.
     arguments = arguments.map((argument) {
       if (argument is DartType) {
         return argument.getDisplayString(withNullability: false);
diff --git a/pkg/analyzer/test/src/diagnostics/invalid_super_invocation_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_super_invocation_test.dart
index bf48fa1..68f2839 100644
--- a/pkg/analyzer/test/src/diagnostics/invalid_super_invocation_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/invalid_super_invocation_test.dart
@@ -21,7 +21,7 @@
   A(int x) : super(), assert(x != null);
 }
 ''', [
-      error(CompileTimeErrorCode.INVALID_SUPER_INVOCATION, 23, 7),
+      error(CompileTimeErrorCode.INVALID_SUPER_INVOCATION, 23, 5),
     ]);
   }
 
@@ -32,7 +32,7 @@
   A() : super(), x = 1;
 }
 ''', [
-      error(CompileTimeErrorCode.INVALID_SUPER_INVOCATION, 33, 7),
+      error(CompileTimeErrorCode.INVALID_SUPER_INVOCATION, 33, 5),
     ]);
   }
 }
diff --git a/pkg/analyzer/test/src/diagnostics/multiple_super_initializers_test.dart b/pkg/analyzer/test/src/diagnostics/multiple_super_initializers_test.dart
index dea4b59..8147f29 100644
--- a/pkg/analyzer/test/src/diagnostics/multiple_super_initializers_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/multiple_super_initializers_test.dart
@@ -22,7 +22,7 @@
   B() : super(), super() {}
 }
 ''', [
-      error(CompileTimeErrorCode.INVALID_SUPER_INVOCATION, 39, 7),
+      error(CompileTimeErrorCode.INVALID_SUPER_INVOCATION, 39, 5),
       error(CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS, 48, 7),
     ]);
   }
diff --git a/pkg/analyzer/test/src/diagnostics/super_in_redirecting_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/super_in_redirecting_constructor_test.dart
index cbd6cdd..9fafaa1 100644
--- a/pkg/analyzer/test/src/diagnostics/super_in_redirecting_constructor_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/super_in_redirecting_constructor_test.dart
@@ -33,7 +33,7 @@
   A.name() {}
 }
 ''', [
-      error(CompileTimeErrorCode.INVALID_SUPER_INVOCATION, 18, 7),
+      error(CompileTimeErrorCode.INVALID_SUPER_INVOCATION, 18, 5),
       error(CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR, 18, 7),
     ]);
   }
diff --git a/pkg/analyzer/test/src/task/strong/checker_test.dart b/pkg/analyzer/test/src/task/strong/checker_test.dart
index b71fb4b..c8fda9d 100644
--- a/pkg/analyzer/test/src/task/strong/checker_test.dart
+++ b/pkg/analyzer/test/src/task/strong/checker_test.dart
@@ -4522,7 +4522,7 @@
 
 main() => new Derived();
 ''', [
-      error(CompileTimeErrorCode.INVALID_SUPER_INVOCATION, 170, 7),
+      error(CompileTimeErrorCode.INVALID_SUPER_INVOCATION, 170, 5),
     ]);
   }
 
diff --git a/tests/language/variable/initializer_super_last_test.dart b/tests/language/variable/initializer_super_last_test.dart
index 5a96d03..7e2b0b8 100644
--- a/tests/language/variable/initializer_super_last_test.dart
+++ b/tests/language/variable/initializer_super_last_test.dart
@@ -39,7 +39,7 @@
   C.cc09(int x)
       : //
         super(),
-//      ^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         x = x;
         //^
@@ -47,7 +47,7 @@
   C.cc10(int x)
       : //
         super.named(),
-//      ^^^^^^^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         x = x;
         //^
@@ -55,7 +55,7 @@
   C.cc11(this.x)
       : //
         super(),
-//      ^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         assert(x == x);
 //      ^
@@ -63,7 +63,7 @@
   C.cc12(this.x)
       : //
         super.named(),
-//      ^^^^^^^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         assert(x == x);
 //      ^
@@ -71,7 +71,7 @@
   C.cc13(int x)
       : //
         super(),
-//      ^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         x = x,
         //^
@@ -82,7 +82,7 @@
   C.cc14(int x)
       : //
         super.named(),
-//      ^^^^^^^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         x = x,
         //^
@@ -93,7 +93,7 @@
   C.cc15(int x)
       : x = x,
         super(),
-//      ^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         assert(x == x);
 //      ^
@@ -101,7 +101,7 @@
   C.cc16(int x)
       : x = x,
         super.named(),
-//      ^^^^^^^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         assert(x == x);
 //      ^
@@ -132,7 +132,7 @@
   const C.cc25(int x)
       : //
         super(),
-//      ^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         x = x;
         //^
@@ -140,7 +140,7 @@
   const C.cc26(int x)
       : //
         super.named(),
-//      ^^^^^^^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         x = x;
         //^
@@ -148,7 +148,7 @@
   const C.cc27(this.x)
       : //
         super(),
-//      ^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         assert(x == x);
 //      ^
@@ -156,7 +156,7 @@
   const C.cc28(this.x)
       : //
         super.named(),
-//      ^^^^^^^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         assert(x == x);
 //      ^
@@ -164,7 +164,7 @@
   const C.cc29(int x)
       : //
         super(),
-//      ^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         x = x,
         //^
@@ -175,7 +175,7 @@
   const C.cc30(int x)
       : //
         super.named(),
-//      ^^^^^^^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         x = x,
         //^
@@ -186,7 +186,7 @@
   const C.cc31(int x)
       : x = x,
         super(),
-//      ^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         assert(x == x);
 //      ^
@@ -194,7 +194,7 @@
   const C.cc32(int x)
       : x = x,
         super.named(),
-//      ^^^^^^^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         assert(x == x);
 //      ^
diff --git a/tests/language_2/variable/initializer_super_last_test.dart b/tests/language_2/variable/initializer_super_last_test.dart
index 5a96d03..7e2b0b8 100644
--- a/tests/language_2/variable/initializer_super_last_test.dart
+++ b/tests/language_2/variable/initializer_super_last_test.dart
@@ -39,7 +39,7 @@
   C.cc09(int x)
       : //
         super(),
-//      ^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         x = x;
         //^
@@ -47,7 +47,7 @@
   C.cc10(int x)
       : //
         super.named(),
-//      ^^^^^^^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         x = x;
         //^
@@ -55,7 +55,7 @@
   C.cc11(this.x)
       : //
         super(),
-//      ^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         assert(x == x);
 //      ^
@@ -63,7 +63,7 @@
   C.cc12(this.x)
       : //
         super.named(),
-//      ^^^^^^^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         assert(x == x);
 //      ^
@@ -71,7 +71,7 @@
   C.cc13(int x)
       : //
         super(),
-//      ^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         x = x,
         //^
@@ -82,7 +82,7 @@
   C.cc14(int x)
       : //
         super.named(),
-//      ^^^^^^^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         x = x,
         //^
@@ -93,7 +93,7 @@
   C.cc15(int x)
       : x = x,
         super(),
-//      ^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         assert(x == x);
 //      ^
@@ -101,7 +101,7 @@
   C.cc16(int x)
       : x = x,
         super.named(),
-//      ^^^^^^^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         assert(x == x);
 //      ^
@@ -132,7 +132,7 @@
   const C.cc25(int x)
       : //
         super(),
-//      ^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         x = x;
         //^
@@ -140,7 +140,7 @@
   const C.cc26(int x)
       : //
         super.named(),
-//      ^^^^^^^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         x = x;
         //^
@@ -148,7 +148,7 @@
   const C.cc27(this.x)
       : //
         super(),
-//      ^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         assert(x == x);
 //      ^
@@ -156,7 +156,7 @@
   const C.cc28(this.x)
       : //
         super.named(),
-//      ^^^^^^^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         assert(x == x);
 //      ^
@@ -164,7 +164,7 @@
   const C.cc29(int x)
       : //
         super(),
-//      ^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         x = x,
         //^
@@ -175,7 +175,7 @@
   const C.cc30(int x)
       : //
         super.named(),
-//      ^^^^^^^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         x = x,
         //^
@@ -186,7 +186,7 @@
   const C.cc31(int x)
       : x = x,
         super(),
-//      ^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         assert(x == x);
 //      ^
@@ -194,7 +194,7 @@
   const C.cc32(int x)
       : x = x,
         super.named(),
-//      ^^^^^^^^^^^^^
+//      ^^^^^
 // [analyzer] COMPILE_TIME_ERROR.INVALID_SUPER_INVOCATION
         assert(x == x);
 //      ^