Skip to content

Commit 2af103b

Browse files
committed
Fix source generator tests, fix generator formatting
1 parent 566b7f2 commit 2af103b

20 files changed

+2557
-1351
lines changed

modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/AbstractGenericNode(Of T)_ScriptProperties.generated.cs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Godot;
22
using Godot.NativeInterop;
3+
using Godot.Bridge;
4+
using System.Runtime.CompilerServices;
35

46
partial class AbstractGenericNode<T>
57
{
@@ -13,26 +15,55 @@ partial class AbstractGenericNode<T>
1315
/// </summary>
1416
public new static readonly global::Godot.StringName @MyArray = "MyArray";
1517
}
18+
#pragma warning restore CS0109 // Disable warning about redundant 'new' keyword
19+
20+
#pragma warning disable CS0618 // Type or member is obsolete
21+
protected new static readonly ScriptPropertyRegistry<AbstractGenericNode<T>> PropertyRegistry = new ScriptPropertyRegistry<AbstractGenericNode<T>>()
22+
.Register(global::Godot.Node.PropertyRegistry)
23+
.Register(PropertyName.@MyArray, 1,
24+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
25+
static (GodotObject scriptInstance, scoped in godot_variant value) =>
26+
{
27+
Unsafe.As<GodotObject, AbstractGenericNode<T>>(ref scriptInstance).@MyArray = global::Godot.NativeInterop.VariantUtils.ConvertToArray<T>(value);
28+
return value;
29+
})
30+
.Register(PropertyName.@MyArray, 0,
31+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
32+
static (GodotObject scriptInstance, scoped in godot_variant _) =>
33+
{
34+
var ret = Unsafe.As<GodotObject, AbstractGenericNode<T>>(ref scriptInstance).@MyArray;
35+
return global::Godot.NativeInterop.VariantUtils.CreateFromArray(ret);
36+
})
37+
.Build();
38+
#pragma warning restore CS0618 // Type or member is obsolete
39+
1640
/// <inheritdoc/>
1741
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
1842
protected override bool SetGodotClassPropertyValue(in godot_string_name name, in godot_variant value)
1943
{
20-
if (name == PropertyName.@MyArray) {
21-
this.@MyArray = global::Godot.NativeInterop.VariantUtils.ConvertToArray<T>(value);
44+
ref readonly var propertySetter = ref PropertyRegistry.GetMethodOrNullRef(in name, 1);
45+
if (!Unsafe.IsNullRef(in propertySetter))
46+
{
47+
propertySetter(this, value);
2248
return true;
2349
}
24-
return base.SetGodotClassPropertyValue(name, value);
50+
return false;
2551
}
52+
2653
/// <inheritdoc/>
2754
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
2855
protected override bool GetGodotClassPropertyValue(in godot_string_name name, out godot_variant value)
2956
{
30-
if (name == PropertyName.@MyArray) {
31-
value = global::Godot.NativeInterop.VariantUtils.CreateFromArray(this.@MyArray);
57+
ref readonly var propertyGetter = ref PropertyRegistry.GetMethodOrNullRef(in name, 0);
58+
if (!Unsafe.IsNullRef(in propertyGetter))
59+
{
60+
value = propertyGetter(this, default);
3261
return true;
3362
}
34-
return base.GetGodotClassPropertyValue(name, out value);
63+
value = default;
64+
return false;
3565
}
66+
3667
/// <summary>
3768
/// Get the property information for all the properties declared in this class.
3869
/// This method is used by Godot to register the available properties in the editor.

modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/AllReadOnly_ScriptProperties.generated.cs

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Godot;
22
using Godot.NativeInterop;
3+
using Godot.Bridge;
4+
using System.Runtime.CompilerServices;
35

46
partial class AllReadOnly
57
{
@@ -25,28 +27,56 @@ partial class AllReadOnly
2527
/// </summary>
2628
public new static readonly global::Godot.StringName @ReadOnlyField = "ReadOnlyField";
2729
}
30+
#pragma warning restore CS0109 // Disable warning about redundant 'new' keyword
31+
32+
#pragma warning disable CS0618 // Type or member is obsolete
33+
protected new static readonly ScriptPropertyRegistry<AllReadOnly> PropertyRegistry = new ScriptPropertyRegistry<AllReadOnly>()
34+
.Register(global::Godot.GodotObject.PropertyRegistry)
35+
.Register(PropertyName.@ReadOnlyAutoProperty, 0,
36+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
37+
static (GodotObject scriptInstance, scoped in godot_variant _) =>
38+
{
39+
var ret = Unsafe.As<GodotObject, AllReadOnly>(ref scriptInstance).@ReadOnlyAutoProperty;
40+
return global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(ret);
41+
})
42+
.Register(PropertyName.@ReadOnlyProperty, 0,
43+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
44+
static (GodotObject scriptInstance, scoped in godot_variant _) =>
45+
{
46+
var ret = Unsafe.As<GodotObject, AllReadOnly>(ref scriptInstance).@ReadOnlyProperty;
47+
return global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(ret);
48+
})
49+
.Register(PropertyName.@InitOnlyAutoProperty, 0,
50+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
51+
static (GodotObject scriptInstance, scoped in godot_variant _) =>
52+
{
53+
var ret = Unsafe.As<GodotObject, AllReadOnly>(ref scriptInstance).@InitOnlyAutoProperty;
54+
return global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(ret);
55+
})
56+
.Register(PropertyName.@ReadOnlyField, 0,
57+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
58+
static (GodotObject scriptInstance, scoped in godot_variant _) =>
59+
{
60+
var ret = Unsafe.As<GodotObject, AllReadOnly>(ref scriptInstance).@ReadOnlyField;
61+
return global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(ret);
62+
})
63+
.Build();
64+
#pragma warning restore CS0618 // Type or member is obsolete
65+
2866
/// <inheritdoc/>
2967
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
3068
protected override bool GetGodotClassPropertyValue(in godot_string_name name, out godot_variant value)
3169
{
32-
if (name == PropertyName.@ReadOnlyAutoProperty) {
33-
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.@ReadOnlyAutoProperty);
70+
ref readonly var propertyGetter = ref PropertyRegistry.GetMethodOrNullRef(in name, 0);
71+
if (!Unsafe.IsNullRef(in propertyGetter))
72+
{
73+
value = propertyGetter(this, default);
3474
return true;
3575
}
36-
if (name == PropertyName.@ReadOnlyProperty) {
37-
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.@ReadOnlyProperty);
38-
return true;
39-
}
40-
if (name == PropertyName.@InitOnlyAutoProperty) {
41-
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.@InitOnlyAutoProperty);
42-
return true;
43-
}
44-
if (name == PropertyName.@ReadOnlyField) {
45-
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.@ReadOnlyField);
46-
return true;
47-
}
48-
return base.GetGodotClassPropertyValue(name, out value);
76+
value = default;
77+
return false;
4978
}
79+
5080
/// <summary>
5181
/// Get the property information for all the properties declared in this class.
5282
/// This method is used by Godot to register the available properties in the editor.

modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/AllWriteOnly_ScriptProperties.generated.cs

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Godot;
22
using Godot.NativeInterop;
3+
using Godot.Bridge;
4+
using System.Runtime.CompilerServices;
35

46
partial class AllWriteOnly
57
{
@@ -17,30 +19,62 @@ partial class AllWriteOnly
1719
/// </summary>
1820
public new static readonly global::Godot.StringName @_writeOnlyBackingField = "_writeOnlyBackingField";
1921
}
22+
#pragma warning restore CS0109 // Disable warning about redundant 'new' keyword
23+
24+
#pragma warning disable CS0618 // Type or member is obsolete
25+
protected new static readonly ScriptPropertyRegistry<AllWriteOnly> PropertyRegistry = new ScriptPropertyRegistry<AllWriteOnly>()
26+
.Register(global::Godot.GodotObject.PropertyRegistry)
27+
.Register(PropertyName.@WriteOnlyProperty, 1,
28+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
29+
static (GodotObject scriptInstance, scoped in godot_variant value) =>
30+
{
31+
Unsafe.As<GodotObject, AllWriteOnly>(ref scriptInstance).@WriteOnlyProperty = global::Godot.NativeInterop.VariantUtils.ConvertTo<bool>(value);
32+
return value;
33+
})
34+
.Register(PropertyName.@_writeOnlyBackingField, 1,
35+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
36+
static (GodotObject scriptInstance, scoped in godot_variant value) =>
37+
{
38+
Unsafe.As<GodotObject, AllWriteOnly>(ref scriptInstance).@_writeOnlyBackingField = global::Godot.NativeInterop.VariantUtils.ConvertTo<bool>(value);
39+
return value;
40+
})
41+
.Register(PropertyName.@_writeOnlyBackingField, 0,
42+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
43+
static (GodotObject scriptInstance, scoped in godot_variant _) =>
44+
{
45+
var ret = Unsafe.As<GodotObject, AllWriteOnly>(ref scriptInstance).@_writeOnlyBackingField;
46+
return global::Godot.NativeInterop.VariantUtils.CreateFrom<bool>(ret);
47+
})
48+
.Build();
49+
#pragma warning restore CS0618 // Type or member is obsolete
50+
2051
/// <inheritdoc/>
2152
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
2253
protected override bool SetGodotClassPropertyValue(in godot_string_name name, in godot_variant value)
2354
{
24-
if (name == PropertyName.@WriteOnlyProperty) {
25-
this.@WriteOnlyProperty = global::Godot.NativeInterop.VariantUtils.ConvertTo<bool>(value);
26-
return true;
27-
}
28-
if (name == PropertyName.@_writeOnlyBackingField) {
29-
this.@_writeOnlyBackingField = global::Godot.NativeInterop.VariantUtils.ConvertTo<bool>(value);
55+
ref readonly var propertySetter = ref PropertyRegistry.GetMethodOrNullRef(in name, 1);
56+
if (!Unsafe.IsNullRef(in propertySetter))
57+
{
58+
propertySetter(this, value);
3059
return true;
3160
}
32-
return base.SetGodotClassPropertyValue(name, value);
61+
return false;
3362
}
63+
3464
/// <inheritdoc/>
3565
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
3666
protected override bool GetGodotClassPropertyValue(in godot_string_name name, out godot_variant value)
3767
{
38-
if (name == PropertyName.@_writeOnlyBackingField) {
39-
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<bool>(this.@_writeOnlyBackingField);
68+
ref readonly var propertyGetter = ref PropertyRegistry.GetMethodOrNullRef(in name, 0);
69+
if (!Unsafe.IsNullRef(in propertyGetter))
70+
{
71+
value = propertyGetter(this, default);
4072
return true;
4173
}
42-
return base.GetGodotClassPropertyValue(name, out value);
74+
value = default;
75+
return false;
4376
}
77+
4478
/// <summary>
4579
/// Get the property information for all the properties declared in this class.
4680
/// This method is used by Godot to register the available properties in the editor.

modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/EventSignals_ScriptSignals.generated.cs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Godot;
22
using Godot.NativeInterop;
3+
using Godot.Bridge;
4+
using System.Runtime.CompilerServices;
35

46
partial class EventSignals
57
{
@@ -13,6 +15,7 @@ partial class EventSignals
1315
/// </summary>
1416
public new static readonly global::Godot.StringName @MySignal = "MySignal";
1517
}
18+
1619
/// <summary>
1720
/// Get the signal information for all the signals declared in this class.
1821
/// This method is used by Godot to register the available signals in the editor.
@@ -26,33 +29,48 @@ partial class EventSignals
2629
return signals;
2730
}
2831
#pragma warning restore CS0109
29-
private global::EventSignals.MySignalEventHandler backing_MySignal;
32+
33+
protected global::EventSignals.MySignalEventHandler backing_MySignal;
3034
/// <inheritdoc cref="global::EventSignals.MySignalEventHandler"/>
31-
public event global::EventSignals.MySignalEventHandler @MySignal {
35+
public event global::EventSignals.MySignalEventHandler @MySignal
36+
{
3237
add => backing_MySignal += value;
3338
remove => backing_MySignal -= value;
34-
}
39+
}
40+
3541
protected void EmitSignalMySignal(string @str, int @num)
3642
{
3743
EmitSignal(SignalName.MySignal, @str, @num);
3844
}
45+
46+
#pragma warning disable CS0618 // Type or member is obsolete
47+
protected new static readonly ScriptSignalRegistry<EventSignals> SignalRegistry = new ScriptSignalRegistry<EventSignals>()
48+
.Register(global::Godot.GodotObject.SignalRegistry)
49+
.Register(SignalName.@MySignal, 2,
50+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
51+
static (GodotObject scriptInstance, scoped in NativeVariantPtrArgs args) =>
52+
{
53+
Unsafe.As<GodotObject, EventSignals>(ref scriptInstance).backing_MySignal?.Invoke(
54+
global::Godot.NativeInterop.VariantUtils.ConvertTo<string>(args[0]), global::Godot.NativeInterop.VariantUtils.ConvertTo<int>(args[1]));
55+
})
56+
.Build();
57+
#pragma warning restore CS0618 // Type or member is obsolete
58+
3959
/// <inheritdoc/>
4060
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
4161
protected override void RaiseGodotClassSignalCallbacks(in godot_string_name signal, NativeVariantPtrArgs args)
4262
{
43-
if (signal == SignalName.@MySignal && args.Count == 2) {
44-
backing_MySignal?.Invoke(global::Godot.NativeInterop.VariantUtils.ConvertTo<string>(args[0]), global::Godot.NativeInterop.VariantUtils.ConvertTo<int>(args[1]));
45-
return;
63+
ref readonly var signalMethod = ref SignalRegistry.GetMethodOrNullRef(in signal, args.Count);
64+
if (!Unsafe.IsNullRef(in signalMethod))
65+
{
66+
signalMethod(this, args);
4667
}
47-
base.RaiseGodotClassSignalCallbacks(signal, args);
4868
}
69+
4970
/// <inheritdoc/>
5071
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
5172
protected override bool HasGodotClassSignal(in godot_string_name signal)
5273
{
53-
if (signal == SignalName.@MySignal) {
54-
return true;
55-
}
56-
return base.HasGodotClassSignal(signal);
74+
return SignalRegistry.ContainsName(signal);
5775
}
5876
}

modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportDiagnostics_GD0108_ScriptProperties.generated.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Godot;
22
using Godot.NativeInterop;
3+
using Godot.Bridge;
4+
using System.Runtime.CompilerServices;
35

46
partial class ExportDiagnostics_GD0108
57
{
@@ -13,16 +15,35 @@ partial class ExportDiagnostics_GD0108
1315
/// </summary>
1416
public new static readonly global::Godot.StringName @MyButton = "MyButton";
1517
}
18+
#pragma warning restore CS0109 // Disable warning about redundant 'new' keyword
19+
20+
#pragma warning disable CS0618 // Type or member is obsolete
21+
protected new static readonly ScriptPropertyRegistry<ExportDiagnostics_GD0108> PropertyRegistry = new ScriptPropertyRegistry<ExportDiagnostics_GD0108>()
22+
.Register(global::Godot.Node.PropertyRegistry)
23+
.Register(PropertyName.@MyButton, 0,
24+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
25+
static (GodotObject scriptInstance, scoped in godot_variant _) =>
26+
{
27+
var ret = Unsafe.As<GodotObject, ExportDiagnostics_GD0108>(ref scriptInstance).@MyButton;
28+
return global::Godot.NativeInterop.VariantUtils.CreateFrom<global::Godot.Callable>(ret);
29+
})
30+
.Build();
31+
#pragma warning restore CS0618 // Type or member is obsolete
32+
1633
/// <inheritdoc/>
1734
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
1835
protected override bool GetGodotClassPropertyValue(in godot_string_name name, out godot_variant value)
1936
{
20-
if (name == PropertyName.@MyButton) {
21-
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<global::Godot.Callable>(this.@MyButton);
37+
ref readonly var propertyGetter = ref PropertyRegistry.GetMethodOrNullRef(in name, 0);
38+
if (!Unsafe.IsNullRef(in propertyGetter))
39+
{
40+
value = propertyGetter(this, default);
2241
return true;
2342
}
24-
return base.GetGodotClassPropertyValue(name, out value);
43+
value = default;
44+
return false;
2545
}
46+
2647
/// <summary>
2748
/// Get the property information for all the properties declared in this class.
2849
/// This method is used by Godot to register the available properties in the editor.

0 commit comments

Comments
 (0)