Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#: Document generated members #79239

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ INamedTypeSymbol symbol

source.Append("#pragma warning disable CS0109 // Disable warning about redundant 'new' keyword\n");

source.Append(" /// <summary>\n")
.Append(" /// Cached StringNames for the methods contained in this class, for fast lookup.\n")
.Append(" /// </summary>\n");

source.Append(
$" public new class MethodName : {symbol.BaseType.FullQualifiedNameIncludeGlobal()}.MethodName {{\n");

Expand All @@ -147,6 +151,12 @@ INamedTypeSymbol symbol

foreach (string methodName in distinctMethodNames)
{
source.Append(" /// <summary>\n")
.Append(" /// Cached name for the '")
.Append(methodName)
.Append("' method.\n")
RedworkDE marked this conversation as resolved.
Show resolved Hide resolved
.Append(" /// </summary>\n");

source.Append(" public new static readonly global::Godot.StringName ");
source.Append(methodName);
source.Append(" = \"");
Expand All @@ -162,6 +172,14 @@ INamedTypeSymbol symbol
{
const string listType = "global::System.Collections.Generic.List<global::Godot.Bridge.MethodInfo>";

source.Append(" /// <summary>\n")
.Append(" /// Get the method information for all the methods declared in this class.\n")
.Append(" /// This method is used by Godot to register the available methods in the editor.\n")
.Append(" /// Do not call this method.\n")
.Append(" /// </summary>\n");

source.Append(" [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]\n");

source.Append(" internal new static ")
.Append(listType)
.Append(" GetGodotMethodList()\n {\n");
Expand All @@ -188,6 +206,8 @@ INamedTypeSymbol symbol

if (godotClassMethods.Length > 0)
{
source.Append(" /// <inheritdoc/>\n");
source.Append(" [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]\n");
source.Append(" protected override bool InvokeGodotClassMethod(in godot_string_name method, ");
source.Append("NativeVariantPtrArgs args, out godot_variant ret)\n {\n");

Expand All @@ -205,6 +225,8 @@ INamedTypeSymbol symbol

if (distinctMethodNames.Length > 0)
{
source.Append(" /// <inheritdoc/>\n");
source.Append(" [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]\n");
source.Append(" protected override bool HasGodotClassMethod(in godot_string_name method)\n {\n");

bool isFirstEntry = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ INamedTypeSymbol symbol

source.Append("#pragma warning disable CS0109 // Disable warning about redundant 'new' keyword\n");

source.Append(" /// <summary>\n")
.Append(" /// Cached StringNames for the properties and fields contained in this class, for fast lookup.\n")
.Append(" /// </summary>\n");

source.Append(
$" public new class PropertyName : {symbol.BaseType.FullQualifiedNameIncludeGlobal()}.PropertyName {{\n");

Expand All @@ -132,6 +136,13 @@ INamedTypeSymbol symbol
foreach (var property in godotClassProperties)
{
string propertyName = property.PropertySymbol.Name;

source.Append(" /// <summary>\n")
.Append(" /// Cached name for the '")
.Append(propertyName)
.Append("' property.\n")
.Append(" /// </summary>\n");

source.Append(" public new static readonly global::Godot.StringName ");
source.Append(propertyName);
source.Append(" = \"");
Expand All @@ -142,6 +153,13 @@ INamedTypeSymbol symbol
foreach (var field in godotClassFields)
{
string fieldName = field.FieldSymbol.Name;

source.Append(" /// <summary>\n")
.Append(" /// Cached name for the '")
.Append(fieldName)
.Append("' field.\n")
.Append(" /// </summary>\n");

source.Append(" public new static readonly global::Godot.StringName ");
source.Append(fieldName);
source.Append(" = \"");
Expand All @@ -162,6 +180,8 @@ INamedTypeSymbol symbol

if (!allPropertiesAreReadOnly)
{
source.Append(" /// <inheritdoc/>\n");
source.Append(" [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]\n");
source.Append(" protected override bool SetGodotClassPropertyValue(in godot_string_name name, ");
source.Append("in godot_variant value)\n {\n");

Expand Down Expand Up @@ -193,6 +213,8 @@ INamedTypeSymbol symbol

// Generate GetGodotClassPropertyValue

source.Append(" /// <inheritdoc/>\n");
source.Append(" [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]\n");
source.Append(" protected override bool GetGodotClassPropertyValue(in godot_string_name name, ");
source.Append("out godot_variant value)\n {\n");

Expand All @@ -217,7 +239,15 @@ INamedTypeSymbol symbol

// Generate GetGodotPropertyList

string dictionaryType = "global::System.Collections.Generic.List<global::Godot.Bridge.PropertyInfo>";
const string dictionaryType = "global::System.Collections.Generic.List<global::Godot.Bridge.PropertyInfo>";

source.Append(" /// <summary>\n")
.Append(" /// Get the property information for all the properties declared in this class.\n")
.Append(" /// This method is used by Godot to register the available properties in the editor.\n")
.Append(" /// Do not call this method.\n")
.Append(" /// </summary>\n");

source.Append(" [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]\n");

source.Append(" internal new static ")
.Append(dictionaryType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,20 @@ INamedTypeSymbol symbol
{
source.Append("#pragma warning disable CS0109 // Disable warning about redundant 'new' keyword\n");

string dictionaryType =
const string dictionaryType =
"global::System.Collections.Generic.Dictionary<global::Godot.StringName, global::Godot.Variant>";

source.Append("#if TOOLS\n");

source.Append(" /// <summary>\n")
.Append(" /// Get the default values for all properties declared in this class.\n")
.Append(" /// This method is used by Godot to determine the value that will be\n")
.Append(" /// used by the inspector when resetting properties.\n")
.Append(" /// Do not call this method.\n")
.Append(" /// </summary>\n");

source.Append(" [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]\n");

source.Append(" internal new static ");
source.Append(dictionaryType);
source.Append(" GetGodotPropertyDefaultValues()\n {\n");
Expand Down Expand Up @@ -320,7 +330,8 @@ INamedTypeSymbol symbol

source.Append(" return values;\n");
source.Append(" }\n");
source.Append("#endif\n");

source.Append("#endif // TOOLS\n");

source.Append("#pragma warning restore CS0109\n");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ INamedTypeSymbol symbol
godotSignalDelegates.Add(new(signalName, signalDelegateSymbol, invokeMethodData.Value));
}

source.Append(" /// <inheritdoc/>\n");
source.Append(" [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]\n");
source.Append(
" protected override void SaveGodotObjectData(global::Godot.Bridge.GodotSerializationInfo info)\n {\n");
source.Append(" base.SaveGodotObjectData(info);\n");
Expand Down Expand Up @@ -196,6 +198,8 @@ INamedTypeSymbol symbol

source.Append(" }\n");

source.Append(" /// <inheritdoc/>\n");
source.Append(" [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]\n");
source.Append(
" protected override void RestoreGodotObjectData(global::Godot.Bridge.GodotSerializationInfo info)\n {\n");
source.Append(" base.RestoreGodotObjectData(info);\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ INamedTypeSymbol symbol

source.Append("#pragma warning disable CS0109 // Disable warning about redundant 'new' keyword\n");

source.Append(" /// <summary>\n")
.Append(" /// Cached StringNames for the signals contained in this class, for fast lookup.\n")
.Append(" /// </summary>\n");

source.Append(
$" public new class SignalName : {symbol.BaseType.FullQualifiedNameIncludeGlobal()}.SignalName {{\n");

Expand All @@ -184,6 +188,13 @@ INamedTypeSymbol symbol
foreach (var signalDelegate in godotSignalDelegates)
{
string signalName = signalDelegate.Name;

source.Append(" /// <summary>\n")
.Append(" /// Cached name for the '")
.Append(signalName)
.Append("' signal.\n")
.Append(" /// </summary>\n");

source.Append(" public new static readonly global::Godot.StringName ");
source.Append(signalName);
source.Append(" = \"");
Expand All @@ -199,6 +210,14 @@ INamedTypeSymbol symbol
{
const string listType = "global::System.Collections.Generic.List<global::Godot.Bridge.MethodInfo>";

source.Append(" /// <summary>\n")
.Append(" /// Get the signal information for all the signals declared in this class.\n")
.Append(" /// This method is used by Godot to register the available signals in the editor.\n")
.Append(" /// Do not call this method.\n")
.Append(" /// </summary>\n");

source.Append(" [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]\n");

source.Append(" internal new static ")
.Append(listType)
.Append(" GetGodotSignalList()\n {\n");
Expand Down Expand Up @@ -258,6 +277,8 @@ INamedTypeSymbol symbol

if (godotSignalDelegates.Count > 0)
{
source.Append(" /// <inheritdoc/>\n");
source.Append(" [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]\n");
source.Append(
" protected override void RaiseGodotClassSignalCallbacks(in godot_string_name signal, ");
source.Append("NativeVariantPtrArgs args)\n {\n");
Expand All @@ -276,6 +297,8 @@ INamedTypeSymbol symbol

if (godotSignalDelegates.Count > 0)
{
source.Append(" /// <inheritdoc/>\n");
source.Append(" [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]\n");
source.Append(
" protected override bool HasGodotClassSignal(in godot_string_name signal)\n {\n");

Expand Down
61 changes: 51 additions & 10 deletions modules/mono/editor/bindings_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,16 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str

// Generate InvokeGodotClassMethod

output << MEMBER_BEGIN "protected internal " << (is_derived_type ? "override" : "virtual")
output << MEMBER_BEGIN "/// <summary>\n"
<< INDENT1 "/// Invokes the method with the given name, using the given arguments.\n"
<< INDENT1 "/// This method is used by Godot to invoke methods from the engine side.\n"
<< INDENT1 "/// Do not call or override this method.\n"
<< INDENT1 "/// </summary>\n"
<< INDENT1 "/// <param name=\"method\">Name of the method to invoke.</param>\n"
<< INDENT1 "/// <param name=\"args\">Arguments to use with the invoked method.</param>\n"
<< INDENT1 "/// <param name=\"ret\">Value returned by the invoked method.</param>\n";

output << INDENT1 "protected internal " << (is_derived_type ? "override" : "virtual")
<< " bool " CS_METHOD_INVOKE_GODOT_CLASS_METHOD "(in godot_string_name method, "
<< "NativeVariantPtrArgs args, out godot_variant ret)\n"
<< INDENT1 "{\n";
Expand Down Expand Up @@ -1696,6 +1705,13 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str

// Generate HasGodotClassMethod

output << MEMBER_BEGIN "/// <summary>\n"
<< INDENT1 "/// Check if the type contains a method with the given name.\n"
<< INDENT1 "/// This method is used by Godot to check if a method exists before invoking it.\n"
<< INDENT1 "/// Do not call or override this method.\n"
<< INDENT1 "/// </summary>\n"
<< INDENT1 "/// <param name=\"method\">Name of the method to check for.</param>\n";

output << MEMBER_BEGIN "protected internal " << (is_derived_type ? "override" : "virtual")
<< " bool " CS_METHOD_HAS_GODOT_CLASS_METHOD "(in godot_string_name method)\n"
<< INDENT1 "{\n";
Expand Down Expand Up @@ -1728,6 +1744,13 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str

// Generate HasGodotClassSignal

output << MEMBER_BEGIN "/// <summary>\n"
<< INDENT1 "/// Check if the type contains a signal with the given name.\n"
<< INDENT1 "/// This method is used by Godot to check if a signal exists before raising it.\n"
<< INDENT1 "/// Do not call or override this method.\n"
<< INDENT1 "/// </summary>\n"
<< INDENT1 "/// <param name=\"method\">Name of the method to check for.</param>\n";

output << MEMBER_BEGIN "protected internal " << (is_derived_type ? "override" : "virtual")
<< " bool " CS_METHOD_HAS_GODOT_CLASS_SIGNAL "(in godot_string_name signal)\n"
<< INDENT1 "{\n";
Expand Down Expand Up @@ -1758,39 +1781,57 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str
//Generate StringName for all class members
bool is_inherit = !itype.is_singleton && obj_types.has(itype.base_name);
//PropertyName
output << MEMBER_BEGIN "/// <summary>\n"
<< INDENT1 "/// Cached StringNames for the properties and fields contained in this class, for fast lookup.\n"
<< INDENT1 "/// </summary>\n";
if (is_inherit) {
output << MEMBER_BEGIN "public new class PropertyName : " << obj_types[itype.base_name].proxy_name << ".PropertyName";
output << INDENT1 "public new class PropertyName : " << obj_types[itype.base_name].proxy_name << ".PropertyName";
} else {
output << MEMBER_BEGIN "public class PropertyName";
output << INDENT1 "public class PropertyName";
}
output << "\n"
<< INDENT1 "{\n";
for (const PropertyInterface &iprop : itype.properties) {
output << INDENT2 "public static readonly StringName " << iprop.proxy_name << " = \"" << iprop.cname << "\";\n";
output << INDENT2 "/// <summary>\n"
<< INDENT2 "/// Cached name for the '" << iprop.cname << "' property.\n"
<< INDENT2 "/// </summary>\n"
<< INDENT2 "public static readonly StringName " << iprop.proxy_name << " = \"" << iprop.cname << "\";\n";
}
output << INDENT1 "}\n";
//MethodName
output << MEMBER_BEGIN "/// <summary>\n"
<< INDENT1 "/// Cached StringNames for the methods contained in this class, for fast lookup.\n"
<< INDENT1 "/// </summary>\n";
if (is_inherit) {
output << MEMBER_BEGIN "public new class MethodName : " << obj_types[itype.base_name].proxy_name << ".MethodName";
output << INDENT1 "public new class MethodName : " << obj_types[itype.base_name].proxy_name << ".MethodName";
} else {
output << MEMBER_BEGIN "public class MethodName";
output << INDENT1 "public class MethodName";
}
output << "\n"
<< INDENT1 "{\n";
for (const MethodInterface &imethod : itype.methods) {
output << INDENT2 "public static readonly StringName " << imethod.proxy_name << " = \"" << imethod.cname << "\";\n";
output << INDENT2 "/// <summary>\n"
<< INDENT2 "/// Cached name for the '" << imethod.cname << "' method.\n"
<< INDENT2 "/// </summary>\n"
<< INDENT2 "public static readonly StringName " << imethod.proxy_name << " = \"" << imethod.cname << "\";\n";
}
output << INDENT1 "}\n";
//SignalName
output << MEMBER_BEGIN "/// <summary>\n"
<< INDENT1 "/// Cached StringNames for the signals contained in this class, for fast lookup.\n"
<< INDENT1 "/// </summary>\n";
if (is_inherit) {
output << MEMBER_BEGIN "public new class SignalName : " << obj_types[itype.base_name].proxy_name << ".SignalName";
output << INDENT1 "public new class SignalName : " << obj_types[itype.base_name].proxy_name << ".SignalName";
} else {
output << MEMBER_BEGIN "public class SignalName";
output << INDENT1 "public class SignalName";
}
output << "\n"
<< INDENT1 "{\n";
for (const SignalInterface &isignal : itype.signals_) {
output << INDENT2 "public static readonly StringName " << isignal.proxy_name << " = \"" << isignal.cname << "\";\n";
output << INDENT2 "/// <summary>\n"
<< INDENT2 "/// Cached name for the '" << isignal.cname << "' signal.\n"
<< INDENT2 "/// </summary>\n"
<< INDENT2 "public static readonly StringName " << isignal.proxy_name << " = \"" << isignal.cname << "\";\n";
}
output << INDENT1 "}\n";

Expand Down
Loading
Loading