summaryrefslogtreecommitdiffstats
path: root/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs
diff options
context:
space:
mode:
authorRémi Verschelde <remi@verschelde.fr>2024-09-17 12:39:29 +0200
committerGitHub <noreply@github.com>2024-09-17 12:39:29 +0200
commit6225d3982604829084c2c92a2ff87fce0ca6ed8b (patch)
tree900076c19513ab8e66f35dd4f11151cdb17e069e /modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs
parentd40fc50f086d14583c7cc979ed4e5363ac223717 (diff)
parent3a2804a7e770ea6f383355815282b77b90c43863 (diff)
downloadredot-engine-6225d3982604829084c2c92a2ff87fce0ca6ed8b.tar.gz
Merge pull request #97082 from akien-mga/4.3-cherrypicks
[4.3] Cherry-picks for the 4.3 branch (future 4.3.1) - 1st batch
Diffstat (limited to 'modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs')
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs51
1 files changed, 33 insertions, 18 deletions
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs
index efe88d8468..626f51ecae 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs
@@ -196,16 +196,13 @@ namespace Godot.SourceGenerators
continue;
}
- if (marshalType == MarshalType.GodotObjectOrDerived)
+ if (!isNode && MemberHasNodeType(propertyType, marshalType.Value))
{
- if (!isNode && propertyType.InheritsFrom("GodotSharp", GodotClasses.Node))
- {
- context.ReportDiagnostic(Diagnostic.Create(
- Common.OnlyNodesShouldExportNodesRule,
- property.Locations.FirstLocationWithSourceTreeOrDefault()
- ));
- continue;
- }
+ context.ReportDiagnostic(Diagnostic.Create(
+ Common.OnlyNodesShouldExportNodesRule,
+ property.Locations.FirstLocationWithSourceTreeOrDefault()
+ ));
+ continue;
}
var propertyDeclarationSyntax = property.DeclaringSyntaxReferences
@@ -315,16 +312,13 @@ namespace Godot.SourceGenerators
continue;
}
- if (marshalType == MarshalType.GodotObjectOrDerived)
+ if (!isNode && MemberHasNodeType(fieldType, marshalType.Value))
{
- if (!isNode && fieldType.InheritsFrom("GodotSharp", GodotClasses.Node))
- {
- context.ReportDiagnostic(Diagnostic.Create(
- Common.OnlyNodesShouldExportNodesRule,
- field.Locations.FirstLocationWithSourceTreeOrDefault()
- ));
- continue;
- }
+ context.ReportDiagnostic(Diagnostic.Create(
+ Common.OnlyNodesShouldExportNodesRule,
+ field.Locations.FirstLocationWithSourceTreeOrDefault()
+ ));
+ continue;
}
EqualsValueClauseSyntax? initializer = field.DeclaringSyntaxReferences
@@ -424,6 +418,27 @@ namespace Godot.SourceGenerators
context.AddSource(uniqueHint, SourceText.From(source.ToString(), Encoding.UTF8));
}
+ private static bool MemberHasNodeType(ITypeSymbol memberType, MarshalType marshalType)
+ {
+ if (marshalType == MarshalType.GodotObjectOrDerived)
+ {
+ return memberType.InheritsFrom("GodotSharp", GodotClasses.Node);
+ }
+ if (marshalType == MarshalType.GodotObjectOrDerivedArray)
+ {
+ var elementType = ((IArrayTypeSymbol)memberType).ElementType;
+ return elementType.InheritsFrom("GodotSharp", GodotClasses.Node);
+ }
+ if (memberType is INamedTypeSymbol { IsGenericType: true } genericType)
+ {
+ return genericType.TypeArguments
+ .Any(static typeArgument
+ => typeArgument.InheritsFrom("GodotSharp", GodotClasses.Node));
+ }
+
+ return false;
+ }
+
private struct ExportedPropertyMetadata
{
public ExportedPropertyMetadata(string name, MarshalType type, ITypeSymbol typeSymbol, string? value)