Macro. Tests for 'typeParameters' in FunctionTypeAnnotation.

Some renames in implementation.

Change-Id: Ib8860d8574061c3d3681f4ff2b6676291a257138
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351640
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/summary2/macro_declarations.dart b/pkg/analyzer/lib/src/summary2/macro_declarations.dart
index 11b803f..19b077b 100644
--- a/pkg/analyzer/lib/src/summary2/macro_declarations.dart
+++ b/pkg/analyzer/lib/src/summary2/macro_declarations.dart
@@ -768,11 +768,11 @@
           isNullable: type.nullabilitySuffix == NullabilitySuffix.question,
           namedParameters: type.parameters
               .where((e) => e.isNamed)
-              .map(_functionTypeFormalParameter)
+              .map(_formalParameter)
               .toList(),
           positionalParameters: type.parameters
               .where((e) => e.isPositional)
-              .map(_functionTypeFormalParameter)
+              .map(_formalParameter)
               .toList(),
           returnType: _dartType(type.returnType),
           typeParameters: _typeParameters(type.typeFormals),
@@ -876,7 +876,20 @@
     );
   }
 
-  macro.FormalParameterDeclarationImpl _formalParameter(
+  macro.FormalParameterImpl _formalParameter(
+    ParameterElement element,
+  ) {
+    return macro.FormalParameterImpl(
+      id: macro.RemoteInstance.uniqueId,
+      isNamed: element.isNamed,
+      isRequired: element.isRequired,
+      metadata: _buildMetadata(element),
+      name: element.name,
+      type: _dartType(element.type),
+    );
+  }
+
+  macro.FormalParameterDeclarationImpl _formalParameterDeclaration(
       ParameterElement element) {
     return macro.FormalParameterDeclarationImpl(
       id: macro.RemoteInstance.uniqueId,
@@ -908,19 +921,6 @@
     );
   }
 
-  macro.FormalParameterImpl _functionTypeFormalParameter(
-    ParameterElement element,
-  ) {
-    return macro.FormalParameterImpl(
-      id: macro.RemoteInstance.uniqueId,
-      isNamed: element.isNamed,
-      isRequired: element.isRequired,
-      metadata: _buildMetadata(element),
-      name: element.name,
-      type: _dartType(element.type),
-    );
-  }
-
   macro.NamedTypeAnnotationImpl _interfaceType(InterfaceType type) {
     return macro.NamedTypeAnnotationImpl(
       id: macro.RemoteInstance.uniqueId,
@@ -974,7 +974,7 @@
   ) {
     return elements
         .where((element) => element.isNamed)
-        .map(_formalParameter)
+        .map(_formalParameterDeclaration)
         .toList();
   }
 
@@ -983,7 +983,7 @@
   ) {
     return elements
         .where((element) => element.isPositional)
-        .map(_formalParameter)
+        .map(_formalParameterDeclaration)
         .toList();
   }
 
@@ -1543,7 +1543,7 @@
 
   (
     List<macro.FormalParameterDeclarationImpl>,
-    List<macro.FormalParameterDeclarationImpl>
+    List<macro.FormalParameterDeclarationImpl>,
   ) _executableFormalParameters(
     ExecutableElement element,
     ast.FormalParameterList? node,
@@ -1553,7 +1553,7 @@
     if (node != null) {
       var elementLocation = ElementTypeLocation(element);
       for (var (index, node) in node.parameters.indexed) {
-        var formalParameter = _formalParameter(
+        var formalParameter = _formalParameterDeclaration(
           node,
           FormalParameterTypeLocation(elementLocation, index),
         );
@@ -1567,7 +1567,34 @@
     return (named, positional);
   }
 
-  macro.FormalParameterDeclarationImpl _formalParameter(
+  macro.FormalParameterImpl _formalParameter(
+    ast.FormalParameter node,
+    TypeAnnotationLocation location,
+  ) {
+    if (node is ast.DefaultFormalParameter) {
+      node = node.parameter;
+    }
+
+    final element = node.declaredElement!;
+
+    final macro.TypeAnnotationImpl typeAnnotation;
+    if (node is ast.SimpleFormalParameter) {
+      typeAnnotation = _typeAnnotationOrDynamic(node.type, location);
+    } else {
+      throw UnimplementedError('(${node.runtimeType}) $node');
+    }
+
+    return macro.FormalParameterImpl(
+      id: macro.RemoteInstance.uniqueId,
+      isNamed: node.isNamed,
+      isRequired: node.isRequired,
+      metadata: _buildMetadata(element),
+      name: node.name?.lexeme,
+      type: typeAnnotation,
+    );
+  }
+
+  macro.FormalParameterDeclarationImpl _formalParameterDeclaration(
     ast.FormalParameter node,
     TypeAnnotationLocation location,
   ) {
@@ -1598,30 +1625,36 @@
     );
   }
 
-  macro.FormalParameterImpl _functionTypeFormalParameter(
-    ast.FormalParameter node,
+  _FunctionTypeAnnotation _functionType(
+    ast.GenericFunctionTypeImpl node,
     TypeAnnotationLocation location,
   ) {
-    if (node is ast.DefaultFormalParameter) {
-      node = node.parameter;
+    var namedParameters = <macro.FormalParameterImpl>[];
+    var positionalParameters = <macro.FormalParameterImpl>[];
+    var formalParameters = node.parameters.parameters;
+    for (var (index, node) in formalParameters.indexed) {
+      var formalParameter = _formalParameter(
+        node,
+        FormalParameterTypeLocation(location, index),
+      );
+      if (node.isNamed) {
+        namedParameters.add(formalParameter);
+      } else {
+        positionalParameters.add(formalParameter);
+      }
     }
 
-    final element = node.declaredElement!;
-
-    final macro.TypeAnnotationImpl typeAnnotation;
-    if (node is ast.SimpleFormalParameter) {
-      typeAnnotation = _typeAnnotationOrDynamic(node.type, location);
-    } else {
-      throw UnimplementedError('(${node.runtimeType}) $node');
-    }
-
-    return macro.FormalParameterImpl(
+    return _FunctionTypeAnnotation(
       id: macro.RemoteInstance.uniqueId,
-      isNamed: node.isNamed,
-      isRequired: node.isRequired,
-      metadata: _buildMetadata(element),
-      name: node.name?.lexeme,
-      type: typeAnnotation,
+      isNullable: node.question != null,
+      namedParameters: namedParameters,
+      positionalParameters: positionalParameters,
+      returnType: _typeAnnotationOrDynamic(
+        node.returnType,
+        ReturnTypeLocation(location),
+      ),
+      typeParameters: _typeParameters(node.typeParameters),
+      location: location,
     );
   }
 
@@ -1705,33 +1738,7 @@
     node as ast.TypeAnnotationImpl;
     switch (node) {
       case ast.GenericFunctionTypeImpl():
-        var namedParameters = <macro.FormalParameterImpl>[];
-        var positionalParameters = <macro.FormalParameterImpl>[];
-        var formalParameters = node.parameters.parameters;
-        for (var (index, node) in formalParameters.indexed) {
-          var formalParameter = _functionTypeFormalParameter(
-            node,
-            FormalParameterTypeLocation(location, index),
-          );
-          if (node.isNamed) {
-            namedParameters.add(formalParameter);
-          } else {
-            positionalParameters.add(formalParameter);
-          }
-        }
-
-        return _FunctionTypeAnnotation(
-          id: macro.RemoteInstance.uniqueId,
-          isNullable: node.question != null,
-          namedParameters: namedParameters,
-          positionalParameters: positionalParameters,
-          returnType: _typeAnnotationOrDynamic(
-            node.returnType,
-            ReturnTypeLocation(location),
-          ),
-          typeParameters: _typeParameters(node.typeParameters),
-          location: location,
-        );
+        return _functionType(node, location);
       case ast.NamedTypeImpl():
         return _namedType(node, location);
       case ast.RecordTypeAnnotationImpl():
diff --git a/pkg/analyzer/test/src/summary/macro_test.dart b/pkg/analyzer/test/src/summary/macro_test.dart
index ce004d0..8147432 100644
--- a/pkg/analyzer/test/src/summary/macro_test.dart
+++ b/pkg/analyzer/test/src/summary/macro_test.dart
@@ -6621,13 +6621,19 @@
 ''');
   }
 
-  @SkippedTest(issue: 'https://github.com/dart-lang/language/issues/3559')
   test_functionType_typeParameters() async {
     newFile('$testPackageLibPath/a.dart', r'''
 void foo(void Function<T, U extends num>() t) {}
 ''');
 
     await _assertIntrospectText('foo', r'''
+foo
+  flags: hasBody
+  positionalParameters
+    t
+      flags: isRequired
+      type: void Function<T, U extends num>()
+  returnType: void
 ''');
   }
 
@@ -8895,6 +8901,17 @@
 ''');
   }
 
+  test_functionType_typeParameters() async {
+    await _assertIntrospectText(r'''
+@Introspect()
+class A extends B<void Function<T, U extends num>()> {}
+''', r'''
+class A
+  superclass: B<void Function<T, U extends num>()>
+    noDeclaration
+''');
+  }
+
   test_functionTypeAnnotation_formalParameters_namedOptional_simpleFormalParameter() async {
     await _assertIntrospectText(r'''
 @Introspect()