Skip to content

Commit

Permalink
Merge pull request #83532 from raulsntos/dotnet/nested-class-generation
Browse files Browse the repository at this point in the history
C#: Fix generated nested class order
  • Loading branch information
akien-mga committed Oct 18, 2023
2 parents 0111637 + fe07821 commit 49f492d
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace Godot.SourceGenerators.Sample;

public partial class NestedClass : GodotObject
{
public partial class NestedClass2 : GodotObject
{
public partial class NestedClass3 : GodotObject
{
[Signal]
public delegate void MySignalEventHandler(string str, int num);

[Export] private String field_String = "foo";
[Export] private String property_String { get; set; } = "foo";

private void Method()
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,20 @@ INamedTypeSymbol symbol
if (isInnerClass)
{
var containingType = symbol.ContainingType;
AppendPartialContainingTypeDeclarations(containingType);

while (containingType != null)
void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
{
if (containingType == null)
return;

AppendPartialContainingTypeDeclarations(containingType.ContainingType);

source.Append("partial ");
source.Append(containingType.GetDeclarationKeyword());
source.Append(" ");
source.Append(containingType.NameWithTypeParameters());
source.Append("\n{\n");

containingType = containingType.ContainingType;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,20 @@ INamedTypeSymbol symbol
if (isInnerClass)
{
var containingType = symbol.ContainingType;
AppendPartialContainingTypeDeclarations(containingType);

while (containingType != null)
void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
{
if (containingType == null)
return;

AppendPartialContainingTypeDeclarations(containingType.ContainingType);

source.Append("partial ");
source.Append(containingType.GetDeclarationKeyword());
source.Append(" ");
source.Append(containingType.NameWithTypeParameters());
source.Append("\n{\n");

containingType = containingType.ContainingType;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,20 @@ INamedTypeSymbol symbol
if (isInnerClass)
{
var containingType = symbol.ContainingType;
AppendPartialContainingTypeDeclarations(containingType);

while (containingType != null)
void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
{
if (containingType == null)
return;

AppendPartialContainingTypeDeclarations(containingType.ContainingType);

source.Append("partial ");
source.Append(containingType.GetDeclarationKeyword());
source.Append(" ");
source.Append(containingType.NameWithTypeParameters());
source.Append("\n{\n");

containingType = containingType.ContainingType;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,20 @@ INamedTypeSymbol symbol
if (isInnerClass)
{
var containingType = symbol.ContainingType;
AppendPartialContainingTypeDeclarations(containingType);

while (containingType != null)
void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
{
if (containingType == null)
return;

AppendPartialContainingTypeDeclarations(containingType.ContainingType);

source.Append("partial ");
source.Append(containingType.GetDeclarationKeyword());
source.Append(" ");
source.Append(containingType.NameWithTypeParameters());
source.Append("\n{\n");

containingType = containingType.ContainingType;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,20 @@ INamedTypeSymbol symbol
if (isInnerClass)
{
var containingType = symbol.ContainingType;
AppendPartialContainingTypeDeclarations(containingType);

while (containingType != null)
void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
{
if (containingType == null)
return;

AppendPartialContainingTypeDeclarations(containingType.ContainingType);

source.Append("partial ");
source.Append(containingType.GetDeclarationKeyword());
source.Append(" ");
source.Append(containingType.NameWithTypeParameters());
source.Append("\n{\n");

containingType = containingType.ContainingType;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,20 @@ private void GenerateInteropMethodImplementations(GeneratorExecutionContext cont
if (isInnerClass)
{
var containingType = symbol.ContainingType;
AppendPartialContainingTypeDeclarations(containingType);

while (containingType != null)
void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
{
if (containingType == null)
return;

AppendPartialContainingTypeDeclarations(containingType.ContainingType);

source.Append("partial ");
source.Append(containingType.GetDeclarationKeyword());
source.Append(" ");
source.Append(containingType.NameWithTypeParameters());
source.Append("\n{\n");

containingType = containingType.ContainingType;
}
}

Expand Down Expand Up @@ -303,16 +307,20 @@ private void GenerateUnmanagedCallbacksStruct(GeneratorExecutionContext context,
if (isInnerClass)
{
var containingType = symbol.ContainingType;
AppendPartialContainingTypeDeclarations(containingType);

while (containingType != null)
void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
{
if (containingType == null)
return;

AppendPartialContainingTypeDeclarations(containingType.ContainingType);

source.Append("partial ");
source.Append(containingType.GetDeclarationKeyword());
source.Append(" ");
source.Append(containingType.NameWithTypeParameters());
source.Append("\n{\n");

containingType = containingType.ContainingType;
}
}

Expand Down

0 comments on commit 49f492d

Please sign in to comment.