From 180542ae35e81842c21d802b325206ec6f087cc0 Mon Sep 17 00:00:00 2001 From: belav Date: Sun, 11 Apr 2021 11:37:41 -0500 Subject: [PATCH] arrow expression methods closes #58 --- .../LongConstructor.cst | 3 +- .../FunctionPointerTypes.cst | 7 ++- .../MethodDeclaration/BasicMethod.cst | 4 -- .../ExplicitlyInterfaceSpecifierMethod.cst | 4 -- .../LongMethodWithParameters.cst | 12 ---- .../MethodDeclaration/MethodComments.cst | 11 ---- .../MethodDeclaration/MethodDeclarations.cst | 57 +++++++++++++++++++ .../MethodWithParameters.cst | 4 -- .../MethodWithStatements.cst | 8 --- .../_MethodDeclarationTests.cs | 32 +---------- .../RecordDeclaration/RecordDeclarations.cst | 4 +- .../Printer/ArrowExpressionClauseSyntax.cs | 6 +- Src/CSharpier/Printer/ParameterListSyntax.cs | 17 +++--- 13 files changed, 80 insertions(+), 89 deletions(-) delete mode 100644 Src/CSharpier.Tests/TestFiles/MethodDeclaration/BasicMethod.cst delete mode 100644 Src/CSharpier.Tests/TestFiles/MethodDeclaration/ExplicitlyInterfaceSpecifierMethod.cst delete mode 100644 Src/CSharpier.Tests/TestFiles/MethodDeclaration/LongMethodWithParameters.cst delete mode 100644 Src/CSharpier.Tests/TestFiles/MethodDeclaration/MethodComments.cst create mode 100644 Src/CSharpier.Tests/TestFiles/MethodDeclaration/MethodDeclarations.cst delete mode 100644 Src/CSharpier.Tests/TestFiles/MethodDeclaration/MethodWithParameters.cst delete mode 100644 Src/CSharpier.Tests/TestFiles/MethodDeclaration/MethodWithStatements.cst diff --git a/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/LongConstructor.cst b/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/LongConstructor.cst index 27342c7a8..ebb544859 100644 --- a/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/LongConstructor.cst +++ b/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/LongConstructor.cst @@ -2,5 +2,6 @@ public class LongConstructorClass { public LongConstructorClass( string oneoneoneoneoneoneone, - string twotwotwotwotwotwo) { } + string twotwotwotwotwotwo + ) { } } diff --git a/Src/CSharpier.Tests/TestFiles/FunctionPointerType/FunctionPointerTypes.cst b/Src/CSharpier.Tests/TestFiles/FunctionPointerType/FunctionPointerTypes.cst index 847ea3349..e789622f6 100644 --- a/Src/CSharpier.Tests/TestFiles/FunctionPointerType/FunctionPointerTypes.cst +++ b/Src/CSharpier.Tests/TestFiles/FunctionPointerType/FunctionPointerTypes.cst @@ -13,12 +13,13 @@ class ClassName int, NativeMethods.REQUEST_NOTIFICATION_STATUS> asyncCallback, delegate* unmanaged requestsDrainedHandler, - IntPtr pvRequestContext) - { + IntPtr pvRequestContext + ) { return; } public static extern unsafe int InvokeCallbackFuncPtr_Inline_NoGCTransition( delegate* unmanaged[Cdecl] cb, - int* n); + int* n + ); } diff --git a/Src/CSharpier.Tests/TestFiles/MethodDeclaration/BasicMethod.cst b/Src/CSharpier.Tests/TestFiles/MethodDeclaration/BasicMethod.cst deleted file mode 100644 index 860800976..000000000 --- a/Src/CSharpier.Tests/TestFiles/MethodDeclaration/BasicMethod.cst +++ /dev/null @@ -1,4 +0,0 @@ -public class ClassName -{ - public void DoStuff() { } -} diff --git a/Src/CSharpier.Tests/TestFiles/MethodDeclaration/ExplicitlyInterfaceSpecifierMethod.cst b/Src/CSharpier.Tests/TestFiles/MethodDeclaration/ExplicitlyInterfaceSpecifierMethod.cst deleted file mode 100644 index b82689d0a..000000000 --- a/Src/CSharpier.Tests/TestFiles/MethodDeclaration/ExplicitlyInterfaceSpecifierMethod.cst +++ /dev/null @@ -1,4 +0,0 @@ -class ClassName : IDisposable -{ - void IDisposable.Dispose() { } -} diff --git a/Src/CSharpier.Tests/TestFiles/MethodDeclaration/LongMethodWithParameters.cst b/Src/CSharpier.Tests/TestFiles/MethodDeclaration/LongMethodWithParameters.cst deleted file mode 100644 index 79d3852c1..000000000 --- a/Src/CSharpier.Tests/TestFiles/MethodDeclaration/LongMethodWithParameters.cst +++ /dev/null @@ -1,12 +0,0 @@ -public class ClassName -{ - public void LongMethodNameForceLineBreak( - string oneoneoneoneoneoneoneoneone, - string twotwotwotwotwotwotwotwo, - string threethreethreethreethreethree) { } - - public void LongMethodNameForceLineBreakasdfasdfasfasdf( - string one, - string two, - string three) { } -} diff --git a/Src/CSharpier.Tests/TestFiles/MethodDeclaration/MethodComments.cst b/Src/CSharpier.Tests/TestFiles/MethodDeclaration/MethodComments.cst deleted file mode 100644 index 5d5e41116..000000000 --- a/Src/CSharpier.Tests/TestFiles/MethodDeclaration/MethodComments.cst +++ /dev/null @@ -1,11 +0,0 @@ -public class ClassName -{ - public void DoStuff( - // leading - string one, // trailing - string two, - string three) - { - var x = 0; - } -} diff --git a/Src/CSharpier.Tests/TestFiles/MethodDeclaration/MethodDeclarations.cst b/Src/CSharpier.Tests/TestFiles/MethodDeclaration/MethodDeclarations.cst new file mode 100644 index 000000000..2c00fa037 --- /dev/null +++ b/Src/CSharpier.Tests/TestFiles/MethodDeclaration/MethodDeclarations.cst @@ -0,0 +1,57 @@ +public class ClassName +{ + public void DoStuff() { } + + public void LongMethodNameForceLineBreak( + string oneoneoneoneoneoneoneoneone, + string twotwotwotwotwotwotwotwo, + string threethreethreethreethreethree + ) { + return; + } + + public void LongMethodNameForceLineBreakasdfasdfasfasdf( + string one, + string two, + string three + ) { } + + public void DoStuff( + // leading + string one, // trailing + string two, + string three + ) { + var x = 0; + } + + public void DoStuff(string one, string two) { } + + public void DoStuff() + { + DoStuff(); + DoStuff(); + } + + private Doc MethodWithParameters( + SomeClass one, + SomeClass two, + SomeClass three + ) => CallSomethingElseWithALongNameThatForcesABreak(one, two, three); + + private Doc ShortMethod() => Method(); + + private Doc ShortishMethod(SomeClass one) => + CallSomeOtherLongMethodSoThatItBreaks(one); + + private Doc MethodWithParameters( + SomeClass one, + SomeClass two, + SomeClass three + ) => CallSomething(one, two, three); +} + +class ExplicitInterfaceSpecifier : IDisposable +{ + void IDisposable.Dispose() { } +} diff --git a/Src/CSharpier.Tests/TestFiles/MethodDeclaration/MethodWithParameters.cst b/Src/CSharpier.Tests/TestFiles/MethodDeclaration/MethodWithParameters.cst deleted file mode 100644 index ff53373e0..000000000 --- a/Src/CSharpier.Tests/TestFiles/MethodDeclaration/MethodWithParameters.cst +++ /dev/null @@ -1,4 +0,0 @@ -public class ClassName -{ - public void DoStuff(string one, string two) { } -} diff --git a/Src/CSharpier.Tests/TestFiles/MethodDeclaration/MethodWithStatements.cst b/Src/CSharpier.Tests/TestFiles/MethodDeclaration/MethodWithStatements.cst deleted file mode 100644 index 4ee1d1af1..000000000 --- a/Src/CSharpier.Tests/TestFiles/MethodDeclaration/MethodWithStatements.cst +++ /dev/null @@ -1,8 +0,0 @@ -public class ClassName -{ - public void DoStuff() - { - DoStuff(); - DoStuff(); - } -} diff --git a/Src/CSharpier.Tests/TestFiles/MethodDeclaration/_MethodDeclarationTests.cs b/Src/CSharpier.Tests/TestFiles/MethodDeclaration/_MethodDeclarationTests.cs index b492cf45f..a6a4ddf54 100644 --- a/Src/CSharpier.Tests/TestFiles/MethodDeclaration/_MethodDeclarationTests.cs +++ b/Src/CSharpier.Tests/TestFiles/MethodDeclaration/_MethodDeclarationTests.cs @@ -6,37 +6,9 @@ namespace CSharpier.Tests.TestFiles public class MethodDeclarationTests : BaseTest { [Test] - public void BasicMethod() + public void MethodDeclarations() { - this.RunTest("MethodDeclaration", "BasicMethod"); - } - [Test] - public void ExplicitlyInterfaceSpecifierMethod() - { - this.RunTest( - "MethodDeclaration", - "ExplicitlyInterfaceSpecifierMethod" - ); - } - [Test] - public void LongMethodWithParameters() - { - this.RunTest("MethodDeclaration", "LongMethodWithParameters"); - } - [Test] - public void MethodComments() - { - this.RunTest("MethodDeclaration", "MethodComments"); - } - [Test] - public void MethodWithParameters() - { - this.RunTest("MethodDeclaration", "MethodWithParameters"); - } - [Test] - public void MethodWithStatements() - { - this.RunTest("MethodDeclaration", "MethodWithStatements"); + this.RunTest("MethodDeclaration", "MethodDeclarations"); } } } diff --git a/Src/CSharpier.Tests/TestFiles/RecordDeclaration/RecordDeclarations.cst b/Src/CSharpier.Tests/TestFiles/RecordDeclaration/RecordDeclarations.cst index b1c039acc..a63da342a 100644 --- a/Src/CSharpier.Tests/TestFiles/RecordDeclaration/RecordDeclarations.cst +++ b/Src/CSharpier.Tests/TestFiles/RecordDeclaration/RecordDeclarations.cst @@ -8,8 +8,8 @@ record MostlyWeeklyTemperature( double monday, double thursday, double friday, - double sunday) -{ + double sunday +) { public double Mean => (monday + monday + thursday + friday + sunday) / 5.0; } diff --git a/Src/CSharpier/Printer/ArrowExpressionClauseSyntax.cs b/Src/CSharpier/Printer/ArrowExpressionClauseSyntax.cs index 05e4f597b..e9717968a 100644 --- a/Src/CSharpier/Printer/ArrowExpressionClauseSyntax.cs +++ b/Src/CSharpier/Printer/ArrowExpressionClauseSyntax.cs @@ -7,10 +7,10 @@ public partial class Printer private Doc PrintArrowExpressionClauseSyntax( ArrowExpressionClauseSyntax node) { - return Group( - Indent( + return Docs.Group( + Docs.Indent( " ", - this.PrintSyntaxToken(node.ArrowToken, Line), + this.PrintSyntaxToken(node.ArrowToken, Docs.Line), this.Print(node.Expression) ) ); diff --git a/Src/CSharpier/Printer/ParameterListSyntax.cs b/Src/CSharpier/Printer/ParameterListSyntax.cs index 9ee622613..01cba7354 100644 --- a/Src/CSharpier/Printer/ParameterListSyntax.cs +++ b/Src/CSharpier/Printer/ParameterListSyntax.cs @@ -10,13 +10,16 @@ private Doc PrintParameterListSyntax(ParameterListSyntax node) return Group( this.PrintSyntaxToken(node.OpenParenToken), node.Parameters.Count > 0 - ? Indent( - SoftLine, - this.PrintSeparatedSyntaxList( - node.Parameters, - this.PrintParameterSyntax, - Line - ) + ? Docs.Concat( + Docs.Indent( + Docs.SoftLine, + this.PrintSeparatedSyntaxList( + node.Parameters, + this.PrintParameterSyntax, + Line + ) + ), + Docs.SoftLine ) : Doc.Null, this.PrintSyntaxToken(node.CloseParenToken)