Skip to content

Commit

Permalink
Bumped version v1.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FaustVX committed Nov 23, 2024
1 parent 3d9a32d commit a884aca
Show file tree
Hide file tree
Showing 20 changed files with 297 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ConsoleApp1/ConsoleApp1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FaustVX.PrimaryParameter.SG" Version="1.8.1" ReferenceOutputAssembly="false" PrivateAssets="All" />
<PackageReference Include="FaustVX.PrimaryParameter.SG" Version="1.9.0" ReferenceOutputAssembly="false" PrivateAssets="All" />
<!-- <ProjectReference Include="..\PrimaryParameter.SG\PrimaryParameter.SG.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="All" /> -->
</ItemGroup>

Expand Down
23 changes: 21 additions & 2 deletions PrimaryParameter.SG/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ static IEnumerable<Parameter> GetTypesToGenerate(Compilation compilation, IEnume
var name = GetAttributeProperty<string>(operation, "Name", out var nameLocation) ?? ("_" + paramSyntax.Identifier.Text);
nameLocation ??= attribute.GetLocation();
var format = GetAttributeProperty<string>(operation, "AssignFormat", out _) ?? "{0}";
var type = GetAttributePropertyTypeOf(operation, "Type", out _);
var type = GetAttributePropertyTypeOf(operation, "Type", out _) ?? ToSyntaxDisplayString(paramSyntax.Type!);
var isReadonly = isReadonlyType || GetAttributeProperty<bool>(operation, "IsReadonly", out _, defaultValue: GenerateField.DefaultReadonly);
var scope = GetAttributeProperty<string>(operation, "Scope", out _) ?? GenerateField.DefaultScope;
var summary = GetAttributeProperty<string>(operation, "Summary", out _);
Expand All @@ -321,7 +321,7 @@ static IEnumerable<Parameter> GetTypesToGenerate(Compilation compilation, IEnume
var name = GetAttributeProperty<string>(operation, "Name", out var nameLocation) ?? (char.ToUpper(paramSyntax.Identifier.Text[0]) + paramSyntax.Identifier.Text[1..]);
nameLocation ??= attribute.GetLocation();
var format = GetAttributeProperty<string>(operation, "AssignFormat", out _) ?? "{0}";
var type = GetAttributePropertyTypeOf(operation, "Type", out _);
var type = GetAttributePropertyTypeOf(operation, "Type", out _) ?? ToSyntaxDisplayString(paramSyntax.Type!);
var setter = GetAttributeProperty<string>(operation, "Setter", out _) ?? GenerateProperty.DefaultSetter;
var scope = GetAttributeProperty<string>(operation, "Scope", out _) ?? GenerateProperty.DefaultScope;
var summary = GetAttributeProperty<string>(operation, "Summary", out _);
Expand All @@ -341,6 +341,25 @@ static IEnumerable<Parameter> GetTypesToGenerate(Compilation compilation, IEnume
var parameter = new Parameter(GetNamespace(containingType), ParentClass.GetParentClasses(containingType)!, paramSyntax.Identifier.Text, semanticModel.GetTypeInfo(paramSyntax.Type!).Type!.ToDisplayString(), [.. memberNames]);
yield return parameter;
containingType.Accept(new ReportErrorWhenAccessingPrimaryParameter(paramSyntax, semanticModel, context, parameter, allowInMemberInit));

static string ToSyntaxDisplayString(TypeSyntax type) => type switch
{
ArrayTypeSyntax { ElementType: var element, RankSpecifiers: var rank } => $"{element}{DisplayStringArrayRank(rank)}",
_ => type.ToString()
};

static string DisplayStringArrayRank(SyntaxList<ArrayRankSpecifierSyntax> arrayRanks)
{
var sb = new StringBuilder();
foreach (var rank in arrayRanks)
{
sb.Append('[');
for (int i = 0; i < rank.Rank - 1; i++)
sb.Append(',');
sb.Append(']');
}
return sb.ToString();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion PrimaryParameter.SG/PrimaryParameter.SG.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<PropertyGroup>
<PackageId>FaustVX.PrimaryParameter.SG</PackageId>
<Version>1.8.1</Version>
<Version>1.9.0</Version>
<Authors>FaustVX</Authors>
<RepositoryUrl>https://github.com/FaustVX/PrimaryParameter</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
39 changes: 39 additions & 0 deletions PrimaryParameter.Tests/PrimaryParameterSnapshotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,32 @@ public class B([Field(Type = typeof(object[,]))]object[,] i);
return TestHelper.Verify(source);
}

[Fact]
public Task AcceptMultidimensionalArrayAsType_Generic()
{
// The source code to test
var source = """
using PrimaryParameter.SG;
public class B<T>([Field(Type = typeof(T[,]))]T[,] i);
""";

// Pass the source code to our helper and snapshot test the output
return TestHelper.Verify(source);
}

[Fact]
public Task AcceptMultidimensionalArrayAsType_WithoutSpecifyingType()
{
// The source code to test
var source = """
using PrimaryParameter.SG;
public class B([Field]object[,] i);
""";

// Pass the source code to our helper and snapshot test the output
return TestHelper.Verify(source);
}

[Fact]
public Task AcceptArrayOfArrayAsType()
{
Expand All @@ -355,6 +381,19 @@ public class B([Field(Type = typeof(object[][]))]object[][] i);
return TestHelper.Verify(source);
}

[Fact]
public Task AcceptMultidimensionnalArrayOfArrayAsType()
{
// The source code to test
var source = """
using PrimaryParameter.SG;
public class B([Field]object[][,] i);
""";

// Pass the source code to our helper and snapshot test the output
return TestHelper.Verify(source);
}

[Fact]
public Task GeneratePropertyWithoutBackingStorageGetOnly()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//HintName: DoNotUseAttribute.g.cs
#pragma warning disable
// <auto-generated/>
using global::System;
using global::System.Diagnostics;
namespace PrimaryParameter.SG
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = false)]
[Conditional("DEBUG")]
sealed class DoNotUseAttribute : Attribute
{
public bool AllowInMemberInit { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//HintName: FaustVX.PrimaryParameter.SG.g.cs
#pragma warning disable
// <auto-generated/>
partial class B<T>
{
private readonly T[,] _i = i;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//HintName: FieldAttribute.g.cs
#pragma warning disable
// <auto-generated/>
using global::System;
using global::System.Diagnostics;
namespace PrimaryParameter.SG
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = true)]
[Conditional("DEBUG")]
sealed class FieldAttribute : Attribute
{
public string Name { get; init; }
public string AssignFormat { get; init; }
public Type Type { get; init; }
public bool IsReadonly { get; init; }
public string Scope { get; init; }
public string Summary { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//HintName: PropertyAttribute.g.cs
#pragma warning disable
// <auto-generated/>
using global::System;
using global::System.Diagnostics;
namespace PrimaryParameter.SG
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = true)]
[Conditional("DEBUG")]
sealed class PropertyAttribute : Attribute
{
public string Name { get; init; }
public string AssignFormat { get; init; }
public Type Type { get; init; }
public string Setter { get; init; }
public string Scope { get; init; }
public string Summary { get; init; }
public bool WithoutBackingStorage { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//HintName: RefFieldAttribute.g.cs
#pragma warning disable
// <auto-generated/>
using global::System;
using global::System.Diagnostics;
namespace PrimaryParameter.SG
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = true)]
[Conditional("DEBUG")]
sealed class RefFieldAttribute : Attribute
{
public string Name { get; init; }
public string Scope { get; init; }
public bool IsReadonlyRef { get; init; }
public bool IsRefReadonly { get; init; }
public string Summary { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//HintName: DoNotUseAttribute.g.cs
#pragma warning disable
// <auto-generated/>
using global::System;
using global::System.Diagnostics;
namespace PrimaryParameter.SG
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = false)]
[Conditional("DEBUG")]
sealed class DoNotUseAttribute : Attribute
{
public bool AllowInMemberInit { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//HintName: FaustVX.PrimaryParameter.SG.g.cs
#pragma warning disable
// <auto-generated/>
partial class B
{
private readonly object[,] _i = i;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//HintName: FieldAttribute.g.cs
#pragma warning disable
// <auto-generated/>
using global::System;
using global::System.Diagnostics;
namespace PrimaryParameter.SG
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = true)]
[Conditional("DEBUG")]
sealed class FieldAttribute : Attribute
{
public string Name { get; init; }
public string AssignFormat { get; init; }
public Type Type { get; init; }
public bool IsReadonly { get; init; }
public string Scope { get; init; }
public string Summary { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//HintName: PropertyAttribute.g.cs
#pragma warning disable
// <auto-generated/>
using global::System;
using global::System.Diagnostics;
namespace PrimaryParameter.SG
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = true)]
[Conditional("DEBUG")]
sealed class PropertyAttribute : Attribute
{
public string Name { get; init; }
public string AssignFormat { get; init; }
public Type Type { get; init; }
public string Setter { get; init; }
public string Scope { get; init; }
public string Summary { get; init; }
public bool WithoutBackingStorage { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//HintName: RefFieldAttribute.g.cs
#pragma warning disable
// <auto-generated/>
using global::System;
using global::System.Diagnostics;
namespace PrimaryParameter.SG
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = true)]
[Conditional("DEBUG")]
sealed class RefFieldAttribute : Attribute
{
public string Name { get; init; }
public string Scope { get; init; }
public bool IsReadonlyRef { get; init; }
public bool IsRefReadonly { get; init; }
public string Summary { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//HintName: DoNotUseAttribute.g.cs
#pragma warning disable
// <auto-generated/>
using global::System;
using global::System.Diagnostics;
namespace PrimaryParameter.SG
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = false)]
[Conditional("DEBUG")]
sealed class DoNotUseAttribute : Attribute
{
public bool AllowInMemberInit { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//HintName: FaustVX.PrimaryParameter.SG.g.cs
#pragma warning disable
// <auto-generated/>
partial class B
{
private readonly object[][,] _i = i;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//HintName: FieldAttribute.g.cs
#pragma warning disable
// <auto-generated/>
using global::System;
using global::System.Diagnostics;
namespace PrimaryParameter.SG
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = true)]
[Conditional("DEBUG")]
sealed class FieldAttribute : Attribute
{
public string Name { get; init; }
public string AssignFormat { get; init; }
public Type Type { get; init; }
public bool IsReadonly { get; init; }
public string Scope { get; init; }
public string Summary { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//HintName: PropertyAttribute.g.cs
#pragma warning disable
// <auto-generated/>
using global::System;
using global::System.Diagnostics;
namespace PrimaryParameter.SG
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = true)]
[Conditional("DEBUG")]
sealed class PropertyAttribute : Attribute
{
public string Name { get; init; }
public string AssignFormat { get; init; }
public Type Type { get; init; }
public string Setter { get; init; }
public string Scope { get; init; }
public string Summary { get; init; }
public bool WithoutBackingStorage { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//HintName: RefFieldAttribute.g.cs
#pragma warning disable
// <auto-generated/>
using global::System;
using global::System.Diagnostics;
namespace PrimaryParameter.SG
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = true)]
[Conditional("DEBUG")]
sealed class RefFieldAttribute : Attribute
{
public string Name { get; init; }
public string Scope { get; init; }
public bool IsReadonlyRef { get; init; }
public bool IsRefReadonly { get; init; }
public string Summary { get; init; }
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ You can type as many attributes as you want on a single parameter (Except for `D
## Versions
|Version|Date|Comments|
|-------|----|--------|
|v1.9.0|23/11/2024|Fixed bug when the `Type` property was not specified with Arrays|
|v1.8.1|17/11/2024|Automatically detect `partial` properties|
|v1.8.0|15/11/2024|Added `IsPartial` for `Property`|
|v1.7.0|23/06/2024|Added `WithoutBackingStorage` for `Property`|
Expand Down

0 comments on commit a884aca

Please sign in to comment.