@@ -1556,7 +1556,18 @@ class SourceVisitor extends ThrowingAstVisitor {
1556
1556
1557
1557
@override
1558
1558
void visitFunctionDeclaration (FunctionDeclaration node) {
1559
- _visitMemberDeclaration (node, node.functionExpression);
1559
+ _visitFunctionOrMethodDeclaration (
1560
+ metadata: node.metadata,
1561
+ externalKeyword: node.externalKeyword,
1562
+ propertyKeyword: node.propertyKeyword,
1563
+ modifierKeyword: null ,
1564
+ operatorKeyword: null ,
1565
+ name: node.name,
1566
+ returnType: node.returnType,
1567
+ typeParameters: node.functionExpression.typeParameters,
1568
+ formalParameters: node.functionExpression.parameters,
1569
+ body: node.functionExpression.body,
1570
+ );
1560
1571
}
1561
1572
1562
1573
@override
@@ -2054,7 +2065,18 @@ class SourceVisitor extends ThrowingAstVisitor {
2054
2065
2055
2066
@override
2056
2067
void visitMethodDeclaration (MethodDeclaration node) {
2057
- _visitMemberDeclaration (node, node);
2068
+ _visitFunctionOrMethodDeclaration (
2069
+ metadata: node.metadata,
2070
+ externalKeyword: node.externalKeyword,
2071
+ propertyKeyword: node.propertyKeyword,
2072
+ modifierKeyword: node.modifierKeyword,
2073
+ operatorKeyword: node.operatorKeyword,
2074
+ name: node.name,
2075
+ returnType: node.returnType,
2076
+ typeParameters: node.typeParameters,
2077
+ formalParameters: node.parameters,
2078
+ body: node.body,
2079
+ );
2058
2080
}
2059
2081
2060
2082
@override
@@ -2795,41 +2817,41 @@ class SourceVisitor extends ThrowingAstVisitor {
2795
2817
}
2796
2818
2797
2819
/// Visits a top-level function or method declaration.
2798
- ///
2799
- /// The two AST node types are very similar but, alas, share no common
2800
- /// interface type in analyzer, hence the dynamic typing.
2801
- void _visitMemberDeclaration (/* FunctionDeclaration|MethodDeclaration */ node,
2802
- /* FunctionExpression|MethodDeclaration */ function) {
2803
- visitMetadata (node.metadata as NodeList <Annotation >);
2820
+ void _visitFunctionOrMethodDeclaration ({
2821
+ required NodeList <Annotation > metadata,
2822
+ required Token ? externalKeyword,
2823
+ required Token ? propertyKeyword,
2824
+ required Token ? modifierKeyword,
2825
+ required Token ? operatorKeyword,
2826
+ required Token name,
2827
+ required TypeAnnotation ? returnType,
2828
+ required TypeParameterList ? typeParameters,
2829
+ required FormalParameterList ? formalParameters,
2830
+ required FunctionBody body,
2831
+ }) {
2832
+ visitMetadata (metadata);
2804
2833
2805
2834
// Nest the signature in case we have to split between the return type and
2806
2835
// name.
2807
2836
builder.nestExpression ();
2808
2837
builder.startSpan ();
2809
- modifier (node. externalKeyword);
2810
- if (node is MethodDeclaration ) modifier (node. modifierKeyword);
2811
- visit (node. returnType, after: soloSplit);
2812
- modifier (node. propertyKeyword);
2813
- if (node is MethodDeclaration ) modifier (node. operatorKeyword);
2814
- token (node.name2 );
2838
+ modifier (externalKeyword);
2839
+ modifier (modifierKeyword);
2840
+ visit (returnType, after: soloSplit);
2841
+ modifier (propertyKeyword);
2842
+ modifier (operatorKeyword);
2843
+ token (name );
2815
2844
builder.endSpan ();
2816
2845
2817
- TypeParameterList ? typeParameters;
2818
- if (node is FunctionDeclaration ) {
2819
- typeParameters = node.functionExpression.typeParameters;
2820
- } else {
2821
- typeParameters = (node as MethodDeclaration ).typeParameters;
2822
- }
2823
-
2824
- _visitFunctionBody (typeParameters, function.parameters, function.body, () {
2846
+ _visitFunctionBody (typeParameters, formalParameters, body, () {
2825
2847
// If the body is a block, we need to exit nesting before we hit the body
2826
2848
// indentation, but we do want to wrap it around the parameters.
2827
- if (function. body is ! ExpressionFunctionBody ) builder.unnest ();
2849
+ if (body is ! ExpressionFunctionBody ) builder.unnest ();
2828
2850
});
2829
2851
2830
2852
// If it's an expression, we want to wrap the nesting around that so that
2831
2853
// the body gets nested farther.
2832
- if (function. body is ExpressionFunctionBody ) builder.unnest ();
2854
+ if (body is ExpressionFunctionBody ) builder.unnest ();
2833
2855
}
2834
2856
2835
2857
/// Visit the given function [parameters] followed by its [body] , printing a
0 commit comments