Skip to content

Commit 6984910

Browse files
committed
Refactor WIP
1 parent 11cf617 commit 6984910

13 files changed

Lines changed: 81 additions & 26 deletions

EasySourceGenerators.GeneratorTests/GeneratesMethodExecutionRuntimeTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Reflection;
33
using EasySourceGenerators.Abstractions;
44
using EasySourceGenerators.Generators;
5+
using EasySourceGenerators.Generators.OldGenerators;
56
using Microsoft.CodeAnalysis;
67
using Microsoft.CodeAnalysis.CSharp;
78

EasySourceGenerators.GeneratorTests/GeneratorTestHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.CodeAnalysis;
44
using Microsoft.CodeAnalysis.CSharp;
55
using EasySourceGenerators.Generators;
6+
using EasySourceGenerators.Generators.OldGenerators;
67

78
namespace EasySourceGenerators.GeneratorTests;
89

EasySourceGenerators.Generators/Consts.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using EasySourceGenerators.Abstractions;
22
using EasySourceGenerators.Generators.DataBuilding;
33

4-
// ReSharper disable InconsistentNaming - names like IFoo are neede here
4+
// ReSharper disable InconsistentNaming - names like IFoo are needed here
55

66
namespace EasySourceGenerators.Generators;
77

EasySourceGenerators.Generators/GeneratesMethodGenerator.Diagnostics.cs renamed to EasySourceGenerators.Generators/Diagnostics.cs

File renamed without changes.

EasySourceGenerators.Generators/EasySourceGenerators.Generators.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<PropertyGroup>
33
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
44
<LangVersion>default</LangVersion>
5-
<ImplicitUsings>enable</ImplicitUsings>
5+
<!-- Implicit using needs to be disabled for code to be runnable in generators -->
6+
<ImplicitUsings>disable</ImplicitUsings>
67
<Nullable>enable</Nullable>
78
<Deterministic>true</Deterministic>
89
<IsRoslynAnalyzer>true</IsRoslynAnalyzer>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Microsoft.CodeAnalysis;
2+
using Microsoft.CodeAnalysis.CSharp.Syntax;
3+
using System.Collections.Immutable;
4+
using System.Linq;
5+
using System.Threading;
6+
using EasySourceGenerators.Abstractions;
7+
8+
namespace EasySourceGenerators.Generators.IncrementalGenerators;
9+
10+
[Generator]
11+
public class MethodGenerator : IIncrementalGenerator
12+
{
13+
public void Initialize(IncrementalGeneratorInitializationContext context)
14+
{
15+
//TODO: Uncomment when new generators code is ready
16+
17+
//IncrementalValueProvider<ImmutableArray<MethodDeclarationSyntax?>> methodsWithAttribute = context.SyntaxProvider
18+
// .CreateSyntaxProvider(
19+
// predicate: IsMethodWithGeneratesMethodAttribute,
20+
// transform: GetMethodDeclaration)
21+
// .Where(method => method != null)
22+
// .Collect();
23+
24+
//context.RegisterSourceOutput(
25+
// methodsWithAttribute.Combine(context.CompilationProvider),
26+
// (productionContext, data) => GeneratesMethodGenerationPipeline.Execute(productionContext, data.Left, data.Right));
27+
}
28+
29+
private static bool IsMethodWithGeneratesMethodAttribute(SyntaxNode node, CancellationToken _)
30+
{
31+
if (node is not MethodDeclarationSyntax method)
32+
{
33+
return false;
34+
}
35+
36+
return method.AttributeLists
37+
.SelectMany(attributeList => attributeList.Attributes)
38+
.Any(attribute => attribute.Name.ToString() is nameof(MethodBodyGenerator));
39+
}
40+
41+
private static MethodDeclarationSyntax? GetMethodDeclaration(GeneratorSyntaxContext context, CancellationToken _)
42+
{
43+
return context.Node as MethodDeclarationSyntax;
44+
}
45+
}

EasySourceGenerators.Generators/GeneratesMethodExecutionRuntime.cs renamed to EasySourceGenerators.Generators/OldGenerators/GeneratesMethodExecutionRuntime.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
using Microsoft.CodeAnalysis;
2-
using Microsoft.CodeAnalysis.CSharp;
3-
using Microsoft.CodeAnalysis.CSharp.Syntax;
4-
using Microsoft.CodeAnalysis.Emit;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
55
using System.Reflection;
66
using System.Runtime.Loader;
77
using System.Text;
88
using EasySourceGenerators.Abstractions;
9+
using Microsoft.CodeAnalysis;
10+
using Microsoft.CodeAnalysis.CSharp;
11+
using Microsoft.CodeAnalysis.CSharp.Syntax;
12+
using Microsoft.CodeAnalysis.Emit;
913

10-
namespace EasySourceGenerators.Generators;
14+
namespace EasySourceGenerators.Generators.OldGenerators;
1115

1216
internal sealed record SwitchBodyData(
1317
IReadOnlyList<(object key, string value)> CasePairs,

EasySourceGenerators.Generators/GeneratesMethodGenerationPipeline.cs renamed to EasySourceGenerators.Generators/OldGenerators/GeneratesMethodGenerationPipeline.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
using System.Collections.Generic;
2+
using System.Collections.Immutable;
3+
using System.Linq;
14
using Microsoft.CodeAnalysis;
25
using Microsoft.CodeAnalysis.CSharp.Syntax;
36
using Microsoft.CodeAnalysis.Text;
4-
using System.Collections.Immutable;
57
using static EasySourceGenerators.Generators.Consts;
68

7-
namespace EasySourceGenerators.Generators;
9+
namespace EasySourceGenerators.Generators.OldGenerators;
810

911
internal static class GeneratesMethodGenerationPipeline
1012
{

EasySourceGenerators.Generators/GeneratesMethodGenerationTargetCollector.cs renamed to EasySourceGenerators.Generators/OldGenerators/GeneratesMethodGenerationTargetCollector.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.Immutable;
4+
using System.Linq;
5+
using EasySourceGenerators.Abstractions;
16
using Microsoft.CodeAnalysis;
27
using Microsoft.CodeAnalysis.CSharp.Syntax;
3-
using EasySourceGenerators.Abstractions;
4-
using System.Collections.Immutable;
58
using static EasySourceGenerators.Generators.Consts;
69

7-
namespace EasySourceGenerators.Generators;
10+
namespace EasySourceGenerators.Generators.OldGenerators;
811

912
internal sealed record GeneratesMethodGenerationTarget(
1013
MethodDeclarationSyntax Syntax,

EasySourceGenerators.Generators/GeneratesMethodGenerator.cs renamed to EasySourceGenerators.Generators/OldGenerators/GeneratesMethodGenerator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using Microsoft.CodeAnalysis;
2-
using Microsoft.CodeAnalysis.CSharp.Syntax;
31
using System.Collections.Immutable;
2+
using System.Linq;
3+
using System.Threading;
44
using EasySourceGenerators.Abstractions;
5+
using Microsoft.CodeAnalysis;
6+
using Microsoft.CodeAnalysis.CSharp.Syntax;
57

6-
namespace EasySourceGenerators.Generators;
7-
8-
#pragma warning disable RS1041 // This generator will only work with dotnet 8 to 10
8+
namespace EasySourceGenerators.Generators.OldGenerators;
99

1010
[Generator]
1111
public sealed class GeneratesMethodGenerator : IIncrementalGenerator

0 commit comments

Comments
 (0)