Skip to content

Commit

Permalink
support inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
nenoNaninu committed Jan 9, 2024
1 parent 2a85097 commit fd98a70
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,34 @@ public TypeMetadata(ITypeSymbol typeSymbol)
{
TypeSymbol = typeSymbol;

Methods = typeSymbol.GetMembers()
.OfType<IMethodSymbol>()
.Where(static x => x.MethodKind is MethodKind.Ordinary)
.Select(static x => new MethodMetadata(x))
.ToArray();
Methods = GetMethods(typeSymbol);

InterfaceName = typeSymbol.Name;
InterfaceFullName = typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
CollisionFreeName = InterfaceFullName.Replace('.', '_').Replace(':', '_');
}

private static IReadOnlyList<MethodMetadata> GetMethods(ITypeSymbol typeSymbol)
{
var methods = typeSymbol.GetMembers()
.OfType<IMethodSymbol>()
.Where(static x => x.MethodKind is MethodKind.Ordinary)
.Select(static x => new MethodMetadata(x));

var allInterfaces = typeSymbol.AllInterfaces;

if (allInterfaces.IsEmpty)
{
return methods.ToArray();
}

var allMethods = allInterfaces
.SelectMany(static x => x.GetMembers())
.OfType<IMethodSymbol>()
.Where(static x => x.MethodKind is MethodKind.Ordinary)
.Select(static x => new MethodMetadata(x))
.Concat(methods);

return allMethods.ToArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,32 @@ public static bool ValidateHubTypeRule(
return false;
}

bool isValid = ValidateHubTypeRuleCore(context, hubTypeSymbol, specialSymbols, accessLocation);

var allInterfaces = hubTypeSymbol.AllInterfaces;

if (allInterfaces.IsEmpty)
{
return isValid;
}

foreach (var typeSymbol in allInterfaces)
{
isValid &= ValidateHubTypeRuleCore(context, typeSymbol, specialSymbols, accessLocation);
}

return isValid;
}

private static bool ValidateHubTypeRuleCore(
SourceProductionContext context,
ITypeSymbol typeSymbol,
SpecialSymbols specialSymbols,
Location accessLocation)
{
bool isValid = true;

foreach (ISymbol memberSymbol in hubTypeSymbol.GetMembers())
foreach (ISymbol memberSymbol in typeSymbol.GetMembers())
{
if (memberSymbol is IMethodSymbol methodSymbol)
{
Expand Down

0 comments on commit fd98a70

Please sign in to comment.