Skip to content

Commit 00b6e8a

Browse files
committed
Merge pull request godotengine#111570 from PavielKraskouski/fix-static-import-sourcegen
[C#] Fix source generation of statically imported members
2 parents c17ca39 + bdb4ca9 commit 00b6e8a

File tree

7 files changed

+124
-5
lines changed

7 files changed

+124
-5
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ partial class ExportedFields
6161
/// </summary>
6262
public new static readonly global::Godot.StringName @_fieldString = "_fieldString";
6363
/// <summary>
64+
/// Cached name for the '_fieldStaticImport' field.
65+
/// </summary>
66+
public new static readonly global::Godot.StringName @_fieldStaticImport = "_fieldStaticImport";
67+
/// <summary>
6468
/// Cached name for the '_fieldVector2' field.
6569
/// </summary>
6670
public new static readonly global::Godot.StringName @_fieldVector2 = "_fieldVector2";
@@ -305,6 +309,10 @@ protected override bool SetGodotClassPropertyValue(in godot_string_name name, in
305309
this.@_fieldString = global::Godot.NativeInterop.VariantUtils.ConvertTo<string>(value);
306310
return true;
307311
}
312+
if (name == PropertyName.@_fieldStaticImport) {
313+
this.@_fieldStaticImport = global::Godot.NativeInterop.VariantUtils.ConvertTo<float>(value);
314+
return true;
315+
}
308316
if (name == PropertyName.@_fieldVector2) {
309317
this.@_fieldVector2 = global::Godot.NativeInterop.VariantUtils.ConvertTo<global::Godot.Vector2>(value);
310318
return true;
@@ -551,6 +559,10 @@ protected override bool GetGodotClassPropertyValue(in godot_string_name name, ou
551559
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.@_fieldString);
552560
return true;
553561
}
562+
if (name == PropertyName.@_fieldStaticImport) {
563+
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<float>(this.@_fieldStaticImport);
564+
return true;
565+
}
554566
if (name == PropertyName.@_fieldVector2) {
555567
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<global::Godot.Vector2>(this.@_fieldVector2);
556568
return true;
@@ -763,6 +775,7 @@ protected override bool GetGodotClassPropertyValue(in godot_string_name name, ou
763775
properties.Add(new(type: (global::Godot.Variant.Type)3, name: PropertyName.@_fieldSingle, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
764776
properties.Add(new(type: (global::Godot.Variant.Type)3, name: PropertyName.@_fieldDouble, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
765777
properties.Add(new(type: (global::Godot.Variant.Type)4, name: PropertyName.@_fieldString, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
778+
properties.Add(new(type: (global::Godot.Variant.Type)3, name: PropertyName.@_fieldStaticImport, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
766779
properties.Add(new(type: (global::Godot.Variant.Type)5, name: PropertyName.@_fieldVector2, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
767780
properties.Add(new(type: (global::Godot.Variant.Type)6, name: PropertyName.@_fieldVector2I, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
768781
properties.Add(new(type: (global::Godot.Variant.Type)7, name: PropertyName.@_fieldRect2, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ partial class ExportedFields
1111
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
1212
internal new static global::System.Collections.Generic.Dictionary<global::Godot.StringName, global::Godot.Variant> GetGodotPropertyDefaultValues()
1313
{
14-
var values = new global::System.Collections.Generic.Dictionary<global::Godot.StringName, global::Godot.Variant>(60);
14+
var values = new global::System.Collections.Generic.Dictionary<global::Godot.StringName, global::Godot.Variant>(61);
1515
bool ___fieldBoolean_default_value = true;
1616
values.Add(PropertyName.@_fieldBoolean, global::Godot.Variant.From<bool>(___fieldBoolean_default_value));
1717
char ___fieldChar_default_value = 'f';
@@ -38,6 +38,8 @@ partial class ExportedFields
3838
values.Add(PropertyName.@_fieldDouble, global::Godot.Variant.From<double>(___fieldDouble_default_value));
3939
string ___fieldString_default_value = "foo";
4040
values.Add(PropertyName.@_fieldString, global::Godot.Variant.From<string>(___fieldString_default_value));
41+
float ___fieldStaticImport_default_value = global::Godot.Mathf.RadToDeg(2 * global::Godot.Mathf.Pi);
42+
values.Add(PropertyName.@_fieldStaticImport, global::Godot.Variant.From<float>(___fieldStaticImport_default_value));
4143
global::Godot.Vector2 ___fieldVector2_default_value = new(10f, 10f);
4244
values.Add(PropertyName.@_fieldVector2, global::Godot.Variant.From<global::Godot.Vector2>(___fieldVector2_default_value));
4345
global::Godot.Vector2I ___fieldVector2I_default_value = global::Godot.Vector2I.Up;

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,18 @@ partial class ExportedProperties
3333
/// </summary>
3434
public new static readonly global::Godot.StringName @FullPropertyString_Complex = "FullPropertyString_Complex";
3535
/// <summary>
36+
/// Cached name for the 'FullPropertyStaticImport' property.
37+
/// </summary>
38+
public new static readonly global::Godot.StringName @FullPropertyStaticImport = "FullPropertyStaticImport";
39+
/// <summary>
3640
/// Cached name for the 'LamdaPropertyString' property.
3741
/// </summary>
3842
public new static readonly global::Godot.StringName @LamdaPropertyString = "LamdaPropertyString";
3943
/// <summary>
44+
/// Cached name for the 'LambdaPropertyStaticImport' property.
45+
/// </summary>
46+
public new static readonly global::Godot.StringName @LambdaPropertyStaticImport = "LambdaPropertyStaticImport";
47+
/// <summary>
4048
/// Cached name for the 'PrimaryCtorParameter' property.
4149
/// </summary>
4250
public new static readonly global::Godot.StringName @PrimaryCtorParameter = "PrimaryCtorParameter";
@@ -45,6 +53,10 @@ partial class ExportedProperties
4553
/// </summary>
4654
public new static readonly global::Godot.StringName @ConstantMath = "ConstantMath";
4755
/// <summary>
56+
/// Cached name for the 'ConstantMathStaticImport' property.
57+
/// </summary>
58+
public new static readonly global::Godot.StringName @ConstantMathStaticImport = "ConstantMathStaticImport";
59+
/// <summary>
4860
/// Cached name for the 'StaticStringAddition' property.
4961
/// </summary>
5062
public new static readonly global::Godot.StringName @StaticStringAddition = "StaticStringAddition";
@@ -293,9 +305,17 @@ partial class ExportedProperties
293305
/// </summary>
294306
public new static readonly global::Godot.StringName @_fullPropertyStringComplex = "_fullPropertyStringComplex";
295307
/// <summary>
308+
/// Cached name for the '_fullPropertyStaticImport' field.
309+
/// </summary>
310+
public new static readonly global::Godot.StringName @_fullPropertyStaticImport = "_fullPropertyStaticImport";
311+
/// <summary>
296312
/// Cached name for the '_lamdaPropertyString' field.
297313
/// </summary>
298314
public new static readonly global::Godot.StringName @_lamdaPropertyString = "_lamdaPropertyString";
315+
/// <summary>
316+
/// Cached name for the '_lambdaPropertyStaticImport' field.
317+
/// </summary>
318+
public new static readonly global::Godot.StringName @_lambdaPropertyStaticImport = "_lambdaPropertyStaticImport";
299319
}
300320
/// <inheritdoc/>
301321
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
@@ -325,10 +345,18 @@ protected override bool SetGodotClassPropertyValue(in godot_string_name name, in
325345
this.@FullPropertyString_Complex = global::Godot.NativeInterop.VariantUtils.ConvertTo<string>(value);
326346
return true;
327347
}
348+
if (name == PropertyName.@FullPropertyStaticImport) {
349+
this.@FullPropertyStaticImport = global::Godot.NativeInterop.VariantUtils.ConvertTo<float>(value);
350+
return true;
351+
}
328352
if (name == PropertyName.@LamdaPropertyString) {
329353
this.@LamdaPropertyString = global::Godot.NativeInterop.VariantUtils.ConvertTo<string>(value);
330354
return true;
331355
}
356+
if (name == PropertyName.@LambdaPropertyStaticImport) {
357+
this.@LambdaPropertyStaticImport = global::Godot.NativeInterop.VariantUtils.ConvertTo<float>(value);
358+
return true;
359+
}
332360
if (name == PropertyName.@PrimaryCtorParameter) {
333361
this.@PrimaryCtorParameter = global::Godot.NativeInterop.VariantUtils.ConvertTo<string>(value);
334362
return true;
@@ -337,6 +365,10 @@ protected override bool SetGodotClassPropertyValue(in godot_string_name name, in
337365
this.@ConstantMath = global::Godot.NativeInterop.VariantUtils.ConvertTo<float>(value);
338366
return true;
339367
}
368+
if (name == PropertyName.@ConstantMathStaticImport) {
369+
this.@ConstantMathStaticImport = global::Godot.NativeInterop.VariantUtils.ConvertTo<float>(value);
370+
return true;
371+
}
340372
if (name == PropertyName.@StaticStringAddition) {
341373
this.@StaticStringAddition = global::Godot.NativeInterop.VariantUtils.ConvertTo<string>(value);
342374
return true;
@@ -585,10 +617,18 @@ protected override bool SetGodotClassPropertyValue(in godot_string_name name, in
585617
this.@_fullPropertyStringComplex = global::Godot.NativeInterop.VariantUtils.ConvertTo<string>(value);
586618
return true;
587619
}
620+
if (name == PropertyName.@_fullPropertyStaticImport) {
621+
this.@_fullPropertyStaticImport = global::Godot.NativeInterop.VariantUtils.ConvertTo<float>(value);
622+
return true;
623+
}
588624
if (name == PropertyName.@_lamdaPropertyString) {
589625
this.@_lamdaPropertyString = global::Godot.NativeInterop.VariantUtils.ConvertTo<string>(value);
590626
return true;
591627
}
628+
if (name == PropertyName.@_lambdaPropertyStaticImport) {
629+
this.@_lambdaPropertyStaticImport = global::Godot.NativeInterop.VariantUtils.ConvertTo<float>(value);
630+
return true;
631+
}
592632
return base.SetGodotClassPropertyValue(name, value);
593633
}
594634
/// <inheritdoc/>
@@ -619,10 +659,18 @@ protected override bool GetGodotClassPropertyValue(in godot_string_name name, ou
619659
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.@FullPropertyString_Complex);
620660
return true;
621661
}
662+
if (name == PropertyName.@FullPropertyStaticImport) {
663+
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<float>(this.@FullPropertyStaticImport);
664+
return true;
665+
}
622666
if (name == PropertyName.@LamdaPropertyString) {
623667
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.@LamdaPropertyString);
624668
return true;
625669
}
670+
if (name == PropertyName.@LambdaPropertyStaticImport) {
671+
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<float>(this.@LambdaPropertyStaticImport);
672+
return true;
673+
}
626674
if (name == PropertyName.@PrimaryCtorParameter) {
627675
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.@PrimaryCtorParameter);
628676
return true;
@@ -631,6 +679,10 @@ protected override bool GetGodotClassPropertyValue(in godot_string_name name, ou
631679
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<float>(this.@ConstantMath);
632680
return true;
633681
}
682+
if (name == PropertyName.@ConstantMathStaticImport) {
683+
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<float>(this.@ConstantMathStaticImport);
684+
return true;
685+
}
634686
if (name == PropertyName.@StaticStringAddition) {
635687
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.@StaticStringAddition);
636688
return true;
@@ -879,10 +931,18 @@ protected override bool GetGodotClassPropertyValue(in godot_string_name name, ou
879931
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.@_fullPropertyStringComplex);
880932
return true;
881933
}
934+
if (name == PropertyName.@_fullPropertyStaticImport) {
935+
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<float>(this.@_fullPropertyStaticImport);
936+
return true;
937+
}
882938
if (name == PropertyName.@_lamdaPropertyString) {
883939
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.@_lamdaPropertyString);
884940
return true;
885941
}
942+
if (name == PropertyName.@_lambdaPropertyStaticImport) {
943+
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<float>(this.@_lambdaPropertyStaticImport);
944+
return true;
945+
}
886946
return base.GetGodotClassPropertyValue(name, out value);
887947
}
888948
/// <summary>
@@ -904,10 +964,15 @@ protected override bool GetGodotClassPropertyValue(in godot_string_name name, ou
904964
properties.Add(new(type: (global::Godot.Variant.Type)4, name: PropertyName.@FullPropertyString, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
905965
properties.Add(new(type: (global::Godot.Variant.Type)4, name: PropertyName.@_fullPropertyStringComplex, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4096, exported: false));
906966
properties.Add(new(type: (global::Godot.Variant.Type)4, name: PropertyName.@FullPropertyString_Complex, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
967+
properties.Add(new(type: (global::Godot.Variant.Type)3, name: PropertyName.@_fullPropertyStaticImport, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4096, exported: false));
968+
properties.Add(new(type: (global::Godot.Variant.Type)3, name: PropertyName.@FullPropertyStaticImport, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
907969
properties.Add(new(type: (global::Godot.Variant.Type)4, name: PropertyName.@_lamdaPropertyString, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4096, exported: false));
908970
properties.Add(new(type: (global::Godot.Variant.Type)4, name: PropertyName.@LamdaPropertyString, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
971+
properties.Add(new(type: (global::Godot.Variant.Type)3, name: PropertyName.@_lambdaPropertyStaticImport, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4096, exported: false));
972+
properties.Add(new(type: (global::Godot.Variant.Type)3, name: PropertyName.@LambdaPropertyStaticImport, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
909973
properties.Add(new(type: (global::Godot.Variant.Type)4, name: PropertyName.@PrimaryCtorParameter, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
910974
properties.Add(new(type: (global::Godot.Variant.Type)3, name: PropertyName.@ConstantMath, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
975+
properties.Add(new(type: (global::Godot.Variant.Type)3, name: PropertyName.@ConstantMathStaticImport, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
911976
properties.Add(new(type: (global::Godot.Variant.Type)4, name: PropertyName.@StaticStringAddition, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
912977
properties.Add(new(type: (global::Godot.Variant.Type)1, name: PropertyName.@PropertyBoolean, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
913978
properties.Add(new(type: (global::Godot.Variant.Type)2, name: PropertyName.@PropertyChar, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ partial class ExportedProperties
1111
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
1212
internal new static global::System.Collections.Generic.Dictionary<global::Godot.StringName, global::Godot.Variant> GetGodotPropertyDefaultValues()
1313
{
14-
var values = new global::System.Collections.Generic.Dictionary<global::Godot.StringName, global::Godot.Variant>(67);
14+
var values = new global::System.Collections.Generic.Dictionary<global::Godot.StringName, global::Godot.Variant>(70);
1515
string __NotGenerateComplexLamdaProperty_default_value = default;
1616
values.Add(PropertyName.@NotGenerateComplexLamdaProperty, global::Godot.Variant.From<string>(__NotGenerateComplexLamdaProperty_default_value));
1717
string __NotGenerateLamdaNoFieldProperty_default_value = default;
@@ -24,12 +24,18 @@ partial class ExportedProperties
2424
values.Add(PropertyName.@FullPropertyString, global::Godot.Variant.From<string>(__FullPropertyString_default_value));
2525
string __FullPropertyString_Complex_default_value = new string("FullPropertyString_Complex") + global::System.Convert.ToInt32("1");
2626
values.Add(PropertyName.@FullPropertyString_Complex, global::Godot.Variant.From<string>(__FullPropertyString_Complex_default_value));
27+
float __FullPropertyStaticImport_default_value = global::Godot.Mathf.Pi;
28+
values.Add(PropertyName.@FullPropertyStaticImport, global::Godot.Variant.From<float>(__FullPropertyStaticImport_default_value));
2729
string __LamdaPropertyString_default_value = "LamdaPropertyString";
2830
values.Add(PropertyName.@LamdaPropertyString, global::Godot.Variant.From<string>(__LamdaPropertyString_default_value));
31+
float __LambdaPropertyStaticImport_default_value = global::Godot.Mathf.Tau;
32+
values.Add(PropertyName.@LambdaPropertyStaticImport, global::Godot.Variant.From<float>(__LambdaPropertyStaticImport_default_value));
2933
string __PrimaryCtorParameter_default_value = default;
3034
values.Add(PropertyName.@PrimaryCtorParameter, global::Godot.Variant.From<string>(__PrimaryCtorParameter_default_value));
3135
float __ConstantMath_default_value = 2 * global::Godot.Mathf.Pi;
3236
values.Add(PropertyName.@ConstantMath, global::Godot.Variant.From<float>(__ConstantMath_default_value));
37+
float __ConstantMathStaticImport_default_value = global::Godot.Mathf.RadToDeg(2 * global::Godot.Mathf.Pi);
38+
values.Add(PropertyName.@ConstantMathStaticImport, global::Godot.Variant.From<float>(__ConstantMathStaticImport_default_value));
3339
string __StaticStringAddition_default_value = string.Empty + string.Empty;
3440
values.Add(PropertyName.@StaticStringAddition, global::Godot.Variant.From<string>(__StaticStringAddition_default_value));
3541
bool __PropertyBoolean_default_value = true;

modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/ExportedFields.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Godot;
22
using System;
33
using System.Collections.Generic;
4+
using static Godot.Mathf;
45

56
public partial class ExportedFields : GodotObject
67
{
@@ -18,6 +19,9 @@ public partial class ExportedFields : GodotObject
1819
[Export] private Double _fieldDouble = 10;
1920
[Export] private String _fieldString = "foo";
2021

22+
// Static import
23+
[Export] private Single _fieldStaticImport = RadToDeg(2 * Pi);
24+
2125
// Godot structs
2226
[Export] private Vector2 _fieldVector2 = new(10f, 10f);
2327
[Export] private Vector2I _fieldVector2I = Vector2I.Up;

0 commit comments

Comments
 (0)