C#: Set PropertyInfo.class_name for method parameters

This commit is contained in:
Raul Santos 2023-06-16 23:05:11 +02:00
parent c0d8d91b15
commit 48e20c628a
No known key found for this signature in database
GPG key ID: B532473AE3A803E4
6 changed files with 74 additions and 14 deletions

View file

@ -288,8 +288,14 @@ namespace Godot.SourceGenerators
.Append("\", usage: (global::Godot.PropertyUsageFlags)")
.Append((int)propertyInfo.Usage)
.Append(", exported: ")
.Append(propertyInfo.Exported ? "true" : "false")
.Append(")");
.Append(propertyInfo.Exported ? "true" : "false");
if (propertyInfo.ClassName != null)
{
source.Append(", className: new global::Godot.StringName(\"")
.Append(propertyInfo.ClassName)
.Append("\")");
}
source.Append(")");
}
private static MethodInfo DetermineMethodInfo(GodotMethodData method)
@ -298,7 +304,9 @@ namespace Godot.SourceGenerators
if (method.RetType != null)
{
returnVal = DeterminePropertyInfo(method.RetType.Value.MarshalType, name: string.Empty);
returnVal = DeterminePropertyInfo(method.RetType.Value.MarshalType,
method.RetType.Value.TypeSymbol,
name: string.Empty);
}
else
{
@ -317,6 +325,7 @@ namespace Godot.SourceGenerators
for (int i = 0; i < paramCount; i++)
{
arguments.Add(DeterminePropertyInfo(method.ParamTypes[i],
method.Method.Parameters[i].Type,
name: method.Method.Parameters[i].Name));
}
}
@ -329,7 +338,7 @@ namespace Godot.SourceGenerators
defaultArguments: null);
}
private static PropertyInfo DeterminePropertyInfo(MarshalType marshalType, string name)
private static PropertyInfo DeterminePropertyInfo(MarshalType marshalType, ITypeSymbol typeSymbol, string name)
{
var memberVariantType = MarshalUtils.ConvertMarshalTypeToVariantType(marshalType)!.Value;
@ -338,8 +347,14 @@ namespace Godot.SourceGenerators
if (memberVariantType == VariantType.Nil)
propUsage |= PropertyUsageFlags.NilIsVariant;
string? className = null;
if (memberVariantType == VariantType.Object && typeSymbol is INamedTypeSymbol namedTypeSymbol)
{
className = namedTypeSymbol.GetGodotScriptNativeClassName();
}
return new PropertyInfo(memberVariantType, name,
PropertyHint.None, string.Empty, propUsage, exported: false);
PropertyHint.None, string.Empty, propUsage, className, exported: false);
}
private static void GenerateHasMethodEntry(