Change WRONG_NUMBER_OF_TYPE_ARGUMENTS_CONSTRUCTOR to use `.new` consistently.

This changes the behavior of the
CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS_CONSTRUCTOR error
so that instead of referring to unnamed constructors with a clumsy
trailing `.` (e.g. `The constructor 'Foo.'`), it refers to them in the
same way the user's code refers to them (so, e.g. if the user's code
refers to the constructor using the name "new", the error message does
too).

Change-Id: Ib29b64ce0122d8928b3a59f5e0125561da8f73d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216840
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
diff --git a/pkg/analyzer/lib/src/dart/resolver/ast_rewrite.dart b/pkg/analyzer/lib/src/dart/resolver/ast_rewrite.dart
index 875fa4b..25dfe1a 100644
--- a/pkg/analyzer/lib/src/dart/resolver/ast_rewrite.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/ast_rewrite.dart
@@ -383,7 +383,7 @@
       _errorReporter.reportErrorForNode(
           CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS_CONSTRUCTOR,
           typeArguments,
-          [classElement.name, constructorElement.name]);
+          [typeNameIdentifier.toString(), constructorIdentifier.name]);
     }
 
     var typeName = astFactory.namedType(
@@ -501,7 +501,7 @@
       _errorReporter.reportErrorForNode(
           CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS_CONSTRUCTOR,
           typeArguments,
-          [classElement.name, constructorElement.name]);
+          [typeIdentifier.name, constructorIdentifier.name]);
     }
     var typeName = astFactory.namedType(name: typeIdentifier);
     var constructorName = astFactory.constructorName(
diff --git a/pkg/analyzer/test/src/dart/resolution/ast_rewrite_test.dart b/pkg/analyzer/test/src/dart/resolution/ast_rewrite_test.dart
index cec815e..800bc3e 100644
--- a/pkg/analyzer/test/src/dart/resolution/ast_rewrite_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/ast_rewrite_test.dart
@@ -190,7 +190,7 @@
 ''', [
       error(CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS_CONSTRUCTOR, 50,
           5,
-          messageContains: "The constructor 'A.named'"),
+          messageContains: "The constructor 'prefix.A.named'"),
     ]);
 
     var importFind = findElement.importFind('package:test/a.dart');
@@ -229,7 +229,7 @@
 ''', [
       error(CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS_CONSTRUCTOR, 48,
           5,
-          messageContains: "The constructor 'A.'"),
+          messageContains: "The constructor 'prefix.A.new'"),
     ]);
 
     var importFind = findElement.importFind('package:test/a.dart');
@@ -382,7 +382,7 @@
 ''', [
       error(CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS_CONSTRUCTOR, 48,
           13,
-          messageContains: "The constructor 'A.'"),
+          messageContains: "The constructor 'A.new'"),
     ]);
 
     var creation = findNode.instanceCreation('new<int, String>(0);');