C#: Generate signal event with the same accessibility as the delegate
This commit is contained in:
parent
2d6af000e7
commit
445e822bcf
2 changed files with 27 additions and 1 deletions
|
@ -155,6 +155,32 @@ namespace Godot.SourceGenerators
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetAccessibilityKeyword(this INamedTypeSymbol namedTypeSymbol)
|
||||||
|
{
|
||||||
|
if (namedTypeSymbol.DeclaredAccessibility == Accessibility.NotApplicable)
|
||||||
|
{
|
||||||
|
// Accessibility not specified. Get the default accessibility.
|
||||||
|
return namedTypeSymbol.ContainingSymbol switch
|
||||||
|
{
|
||||||
|
null or INamespaceSymbol => "internal",
|
||||||
|
ITypeSymbol { TypeKind: TypeKind.Class or TypeKind.Struct } => "private",
|
||||||
|
ITypeSymbol { TypeKind: TypeKind.Interface } => "public",
|
||||||
|
_ => "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return namedTypeSymbol.DeclaredAccessibility switch
|
||||||
|
{
|
||||||
|
Accessibility.Private => "private",
|
||||||
|
Accessibility.Protected => "protected",
|
||||||
|
Accessibility.Internal => "internal",
|
||||||
|
Accessibility.ProtectedAndInternal => "private",
|
||||||
|
Accessibility.ProtectedOrInternal => "private",
|
||||||
|
Accessibility.Public => "public",
|
||||||
|
_ => "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static string NameWithTypeParameters(this INamedTypeSymbol symbol)
|
public static string NameWithTypeParameters(this INamedTypeSymbol symbol)
|
||||||
{
|
{
|
||||||
return symbol.IsGenericType ?
|
return symbol.IsGenericType ?
|
||||||
|
|
|
@ -276,7 +276,7 @@ namespace Godot.SourceGenerators
|
||||||
source.Append(
|
source.Append(
|
||||||
$" /// <inheritdoc cref=\"{signalDelegate.DelegateSymbol.FullQualifiedNameIncludeGlobal()}\"/>\n");
|
$" /// <inheritdoc cref=\"{signalDelegate.DelegateSymbol.FullQualifiedNameIncludeGlobal()}\"/>\n");
|
||||||
|
|
||||||
source.Append(" public event ")
|
source.Append($" {signalDelegate.DelegateSymbol.GetAccessibilityKeyword()} event ")
|
||||||
.Append(signalDelegate.DelegateSymbol.FullQualifiedNameIncludeGlobal())
|
.Append(signalDelegate.DelegateSymbol.FullQualifiedNameIncludeGlobal())
|
||||||
.Append(" @")
|
.Append(" @")
|
||||||
.Append(signalName)
|
.Append(signalName)
|
||||||
|
|
Loading…
Reference in a new issue