Skip to content

Commit

Permalink
fix: Fixed version in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Nov 30, 2023
1 parent c40faa7 commit cd54842
Show file tree
Hide file tree
Showing 22 changed files with 164 additions and 174 deletions.
4 changes: 2 additions & 2 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageVersion Include="H.Resources.Generator" Version="1.5.1" />
<PackageVersion Include="IsExternalInit" Version="1.0.3" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.1" />
<PackageVersion Include="H.Generators.Extensions" Version="1.21.1" />
<PackageVersion Include="H.Generators.Extensions" Version="1.22.0" />
<PackageVersion Include="ConventionalCommitsGitInfo" Version="0.3.6" />
<PackageVersion Include="DotNet.ReproducibleBuilds" Version="1.1.1" />
</ItemGroup>
Expand All @@ -21,6 +21,6 @@
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
<PackageVersion Include="Verify.MSTest" Version="22.6.0" />
<PackageVersion Include="Verify.SourceGenerators" Version="2.2.0" />
<PackageVersion Include="H.Generators.Tests.Extensions" Version="1.21.1" />
<PackageVersion Include="H.Generators.Tests.Extensions" Version="1.22.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<ItemGroup>
<CompilerVisibleProperty Include="RecognizeFramework_DefineConstants" />
<CompilerVisibleProperty Include="RecognizeFramework_Version" />
<CompilerVisibleProperty Include="UseWPF" />
<CompilerVisibleProperty Include="UseWinUI" />
<CompilerVisibleProperty Include="UseMaui" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using H.Generators.Extensions;
using Microsoft.CodeAnalysis;

namespace H.Generators;

Expand All @@ -24,39 +24,42 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
});

var framework = context.DetectFramework();
var version = context.DetectVersion();

context.SyntaxProvider
.ForAttributeWithMetadataName("DependencyPropertyGenerator.AddOwnerAttribute")
.ForAttributeWithMetadataNameOfClassesAndRecords("DependencyPropertyGenerator.AddOwnerAttribute")
.SelectManyAllAttributesOfCurrentClassSyntax()
.Combine(framework)
.Combine(framework)
.Combine(version)
.SelectAndReportExceptions(PrepareData, context, Id)
.WhereNotNull()
.SelectAndReportExceptions(GetSourceCode, context, Id)
.AddSource(context);
context.SyntaxProvider
.ForAttributeWithMetadataName("DependencyPropertyGenerator.AddOwnerAttribute`2")
.ForAttributeWithMetadataNameOfClassesAndRecords("DependencyPropertyGenerator.AddOwnerAttribute`2")
.SelectManyAllAttributesOfCurrentClassSyntax()
.Combine(framework)
.Combine(version)
.SelectAndReportExceptions(PrepareData, context, Id)
.WhereNotNull()
.SelectAndReportExceptions(GetSourceCode, context, Id)
.AddSource(context);
}

private static (ClassData Class, DependencyPropertyData DependencyProperty)? PrepareData(
Framework framework,
(SemanticModel SemanticModel, AttributeData AttributeData, ClassDeclarationSyntax ClassSyntax, INamedTypeSymbol
ClassSymbol) tuple)
((ClassWithAttributesContext context,
Framework framework) left,
string version) tuple)
{
if (framework is not (Framework.Avalonia or Framework.Wpf))
var (((_, attributes, _, classSymbol), framework), version) = tuple;
if (framework is not (Framework.Avalonia or Framework.Wpf) ||
attributes.FirstOrDefault() is not { } attribute)
{
return null;
}

var (_, attribute, _, classSymbol) = tuple;

var classData = classSymbol.GetClassData(framework);
var dependencyPropertyData = attribute.GetDependencyPropertyData(framework, isAddOwner: true);
var classData = classSymbol.GetClassData(framework, version);
var dependencyPropertyData = attribute.GetDependencyPropertyData(framework, version, isAddOwner: true);

return (classData, dependencyPropertyData);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using H.Generators.Extensions;
using Microsoft.CodeAnalysis;

namespace H.Generators;

Expand All @@ -24,41 +24,50 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
});

var framework = context.DetectFramework();
var version = context.DetectVersion();

context.SyntaxProvider
.ForAttributeWithMetadataName("DependencyPropertyGenerator.AttachedDependencyPropertyAttribute")
.ForAttributeWithMetadataNameOfClassesAndRecords("DependencyPropertyGenerator.AttachedDependencyPropertyAttribute")
.SelectManyAllAttributesOfCurrentClassSyntax()
.Combine(framework)
.Combine(version)
.SelectAndReportExceptions(PrepareData, context, Id)
.WhereNotNull()
.SelectAndReportExceptions(GetSourceCode, context, Id)
.AddSource(context);
context.SyntaxProvider
.ForAttributeWithMetadataName("DependencyPropertyGenerator.AttachedDependencyPropertyAttribute`1")
.ForAttributeWithMetadataNameOfClassesAndRecords("DependencyPropertyGenerator.AttachedDependencyPropertyAttribute`1")
.SelectManyAllAttributesOfCurrentClassSyntax()
.Combine(framework)
.Combine(version)
.SelectAndReportExceptions(PrepareData, context, Id)
.WhereNotNull()
.SelectAndReportExceptions(GetSourceCode, context, Id)
.AddSource(context);
context.SyntaxProvider
.ForAttributeWithMetadataName("DependencyPropertyGenerator.AttachedDependencyPropertyAttribute`2")
.ForAttributeWithMetadataNameOfClassesAndRecords("DependencyPropertyGenerator.AttachedDependencyPropertyAttribute`2")
.SelectManyAllAttributesOfCurrentClassSyntax()
.Combine(framework)
.Combine(version)
.SelectAndReportExceptions(PrepareData, context, Id)
.WhereNotNull()
.SelectAndReportExceptions(GetSourceCode, context, Id)
.AddSource(context);
}

private static (ClassData Class, DependencyPropertyData DependencyProperty)? PrepareData(
Framework framework,
(SemanticModel SemanticModel, AttributeData AttributeData, ClassDeclarationSyntax ClassSyntax, INamedTypeSymbol
ClassSymbol) tuple)
((ClassWithAttributesContext context,
Framework framework) left,
string version) tuple)
{
var (_, attribute, classSyntax, classSymbol) = tuple;
var classData = classSymbol.GetClassData(framework);
var dependencyPropertyData = attribute.GetDependencyPropertyData(framework,
var (((_, attributes, classSyntax, classSymbol), framework), version) = tuple;
if (attributes.FirstOrDefault() is not { } attribute)
{
return null;
}

var classData = classSymbol.GetClassData(framework, version);
var dependencyPropertyData = attribute.GetDependencyPropertyData(framework, version,
classSyntax.TryFindAttributeSyntax(attribute), isAttached: true);

return (classData, dependencyPropertyData);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using H.Generators.Extensions;
using Microsoft.CodeAnalysis;

namespace H.Generators;

Expand All @@ -24,34 +24,42 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
});

var framework = context.DetectFramework();
var version = context.DetectVersion();

context.SyntaxProvider
.ForAttributeWithMetadataName("DependencyPropertyGenerator.DependencyPropertyAttribute")
.ForAttributeWithMetadataNameOfClassesAndRecords("DependencyPropertyGenerator.DependencyPropertyAttribute")
.SelectManyAllAttributesOfCurrentClassSyntax()
.Combine(framework)
.Combine(version)
.SelectAndReportExceptions(PrepareData, context, Id)
.WhereNotNull()
.SelectAndReportExceptions(GetSourceCode, context, Id)
.AddSource(context);
context.SyntaxProvider
.ForAttributeWithMetadataName("DependencyPropertyGenerator.DependencyPropertyAttribute`1")
.ForAttributeWithMetadataNameOfClassesAndRecords("DependencyPropertyGenerator.DependencyPropertyAttribute`1")
.SelectManyAllAttributesOfCurrentClassSyntax()
.Combine(framework)
.Combine(version)
.SelectAndReportExceptions(PrepareData, context, Id)
.WhereNotNull()
.SelectAndReportExceptions(GetSourceCode, context, Id)
.AddSource(context);
}

private static (ClassData Class, DependencyPropertyData DependencyProperty)? PrepareData(
Framework framework,
(SemanticModel SemanticModel, AttributeData AttributeData, ClassDeclarationSyntax ClassSyntax, INamedTypeSymbol
ClassSymbol) tuple)
((ClassWithAttributesContext context,
Framework framework) left,
string version) tuple)
{
var (_, attribute, classSyntax, classSymbol) = tuple;
var classData = classSymbol.GetClassData(framework);
var (((_, attributes, classSyntax, classSymbol), framework), version) = tuple;
if (attributes.FirstOrDefault() is not { } attribute)
{
return null;
}

var classData = classSymbol.GetClassData(framework, version);
var dependencyPropertyData =
attribute.GetDependencyPropertyData(framework, classSyntax.TryFindAttributeSyntax(attribute));
attribute.GetDependencyPropertyData(framework, version, classSyntax.TryFindAttributeSyntax(attribute));

return (classData, dependencyPropertyData);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Immutable;
using H.Generators.Extensions;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace H.Generators;

Expand All @@ -26,40 +25,42 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
});

var framework = context.DetectFramework();
var version = context.DetectVersion();

context.SyntaxProvider
.ForAttributeWithMetadataName("DependencyPropertyGenerator.OverrideMetadataAttribute")
.ForAttributeWithMetadataNameOfClassesAndRecords("DependencyPropertyGenerator.OverrideMetadataAttribute")
.SelectAllAttributes()
.Combine(framework)
.Combine(version)
.SelectAndReportExceptions(PrepareData, context, Id)
.WhereNotNull()
.SelectAndReportExceptions(GetSourceCode, context, Id)
.AddSource(context);
context.SyntaxProvider
.ForAttributeWithMetadataName("DependencyPropertyGenerator.OverrideMetadataAttribute`1")
.ForAttributeWithMetadataNameOfClassesAndRecords("DependencyPropertyGenerator.OverrideMetadataAttribute`1")
.SelectAllAttributes()
.Combine(framework)
.Combine(version)
.SelectAndReportExceptions(PrepareData, context, Id)
.WhereNotNull()
.SelectAndReportExceptions(GetSourceCode, context, Id)
.AddSource(context);
}

private static (ClassData Class, EquatableArray<DependencyPropertyData> OverrideMetada)? PrepareData(
Framework framework,
(SemanticModel SemanticModel, ImmutableArray<AttributeData> Attributes, ClassDeclarationSyntax ClassSyntax,
INamedTypeSymbol ClassSymbol) tuple)
((ClassWithAttributesContext context,
Framework framework) left,
string version) tuple)
{
var (((_, attributes, _, classSymbol), framework), version) = tuple;
if (framework is not (Framework.Wpf or Framework.Uwp or Framework.WinUi or Framework.Uno or Framework.UnoWinUi))
{
return null;
}

var (_, attributes, _, classSymbol) = tuple;

var classData = classSymbol.GetClassData(framework);
var classData = classSymbol.GetClassData(framework, version);
var overrideMetadata = attributes
.Select(attribute => attribute.GetDependencyPropertyData(framework))
.Select(attribute => attribute.GetDependencyPropertyData(framework, version))
.ToImmutableArray()
.AsEquatableArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static class PrepareData
public static DependencyPropertyData GetDependencyPropertyData(
this AttributeData attribute,
Framework framework,
string version,
AttributeSyntax? attributeSyntax = null,
bool isAddOwner = false,
bool isAttached = false)
Expand Down Expand Up @@ -105,6 +106,7 @@ public static DependencyPropertyData GetDependencyPropertyData(
return new DependencyPropertyData(
Name: name,
Type: type,
Version: version,
ShortType: shortType,
IsValueType: isValueType,
IsSpecialType: isSpecialType,
Expand Down Expand Up @@ -201,7 +203,8 @@ public static EventData GetEventData(this AttributeData attribute, bool isStatic

public static ClassData GetClassData(
this INamedTypeSymbol classSymbol,
Framework framework)
Framework framework,
string version)
{
classSymbol = classSymbol ?? throw new ArgumentNullException(nameof(classSymbol));

Expand All @@ -227,6 +230,7 @@ public static ClassData GetClassData(
FullName: fullClassName,
Type: type,
Modifiers: classModifiers,
Version: version,
IsStatic: isStaticClass,
Framework: framework,
Methods: methods.ToImmutableArray().AsEquatableArray());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using H.Generators.Extensions;
using Microsoft.CodeAnalysis;

namespace H.Generators;

Expand Down Expand Up @@ -27,31 +27,38 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
});

var framework = context.DetectFramework();
var version = context.DetectVersion();

context.SyntaxProvider
.ForAttributeWithMetadataName("DependencyPropertyGenerator.RoutedEventAttribute")
.ForAttributeWithMetadataNameOfClassesAndRecords("DependencyPropertyGenerator.RoutedEventAttribute")
.SelectManyAllAttributesOfCurrentClassSyntax()
.Combine(framework)
.Combine(version)
.SelectAndReportExceptions(PrepareData, context, Id)
.WhereNotNull()
.SelectAndReportExceptions(GetSourceCode, context, Id)
.AddSource(context);
context.SyntaxProvider
.ForAttributeWithMetadataName("DependencyPropertyGenerator.RoutedEventAttribute`1")
.ForAttributeWithMetadataNameOfClassesAndRecords("DependencyPropertyGenerator.RoutedEventAttribute`1")
.SelectManyAllAttributesOfCurrentClassSyntax()
.Combine(framework)
.Combine(version)
.SelectAndReportExceptions(PrepareData, context, Id)
.WhereNotNull()
.SelectAndReportExceptions(GetSourceCode, context, Id)
.AddSource(context);
}

private static (ClassData Class, EventData Event)? PrepareData(
Framework framework,
(SemanticModel SemanticModel, AttributeData AttributeData, ClassDeclarationSyntax ClassSyntax, INamedTypeSymbol
ClassSymbol) tuple)
((ClassWithAttributesContext context,
Framework framework) left,
string version) tuple)
{
var (_, attribute, _, classSymbol) = tuple;
var (((_, attributes, _, classSymbol), framework), version) = tuple;
if (attributes.FirstOrDefault() is not { } attribute)
{
return null;
}

var eventData = attribute.GetEventData(isStaticClass: false);
if (framework is Framework.Maui ||
Expand All @@ -60,7 +67,7 @@ private static (ClassData Class, EventData Event)? PrepareData(
return null;
}

var classData = classSymbol.GetClassData(framework);
var classData = classSymbol.GetClassData(framework, version);

return (classData, eventData);
}
Expand Down
Loading

0 comments on commit cd54842

Please sign in to comment.