Skip to content

Commit 5c6245d

Browse files
committed
Merge branch 'releases/9.6.x'
2 parents 80d3e43 + d03ee6f commit 5c6245d

106 files changed

Lines changed: 961 additions & 24 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/AdHocUnions/AdHocUnionCodeGenerator.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ private void GenerateSwitchForAction(bool withState, bool isPartially)
402402
{
403403
_sb.Append(@"
404404
405+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
405406
/// <summary>
406407
/// Executes an action depending on the current value.
407408
/// </summary>");
@@ -497,7 +498,8 @@ private void GenerateSwitchForAction(bool withState, bool isPartially)
497498
GenerateIndexBasedActionSwitchBody(withState, isPartially);
498499

499500
_sb.Append(@"
500-
}");
501+
}
502+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly");
501503
}
502504

503505
private void GenerateIndexBasedActionSwitchBody(bool withState, bool isPartially)
@@ -560,6 +562,7 @@ private void GenerateSwitchForFunc(bool withState, bool isPartially)
560562
{
561563
_sb.Append(@"
562564
565+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
563566
/// <summary>
564567
/// Executes a function depending on the current value.
565568
/// </summary>");
@@ -658,7 +661,8 @@ private void GenerateSwitchForFunc(bool withState, bool isPartially)
658661
GenerateIndexBasedFuncSwitchBody(withState, isPartially);
659662

660663
_sb.Append(@"
661-
}");
664+
}
665+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly");
662666
}
663667

664668
private void GenerateIndexBasedFuncSwitchBody(bool withState, bool isPartially)

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/Annotations/AnnotationsSourceGenerator.cs

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,57 @@
1+
using Microsoft.CodeAnalysis.CSharp.Syntax;
2+
13
namespace Thinktecture.CodeAnalysis.Annotations;
24

35
[Generator]
4-
public class AnnotationsSourceGenerator : ThinktectureSourceGeneratorBase, IIncrementalGenerator
6+
public class AnnotationsSourceGenerator() : ThinktectureSourceGeneratorBase(1), IIncrementalGenerator
57
{
6-
public AnnotationsSourceGenerator()
7-
: base(1)
8-
{
9-
}
8+
private const string _INSTANT_HANDLE_ATTRIBUTE = "InstantHandleAttribute";
109

1110
public void Initialize(IncrementalGeneratorInitializationContext context)
1211
{
1312
var options = GetGeneratorOptions(context);
1413

15-
var annotationsCheck = context.MetadataReferencesProvider
16-
.Select((reference, _) => HasJetbrainsAnnotations(reference))
17-
.Collect();
14+
var localAttribute = context.SyntaxProvider
15+
.CreateSyntaxProvider(
16+
(node, _) => node is ClassDeclarationSyntax { Identifier.Text: _INSTANT_HANDLE_ATTRIBUTE },
17+
(ctx, token) => IsInstantHandleAttribute(ctx.SemanticModel.GetDeclaredSymbol(ctx.Node, token)))
18+
.Where(hasLocal => hasLocal)
19+
.Collect();
20+
21+
var referencedAttribute = context.MetadataReferencesProvider
22+
.Select((reference, _) => HasJetbrainsAnnotations(reference))
23+
.Where(hasAttribute => hasAttribute)
24+
.Collect();
25+
26+
var pipeline = localAttribute
27+
.Combine(referencedAttribute.Combine(options))
28+
.SelectMany((tuple, _) =>
29+
{
30+
var (localAttributes, (referencedAttributes, opts)) = tuple;
1831

19-
context.RegisterSourceOutput(
20-
annotationsCheck.Combine(options)
21-
.SelectMany((tuple, _) => tuple.Left.Any(hasAnnotations => hasAnnotations) || !tuple.Right.GenerateJetbrainsAnnotations ? ImmutableArray<bool>.Empty : [false]),
22-
(ctx, _) => AddAnnotations(ctx));
32+
return !localAttributes.IsDefaultOrEmpty || !referencedAttributes.IsDefaultOrEmpty || !opts.GenerateJetbrainsAnnotations ? ImmutableArray<bool>.Empty : [true];
33+
});
34+
35+
context.RegisterSourceOutput(pipeline, (ctx, _) => AddAnnotations(ctx));
36+
}
37+
38+
private static bool IsInstantHandleAttribute(ISymbol? symbol)
39+
{
40+
return symbol is
41+
{
42+
Name: _INSTANT_HANDLE_ATTRIBUTE, ContainingNamespace:
43+
{
44+
Name: "Annotations",
45+
ContainingNamespace :
46+
{
47+
Name: "JetBrains",
48+
ContainingNamespace.IsGlobalNamespace: true
49+
}
50+
}
51+
};
2352
}
2453

25-
private bool HasJetbrainsAnnotations(MetadataReference reference)
54+
private static bool HasJetbrainsAnnotations(MetadataReference reference)
2655
{
2756
try
2857
{

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/RegularUnions/RegularUnionCodeGenerator.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ private void GenerateSwitchForAction(bool withState, bool isPartially, IReadOnly
225225
{
226226
_sb.Append(@"
227227
228+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
228229
/// <summary>
229230
/// Executes an action depending on the current type.
230231
/// </summary>");
@@ -314,7 +315,8 @@ private void GenerateSwitchForAction(bool withState, bool isPartially, IReadOnly
314315
GenerateIndexBasedActionSwitchBody(withState, isPartially, typeMembers);
315316

316317
_sb.Append(@"
317-
}");
318+
}
319+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly");
318320
}
319321

320322
private void GenerateIndexBasedActionSwitchBody(bool withState, bool isPartially, IReadOnlyList<TypeMember> typeMembers)
@@ -384,6 +386,7 @@ private void GenerateSwitchForFunc(bool withState, bool isPartially, IReadOnlyLi
384386
{
385387
_sb.Append(@"
386388
389+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
387390
/// <summary>
388391
/// Executes a function depending on the current type.
389392
/// </summary>");
@@ -474,7 +477,8 @@ private void GenerateSwitchForFunc(bool withState, bool isPartially, IReadOnlyLi
474477
GenerateIndexBasedFuncSwitchBody(withState, isPartially, typeMembers);
475478

476479
_sb.Append(@"
477-
}");
480+
}
481+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly");
478482
}
479483

480484
private void GenerateIndexBasedFuncSwitchBody(bool withState, bool isPartially, IReadOnlyList<TypeMember> typeMembers)

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/SmartEnums/SmartEnumCodeGenerator.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ private void GenerateSwitchForAction(bool withState, bool isPartially)
381381

382382
_sb.Append(@"
383383
384+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
384385
/// <summary>
385386
/// Executes an action depending on the current item.
386387
/// </summary>");
@@ -468,7 +469,8 @@ private void GenerateSwitchForAction(bool withState, bool isPartially)
468469
GenerateIndexBasedActionSwitchBody(withState, isPartially);
469470

470471
_sb.Append(@"
471-
}");
472+
}
473+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly");
472474
}
473475

474476
private void GenerateIndexBasedActionSwitchBody(bool withState, bool isPartially)
@@ -525,6 +527,7 @@ private void GenerateSwitchForFunc(bool withState, bool isPartially)
525527

526528
_sb.Append(@"
527529
530+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
528531
/// <summary>
529532
/// Executes a function depending on the current item.
530533
/// </summary>");
@@ -617,7 +620,8 @@ private void GenerateSwitchForFunc(bool withState, bool isPartially)
617620
GenerateIndexBasedFuncSwitchBody(withState, isPartially);
618621

619622
_sb.Append(@"
620-
}");
623+
}
624+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly");
621625
}
622626

623627
private void GenerateIndexBasedFuncSwitchBody(bool withState, bool isPartially)

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/SmartEnums/SmartEnumSourceGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Thinktecture.CodeAnalysis.SmartEnums;
66
public sealed class SmartEnumSourceGenerator : ThinktectureSourceGeneratorBase, IIncrementalGenerator
77
{
88
public SmartEnumSourceGenerator()
9-
: base(25_000)
9+
: base(30_000)
1010
{
1111
}
1212

src/Thinktecture.Runtime.Extensions.SourceGenerator/Extensions/MetadataReferenceExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public static IEnumerable<ModuleInfo> GetModules(this MetadataReference metadata
1818
if (metadataReference is PortableExecutableReference portable && portable.GetMetadata() is AssemblyMetadata assemblyMetadata)
1919
return assemblyMetadata.GetModules().Select(m => new ModuleInfo(m.Name));
2020

21-
return Array.Empty<ModuleInfo>();
21+
return [];
2222
}
2323
}

test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/AdHocUnionSourceGeneratorTests.Should_generate_class_with_array.verified.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ namespace Thinktecture.Tests
8080
this._valueIndex = 2;
8181
}
8282

83+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
8384
/// <summary>
8485
/// Executes an action depending on the current value.
8586
/// </summary>
@@ -102,7 +103,9 @@ namespace Thinktecture.Tests
102103
throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.");
103104
}
104105
}
106+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly
105107

108+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
106109
/// <summary>
107110
/// Executes an action depending on the current value.
108111
/// </summary>
@@ -130,7 +133,9 @@ namespace Thinktecture.Tests
130133
throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.");
131134
}
132135
}
136+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly
133137

138+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
134139
/// <summary>
135140
/// Executes a function depending on the current value.
136141
/// </summary>
@@ -154,7 +159,9 @@ namespace Thinktecture.Tests
154159
throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.");
155160
}
156161
}
162+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly
157163

164+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
158165
/// <summary>
159166
/// Executes a function depending on the current value.
160167
/// </summary>
@@ -181,6 +188,7 @@ namespace Thinktecture.Tests
181188
throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.");
182189
}
183190
}
191+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly
184192

185193
/// <summary>
186194
/// Maps current value to an instance of type <typeparamref name="TResult"/>.

test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/AdHocUnionSourceGeneratorTests.Should_generate_class_with_generics.verified.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ namespace Thinktecture.Tests
7979
this._valueIndex = 2;
8080
}
8181

82+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
8283
/// <summary>
8384
/// Executes an action depending on the current value.
8485
/// </summary>
@@ -101,7 +102,9 @@ namespace Thinktecture.Tests
101102
throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.");
102103
}
103104
}
105+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly
104106

107+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
105108
/// <summary>
106109
/// Executes an action depending on the current value.
107110
/// </summary>
@@ -129,7 +132,9 @@ namespace Thinktecture.Tests
129132
throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.");
130133
}
131134
}
135+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly
132136

137+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
133138
/// <summary>
134139
/// Executes a function depending on the current value.
135140
/// </summary>
@@ -153,7 +158,9 @@ namespace Thinktecture.Tests
153158
throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.");
154159
}
155160
}
161+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly
156162

163+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
157164
/// <summary>
158165
/// Executes a function depending on the current value.
159166
/// </summary>
@@ -180,6 +187,7 @@ namespace Thinktecture.Tests
180187
throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.");
181188
}
182189
}
190+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly
183191

184192
/// <summary>
185193
/// Maps current value to an instance of type <typeparamref name="TResult"/>.

test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/AdHocUnionSourceGeneratorTests.Should_generate_class_with_named_ctor_args_for_AdHocUnionAttribute.verified.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ namespace Thinktecture.Tests
8080
this._valueIndex = 2;
8181
}
8282

83+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
8384
/// <summary>
8485
/// Executes an action depending on the current value.
8586
/// </summary>
@@ -102,7 +103,9 @@ namespace Thinktecture.Tests
102103
throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.");
103104
}
104105
}
106+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly
105107

108+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
106109
/// <summary>
107110
/// Executes an action depending on the current value.
108111
/// </summary>
@@ -130,7 +133,9 @@ namespace Thinktecture.Tests
130133
throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.");
131134
}
132135
}
136+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly
133137

138+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
134139
/// <summary>
135140
/// Executes a function depending on the current value.
136141
/// </summary>
@@ -154,7 +159,9 @@ namespace Thinktecture.Tests
154159
throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.");
155160
}
156161
}
162+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly
157163

164+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
158165
/// <summary>
159166
/// Executes a function depending on the current value.
160167
/// </summary>
@@ -181,6 +188,7 @@ namespace Thinktecture.Tests
181188
throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.");
182189
}
183190
}
191+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly
184192

185193
/// <summary>
186194
/// Maps current value to an instance of type <typeparamref name="TResult"/>.

test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/AdHocUnionSourceGeneratorTests.Should_generate_class_with_nullable_string_and_nullable_int.verified.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ namespace Thinktecture.Tests
8080
this._valueIndex = 2;
8181
}
8282

83+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
8384
/// <summary>
8485
/// Executes an action depending on the current value.
8586
/// </summary>
@@ -102,7 +103,9 @@ namespace Thinktecture.Tests
102103
throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.");
103104
}
104105
}
106+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly
105107

108+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
106109
/// <summary>
107110
/// Executes an action depending on the current value.
108111
/// </summary>
@@ -130,7 +133,9 @@ namespace Thinktecture.Tests
130133
throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.");
131134
}
132135
}
136+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly
133137

138+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
134139
/// <summary>
135140
/// Executes a function depending on the current value.
136141
/// </summary>
@@ -154,7 +159,9 @@ namespace Thinktecture.Tests
154159
throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.");
155160
}
156161
}
162+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly
157163

164+
#pragma warning disable CS0436 // InstantHandleAttribute may come from a different assembly
158165
/// <summary>
159166
/// Executes a function depending on the current value.
160167
/// </summary>
@@ -181,6 +188,7 @@ namespace Thinktecture.Tests
181188
throw new global::System.IndexOutOfRangeException($"Unexpected value index '{this._valueIndex}'.");
182189
}
183190
}
191+
#pragma warning restore CS0436 // InstantHandleAttribute may come from a different assembly
184192

185193
/// <summary>
186194
/// Maps current value to an instance of type <typeparamref name="TResult"/>.

0 commit comments

Comments
 (0)