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 Feb 1, 2025
1 parent e29d36f commit b51a8d8
Show file tree
Hide file tree
Showing 16 changed files with 285 additions and 309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum VariableType {
PrimitivePointer,
StringPointer,
}

public static bool TryCreate (IParameterSymbol symbol, ParameterSyntax declaration, SemanticModel semanticModel,
[NotNullWhen (true)] out Parameter? parameter)
{
Expand Down
2 changes: 1 addition & 1 deletion src/rgen/Microsoft.Macios.Generator/DataModel/Parameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Parameter (int position, TypeInfo type, string name)
Type = type;
Name = name;
}

/// <inheritdoc/>
public bool Equals (Parameter other)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ public bool RequiresDirtyCheck {

return fieldInfo;
}

internal Property (string name, TypeInfo returnType,
SymbolAvailability symbolAvailability,
ImmutableArray<AttributeCodeChange> attributes,
ImmutableArray<SyntaxToken> modifiers,
ImmutableArray<SyntaxToken> modifiers,
ImmutableArray<Accessor> accessors)
{
Name = name;
Expand Down
4 changes: 2 additions & 2 deletions src/rgen/Microsoft.Macios.Generator/DataModel/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private init {
/// <summary>
/// Get the modifiers of the property.
/// </summary>
public ImmutableArray<SyntaxToken> Modifiers { get; init; } = [];
public ImmutableArray<SyntaxToken> Modifiers { get; init; } = [];

/// <summary>
/// Get the list of accessor changes of the property.
Expand All @@ -79,7 +79,7 @@ private init {
}
return null;
}

bool CoreEquals (Property other)
{
// this could be a large && but ifs are more readable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Accessor (AccessorKind accessorKind,
// we trust the modifiers of the property itself
Modifiers = [];
}

/// <inheritdoc />
public override string ToString ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ public ExportData? ExportMethodData {
/// </summary>
public bool MarshalNativeExceptions => HasMarshalNativeExceptionsFlag;

public Method (string type,
string name,
public Method (string type,
string name,
TypeInfo returnType,
SymbolAvailability symbolAvailability,
Dictionary<string, List<AttributeData>> attributes,
ImmutableArray<Parameter> parameters)
{
Type = type;
Name = name;
AttributesDictionary = attributes;
AttributesDictionary = attributes;
ReturnType = returnType;
SymbolAvailability = symbolAvailability;
Parameters = parameters;

// create a helper struct to retrieve the modifiers
var flags = new ModifiersFlags (HasAbstractFlag, HasInternalFlag, HasNewFlag, HasOverrideFlag, HasStaticFlag);
Modifiers = flags.ToModifiersArray ();
Expand All @@ -67,7 +67,7 @@ public static bool TryCreate (MethodDeclarationSyntax declaration, SemanticModel
// get the attributes of the method, this are used for two reasons:
// 1. The attributes might have flags such as [Internal] or [Abstract] that we need to set in the modifiers
// 2. The attributes might have return attributes that we need to set in the return type
var attributes = method.GetAttributeData ();
var attributes = method.GetAttributeData ();
change = new (
type: method.ContainingSymbol.ToDisplayString ().Trim (), // we want the full name
name: method.Name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ namespace Microsoft.Macios.Generator.DataModel;
/// return the correct modifiers according to the flags;
/// </summary>
readonly record struct ModifiersFlags {

public bool HasAbstractFlag { get; }
public bool HasInternalFlag { get; }
public bool HasNewFlag { get; }
public bool HasOverrideFlag { get; }
public bool HasStaticFlag { get; }

/// <summary>
/// Create a new structure with the provided flags.
/// </summary>
Expand All @@ -28,7 +28,7 @@ readonly record struct ModifiersFlags {
/// <param name="hasNewFlag">The state of the new flag.</param>
/// <param name="hasOverrideFlag">The state of the override flag.</param>
/// <param name="hasStaticFlag">The state of the static flag.</param>
public ModifiersFlags(bool hasAbstractFlag, bool hasInternalFlag, bool hasNewFlag, bool hasOverrideFlag, bool hasStaticFlag)
public ModifiersFlags (bool hasAbstractFlag, bool hasInternalFlag, bool hasNewFlag, bool hasOverrideFlag, bool hasStaticFlag)
{
HasAbstractFlag = hasAbstractFlag;
HasInternalFlag = hasInternalFlag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Microsoft.Macios.Generator.DataModel;

readonly partial struct Parameter {

public static bool TryCreate (IParameterSymbol symbol, ParameterSyntax declaration, SemanticModel semanticModel,
[NotNullWhen (true)] out Parameter? parameter)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public FieldData? ExportFieldData {
/// </summary>
public bool IsNotification => HasNotificationAttribute;


readonly ExportData? overrideExportData;

/// <summary>
Expand All @@ -57,17 +57,17 @@ public ExportData? ExportPropertyData {
/// <summary>
/// True if the method was exported with the MarshalNativeExceptions flag allowing it to support native exceptions.
/// </summary>
public bool MarshalNativeExceptions => HasMarshalNativeExceptionsFlag;
public bool MarshalNativeExceptions => HasMarshalNativeExceptionsFlag;

/// <summary>
/// True if the property should be generated without a backing field.
/// </summary>
public bool IsTransient => IsProperty && HasTransientFlag;

/// <inheritdoc />
public bool Equals (Property other) => CoreEquals (other);
internal Property (string name,

internal Property (string name,
TypeInfo returnType,
SymbolAvailability symbolAvailability,
Dictionary<string, List<AttributeData>> attributes,
Expand All @@ -79,13 +79,13 @@ internal Property (string name,
SymbolAvailability = symbolAvailability;
AttributesDictionary = attributes;
Accessors = accessors;

// the modifiers depend in we are talking about a field or a property. If we are talking
// about a field, we always have the same modifiers, public static. With a property we need to
// respect the flags that are set in the attributes.
if (IsField) {
// public static partial
Modifiers = [Token (SyntaxKind.PublicKeyword), Token (SyntaxKind.StaticKeyword), Token (SyntaxKind.PartialKeyword)];
Modifiers = [Token (SyntaxKind.PublicKeyword), Token (SyntaxKind.StaticKeyword), Token (SyntaxKind.PartialKeyword)];
} else {
// create a helper struct to retrieve the modifiers
var flags = new ModifiersFlags (HasAbstractFlag, HasInternalFlag, HasNewFlag, HasOverrideFlag, HasStaticFlag);
Expand All @@ -112,18 +112,18 @@ public static bool TryCreate (PropertyDeclarationSyntax declaration, SemanticMod
if (semanticModel.GetDeclaredSymbol (accessorDeclaration) is not ISymbol accessorSymbol)
continue;
var kind = accessorDeclaration.Kind ().ToAccessorKind ();
accessorsBucket.Add (new(
accessorsBucket.Add (new (
accessorKind: kind,
// just for the current symbol, not the parents etc..
symbolAvailability: accessorSymbol.GetAvailabilityForSymbol (),
symbolAvailability: accessorSymbol.GetAvailabilityForSymbol (),
attributes: accessorSymbol.GetAttributeData ()
));
}

accessors = accessorsBucket.ToImmutable ();
}

var propertyAttributes = propertySymbol.GetAttributeData ();
var propertyAttributes = propertySymbol.GetAttributeData ();
property = new (
name: memberName,
returnType: new (propertySymbol.Type, propertyAttributes),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ symbol is IArrayTypeSymbol arrayTypeSymbol
{
IsNullable = attributes.HasNullAllowedFlag ();
// special case, the old bindings might not have the ? operator but will have the attr
IsBlittable = symbol.IsBlittable () && !IsNullable;
IsBlittable = symbol.IsBlittable () && !IsNullable;
IsSmartEnum = symbol.IsSmartEnum ();
IsReferenceType = symbol.IsReferenceType;
IsStruct = symbol.TypeKind == TypeKind.Struct;
IsInterface = symbol.TypeKind == TypeKind.Interface;
IsNativeIntegerType = symbol.IsNativeIntegerType;
IsNativeEnum = symbol.HasAttribute (AttributesNames.NativeAttribute);

// data that we can get from the symbol without being INamedType
symbol.GetInheritance (
isNSObject: out isNSObject,
Expand All @@ -35,7 +35,7 @@ symbol is IArrayTypeSymbol arrayTypeSymbol
parents: out parents,
interfaces: out interfaces);
IsArray = symbol is IArrayTypeSymbol;

// try to get the named type symbol to have more educated decisions
var namedTypeSymbol = symbol as INamedTypeSymbol;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public static bool IsSmartEnum (this ITypeSymbol symbol)
// to find AT LEAST one enum field that contains the Field attribute.
if (symbol.TypeKind != TypeKind.Enum)
return false;
foreach (var member in symbol.GetMembers()) {
if (member is not IFieldSymbol field || !field.IsConst)

foreach (var member in symbol.GetMembers ()) {
if (member is not IFieldSymbol field || !field.IsConst)
continue;

// try to get the Field attribute from the current member, if we found it, then we have a smart enum
var attributeData = field.GetAttributeData ();
if (attributeData.HasFieldAttribute ())
Expand Down
12 changes: 6 additions & 6 deletions tests/rgen/Microsoft.Macios.Generator.Tests/TestDataFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ public static TypeInfo ReturnTypeForInterface (string interfaceName)
public static TypeInfo ReturnTypeForStruct (string structName, bool isBlittable = false)
=> new (
name: structName,
isBlittable: isBlittable,
isBlittable: isBlittable,
isStruct: true
) { Parents = ["System.ValueType", "object"] };

public static TypeInfo ReturnTypeForEnum (string enumName, bool isSmartEnum = false, bool isNativeEnum = false,
public static TypeInfo ReturnTypeForEnum (string enumName, bool isSmartEnum = false, bool isNativeEnum = false,
bool isNullable = false, bool isBlittable = true, SpecialType underlyingType = SpecialType.System_Int32)
=> new (
name: enumName,
Expand Down Expand Up @@ -312,11 +312,11 @@ public static TypeInfo ReturnTypeForNSObject (string? nsObjectName = null, bool
IsNSObject = true,
IsINativeObject = true,
Parents = nsObjectName is null ? ["object"] : ["Foundation.NSObject", "object"],
Interfaces = isApiDefinition
Interfaces = isApiDefinition
? [
"ObjCRuntime.INativeObject",
"ObjCRuntime.INativeObject",
"Foundation.INSObjectFactory",
]
]
: [
"ObjCRuntime.INativeObject",
$"System.IEquatable<{nsObjectName ?? "Foundation.NSObject"}>",
Expand All @@ -339,7 +339,7 @@ public static TypeInfo ReturnTypeForINativeObject (string nativeObjectName, bool
};

public static TypeInfo ReturnTypeForNSString (bool isNullable = false)
=> new(
=> new (
name: "Foundation.NSString",
isNullable: isNullable,
isArray: false, isReferenceType: true) {
Expand Down
Loading

0 comments on commit b51a8d8

Please sign in to comment.