Skip to content

Commit 2ac1033

Browse files
committed
Fix generating multiple fields in same class
1 parent 94da7a2 commit 2ac1033

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

SourceGenerator/SourceGenerator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<PropertyGroup>
1313
<Description>Source Generator for adding missing methods and classes inside tests to allow compilation. Assists on creating code exercises.</Description>
14-
<Version>1.1.1</Version>
14+
<Version>1.1.2</Version>
1515
</PropertyGroup>
1616

1717
<ItemGroup>

SourceGenerator/TestGenerator.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ private void ProcessObjectCreation(SourceGeneratorContext context, ref Compilati
140140
SemanticModel methodModel = compilation.GetSemanticModel(objectCreation.SyntaxTree);
141141
SymbolInfo targetSymbol = methodModel.GetSymbolInfo(objectCreation.Type);
142142

143+
this.ProcessArguments(context, ref compilation, @namespace, @class, objectCreation.ArgumentList!.Arguments);
144+
143145
//This is used for generating constructors only (for now, at least), type should exist already
144146
if (targetSymbol.Symbol is null)
145147
{
@@ -156,9 +158,7 @@ private void ProcessObjectCreation(SourceGeneratorContext context, ref Compilati
156158
}
157159

158160
string className = objectCreation.Type.ToString();
159-
string arguments = CSharpMemberGenerator.GetArgumentList(objectCreation.ArgumentList!.Arguments);
160-
161-
this.ProcessArguments(context, ref compilation, @namespace, @class, objectCreation.ArgumentList.Arguments);
161+
string arguments = CSharpMemberGenerator.GetArgumentList(objectCreation.ArgumentList.Arguments);
162162

163163
string identifier = $"{className}_{arguments.Length}.cs";
164164
if (!this.GeneratedMethods.Add(identifier))
@@ -191,6 +191,11 @@ private void ProcessLocalDeclaration(SourceGeneratorContext context, ref Compila
191191

192192
private ITypeSymbol GenerateEmptyClass(SourceGeneratorContext context, ref Compilation compilation, NamespaceDeclarationSyntax @namespace, string className)
193193
{
194+
if (!this.GeneratedMethods.Add($"{className}.cs"))
195+
{
196+
return compilation.GetTypeByMetadataName($"{@namespace.Name}.{className}")!;
197+
}
198+
194199
SyntaxToken classIdentifier = SyntaxFactory.Identifier(className);
195200

196201
ClassDeclarationSyntax declarationClass = SyntaxFactory.ClassDeclaration(
@@ -386,11 +391,6 @@ private void ProcessInvocation(SourceGeneratorContext context, ref Compilation c
386391
default:
387392
{
388393
//Ehh... Lets assume its a missing static class? Ehheheh...
389-
if (targetIdentifier.ToString() == "Test")
390-
{
391-
return default;
392-
}
393-
394394
ITypeSymbol symbol = this.GenerateEmptyClass(context, ref compilation, @namespace, targetIdentifier.ToString());
395395

396396
return (true, symbol);

0 commit comments

Comments
 (0)