Skip to content

Commit

Permalink
Break after type constraints for method declarations. It keeps things…
Browse files Browse the repository at this point in the history
… more consistent (#365)

* Break after type constraints for method declarations. It keeps things more consistent

closes #299

* Adding back test cases with empty Blocks
  • Loading branch information
belav authored Jul 24, 2021
1 parent f7b994d commit dfc0d2a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,49 @@ class ClassName<T> where T : class
}
}

public static ReturnType<T> MethodName<T, U>()
where T : class
where U : class
{
return;
}

public static ReturnType<T> MethodName<T, U>()
where T : class
where U : class { }

public static ReturnType<T> MethodName<T, U>(string parameter)
where T : class
where U : class { }
where U : class
{
return;
}

public static ReturnType<T> MethodName<T, U>(
string longParameter_______________________,
string longParameter_______________________
) where T : class
{
return;
}

public static ReturnType<T> MethodName<T, U>(
string longParameter_______________________,
string longParameter_______________________
) where T : class { }

public static ReturnType<T> MethodName<T, U>(
string reallyLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongParameterIMeanIt
string longParameter_______________________,
string longParameter_______________________
) where T : class
where U : class
{
return;
}

public static ReturnType<T> MethodName<T, U>(
string longParameter_______________________,
string longParameter_______________________
) where T : class
where U : class { }
}
Expand All @@ -28,6 +61,16 @@ interface InterfaceName<T> where T : class { }

struct Struct<T> where T : class { }

class ClassName<N, C, T, TT, L>
where N : new()
where C : class
where T : IComparable
where TT : IList<N>
where L : class, new()
{
private string x;
}

class ClassName<N, C, T, TT, L>
where N : new()
where C : class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static Doc Print(CSharpSyntaxNode node)
ExplicitInterfaceSpecifierSyntax? explicitInterfaceSpecifier = null;
TypeParameterListSyntax? typeParameterList = null;
Doc identifier = Doc.Null;
var constraintClauses = Enumerable.Empty<TypeParameterConstraintClauseSyntax>();
SyntaxList<TypeParameterConstraintClauseSyntax>? constraintClauses = null;
ParameterListSyntax? parameterList = null;
ConstructorInitializerSyntax? constructorInitializer = null;
BlockSyntax? body = null;
Expand Down Expand Up @@ -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]));
}
Expand All @@ -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)
);
Expand Down

0 comments on commit dfc0d2a

Please sign in to comment.