Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: overriden properties #423

Merged
merged 8 commits into from
Jun 14, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
string? desiredCommandInterface,
bool makeClassesPublic,
bool includeObsoleteItems,
string? platformCommandType)

Check warning on line 35 in src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'platformCommandType' has no matching param tag in the XML comment for 'ControlBindingModelPropertyGenerator.GetProperties(INamedTypeSymbol, string?, bool, bool, string?)' (but other parameters do)

Check warning on line 35 in src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Parameter 'platformCommandType' has no matching param tag in the XML comment for 'ControlBindingModelPropertyGenerator.GetProperties(INamedTypeSymbol, string?, bool, bool, string?)' (but other parameters do)

Check warning on line 35 in src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'platformCommandType' has no matching param tag in the XML comment for 'ControlBindingModelPropertyGenerator.GetProperties(INamedTypeSymbol, string?, bool, bool, string?)' (but other parameters do)
{
if (namedTypeSymbol == null)
{
Expand Down Expand Up @@ -77,7 +77,7 @@
continue;
}

var treatAsNewImplementation = ReplacesBaseProperty(propertySymbol);
var treatAsNewImplementation = ReplacesBaseProperty(propertySymbol, namedTypeSymbol);

var accessorList = GetAccessorDeclarationSyntaxes();

Expand Down Expand Up @@ -139,11 +139,31 @@
platformCommandType);
}

private static bool ReplacesBaseProperty(IPropertySymbol propertySymbol)
private static bool ReplacesBaseProperty(
IPropertySymbol propertySymbol,
INamedTypeSymbol namedTypeSymbol)
{
var accessor = propertySymbol.GetMethod ?? propertySymbol.SetMethod;
var wantedName = propertySymbol.Name;
var baseType = namedTypeSymbol.BaseType;
while (baseType != null)
{
var nameMatches = baseType.GetMembers()
.Where(x => x.Kind == SymbolKind.Property && x.Name.Equals(wantedName, StringComparison.Ordinal))
.Cast<IPropertySymbol>()
.ToImmutableArray();

foreach (var nameMatch in nameMatches)
{
if (SymbolEqualityComparer.Default.Equals(nameMatch.Type, propertySymbol.Type))
{
return !propertySymbol.IsOverride;
}
}

baseType = baseType.BaseType;
}

return accessor is { HidesBaseMethodsByName: true };
return false;
}

private static PropertyDeclarationSyntax GetBindCommandPropertyDeclaration(
Expand Down
Loading