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#] Remove useless isFirstEntry and useless source.Append("else ") #91924

Merged
merged 1 commit into from
May 14, 2024
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 @@ -33,15 +33,15 @@ protected override bool GetGodotClassPropertyValue(in godot_string_name name, ou
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.ReadOnlyAutoProperty);
return true;
}
else if (name == PropertyName.ReadOnlyProperty) {
if (name == PropertyName.ReadOnlyProperty) {
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.ReadOnlyProperty);
return true;
}
else if (name == PropertyName.InitOnlyAutoProperty) {
if (name == PropertyName.InitOnlyAutoProperty) {
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.InitOnlyAutoProperty);
return true;
}
else if (name == PropertyName.ReadOnlyField) {
if (name == PropertyName.ReadOnlyField) {
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.ReadOnlyField);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override bool SetGodotClassPropertyValue(in godot_string_name name, in
this.WriteOnlyProperty = global::Godot.NativeInterop.VariantUtils.ConvertTo<bool>(value);
return true;
}
else if (name == PropertyName._writeOnlyBackingField) {
if (name == PropertyName._writeOnlyBackingField) {
this._writeOnlyBackingField = global::Godot.NativeInterop.VariantUtils.ConvertTo<bool>(value);
return true;
}
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected override bool SetGodotClassPropertyValue(in godot_string_name name, in
this.WriteOnlyProperty = global::Godot.NativeInterop.VariantUtils.ConvertTo<bool>(value);
return true;
}
else if (name == PropertyName._writeOnlyBackingField) {
if (name == PropertyName._writeOnlyBackingField) {
this._writeOnlyBackingField = global::Godot.NativeInterop.VariantUtils.ConvertTo<bool>(value);
return true;
}
Expand All @@ -55,19 +55,19 @@ protected override bool GetGodotClassPropertyValue(in godot_string_name name, ou
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.ReadOnlyAutoProperty);
return true;
}
else if (name == PropertyName.ReadOnlyProperty) {
if (name == PropertyName.ReadOnlyProperty) {
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.ReadOnlyProperty);
return true;
}
else if (name == PropertyName.InitOnlyAutoProperty) {
if (name == PropertyName.InitOnlyAutoProperty) {
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.InitOnlyAutoProperty);
return true;
}
else if (name == PropertyName.ReadOnlyField) {
if (name == PropertyName.ReadOnlyField) {
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<string>(this.ReadOnlyField);
return true;
}
else if (name == PropertyName._writeOnlyBackingField) {
if (name == PropertyName._writeOnlyBackingField) {
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<bool>(this._writeOnlyBackingField);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected override bool HasGodotClassMethod(in godot_string_name method)
if (method == MethodName._Process) {
return true;
}
else if (method == MethodName.Bazz) {
if (method == MethodName.Bazz) {
return true;
}
return base.HasGodotClassMethod(method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override bool SetGodotClassPropertyValue(in godot_string_name name, in
this._nodePath = global::Godot.NativeInterop.VariantUtils.ConvertTo<global::Godot.NodePath>(value);
return true;
}
else if (name == PropertyName._velocity) {
if (name == PropertyName._velocity) {
this._velocity = global::Godot.NativeInterop.VariantUtils.ConvertTo<int>(value);
return true;
}
Expand All @@ -39,7 +39,7 @@ protected override bool GetGodotClassPropertyValue(in godot_string_name name, ou
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<global::Godot.NodePath>(this._nodePath);
return true;
}
else if (name == PropertyName._velocity) {
if (name == PropertyName._velocity) {
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<int>(this._velocity);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,9 @@ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
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;
foreach (string methodName in distinctMethodNames)
{
GenerateHasMethodEntry(methodName, source, isFirstEntry);
isFirstEntry = false;
GenerateHasMethodEntry(methodName, source);
}

source.Append(" return base.HasGodotClassMethod(method);\n");
Expand Down Expand Up @@ -412,13 +410,10 @@ private static PropertyInfo DeterminePropertyInfo(MarshalType marshalType, IType

private static void GenerateHasMethodEntry(
string methodName,
StringBuilder source,
bool isFirstEntry
StringBuilder source
)
{
source.Append(" ");
if (!isFirstEntry)
source.Append("else ");
source.Append("if (method == MethodName.");
source.Append(methodName);
source.Append(") {\n return true;\n }\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)

if (godotClassProperties.Length > 0 || godotClassFields.Length > 0)
{
bool isFirstEntry;

// Generate SetGodotClassPropertyValue

Expand All @@ -186,15 +185,13 @@ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
source.Append(" protected override bool SetGodotClassPropertyValue(in godot_string_name name, ");
source.Append("in godot_variant value)\n {\n");

isFirstEntry = true;
foreach (var property in godotClassProperties)
{
if (property.PropertySymbol.IsReadOnly || property.PropertySymbol.SetMethod!.IsInitOnly)
continue;

GeneratePropertySetter(property.PropertySymbol.Name,
property.PropertySymbol.Type, property.Type, source, isFirstEntry);
isFirstEntry = false;
property.PropertySymbol.Type, property.Type, source);
}

foreach (var field in godotClassFields)
Expand All @@ -203,8 +200,7 @@ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
continue;

GeneratePropertySetter(field.FieldSymbol.Name,
field.FieldSymbol.Type, field.Type, source, isFirstEntry);
isFirstEntry = false;
field.FieldSymbol.Type, field.Type, source);
}

source.Append(" return base.SetGodotClassPropertyValue(name, value);\n");
Expand All @@ -222,22 +218,19 @@ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
source.Append(" protected override bool GetGodotClassPropertyValue(in godot_string_name name, ");
source.Append("out godot_variant value)\n {\n");

isFirstEntry = true;
foreach (var property in godotClassProperties)
{
if (property.PropertySymbol.IsWriteOnly)
continue;

GeneratePropertyGetter(property.PropertySymbol.Name,
property.PropertySymbol.Type, property.Type, source, isFirstEntry);
isFirstEntry = false;
property.PropertySymbol.Type, property.Type, source);
}

foreach (var field in godotClassFields)
{
GeneratePropertyGetter(field.FieldSymbol.Name,
field.FieldSymbol.Type, field.Type, source, isFirstEntry);
isFirstEntry = false;
field.FieldSymbol.Type, field.Type, source);
}

source.Append(" return base.GetGodotClassPropertyValue(name, out value);\n");
Expand Down Expand Up @@ -318,15 +311,11 @@ private static void GeneratePropertySetter(
string propertyMemberName,
ITypeSymbol propertyTypeSymbol,
MarshalType propertyMarshalType,
StringBuilder source,
bool isFirstEntry
StringBuilder source
)
{
source.Append(" ");

if (!isFirstEntry)
source.Append("else ");

source.Append("if (name == PropertyName.")
.Append(propertyMemberName)
.Append(") {\n")
Expand All @@ -343,15 +332,11 @@ private static void GeneratePropertyGetter(
string propertyMemberName,
ITypeSymbol propertyTypeSymbol,
MarshalType propertyMarshalType,
StringBuilder source,
bool isFirstEntry
StringBuilder source
)
{
source.Append(" ");

if (!isFirstEntry)
source.Append("else ");

source.Append("if (name == PropertyName.")
.Append(propertyMemberName)
.Append(") {\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,9 @@ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
source.Append(
" protected override bool HasGodotClassSignal(in godot_string_name signal)\n {\n");

bool isFirstEntry = true;
foreach (var signal in godotSignalDelegates)
{
GenerateHasSignalEntry(signal.Name, source, isFirstEntry);
isFirstEntry = false;
GenerateHasSignalEntry(signal.Name, source);
}

source.Append(" return base.HasGodotClassSignal(signal);\n");
Expand Down Expand Up @@ -473,13 +471,10 @@ private static PropertyInfo DeterminePropertyInfo(MarshalType marshalType, IType

private static void GenerateHasSignalEntry(
string signalName,
StringBuilder source,
bool isFirstEntry
StringBuilder source
)
{
source.Append(" ");
if (!isFirstEntry)
source.Append("else ");
source.Append("if (signal == SignalName.");
source.Append(signalName);
source.Append(") {\n return true;\n }\n");
Expand Down
Loading