Skip to content

Commit

Permalink
Fixing some edge cases for ConstructorDeclaration
Browse files Browse the repository at this point in the history
closes #298
  • Loading branch information
belav committed Jul 26, 2021
1 parent dfc0d2a commit 9b705a8
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,68 @@ public class Initializers : BasicClass
public Initializers(string value) : base(value) { }

public Initializers(
string reallyLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongParameter
string longParameter_______________________________________________________________________________
) : base(
reallyLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongParameterIMeanIt
longParameter_______________________________________________________________________________
) { }

public Initializers(
string reallyLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongParameter
string longParameter_______________________________________________________________________________
) : base(
longParameter_______________________________________________________________________________
) {
WithBody();
}

public Initializers(
string longParameter____________________________________________________________
) : base(false) { }

public ReallyLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogMethodName()
public Initializers(
string longParameter____________________________________________________________
) : base(false)
{
WithBody();
}

public LongMethodName___________________________________________________________________________()
: base(false) { }

public ReallyLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogMethodName()
public WithParameters(string parameter)
: base(
longParameter____________________________________________________________________________
) { }

public WithParameters(string parameter)
: base(
longParameter____________________________________________________________________________
) {
WithBody();
}

public LongMethodName___________________________________________________________________________()
: base(
reallyLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongParameterIMeanIt
longParameter____________________________________________________________________________
) { }

public Initializers(
string value
) /*Comment*/
: base(value) { }

public ReallyLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogMethodName()
public LongMethodName___________________________________________________________()
/*Comment*/: base(false) { }
}

public class Exactly80
{
public Exactly80(int lajsfaskdlfklasdfklskadlfklsdfkasdkfjaskdfkdfdddd)
public Exactly80(int longParameter____________________________________)
{
return;
}

// leading comments don't affect this
public Exactly80(string lajsfaskdlfklasdfklskadlfklsdfkasdkfjaskdfkdfd)
public Exactly80(string longParameter_________________________________)
{
return;
}
Expand Down
2 changes: 0 additions & 2 deletions Src/CSharpier/SyntaxPrinter/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ public static Doc Print(SyntaxNode syntaxNode)
return ConstantPattern.Print(constantPatternSyntax);
case ConstructorConstraintSyntax constructorConstraintSyntax:
return ConstructorConstraint.Print(constructorConstraintSyntax);
case ConstructorInitializerSyntax constructorInitializerSyntax:
return ConstructorInitializer.Print(constructorInitializerSyntax);
case ContinueStatementSyntax continueStatementSyntax:
return ContinueStatement.Print(continueStatementSyntax);
case DeclarationExpressionSyntax declarationExpressionSyntax:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public static Doc Print(CSharpSyntaxNode node)
BlockSyntax? body = null;
ArrowExpressionClauseSyntax? expressionBody = null;
SyntaxToken? semicolonToken = null;
string? groupId = null;
string? parameterGroupId = null;
string? constructorInitializerGroupId = null;

if (node is BaseMethodDeclarationSyntax baseMethodDeclarationSyntax)
{
Expand Down Expand Up @@ -141,22 +142,49 @@ public static Doc Print(CSharpSyntaxNode node)
// will cause SpaceBrace when it isn't wanted.
if (parameterList.Parameters.Count > 0)
{
groupId = Guid.NewGuid().ToString();
parameterGroupId = Guid.NewGuid().ToString();
}
declarationGroup.Add(ParameterList.Print(parameterList, groupId));
declarationGroup.Add(ParameterList.Print(parameterList, parameterGroupId));
declarationGroup.Add(Doc.IfBreak(Doc.Null, Doc.SoftLine));
}

if (constructorInitializer != null)
{
declarationGroup.Add(
groupId != null
? ConstructorInitializer.PrintWithConditionalSpace(
constructorInitializer,
groupId
constructorInitializerGroupId = Guid.NewGuid().ToString();
var colonToken = Token.PrintWithSuffix(constructorInitializer.ColonToken, " ");

if (parameterGroupId != null)
{
declarationGroup.Add(
Doc.GroupWithId(
constructorInitializerGroupId,
Doc.Indent(Doc.IfBreak(" ", Doc.Line, parameterGroupId)),
Doc.IfBreak(
Doc.Align(2, colonToken),
Doc.Indent(colonToken),
parameterGroupId
),
Token.Print(constructorInitializer.ThisOrBaseKeyword),
Doc.IfBreak(
ArgumentList.Print(constructorInitializer.ArgumentList),
Doc.Indent(ArgumentList.Print(constructorInitializer.ArgumentList)),
parameterGroupId
)
: ConstructorInitializer.Print(constructorInitializer)
);
)
);
}
else
{
declarationGroup.Add(
Doc.GroupWithId(
constructorInitializerGroupId,
Doc.Indent(Doc.Line),
Doc.Indent(colonToken),
Token.Print(constructorInitializer.ThisOrBaseKeyword),
Doc.Indent(ArgumentList.Print(constructorInitializer.ArgumentList))
)
);
}
}

if (modifiers is { Count: > 0 })
Expand All @@ -173,18 +201,31 @@ public static Doc Print(CSharpSyntaxNode node)
if (constraintClauses != null)
{
docs.Add(
groupId != null
? ConstraintClauses.PrintWithConditionalSpace(constraintClauses, groupId)
parameterGroupId != null
? ConstraintClauses.PrintWithConditionalSpace(
constraintClauses,
parameterGroupId
)
: ConstraintClauses.Print(constraintClauses)
);
}

if (body != null)
{
docs.Add(
groupId != null
string? conditionalSpaceGroupId = null;
if (constructorInitializerGroupId != null)
{
conditionalSpaceGroupId = constructorInitializerGroupId;
}
else if (
parameterGroupId != null
&& (constraintClauses == null || constraintClauses.Value.Count == 0)
? Block.PrintWithConditionalSpace(body, groupId)
) {
conditionalSpaceGroupId = parameterGroupId;
}
docs.Add(
conditionalSpaceGroupId != null
? Block.PrintWithConditionalSpace(body, conditionalSpaceGroupId)
: Block.Print(body)
);
}
Expand Down

This file was deleted.

0 comments on commit 9b705a8

Please sign in to comment.