diff --git a/Src/CSharpier.Tests/TestFiles/TypeParameterConstraintClause/TypeParameterConstraintClauses.cst b/Src/CSharpier.Tests/TestFiles/TypeParameterConstraintClause/TypeParameterConstraintClauses.cst index c51401acb..b7d25e781 100644 --- a/Src/CSharpier.Tests/TestFiles/TypeParameterConstraintClause/TypeParameterConstraintClauses.cst +++ b/Src/CSharpier.Tests/TestFiles/TypeParameterConstraintClause/TypeParameterConstraintClauses.cst @@ -10,16 +10,49 @@ class ClassName where T : class } } + public static ReturnType MethodName() + where T : class + where U : class + { + return; + } + public static ReturnType MethodName() where T : class where U : class { } public static ReturnType MethodName(string parameter) where T : class - where U : class { } + where U : class + { + return; + } + + public static ReturnType MethodName( + string longParameter_______________________, + string longParameter_______________________ + ) where T : class + { + return; + } + + public static ReturnType MethodName( + string longParameter_______________________, + string longParameter_______________________ + ) where T : class { } public static ReturnType MethodName( - string reallyLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongParameterIMeanIt + string longParameter_______________________, + string longParameter_______________________ + ) where T : class + where U : class + { + return; + } + + public static ReturnType MethodName( + string longParameter_______________________, + string longParameter_______________________ ) where T : class where U : class { } } @@ -28,6 +61,16 @@ interface InterfaceName where T : class { } struct Struct where T : class { } +class ClassName + where N : new() + where C : class + where T : IComparable + where TT : IList + where L : class, new() +{ + private string x; +} + class ClassName where N : new() where C : class diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs index 074d7552a..2d1b30095 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs @@ -19,7 +19,7 @@ public static Doc Print(CSharpSyntaxNode node) ExplicitInterfaceSpecifierSyntax? explicitInterfaceSpecifier = null; TypeParameterListSyntax? typeParameterList = null; Doc identifier = Doc.Null; - var constraintClauses = Enumerable.Empty(); + SyntaxList? constraintClauses = null; ParameterListSyntax? parameterList = null; ConstructorInitializerSyntax? constructorInitializer = null; BlockSyntax? body = null; @@ -159,7 +159,7 @@ public static Doc Print(CSharpSyntaxNode node) ); } - if (modifiers.HasValue && modifiers.Value.Count > 0) + if (modifiers is { Count: > 0 }) { docs.Add(Token.PrintLeadingTrivia(modifiers.Value[0])); } @@ -170,15 +170,20 @@ public static Doc Print(CSharpSyntaxNode node) docs.Add(Doc.Group(declarationGroup)); - docs.Add( - groupId != null - ? ConstraintClauses.PrintWithConditionalSpace(constraintClauses, groupId) - : ConstraintClauses.Print(constraintClauses) - ); + if (constraintClauses != null) + { + docs.Add( + groupId != null + ? ConstraintClauses.PrintWithConditionalSpace(constraintClauses, groupId) + : ConstraintClauses.Print(constraintClauses) + ); + } + if (body != null) { docs.Add( groupId != null + && (constraintClauses == null || constraintClauses.Value.Count == 0) ? Block.PrintWithConditionalSpace(body, groupId) : Block.Print(body) );