Skip to content

Commit

Permalink
Bumped version v1.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
FaustVX committed Nov 23, 2024
1 parent a884aca commit d139d43
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 28 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.9.0" ReferenceOutputAssembly="false" PrivateAssets="All" />
<PackageReference Include="FaustVX.PrimaryParameter.SG" Version="1.9.1" ReferenceOutputAssembly="false" PrivateAssets="All" />
<!-- <ProjectReference Include="..\PrimaryParameter.SG\PrimaryParameter.SG.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="All" /> -->
</ItemGroup>

Expand Down
46 changes: 20 additions & 26 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 _) ?? ToSyntaxDisplayString(paramSyntax.Type!);
var type = GetAttributePropertyTypeOf(operation, "Type", out _) ?? ToSyntaxDisplayString(paramSyntax.Type!, semanticModel);
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 _) ?? ToSyntaxDisplayString(paramSyntax.Type!);
var type = GetAttributePropertyTypeOf(operation, "Type", out _) ?? ToSyntaxDisplayString(paramSyntax.Type!, semanticModel);
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,27 +341,27 @@ 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 ToSyntaxDisplayString(TypeSyntax type, SemanticModel semanticModel) => type switch
{
ArrayTypeSyntax { ElementType: var element, RankSpecifiers: var rank } => $"{ToSyntaxDisplayString(element, semanticModel)}{DisplayStringArrayRank(rank)}",
_ => semanticModel.GetTypeInfo(type!).Type!.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat.WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.OmittedAsContaining))
};

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

sealed class IsPartialPropertyVisitor(string propertyName) : CSharpSyntaxWalker
{
Expand Down Expand Up @@ -419,16 +419,10 @@ public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node)
#pragma warning restore IDE0220 // Add explicit cast
{
// Is this the Name argument?
if (((IPropertyReferenceOperation)namedArgument.Target).Property.Name == propertyName && namedArgument.Value is ITypeOfOperation { TypeOperand: var type })
if (((IPropertyReferenceOperation)namedArgument.Target).Property.Name == propertyName && namedArgument.Value is ITypeOfOperation { Syntax: TypeOfExpressionSyntax { Type: TypeSyntax type } })
{
location = namedArgument.Value.Syntax.GetLocation();
return ToDisplayString(type);

static string ToDisplayString(ITypeSymbol type) => type switch
{
IArrayTypeSymbol array => $"{ToDisplayString(array.ElementType)}[{new string(',', array.Rank - 1)}]",
_ => type.ToDisplayString()
};
return ToSyntaxDisplayString(type, attributeData.SemanticModel!);
}
}

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.9.0</Version>
<Version>1.9.1</Version>
<Authors>FaustVX</Authors>
<RepositoryUrl>https://github.com/FaustVX/PrimaryParameter</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
14 changes: 14 additions & 0 deletions PrimaryParameter.Tests/PrimaryParameterSnapshotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,20 @@ public class D([DoNotUse]int i) : B(i);
return TestHelper.Verify(source);
}

[Fact]
public Task AcceptNamespacedType()
{
// The source code to test
var source = """
using PrimaryParameter.SG;
using System.Xml.XPath;
public class B([Field]XPathExpression b);
""";

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

[Fact]
public Task AcceptArrayImplicitly()
{
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
{
private readonly XPathExpression _b = b;
}
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.1|23/11/2024|Fixed bug (emitting the non fully-qualified type name)|
|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`|
Expand Down

0 comments on commit d139d43

Please sign in to comment.