1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-18 14:21:41 +00:00

C#: Document generated members

Documents generated members and tries to discourage users from calling/overriding internal methods that only exist to be used by the engine.
This commit is contained in:
Raul Santos
2023-07-09 14:14:36 +02:00
parent 83cc5d4914
commit 12e4aa93b3
8 changed files with 195 additions and 14 deletions

View File

@@ -135,6 +135,10 @@ namespace Godot.SourceGenerators
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");
@@ -147,6 +151,12 @@ namespace Godot.SourceGenerators
foreach (string methodName in distinctMethodNames)
{
source.Append(" /// <summary>\n")
.Append(" /// Cached name for the '")
.Append(methodName)
.Append("' method.\n")
.Append(" /// </summary>\n");
source.Append(" public new static readonly global::Godot.StringName ");
source.Append(methodName);
source.Append(" = \"");
@@ -162,6 +172,14 @@ namespace Godot.SourceGenerators
{
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");
@@ -188,6 +206,8 @@ namespace Godot.SourceGenerators
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");
@@ -205,6 +225,8 @@ namespace Godot.SourceGenerators
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;

View File

@@ -124,6 +124,10 @@ namespace Godot.SourceGenerators
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");
@@ -132,6 +136,13 @@ namespace Godot.SourceGenerators
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(" = \"");
@@ -142,6 +153,13 @@ namespace Godot.SourceGenerators
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(" = \"");
@@ -162,6 +180,8 @@ namespace Godot.SourceGenerators
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");
@@ -193,6 +213,8 @@ namespace Godot.SourceGenerators
// 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");
@@ -217,7 +239,15 @@ namespace Godot.SourceGenerators
// 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)

View File

@@ -285,10 +285,20 @@ namespace Godot.SourceGenerators
{
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");
@@ -320,7 +330,8 @@ namespace Godot.SourceGenerators
source.Append(" return values;\n");
source.Append(" }\n");
source.Append("#endif\n");
source.Append("#endif // TOOLS\n");
source.Append("#pragma warning restore CS0109\n");
}

View File

@@ -149,6 +149,8 @@ namespace Godot.SourceGenerators
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");
@@ -196,6 +198,8 @@ namespace Godot.SourceGenerators
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");

View File

@@ -176,6 +176,10 @@ namespace Godot.SourceGenerators
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");
@@ -184,6 +188,13 @@ namespace Godot.SourceGenerators
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(" = \"");
@@ -199,6 +210,14 @@ namespace Godot.SourceGenerators
{
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");
@@ -258,6 +277,8 @@ namespace Godot.SourceGenerators
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");
@@ -276,6 +297,8 @@ namespace Godot.SourceGenerators
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");