Skip to content

Commit 8c2ca1a

Browse files
committed
Refactor Indentation Methods and Enhance Attribute Handling
Refactor StringBuilder Indentation -- Renamed `Ident` to `Indent` and `IdentPlus` to `IndentPlus` in `StringBuilderExtensions`. -- Updated all usage across multiple source files to reflect the new method names. Enhance Attribute Handling -- Added `InLine` property in `AttributeGenerator.cs` to control spacing after attributes. -- Updated `ParameterGenerator.cs` to include namespaces from `attributes` if they implement `IWithNamespaces`. Version Update -- Incremented project version from `0.1.11` to `0.1.12`.
1 parent 2703c61 commit 8c2ca1a

21 files changed

Lines changed: 47 additions & 37 deletions

RoyalCode.Utils/RoyalCode.Extensions.SourceGenerator/Generators/ArgumentsGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ public override void Write(StringBuilder sb, int indent = 0)
4545
if (first)
4646
{
4747
if (!InLine)
48-
sb.AppendLine().IdentPlus(indent);
48+
sb.AppendLine().IndentPlus(indent);
4949
first = false;
5050
}
5151
else
5252
{
5353
if (!InLine)
54-
sb.AppendLine(",").IdentPlus(indent);
54+
sb.AppendLine(",").IndentPlus(indent);
5555
else
5656
sb.Append(", ");
5757
}

RoyalCode.Utils/RoyalCode.Extensions.SourceGenerator/Generators/AttributeGenerator.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public AttributeGenerator(string name, string[] namespaces, params ValueNode[] a
3030

3131
public ArgumentsGenerator Arguments => arguments ??= new();
3232

33+
public bool InLine { get; set; } = false;
34+
3335
public IEnumerable<string> GetNamespaces()
3436
{
3537
for (var i = 0; i < namespaces.Length; i++)
@@ -38,12 +40,17 @@ public IEnumerable<string> GetNamespaces()
3840

3941
public override void Write(StringBuilder sb, int indent = 0)
4042
{
41-
sb.Ident(indent)
43+
sb.Indent(indent)
4244
.Append('[')
4345
.Append(name);
4446

4547
arguments?.Write(sb);
46-
47-
sb.Append(']').AppendLine();
48+
49+
sb.Append(']');
50+
51+
if (InLine)
52+
sb.Append(' ');
53+
else
54+
sb.AppendLine();
4855
}
4956
}

RoyalCode.Utils/RoyalCode.Extensions.SourceGenerator/Generators/BaseParametersGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public override void Write(StringBuilder sb, int indent = 0)
1818
return;
1919

2020
sb.AppendLine()
21-
.IdentPlus(indent)
21+
.IndentPlus(indent)
2222
.Append(" : base (");
2323

2424
bool first = true;

RoyalCode.Utils/RoyalCode.Extensions.SourceGenerator/Generators/Commands/AddServiceCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public IEnumerable<string> GetNamespaces()
2525

2626
public override void Write(StringBuilder sb, int indent = 0)
2727
{
28-
sb.Ident(indent);
28+
sb.Indent(indent);
2929

3030
sb.Append(servicesVarName).Append(".AddTransient<")
3131
.Append(serviceTypeDescriptor.InterfaceType.Name).Append(", ")

RoyalCode.Utils/RoyalCode.Extensions.SourceGenerator/Generators/Commands/AssignValueCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public AssignValueCommand(ValueNode left, ValueNode right)
2424

2525
public override void Write(StringBuilder sb, int indent = 0)
2626
{
27-
sb.Ident(indent).Append(left.GetValue(indent)).Append(" = ").Append(right.GetValue(indent)).AppendLine(";");
27+
sb.Indent(indent).Append(left.GetValue(indent)).Append(" = ").Append(right.GetValue(indent)).AppendLine(";");
2828

2929
if (AppendLine)
3030
sb.AppendLine();

RoyalCode.Utils/RoyalCode.Extensions.SourceGenerator/Generators/Commands/Command.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public Command(GeneratorNode generatorNode)
2222
public override void Write(StringBuilder sb, int indent = 0)
2323
{
2424
if (Idented)
25-
sb.Ident(indent);
25+
sb.Indent(indent);
2626

2727
if (Await)
2828
sb.Append("await ");

RoyalCode.Utils/RoyalCode.Extensions.SourceGenerator/Generators/Commands/IfCommand.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public override void Write(StringBuilder sb, int indent = 0)
4747
{
4848
int localIdent = Idented ? indent : 0;
4949

50-
sb.Ident(localIdent);
50+
sb.Indent(localIdent);
5151
sb.Append("if (").Append(condition.GetValue(localIdent)).Append(")");
5252

5353
if (commands is null || commands.Count is 0)
@@ -61,14 +61,14 @@ public override void Write(StringBuilder sb, int indent = 0)
6161
}
6262
else
6363
{
64-
sb.AppendLine().Ident(localIdent).AppendLine("{");
64+
sb.AppendLine().Indent(localIdent).AppendLine("{");
6565
commands.Write(sb, localIdent + 1);
66-
sb.Ident(localIdent).AppendLine("}");
66+
sb.Indent(localIdent).AppendLine("}");
6767
}
6868

6969
if (elseCommands is not null && elseCommands.Count > 0)
7070
{
71-
sb.Ident(localIdent);
71+
sb.Indent(localIdent);
7272

7373
sb.AppendLine("else");
7474

@@ -78,9 +78,9 @@ public override void Write(StringBuilder sb, int indent = 0)
7878
}
7979
else
8080
{
81-
sb.Ident(localIdent).AppendLine("{");
81+
sb.Indent(localIdent).AppendLine("{");
8282
elseCommands.Write(sb, localIdent + 1);
83-
sb.Ident(localIdent).AppendLine("}");
83+
sb.Indent(localIdent).AppendLine("}");
8484
}
8585
}
8686

RoyalCode.Utils/RoyalCode.Extensions.SourceGenerator/Generators/Commands/ReturnCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public ReturnCommand(ValueNode valueNode)
1515

1616
public override void Write(StringBuilder sb, int indent = 0)
1717
{
18-
sb.Ident(indent).Append("return ").Append(valueNode.GetValue(indent)).Append(";");
18+
sb.Indent(indent).Append("return ").Append(valueNode.GetValue(indent)).Append(";");
1919

2020
if (AppendLine)
2121
sb.AppendLine();

RoyalCode.Utils/RoyalCode.Extensions.SourceGenerator/Generators/Commands/ThrowCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public ThrowCommand(TypeDescriptor exceptionType)
2222

2323
public override void Write(StringBuilder sb, int indent = 0)
2424
{
25-
sb.Ident(indent);
25+
sb.Indent(indent);
2626
sb.Append("throw new ").Append(exceptionType.Name);
2727
if (parameters is null)
2828
sb.Append("()");

RoyalCode.Utils/RoyalCode.Extensions.SourceGenerator/Generators/Commands/ValidateHasProblemsCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public ValidateHasProblemsCommand(string identifier)
1313

1414
public override void Write(StringBuilder sb, int indent = 0)
1515
{
16-
sb.Ident(indent);
16+
sb.Indent(indent);
1717
sb.Append("if (");
1818
sb.Append(identifier).Append(".HasProblems(out var validationProblems)");
1919
sb.AppendLine(")");
20-
sb.IdentPlus(indent);
20+
sb.IndentPlus(indent);
2121
sb.AppendLine("return validationProblems;");
2222
sb.AppendLine();
2323
}

0 commit comments

Comments
 (0)