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 b3cfcca commit 1926da5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 51 deletions.
25 changes: 12 additions & 13 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Microsoft.Macios.Transformer.Attributes;

readonly record struct NotificationData {

/// <summary>
/// Diff the constructor used in the bindings.
/// </summary>
Expand All @@ -16,7 +16,7 @@ internal enum ConstructorType {
NotificationCenter,
All
}

public string? Type { get; init; }
public string? NotificationCenter { get; init; }

Expand All @@ -43,35 +43,35 @@ public static bool TryParse (AttributeData attributeData,
ConstructorType constructorType = ConstructorType.NotificationType;
string? notificationType = null;
string? notificationCenter = 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 notificationCenterValue) {
if (attributeData.ConstructorArguments [0].Value! is string notificationCenterValue) {
constructorType = ConstructorType.NotificationCenter;
notificationCenter = notificationCenterValue;
} else {
constructorType = ConstructorType.NotificationType;
notificationType = ((INamedTypeSymbol) attributeData.ConstructorArguments[0].Value!).ToDisplayString();
notificationType = ((INamedTypeSymbol) attributeData.ConstructorArguments [0].Value!).ToDisplayString ();
}
break;
case 2:
constructorType = ConstructorType.All;
notificationType = ((INamedTypeSymbol) attributeData.ConstructorArguments[0].Value!).ToDisplayString();
notificationType = ((INamedTypeSymbol) attributeData.ConstructorArguments [0].Value!).ToDisplayString ();
notificationCenter = (string?) attributeData.ConstructorArguments [1].Value!;
break;
default:
// 0 should not be an option..
return false;
}

if (attributeData.NamedArguments.Length == 0) {
data = constructorType switch {
ConstructorType.NotificationCenter => new(notificationCenter, ConstructorType.NotificationCenter),
ConstructorType.NotificationType => new(notificationType, ConstructorType.NotificationType),
_ => new(notificationType, notificationCenter)
ConstructorType.NotificationCenter => new (notificationCenter, ConstructorType.NotificationCenter),
ConstructorType.NotificationType => new (notificationType, ConstructorType.NotificationType),
_ => new (notificationType, notificationCenter)
};
return true;
}
Expand All @@ -90,8 +90,8 @@ public static bool TryParse (AttributeData attributeData,
}
}

data = new(notificationType, notificationCenter);
data = new (notificationType, notificationCenter);
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Microsoft.Macios.Transformer.Tests.Attributes;

public class AsyncDataTests : AttributeParsingTestClass {

class TestDataTryCreate : IEnumerable<object []> {
public IEnumerator<object []> GetEnumerator ()
{
Expand Down Expand Up @@ -54,10 +54,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 @@ -77,10 +78,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 @@ -102,10 +104,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 @@ -128,10 +131,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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Microsoft.Macios.Transformer.Tests.Attributes;

public class AttributeParsingTestClass : BaseTransformerTestClass {

internal void AssertTryCreate<T, TR> (ApplePlatform platform, (string Source, string Path) source,
string attributeName, T expectedData, TypeSymbolExtensions.TryParse<T> tryParse, bool lastOrDefault = false)
where T : struct
Expand All @@ -29,7 +29,7 @@ internal void AssertTryCreate<T, TR> (ApplePlatform platform, (string Source, st
if (lastOrDefault) {
declaration = syntaxTree.GetRoot ()
.DescendantNodes ().OfType<TR> ()
.LastOrDefault();
.LastOrDefault ();
} else {
declaration = syntaxTree.GetRoot ()
.DescendantNodes ().OfType<TR> ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
namespace Microsoft.Macios.Transformer.Tests.Attributes;

public class NotificationDataTests : AttributeParsingTestClass {

class TestDataTryCreate : IEnumerable<object []> {
public IEnumerator<object []> GetEnumerator ()
{
const string path = "/some/random/path.cs";

// simple notification
const string simpleNotification = @"
using System;
Expand All @@ -34,7 +34,7 @@ partial interface NSSplitView {
}
";
yield return [(Source: simpleNotification, Path: path), new NotificationData (null, null)];

// notification type
const string notificationWithType = @"
using System;
Expand All @@ -54,9 +54,9 @@ partial interface NSSplitView {
NSString NSSplitViewWillResizeSubviewsNotification { get; }
}
";

yield return [(Source: notificationWithType, Path: path), new NotificationData ("Test.MyNotification", null)];

// notification center
const string notificationWithCenter = @"
using System;
Expand Down Expand Up @@ -102,7 +102,7 @@ partial interface NSSplitView {

IEnumerator IEnumerable.GetEnumerator () => GetEnumerator ();
}

[Theory]
[AllSupportedPlatformsClassData<TestDataTryCreate>]
void TryCreateTests (ApplePlatform platform, (string Source, string Path) source,
Expand Down

0 comments on commit 1926da5

Please sign in to comment.