Skip to content

Commit

Permalink
Auto-format source code
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Actions Autoformatter committed Jan 28, 2025
1 parent a6332d4 commit 3c90ebb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
27 changes: 13 additions & 14 deletions src/rgen/Microsoft.Macios.Transformer/Attributes/AsyncData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ internal enum ConstructorType {
ResultType,
MethodName
}

public string? ResultType { get; init; } // this in the attr is a type, but we do not care for the transformation
public string? MethodName { get; init; }
public string? ResultTypeName { get; init; }
public string? PostNonResultSnippet { get; init; }
public AsyncData () {}

public AsyncData () { }

public AsyncData (string resultType, ConstructorType constructorType)
{
if (constructorType == ConstructorType.ResultType)
Expand All @@ -40,25 +40,25 @@ public static bool TryParse (AttributeData attributeData,
string? resultTypeName = null;
string? methodName = null;
string? postNonResultSnippet = null;

switch (count) {
case 0:
case 0:
break;
case 1:
// we have to diff constructors that take a single parameter, either a string or a type
if (attributeData.ConstructorArguments[0].Value! is string methodNameValue) {
if (attributeData.ConstructorArguments [0].Value! is string methodNameValue) {
constructorType = ConstructorType.MethodName;
methodName = methodNameValue;
} else {
constructorType = ConstructorType.ResultType;
resultType = ((INamedTypeSymbol) attributeData.ConstructorArguments[0].Value!).ToDisplayString();
resultType = ((INamedTypeSymbol) attributeData.ConstructorArguments [0].Value!).ToDisplayString ();
}
break;
default:
// 0 should not be an option..
return false;
}

if (attributeData.NamedArguments.Length == 0) {
if (constructorType == ConstructorType.ResultType)
data = new (resultType!, ConstructorType.ResultType);
Expand All @@ -70,7 +70,7 @@ public static bool TryParse (AttributeData attributeData,
foreach (var (argumentName, value) in attributeData.NamedArguments) {
switch (argumentName) {
case "ResultType":
resultType = ((INamedTypeSymbol) value.Value!).ToDisplayString();
resultType = ((INamedTypeSymbol) value.Value!).ToDisplayString ();
break;
case "MethodName":
methodName = (string) value.Value!;
Expand All @@ -89,7 +89,7 @@ public static bool TryParse (AttributeData attributeData,

if (count == 0) {
// use the default constructor and use the init properties
data = new() {
data = new () {
ResultType = resultType,
MethodName = methodName,
ResultTypeName = resultTypeName,
Expand All @@ -98,8 +98,7 @@ public static bool TryParse (AttributeData attributeData,
return true;
}

switch (constructorType)
{
switch (constructorType) {
case ConstructorType.MethodName:
data = new (methodName!, ConstructorType.MethodName) {
ResultType = resultType,
Expand All @@ -118,7 +117,7 @@ public static bool TryParse (AttributeData attributeData,

return false;
}

public bool Equals (AsyncData other)
{
if (ResultType != other.ResultType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Microsoft.Macios.Transformer.Tests.Attributes;

public class AsyncDataTests : BaseTransformerTestClass {

class TestDataTryCreate : IEnumerable<object []> {
public IEnumerator<object []> GetEnumerator ()
{
Expand Down Expand Up @@ -56,10 +56,11 @@ interface NSTableViewDiffableDataSource {
void ApplySnapshot (NSObject snapshot, bool animatingDifferences, [NullAllowed] Action completion);
}
";

yield return [(Source: asyncResultTypeName, Path: path), new AsyncData {
ResultTypeName = "NSSpellCheckerCandidates"
}];

yield return [(Source: asyncResultTypeName, Path: path),
new AsyncData {
ResultTypeName = "NSSpellCheckerCandidates"
}];

const string asyncMethodName = @"
using System;
Expand All @@ -79,10 +80,11 @@ interface NSTableViewDiffableDataSource {
void ApplySnapshot (NSObject snapshot, bool animatingDifferences, [NullAllowed] Action completion);
}
";

yield return [(Source: asyncMethodName, Path: path), new AsyncData {
MethodName = "ApplyTheSnapshotAsync"
}];

yield return [(Source: asyncMethodName, Path: path),
new AsyncData {
MethodName = "ApplyTheSnapshotAsync"
}];

const string asyncTypeOf = @"
using System;
Expand All @@ -104,10 +106,11 @@ interface NSTableViewDiffableDataSource {
void ApplySnapshot (NSObject snapshot, bool animatingDifferences, [NullAllowed] Action completion);
}
";

yield return [(Source: asyncTypeOf, Path: path), new AsyncData {
ResultType = "Test.SampleResult"
}];

yield return [(Source: asyncTypeOf, Path: path),
new AsyncData {
ResultType = "Test.SampleResult"
}];

const string postResult = @"
using System;
Expand All @@ -130,10 +133,11 @@ interface NSTableViewDiffableDataSource {
}
";

yield return [(Source: postResult, Path: path), new AsyncData {
ResultTypeName = "NSUrlSessionDataTaskRequest",
PostNonResultSnippet = "result.Resume ();"
}];
yield return [(Source: postResult, Path: path),
new AsyncData {
ResultTypeName = "NSUrlSessionDataTaskRequest",
PostNonResultSnippet = "result.Resume ();"
}];
}

IEnumerator IEnumerable.GetEnumerator () => GetEnumerator ();
Expand Down

0 comments on commit 3c90ebb

Please sign in to comment.