diff options
Diffstat (limited to 'modules/mono/glue')
4 files changed, 35 insertions, 25 deletions
diff --git a/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/Common.cs b/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/Common.cs index 16e96c725a..d3726d69f0 100644 --- a/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/Common.cs +++ b/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/Common.cs @@ -12,7 +12,7 @@ internal static class Common { string message = "Missing partial modifier on declaration of type '" + - $"{symbol.FullQualifiedName()}' which has attribute '{GeneratorClasses.GenerateUnmanagedCallbacksAttr}'"; + $"{symbol.FullQualifiedNameOmitGlobal()}' which has attribute '{GeneratorClasses.GenerateUnmanagedCallbacksAttr}'"; string description = $"{message}. Classes with attribute '{GeneratorClasses.GenerateUnmanagedCallbacksAttr}' " + "must be declared with the partial modifier."; @@ -39,7 +39,7 @@ internal static class Common .GetDeclaredSymbol(outerTypeDeclSyntax); string fullQualifiedName = outerSymbol is INamedTypeSymbol namedTypeSymbol ? - namedTypeSymbol.FullQualifiedName() : + namedTypeSymbol.FullQualifiedNameOmitGlobal() : "type not found"; string message = diff --git a/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/ExtensionMethods.cs b/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/ExtensionMethods.cs index fac362479a..37f7005d01 100644 --- a/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/ExtensionMethods.cs +++ b/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/ExtensionMethods.cs @@ -94,13 +94,6 @@ internal static class ExtensionMethods }; } - private static SymbolDisplayFormat FullyQualifiedFormatOmitGlobal { get; } = - SymbolDisplayFormat.FullyQualifiedFormat - .WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted); - - public static string FullQualifiedName(this ITypeSymbol symbol) - => symbol.ToDisplayString(NullableFlowState.NotNull, FullyQualifiedFormatOmitGlobal); - public static string NameWithTypeParameters(this INamedTypeSymbol symbol) { return symbol.IsGenericType ? @@ -108,8 +101,25 @@ internal static class ExtensionMethods symbol.Name; } - public static string FullQualifiedName(this INamespaceSymbol symbol) - => symbol.ToDisplayString(FullyQualifiedFormatOmitGlobal); + private static SymbolDisplayFormat FullyQualifiedFormatOmitGlobal { get; } = + SymbolDisplayFormat.FullyQualifiedFormat + .WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted); + + private static SymbolDisplayFormat FullyQualifiedFormatIncludeGlobal { get; } = + SymbolDisplayFormat.FullyQualifiedFormat + .WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Included); + + public static string FullQualifiedNameOmitGlobal(this ITypeSymbol symbol) + => symbol.ToDisplayString(NullableFlowState.NotNull, FullyQualifiedFormatOmitGlobal); + + public static string FullQualifiedNameOmitGlobal(this INamespaceSymbol namespaceSymbol) + => namespaceSymbol.ToDisplayString(FullyQualifiedFormatOmitGlobal); + + public static string FullQualifiedNameIncludeGlobal(this ITypeSymbol symbol) + => symbol.ToDisplayString(NullableFlowState.NotNull, FullyQualifiedFormatIncludeGlobal); + + public static string FullQualifiedNameIncludeGlobal(this INamespaceSymbol namespaceSymbol) + => namespaceSymbol.ToDisplayString(FullyQualifiedFormatIncludeGlobal); public static string SanitizeQualifiedNameForUniqueHint(this string qualifiedName) => qualifiedName diff --git a/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/UnmanagedCallbacksGenerator.cs b/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/UnmanagedCallbacksGenerator.cs index da578309bc..3226ca79e5 100644 --- a/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/UnmanagedCallbacksGenerator.cs +++ b/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/UnmanagedCallbacksGenerator.cs @@ -96,7 +96,7 @@ internal class GenerateUnmanagedCallbacksAttribute : Attribute INamespaceSymbol namespaceSymbol = symbol.ContainingNamespace; string classNs = namespaceSymbol != null && !namespaceSymbol.IsGlobalNamespace ? - namespaceSymbol.FullQualifiedName() : + namespaceSymbol.FullQualifiedNameOmitGlobal() : string.Empty; bool hasNamespace = classNs.Length != 0; bool isInnerClass = symbol.ContainingType != null; @@ -144,7 +144,7 @@ using Godot.NativeInterop; source.Append("[System.Runtime.CompilerServices.SkipLocalsInit]\n"); source.Append($"unsafe partial class {symbol.Name}\n"); source.Append("{\n"); - source.Append($" private static {data.FuncStructSymbol.FullQualifiedName()} _unmanagedCallbacks;\n\n"); + source.Append($" private static {data.FuncStructSymbol.FullQualifiedNameIncludeGlobal()} _unmanagedCallbacks;\n\n"); foreach (var callback in data.Methods) { @@ -159,7 +159,7 @@ using Godot.NativeInterop; source.Append("static "); source.Append("partial "); - source.Append(callback.ReturnType.FullQualifiedName()); + source.Append(callback.ReturnType.FullQualifiedNameIncludeGlobal()); source.Append(' '); source.Append(callback.Name); source.Append('('); @@ -228,7 +228,7 @@ using Godot.NativeInterop; if (!callback.ReturnsVoid) { if (methodSourceAfterCall.Length != 0) - source.Append($"{callback.ReturnType.FullQualifiedName()} ret = "); + source.Append($"{callback.ReturnType.FullQualifiedNameIncludeGlobal()} ret = "); else source.Append("return "); } @@ -267,7 +267,7 @@ using Godot.NativeInterop; source.Append("\n\n#pragma warning restore CA1707\n"); - context.AddSource($"{data.NativeTypeSymbol.FullQualifiedName().SanitizeQualifiedNameForUniqueHint()}.generated", + context.AddSource($"{data.NativeTypeSymbol.FullQualifiedNameOmitGlobal().SanitizeQualifiedNameForUniqueHint()}.generated", SourceText.From(source.ToString(), Encoding.UTF8)); } @@ -277,7 +277,7 @@ using Godot.NativeInterop; INamespaceSymbol namespaceSymbol = symbol.ContainingNamespace; string classNs = namespaceSymbol != null && !namespaceSymbol.IsGlobalNamespace ? - namespaceSymbol.FullQualifiedName() : + namespaceSymbol.FullQualifiedNameOmitGlobal() : string.Empty; bool hasNamespace = classNs.Length != 0; bool isInnerClass = symbol.ContainingType != null; @@ -338,18 +338,18 @@ using Godot.NativeInterop; // just pass it by-ref and let it be pinned. AppendRefKind(source, parameter.RefKind) .Append(' ') - .Append(parameter.Type.FullQualifiedName()); + .Append(parameter.Type.FullQualifiedNameIncludeGlobal()); } } else { - source.Append(parameter.Type.FullQualifiedName()); + source.Append(parameter.Type.FullQualifiedNameIncludeGlobal()); } source.Append(", "); } - source.Append(callback.ReturnType.FullQualifiedName()); + source.Append(callback.ReturnType.FullQualifiedNameIncludeGlobal()); source.Append($"> {callback.Name};\n"); } @@ -372,12 +372,12 @@ using Godot.NativeInterop; source.Append("\n#pragma warning restore CA1707\n"); - context.AddSource($"{symbol.FullQualifiedName().SanitizeQualifiedNameForUniqueHint()}.generated", + context.AddSource($"{symbol.FullQualifiedNameOmitGlobal().SanitizeQualifiedNameForUniqueHint()}.generated", SourceText.From(source.ToString(), Encoding.UTF8)); } private static bool IsGodotInteropStruct(ITypeSymbol type) => - GodotInteropStructs.Contains(type.FullQualifiedName()); + GodotInteropStructs.Contains(type.FullQualifiedNameOmitGlobal()); private static bool IsByRefParameter(IParameterSymbol parameter) => parameter.RefKind is RefKind.In or RefKind.Out or RefKind.Ref; @@ -393,7 +393,7 @@ using Godot.NativeInterop; private static void AppendPointerType(StringBuilder source, ITypeSymbol type) { - source.Append(type.FullQualifiedName()); + source.Append(type.FullQualifiedNameIncludeGlobal()); source.Append('*'); } @@ -426,7 +426,7 @@ using Godot.NativeInterop; { varName = $"{parameter.Name}_copy"; - source.Append(parameter.Type.FullQualifiedName()); + source.Append(parameter.Type.FullQualifiedNameIncludeGlobal()); source.Append(' '); source.Append(varName); if (parameter.RefKind is RefKind.In or RefKind.Ref) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.generic.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.generic.cs index db84175e17..694da6db77 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.generic.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.generic.cs @@ -6,7 +6,7 @@ namespace Godot.NativeInterop; public partial class VariantUtils { - private static Exception UnsupportedType<T>() => throw new InvalidOperationException( + private static Exception UnsupportedType<T>() => new InvalidOperationException( $"The type is not supported for conversion to/from Variant: '{typeof(T).FullName}'"); internal static class GenericConversion<T> |