Merge pull request #65410 from magian1127/4.0UnifiedMemberName

C# Modify the MemberName generated for the user script
This commit is contained in:
Ignacio Roldán Etcheverry 2022-09-06 18:49:48 +02:00 committed by GitHub
commit 5628ab9215
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 32 deletions

View file

@ -133,7 +133,9 @@ namespace Godot.SourceGenerators
.Distinct(new MethodOverloadEqualityComparer()) .Distinct(new MethodOverloadEqualityComparer())
.ToArray(); .ToArray();
source.Append(" private partial class GodotInternal {\n"); source.Append("#pragma warning disable CS0109 // Disable warning about redundant 'new' keyword\n");
source.Append($" public new class MethodName : {symbol.BaseType.FullQualifiedName()}.MethodName {{\n");
// Generate cached StringNames for methods and properties, for fast lookup // Generate cached StringNames for methods and properties, for fast lookup
@ -144,7 +146,7 @@ namespace Godot.SourceGenerators
foreach (string methodName in distinctMethodNames) foreach (string methodName in distinctMethodNames)
{ {
source.Append(" public static readonly StringName MethodName_"); source.Append(" public new static readonly StringName ");
source.Append(methodName); source.Append(methodName);
source.Append(" = \""); source.Append(" = \"");
source.Append(methodName); source.Append(methodName);
@ -157,8 +159,6 @@ namespace Godot.SourceGenerators
if (godotClassMethods.Length > 0) if (godotClassMethods.Length > 0)
{ {
source.Append("#pragma warning disable CS0109 // Disable warning about redundant 'new' keyword\n");
const string listType = "System.Collections.Generic.List<global::Godot.Bridge.MethodInfo>"; const string listType = "System.Collections.Generic.List<global::Godot.Bridge.MethodInfo>";
source.Append(" internal new static ") source.Append(" internal new static ")
@ -179,9 +179,9 @@ namespace Godot.SourceGenerators
source.Append(" return methods;\n"); source.Append(" return methods;\n");
source.Append(" }\n"); source.Append(" }\n");
}
source.Append("#pragma warning restore CS0109\n"); source.Append("#pragma warning restore CS0109\n");
}
// Generate InvokeGodotClassMethod // Generate InvokeGodotClassMethod
@ -242,7 +242,7 @@ namespace Godot.SourceGenerators
private static void AppendMethodInfo(StringBuilder source, MethodInfo methodInfo) private static void AppendMethodInfo(StringBuilder source, MethodInfo methodInfo)
{ {
source.Append(" methods.Add(new(name: GodotInternal.MethodName_") source.Append(" methods.Add(new(name: MethodName.")
.Append(methodInfo.Name) .Append(methodInfo.Name)
.Append(", returnVal: "); .Append(", returnVal: ");
@ -350,7 +350,7 @@ namespace Godot.SourceGenerators
source.Append(" "); source.Append(" ");
if (!isFirstEntry) if (!isFirstEntry)
source.Append("else "); source.Append("else ");
source.Append("if (method == GodotInternal.MethodName_"); source.Append("if (method == MethodName.");
source.Append(methodName); source.Append(methodName);
source.Append(") {\n return true;\n }\n"); source.Append(") {\n return true;\n }\n");
} }
@ -362,7 +362,7 @@ namespace Godot.SourceGenerators
{ {
string methodName = method.Method.Name; string methodName = method.Method.Name;
source.Append(" if (method == GodotInternal.MethodName_"); source.Append(" if (method == MethodName.");
source.Append(methodName); source.Append(methodName);
source.Append(" && argCount == "); source.Append(" && argCount == ");
source.Append(method.ParamTypes.Length); source.Append(method.ParamTypes.Length);

View file

@ -122,14 +122,16 @@ namespace Godot.SourceGenerators
var godotClassProperties = propertySymbols.WhereIsGodotCompatibleType(typeCache).ToArray(); var godotClassProperties = propertySymbols.WhereIsGodotCompatibleType(typeCache).ToArray();
var godotClassFields = fieldSymbols.WhereIsGodotCompatibleType(typeCache).ToArray(); var godotClassFields = fieldSymbols.WhereIsGodotCompatibleType(typeCache).ToArray();
source.Append(" private partial class GodotInternal {\n"); source.Append("#pragma warning disable CS0109 // Disable warning about redundant 'new' keyword\n");
source.Append($" public new class PropertyName : {symbol.BaseType.FullQualifiedName()}.PropertyName {{\n");
// Generate cached StringNames for methods and properties, for fast lookup // Generate cached StringNames for methods and properties, for fast lookup
foreach (var property in godotClassProperties) foreach (var property in godotClassProperties)
{ {
string propertyName = property.PropertySymbol.Name; string propertyName = property.PropertySymbol.Name;
source.Append(" public static readonly StringName PropName_"); source.Append(" public new static readonly StringName ");
source.Append(propertyName); source.Append(propertyName);
source.Append(" = \""); source.Append(" = \"");
source.Append(propertyName); source.Append(propertyName);
@ -139,7 +141,7 @@ namespace Godot.SourceGenerators
foreach (var field in godotClassFields) foreach (var field in godotClassFields)
{ {
string fieldName = field.FieldSymbol.Name; string fieldName = field.FieldSymbol.Name;
source.Append(" public static readonly StringName PropName_"); source.Append(" public new static readonly StringName ");
source.Append(fieldName); source.Append(fieldName);
source.Append(" = \""); source.Append(" = \"");
source.Append(fieldName); source.Append(fieldName);
@ -214,8 +216,6 @@ namespace Godot.SourceGenerators
// Generate GetGodotPropertyList // Generate GetGodotPropertyList
source.Append("#pragma warning disable CS0109 // Disable warning about redundant 'new' keyword\n");
string dictionaryType = "System.Collections.Generic.List<global::Godot.Bridge.PropertyInfo>"; string dictionaryType = "System.Collections.Generic.List<global::Godot.Bridge.PropertyInfo>";
source.Append(" internal new static ") source.Append(" internal new static ")
@ -289,7 +289,7 @@ namespace Godot.SourceGenerators
if (!isFirstEntry) if (!isFirstEntry)
source.Append("else "); source.Append("else ");
source.Append("if (name == GodotInternal.PropName_") source.Append("if (name == PropertyName.")
.Append(propertyMemberName) .Append(propertyMemberName)
.Append(") {\n") .Append(") {\n")
.Append(" ") .Append(" ")
@ -313,7 +313,7 @@ namespace Godot.SourceGenerators
if (!isFirstEntry) if (!isFirstEntry)
source.Append("else "); source.Append("else ");
source.Append("if (name == GodotInternal.PropName_") source.Append("if (name == PropertyName.")
.Append(propertyMemberName) .Append(propertyMemberName)
.Append(") {\n") .Append(") {\n")
.Append(" value = ") .Append(" value = ")
@ -342,7 +342,7 @@ namespace Godot.SourceGenerators
{ {
source.Append(" properties.Add(new(type: (Godot.Variant.Type)") source.Append(" properties.Add(new(type: (Godot.Variant.Type)")
.Append((int)propertyInfo.Type) .Append((int)propertyInfo.Type)
.Append(", name: GodotInternal.PropName_") .Append(", name: PropertyName.")
.Append(propertyInfo.Name) .Append(propertyInfo.Name)
.Append(", hint: (Godot.PropertyHint)") .Append(", hint: (Godot.PropertyHint)")
.Append((int)propertyInfo.Hint) .Append((int)propertyInfo.Hint)

View file

@ -243,7 +243,7 @@ namespace Godot.SourceGenerators
source.Append(" = "); source.Append(" = ");
source.Append(exportedMember.Value ?? "default"); source.Append(exportedMember.Value ?? "default");
source.Append(";\n"); source.Append(";\n");
source.Append(" values.Add(GodotInternal.PropName_"); source.Append(" values.Add(PropertyName.");
source.Append(exportedMember.Name); source.Append(exportedMember.Name);
source.Append(", "); source.Append(", ");
source.Append(defaultValueLocalName); source.Append(defaultValueLocalName);

View file

@ -159,7 +159,7 @@ namespace Godot.SourceGenerators
{ {
string propertyName = property.PropertySymbol.Name; string propertyName = property.PropertySymbol.Name;
source.Append(" info.AddProperty(GodotInternal.PropName_") source.Append(" info.AddProperty(PropertyName.")
.Append(propertyName) .Append(propertyName)
.Append(", ") .Append(", ")
.AppendManagedToVariantExpr(string.Concat("this.", propertyName), property.Type) .AppendManagedToVariantExpr(string.Concat("this.", propertyName), property.Type)
@ -172,7 +172,7 @@ namespace Godot.SourceGenerators
{ {
string fieldName = field.FieldSymbol.Name; string fieldName = field.FieldSymbol.Name;
source.Append(" info.AddProperty(GodotInternal.PropName_") source.Append(" info.AddProperty(PropertyName.")
.Append(fieldName) .Append(fieldName)
.Append(", ") .Append(", ")
.AppendManagedToVariantExpr(string.Concat("this.", fieldName), field.Type) .AppendManagedToVariantExpr(string.Concat("this.", fieldName), field.Type)
@ -185,7 +185,7 @@ namespace Godot.SourceGenerators
{ {
string signalName = signalDelegate.Name; string signalName = signalDelegate.Name;
source.Append(" info.AddSignalEventDelegate(GodotInternal.SignalName_") source.Append(" info.AddSignalEventDelegate(SignalName.")
.Append(signalName) .Append(signalName)
.Append(", this.backing_") .Append(", this.backing_")
.Append(signalName) .Append(signalName)
@ -204,7 +204,7 @@ namespace Godot.SourceGenerators
{ {
string propertyName = property.PropertySymbol.Name; string propertyName = property.PropertySymbol.Name;
source.Append(" if (info.TryGetProperty(GodotInternal.PropName_") source.Append(" if (info.TryGetProperty(PropertyName.")
.Append(propertyName) .Append(propertyName)
.Append(", out var _value_") .Append(", out var _value_")
.Append(propertyName) .Append(propertyName)
@ -223,7 +223,7 @@ namespace Godot.SourceGenerators
{ {
string fieldName = field.FieldSymbol.Name; string fieldName = field.FieldSymbol.Name;
source.Append(" if (info.TryGetProperty(GodotInternal.PropName_") source.Append(" if (info.TryGetProperty(PropertyName.")
.Append(fieldName) .Append(fieldName)
.Append(", out var _value_") .Append(", out var _value_")
.Append(fieldName) .Append(fieldName)
@ -245,7 +245,7 @@ namespace Godot.SourceGenerators
source.Append(" if (info.TryGetSignalEventDelegate<") source.Append(" if (info.TryGetSignalEventDelegate<")
.Append(signalDelegateQualifiedName) .Append(signalDelegateQualifiedName)
.Append(">(GodotInternal.SignalName_") .Append(">(SignalName.")
.Append(signalName) .Append(signalName)
.Append(", out var _value_") .Append(", out var _value_")
.Append(signalName) .Append(signalName)

View file

@ -173,14 +173,16 @@ namespace Godot.SourceGenerators
godotSignalDelegates.Add(new(signalName, signalDelegateSymbol, invokeMethodData.Value)); godotSignalDelegates.Add(new(signalName, signalDelegateSymbol, invokeMethodData.Value));
} }
source.Append(" private partial class GodotInternal {\n"); source.Append("#pragma warning disable CS0109 // Disable warning about redundant 'new' keyword\n");
source.Append($" public new class SignalName : {symbol.BaseType.FullQualifiedName()}.SignalName {{\n");
// Generate cached StringNames for methods and properties, for fast lookup // Generate cached StringNames for methods and properties, for fast lookup
foreach (var signalDelegate in godotSignalDelegates) foreach (var signalDelegate in godotSignalDelegates)
{ {
string signalName = signalDelegate.Name; string signalName = signalDelegate.Name;
source.Append(" public static readonly StringName SignalName_"); source.Append(" public new static readonly StringName ");
source.Append(signalName); source.Append(signalName);
source.Append(" = \""); source.Append(" = \"");
source.Append(signalName); source.Append(signalName);
@ -193,8 +195,6 @@ namespace Godot.SourceGenerators
if (godotSignalDelegates.Count > 0) if (godotSignalDelegates.Count > 0)
{ {
source.Append("#pragma warning disable CS0109 // Disable warning about redundant 'new' keyword\n");
const string listType = "System.Collections.Generic.List<global::Godot.Bridge.MethodInfo>"; const string listType = "System.Collections.Generic.List<global::Godot.Bridge.MethodInfo>";
source.Append(" internal new static ") source.Append(" internal new static ")
@ -215,9 +215,9 @@ namespace Godot.SourceGenerators
source.Append(" return signals;\n"); source.Append(" return signals;\n");
source.Append(" }\n"); source.Append(" }\n");
}
source.Append("#pragma warning restore CS0109\n"); source.Append("#pragma warning restore CS0109\n");
}
// Generate signal event // Generate signal event
@ -291,7 +291,7 @@ namespace Godot.SourceGenerators
private static void AppendMethodInfo(StringBuilder source, MethodInfo methodInfo) private static void AppendMethodInfo(StringBuilder source, MethodInfo methodInfo)
{ {
source.Append(" signals.Add(new(name: GodotInternal.SignalName_") source.Append(" signals.Add(new(name: SignalName.")
.Append(methodInfo.Name) .Append(methodInfo.Name)
.Append(", returnVal: "); .Append(", returnVal: ");
@ -400,7 +400,7 @@ namespace Godot.SourceGenerators
string signalName = signal.Name; string signalName = signal.Name;
var invokeMethodData = signal.InvokeMethodData; var invokeMethodData = signal.InvokeMethodData;
source.Append(" if (signal == GodotInternal.SignalName_"); source.Append(" if (signal == SignalName.");
source.Append(signalName); source.Append(signalName);
source.Append(" && argCount == "); source.Append(" && argCount == ");
source.Append(invokeMethodData.ParamTypes.Length); source.Append(invokeMethodData.ParamTypes.Length);