Skip to content

Commit 0a77a00

Browse files
committed
Seperate utils
1 parent 545aa3b commit 0a77a00

File tree

6 files changed

+72
-51
lines changed

6 files changed

+72
-51
lines changed
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
global using Microsoft.CodeAnalysis;
1+
//? Utils from other places
2+
global using Microsoft.CodeAnalysis;
23
global using Microsoft.CodeAnalysis.CSharp;
34
global using Microsoft.CodeAnalysis.CSharp.Syntax;
45
global using System.Collections.Immutable;
5-
global using SecretAPI.CodeGeneration.CodeBuilders;
6-
global using SecretAPI.CodeGeneration.Utils;
76

7+
//? Static utils from other places
88
global using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
99
global using static Microsoft.CodeAnalysis.CSharp.SyntaxFacts;
10-
global using static SecretAPI.CodeGeneration.Utils.Util;
10+
11+
//? Utils from SecretAPI
12+
global using SecretAPI.CodeGeneration.CodeBuilders;
13+
global using SecretAPI.CodeGeneration.Utils;
14+
15+
//? Static utils from SecretAPI
16+
global using static SecretAPI.CodeGeneration.Utils.GenericTypeUtils;
17+
global using static SecretAPI.CodeGeneration.Utils.GeneratedIdentifyUtils;
18+
global using static SecretAPI.CodeGeneration.Utils.MethodUtils;
19+
global using static SecretAPI.CodeGeneration.Utils.TypeUtils;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace SecretAPI.CodeGeneration.Utils;
2+
3+
internal static class GeneratedIdentifyUtils
4+
{
5+
private static AttributeSyntax GetGeneratedCodeAttributeSyntax()
6+
=> Attribute(IdentifierName("GeneratedCode"))
7+
.WithArgumentList(
8+
AttributeArgumentList(
9+
SeparatedList<AttributeArgumentSyntax>(
10+
new SyntaxNodeOrToken[]
11+
{
12+
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal("SecretAPI.CodeGeneration"))),
13+
Token(SyntaxKind.CommaToken),
14+
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal("1.0.0"))),
15+
})));
16+
17+
internal static AttributeListSyntax GetGeneratedCodeAttributeListSyntax()
18+
=> AttributeList(SingletonSeparatedList(GetGeneratedCodeAttributeSyntax()));
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace SecretAPI.CodeGeneration.Utils;
2+
3+
internal static class GenericTypeUtils
4+
{
5+
internal static TypeSyntax GetSingleGenericTypeSyntax(string genericName, SyntaxKind predefinedType)
6+
=> GenericName(genericName)
7+
.WithTypeArgumentList(
8+
TypeArgumentList(
9+
SingletonSeparatedList<TypeSyntax>(
10+
PredefinedType(
11+
Token(predefinedType)))));
12+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace SecretAPI.CodeGeneration.Utils;
2+
3+
internal static class MethodUtils
4+
{
5+
internal static StatementSyntax MethodCallStatement(string typeName, string methodName)
6+
=> ExpressionStatement(
7+
InvocationExpression(
8+
MemberAccessExpression(
9+
SyntaxKind.SimpleMemberAccessExpression,
10+
ParseTypeName(typeName), IdentifierName(methodName))));
11+
12+
internal static StatementSyntax[] MethodCallStatements(IMethodSymbol[] methodCalls)
13+
{
14+
List<StatementSyntax> statements = new();
15+
16+
foreach (IMethodSymbol method in methodCalls)
17+
statements.Add(MethodCallStatement(method.ContainingType.ToDisplayString(), method.Name));
18+
19+
return statements.ToArray();
20+
}
21+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace SecretAPI.CodeGeneration.Utils;
2+
3+
internal static class TypeUtils
4+
{
5+
internal static PredefinedTypeSyntax GetPredefinedTypeSyntax(SyntaxKind kind)
6+
=> PredefinedType(Token(kind));
7+
}

SecretAPI.CodeGeneration/Utils/Util.cs

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)