Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,4 @@ __pycache__/
/.aider.tags.cache.v3/cache.db-shm
/.aider.tags.cache.v3/cache.db-wal
/.aider.input.history
.nuget-cache/
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<!-- Output packages to our local feed directory -->
<PackageOutputPath>$(PackagesDirectory)</PackageOutputPath>

<!-- Use local NuGet cache instead of global -->
<RestorePackagesPath>$(RepositoryRoot).nuget-cache/</RestorePackagesPath>

<!-- Suppress .NET preview SDK message -->
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<ItemGroup>
<PackageVersion Include="TimeWarp.SourceGenerators" Version="1.0.0-beta.6" />
<PackageVersion Include="TimeWarp.SourceGenerators" Version="$(Version)" />
<PackageVersion Include="FakeItEasy" Version="7.3.1" />
<PackageVersion Include="Fixie" Version="3.2.0" />
<PackageVersion Include="Fixie.TestAdapter" Version="3.3.0" />
Expand Down
2 changes: 1 addition & 1 deletion source/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<!-- Default package metadata (can be overridden in individual projects) -->
<PropertyGroup Label="Package Metadata">
<Version>1.0.0-beta.6</Version>
<Version>1.0.0-beta.7</Version>
<Authors>Steven T. Cramer</Authors>
<Product>TimeWarp.SourceGenerators</Product>
<PackageId>TimeWarp.SourceGenerators</PackageId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,59 @@ private static List<string> GenerateInterfaceDelegation(
SemanticModel semanticModel)
{
var code = new List<string>();
var processedMembers = new HashSet<string>();

// Get all members of the interface
// Process the interface and all inherited interfaces
if (interfaceType is INamedTypeSymbol namedInterface)
{
ProcessInterfaceMembers(namedInterface, delegateMemberName, classSymbol, code, processedMembers);
}

return code;
}

private static void ProcessInterfaceMembers(
INamedTypeSymbol interfaceType,
string delegateMemberName,
INamedTypeSymbol classSymbol,
List<string> code,
HashSet<string> processedMembers)
{
// First, recursively process all base interfaces
foreach (INamedTypeSymbol baseInterface in interfaceType.AllInterfaces)
{
ProcessInterfaceMembersCore(baseInterface, delegateMemberName, classSymbol, code, processedMembers);
}

// Then process the current interface's own members
ProcessInterfaceMembersCore(interfaceType, delegateMemberName, classSymbol, code, processedMembers);
}

private static void ProcessInterfaceMembersCore(
INamedTypeSymbol interfaceType,
string delegateMemberName,
INamedTypeSymbol classSymbol,
List<string> code,
HashSet<string> processedMembers)
{
ImmutableArray<ISymbol> interfaceMembers = interfaceType.GetMembers();

foreach (ISymbol member in interfaceMembers)
{
// Create a unique key for this member to avoid duplicates
string memberKey = $"{member.Name}_{member.Kind}";
if (member is IMethodSymbol method)
{
// Include return type and parameter types in key to handle overloads and different return types
string returnType = method.ReturnType.ToDisplayString();
string paramTypes = string.Join(",", method.Parameters.Select(p => p.Type.ToDisplayString()));
memberKey = $"{member.Name}_{method.MethodKind}_{returnType}_{paramTypes}";
}

// Skip if we've already processed this member
if (!processedMembers.Add(memberKey))
continue;

// Skip if the class already implements this member explicitly
ISymbol? existingImplementation = classSymbol.GetMembers(member.Name)
.FirstOrDefault(m => !m.IsImplicitlyDeclared);
Expand All @@ -282,8 +329,8 @@ private static List<string> GenerateInterfaceDelegation(

switch (member)
{
case IMethodSymbol method when method.MethodKind == MethodKind.Ordinary:
code.Add(GenerateMethodDelegation(method, delegateMemberName));
case IMethodSymbol methodSymbol when methodSymbol.MethodKind == MethodKind.Ordinary:
code.Add(GenerateMethodDelegation(methodSymbol, delegateMemberName));
break;

case IPropertySymbol property:
Expand All @@ -295,8 +342,6 @@ private static List<string> GenerateInterfaceDelegation(
break;
}
}

return code;
}

private static string GenerateMethodDelegation(IMethodSymbol method, string delegateMemberName)
Expand Down Expand Up @@ -375,7 +420,7 @@ private static string GenerateSourceFile(
builder.AppendLine();
}

builder.AppendLine($"// Interface delegation for {className}");
builder.AppendLine($"// Interface delegation for {className} - YO YO YO MAMA v2 with inherited interfaces!");
builder.AppendLine($"public partial class {className}");
builder.AppendLine("{");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace TimeWarp.SourceGenerators.TestConsole;

// Interface delegation for DataService
// Interface delegation for DataService - YO YO YO MAMA v2 with inherited interfaces!
public partial class DataService
{
// Delegation to _logger for TimeWarp.SourceGenerators.TestConsole.ILogger
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// <auto-generated/>
#nullable enable

namespace TimeWarp.SourceGenerators.TestConsole;

// Interface delegation for StringListWrapper - YO YO YO MAMA v2 with inherited interfaces!
public partial class StringListWrapper
{
// Delegation to InnerList for System.Collections.Generic.IList<string>
public void Add(string item)
{
InnerList.Add(item);
}

public void Clear()
{
InnerList.Clear();
}

public bool Contains(string item)
{
return InnerList.Contains(item);
}

public void CopyTo(string[] array, int arrayIndex)
{
InnerList.CopyTo(array, arrayIndex);
}

public bool Remove(string item)
{
return InnerList.Remove(item);
}

public int Count
{
get => InnerList.Count;
}

public bool IsReadOnly
{
get => InnerList.IsReadOnly;
}

public System.Collections.Generic.IEnumerator<string> GetEnumerator()
{
return InnerList.GetEnumerator();
}

public int IndexOf(string item)
{
return InnerList.IndexOf(item);
}

public void Insert(int index, string item)
{
InnerList.Insert(index, item);
}

public void RemoveAt(int index)
{
InnerList.RemoveAt(index);
}

public string this[int index]
{
get => InnerList[index]; set => InnerList[index] = value;
}

}