diff options
author | Raul Santos <raulsntos@gmail.com> | 2022-11-03 20:10:11 +0100 |
---|---|---|
committer | Raul Santos <raulsntos@gmail.com> | 2024-09-23 03:38:18 +0200 |
commit | 445e822bcf2dc2cbc4391ce3df18803bd26c0f79 (patch) | |
tree | 0e7a28d844f75d3dac9ed354508c69f9d06d2dca /modules/mono/editor | |
parent | 2d6af000e763b64967672bb8603c699eaef40949 (diff) | |
download | redot-engine-445e822bcf2dc2cbc4391ce3df18803bd26c0f79.tar.gz |
C#: Generate signal event with the same accessibility as the delegate
Diffstat (limited to 'modules/mono/editor')
-rw-r--r-- | modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs | 26 | ||||
-rw-r--r-- | modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs | 2 |
2 files changed, 27 insertions, 1 deletions
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs index 957d5789df..62fa7b0a36 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs @@ -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) { return symbol.IsGenericType ? diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs index 54f2212339..23253524ab 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs @@ -276,7 +276,7 @@ namespace Godot.SourceGenerators source.Append( $" /// <inheritdoc cref=\"{signalDelegate.DelegateSymbol.FullQualifiedNameIncludeGlobal()}\"/>\n"); - source.Append(" public event ") + source.Append($" {signalDelegate.DelegateSymbol.GetAccessibilityKeyword()} event ") .Append(signalDelegate.DelegateSymbol.FullQualifiedNameIncludeGlobal()) .Append(" @") .Append(signalName) |