[messages] Use analyzerCodeReference more.

Updates some of the logic in `analyzer_messages.dart` to make use of
the getter `AnalyzerCode.analyzerCodeReference`. There is no change in
the generated code.

This paves the way for a follow-up CL that will move the declarations
of the analyzer diagnostic constants out of classes like
`CompileTimeErrorCode` and to top level constants. When that move
happens, references to these constants will need to be
changed. Consolidating more of the logic in `analyzer_messages.dart`
to use `analyzerCodeReference` reduces the number of places in the
code generator that will need to be updated in order to change these
references.

Change-Id: I6a6a6964534cb68074f316c4f2c914e957b37528
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461144
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/tool/messages/generate.dart b/pkg/analyzer/tool/messages/generate.dart
index bed572c..d597ab6 100644
--- a/pkg/analyzer/tool/messages/generate.dart
+++ b/pkg/analyzer/tool/messages/generate.dart
@@ -160,9 +160,7 @@
     for (var message
         in diagnosticTables.activeMessagesByPackage[AnalyzerDiagnosticPackage
             .analyzer]!) {
-      var analyzerCode = message.analyzerCode;
-      var diagnosticName = analyzerCode.camelCaseName;
-      out.writeln('  ${analyzerCode.diagnosticClass.name}.$diagnosticName,');
+      out.writeln('  ${message.analyzerCode.analyzerCodeReference},');
     }
     out.writeln('];');
     out.writeln();
diff --git a/pkg/analyzer_utilities/lib/analyzer_messages.dart b/pkg/analyzer_utilities/lib/analyzer_messages.dart
index 646837d..9baac51 100644
--- a/pkg/analyzer_utilities/lib/analyzer_messages.dart
+++ b/pkg/analyzer_utilities/lib/analyzer_messages.dart
@@ -632,7 +632,7 @@
           '''
 static LocatableDiagnostic $withArgumentsName({$withArgumentsParams}) {
   return LocatableDiagnosticImpl(
-    ${diagnosticClassInfo.name}.$constantName, [$argumentNames]);
+    ${analyzerCode.analyzerCodeReference}, [$argumentNames]);
 }''';
     }