Skip to content

Commit 4dffd37

Browse files
committed
Format all files changed in my name improvements set of PRs
Command used (csharpier v0.29.2): dotnet csharpier sources/Core/Core/Annotations/NameAffixAttribute.cs && dotnet csharpier sources/Core/Core/Annotations/NativeNameAttribute.cs && dotnet csharpier sources/Core/Core/Annotations/SupportedApiProfileAttribute.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Clang/WindowsStdIncludeResolver.cs && dotnet csharpier sources/SilkTouch/SilkTouch/JobDependencies.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/AddIncludes.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/AddVTables.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/Bakery/DefaultBakeStrategy.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/Common/AttributeUtils.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/Common/ModCSharpSyntaxRewriter.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/Common/ModLoader.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/Common/ModUtils.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/ExtractNestedTyping.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/InterceptNativeFunctions.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/MarkNativeNames.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/MixKhronosData.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/PrettifyNames.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/StripAttributes.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/TransformEnums.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/TransformHandles.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/Transformation/ArrayParameterTransformer.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Mods/Transformation/FunctionTransformer.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Naming/CandidateNames.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Naming/CandidateNamesWithOriginal.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Naming/INameTrimmer.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Naming/NameTrimmer.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Naming/NameTrimmer217.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Naming/NameTrimmer218.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Naming/NameTrimmerContext.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Naming/NameUtils.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Naming/TrimmerOrder.cs && dotnet csharpier sources/SilkTouch/SilkTouch/Sources/IInputResolver.cs && dotnet csharpier tests/SilkTouch/SilkTouch/Khronos/MixKhronosDataTests.cs && dotnet csharpier tests/SilkTouch/SilkTouch/Naming/NameTests.cs
1 parent 7eaa45c commit 4dffd37

24 files changed

+1122
-569
lines changed

sources/Core/Core/Annotations/NameAffixAttribute.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ namespace Silk.NET.Core;
77
/// </summary>
88
[AttributeUsage(
99
AttributeTargets.Class
10-
| AttributeTargets.Delegate
11-
| AttributeTargets.Enum
12-
| AttributeTargets.Field
13-
| AttributeTargets.Method
14-
| AttributeTargets.Parameter
15-
| AttributeTargets.Property
16-
| AttributeTargets.Struct,
10+
| AttributeTargets.Delegate
11+
| AttributeTargets.Enum
12+
| AttributeTargets.Field
13+
| AttributeTargets.Method
14+
| AttributeTargets.Parameter
15+
| AttributeTargets.Property
16+
| AttributeTargets.Struct,
1717
AllowMultiple = true,
1818
Inherited = true
1919
)]

sources/Core/Core/Annotations/NativeNameAttribute.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ namespace Silk.NET.Core;
88
/// </summary>
99
[AttributeUsage(
1010
AttributeTargets.Class
11-
| AttributeTargets.Delegate
12-
| AttributeTargets.Enum
13-
| AttributeTargets.Field
14-
| AttributeTargets.Method
15-
| AttributeTargets.Parameter
16-
| AttributeTargets.Property
17-
| AttributeTargets.Struct,
11+
| AttributeTargets.Delegate
12+
| AttributeTargets.Enum
13+
| AttributeTargets.Field
14+
| AttributeTargets.Method
15+
| AttributeTargets.Parameter
16+
| AttributeTargets.Property
17+
| AttributeTargets.Struct,
1818
AllowMultiple = false,
1919
Inherited = true
2020
)]

sources/SilkTouch/SilkTouch/Mods/AddIncludes.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ public async Task<List<ResponseFile>> BeforeScrapeAsync(string key, List<Respons
6464
var rsp = rsps[i];
6565
var cmdLineArgs = rsp.ClangCommandLineArgs.ToList();
6666

67-
cmdLineArgs.InsertRange(0, cfg.PriorityIncludes?.Select(x => $"--include-directory={x}") ?? []);
68-
cmdLineArgs.AddRange(cfg.AdditionalIncludes?.Select(x => $"--include-directory={x}") ?? []);
67+
cmdLineArgs.InsertRange(
68+
0,
69+
cfg.PriorityIncludes?.Select(x => $"--include-directory={x}") ?? []
70+
);
71+
cmdLineArgs.AddRange(
72+
cfg.AdditionalIncludes?.Select(x => $"--include-directory={x}") ?? []
73+
);
6974

7075
if (!cfg.SuppressStdIncludes)
7176
{

sources/SilkTouch/SilkTouch/Mods/AddVTables.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -777,9 +777,13 @@ out var callConv
777777
x.WithAttributes(
778778
SeparatedList(
779779
x.Attributes.Where(y =>
780-
!y.IsAttribute("System.Runtime.InteropServices.DllImport")
780+
!y.IsAttribute(
781+
"System.Runtime.InteropServices.DllImport"
782+
)
781783
&& !y.IsAttribute("Silk.NET.Core.NativeFunction")
782-
&& !y.IsAttribute("System.Runtime.CompilerServices.MethodImpl")
784+
&& !y.IsAttribute(
785+
"System.Runtime.CompilerServices.MethodImpl"
786+
)
783787
)
784788
)
785789
)
@@ -995,7 +999,8 @@ is not (SyntaxKind.ExternKeyword or SyntaxKind.PartialKeyword)
995999
&& x.ChildTokens()
9961000
.FirstOrDefault(y => y.IsKind(SyntaxKind.IdentifierToken))
9971001
.ToString() == tok.ToString()
998-
) ?? false
1002+
)
1003+
?? false
9991004
)
10001005
)
10011006
{

sources/SilkTouch/SilkTouch/Mods/Bakery/DefaultBakeStrategy.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public virtual MemberDeclarationSyntax BakeMember(
8080
ty.BaseList.Types.Concat(
8181
((BaseTypeDeclarationSyntax)existing.Value.Syntax)
8282
.BaseList
83-
?.Types ?? []
83+
?.Types
84+
?? []
8485
)
8586
.DistinctBy(x => x.ToString())
8687
)
@@ -197,7 +198,9 @@ node is BaseMethodDeclarationSyntax meth
197198
node.AttributeLists.Select(x =>
198199
x.WithAttributes(
199200
SeparatedList(
200-
x.Attributes.Where(y => y.IsAttribute("Silk.NET.Core.SupportedApiAttribute"))
201+
x.Attributes.Where(y =>
202+
y.IsAttribute("Silk.NET.Core.SupportedApiAttribute")
203+
)
201204
)
202205
)
203206
)
@@ -210,7 +213,6 @@ node is BaseMethodDeclarationSyntax meth
210213
// Check that constants and enums have the same value
211214
if (
212215
(existing.Value.Syntax, node) is
213-
214216
(EnumMemberDeclarationSyntax lEnum, EnumMemberDeclarationSyntax rEnum)
215217
)
216218
{
@@ -226,7 +228,6 @@ node is BaseMethodDeclarationSyntax meth
226228
}
227229
else if (
228230
(existing.Value.Syntax, node) is
229-
230231
(FieldDeclarationSyntax lConst, FieldDeclarationSyntax rConst)
231232
)
232233
{

sources/SilkTouch/SilkTouch/Mods/Common/AttributeUtils.cs

Lines changed: 93 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public static bool IsAttribute(this AttributeSyntax node, string fullNameWithout
2929
var sep = node.Name.ToString().Split("::").Last();
3030
var name = fullNameWithoutSuffix.Split('.').Last();
3131
return sep == name
32-
|| sep == $"{name}Attribute"
33-
|| sep.EndsWith(fullNameWithoutSuffix)
34-
|| sep.EndsWith($"{fullNameWithoutSuffix}Attribute");
32+
|| sep == $"{name}Attribute"
33+
|| sep.EndsWith(fullNameWithoutSuffix)
34+
|| sep.EndsWith($"{fullNameWithoutSuffix}Attribute");
3535
}
3636

3737
/// <summary>
@@ -41,8 +41,13 @@ public static bool IsAttribute(this AttributeSyntax node, string fullNameWithout
4141
/// <param name="fullNameWithoutSuffix">
4242
/// The fully-qualified attribute name including the namespace but without the <c>Attribute</c> suffix.
4343
/// </param>
44-
public static bool ContainsAttribute(this IEnumerable<AttributeListSyntax> attributeLists, string fullNameWithoutSuffix) =>
45-
attributeLists.Any(list => list.Attributes.Any(attribute => attribute.IsAttribute(fullNameWithoutSuffix)));
44+
public static bool ContainsAttribute(
45+
this IEnumerable<AttributeListSyntax> attributeLists,
46+
string fullNameWithoutSuffix
47+
) =>
48+
attributeLists.Any(list =>
49+
list.Attributes.Any(attribute => attribute.IsAttribute(fullNameWithoutSuffix))
50+
);
4651

4752
/// <summary>
4853
/// Modifies the <see cref="DllImportAttribute"/>s the method may have to make them resistant to method identifier
@@ -63,7 +68,8 @@ this MethodDeclarationSyntax node
6368
&& (
6469
y.ArgumentList?.Arguments.All(z =>
6570
z.NameEquals?.Name.ToString() != "EntryPoint"
66-
) ?? true
71+
)
72+
?? true
6773
)
6874
? y.AddArgumentListArguments(
6975
AttributeArgument(
@@ -209,8 +215,12 @@ out _
209215
/// Use false if not (outside or appended to end).
210216
/// True means that the attribute is added to the start of the attribute list, meaning that the affix is re-appended earlier.
211217
/// </param>
212-
public static SyntaxList<AttributeListSyntax> AddNamePrefix(this IEnumerable<AttributeListSyntax> attributeLists, string category, string prefix, bool addToInner = false)
213-
=> attributeLists.AddNamePrefixOrSuffix("Prefix", category, prefix, addToInner);
218+
public static SyntaxList<AttributeListSyntax> AddNamePrefix(
219+
this IEnumerable<AttributeListSyntax> attributeLists,
220+
string category,
221+
string prefix,
222+
bool addToInner = false
223+
) => attributeLists.AddNamePrefixOrSuffix("Prefix", category, prefix, addToInner);
214224

215225
/// <summary>
216226
/// Adds a name suffix attribute to the given attribute list.
@@ -223,23 +233,38 @@ public static SyntaxList<AttributeListSyntax> AddNamePrefix(this IEnumerable<Att
223233
/// Use false if not (outside or appended to end).
224234
/// True means that the attribute is added to the start of the attribute list, meaning that the affix is re-appended earlier.
225235
/// </param>
226-
public static SyntaxList<AttributeListSyntax> AddNameSuffix(this IEnumerable<AttributeListSyntax> attributeLists, string category, string suffix, bool addToInner = false)
227-
=> attributeLists.AddNamePrefixOrSuffix("Suffix", category, suffix, addToInner);
228-
229-
private static SyntaxList<AttributeListSyntax> AddNamePrefixOrSuffix(this IEnumerable<AttributeListSyntax> attributeLists, string type, string category, string affix, bool addToInner = false)
236+
public static SyntaxList<AttributeListSyntax> AddNameSuffix(
237+
this IEnumerable<AttributeListSyntax> attributeLists,
238+
string category,
239+
string suffix,
240+
bool addToInner = false
241+
) => attributeLists.AddNamePrefixOrSuffix("Suffix", category, suffix, addToInner);
242+
243+
private static SyntaxList<AttributeListSyntax> AddNamePrefixOrSuffix(
244+
this IEnumerable<AttributeListSyntax> attributeLists,
245+
string type,
246+
string category,
247+
string affix,
248+
bool addToInner = false
249+
)
230250
{
231-
var typeArgument = AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal($"\"{type}\"", type)));
232-
var categoryArgument = AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal($"\"{category}\"", category)));
233-
var affixArgument = AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal($"\"{affix}\"", affix)));
251+
var typeArgument = AttributeArgument(
252+
LiteralExpression(SyntaxKind.StringLiteralExpression, Literal($"\"{type}\"", type))
253+
);
254+
var categoryArgument = AttributeArgument(
255+
LiteralExpression(
256+
SyntaxKind.StringLiteralExpression,
257+
Literal($"\"{category}\"", category)
258+
)
259+
);
260+
var affixArgument = AttributeArgument(
261+
LiteralExpression(SyntaxKind.StringLiteralExpression, Literal($"\"{affix}\"", affix))
262+
);
234263
var argumentList = AttributeArgumentList([typeArgument, categoryArgument, affixArgument]);
235264

236-
var attribute = AttributeList([
237-
Attribute(IdentifierName("NameAffix"), argumentList),
238-
]);
265+
var attribute = AttributeList([Attribute(IdentifierName("NameAffix"), argumentList)]);
239266

240-
return addToInner
241-
? [attribute, ..attributeLists]
242-
: [..attributeLists, attribute];
267+
return addToInner ? [attribute, .. attributeLists] : [.. attributeLists, attribute];
243268
}
244269

245270
/// <summary>
@@ -248,7 +273,10 @@ private static SyntaxList<AttributeListSyntax> AddNamePrefixOrSuffix(this IEnume
248273
/// <remarks>
249274
/// The default usually should be the node's identifier.
250275
/// </remarks>
251-
public static string GetNativeNameOrDefault(this IEnumerable<AttributeListSyntax> attributeLists, SyntaxToken identifier)
276+
public static string GetNativeNameOrDefault(
277+
this IEnumerable<AttributeListSyntax> attributeLists,
278+
SyntaxToken identifier
279+
)
252280
{
253281
if (TryGetNativeName(attributeLists, out var nativeName))
254282
{
@@ -264,7 +292,10 @@ public static string GetNativeNameOrDefault(this IEnumerable<AttributeListSyntax
264292
/// <remarks>
265293
/// The default usually should be the node's identifier.
266294
/// </remarks>
267-
public static string GetNativeNameOrDefault(this IEnumerable<AttributeListSyntax> attributeLists, string defaultName)
295+
public static string GetNativeNameOrDefault(
296+
this IEnumerable<AttributeListSyntax> attributeLists,
297+
string defaultName
298+
)
268299
{
269300
if (TryGetNativeName(attributeLists, out var nativeName))
270301
{
@@ -277,9 +308,14 @@ public static string GetNativeNameOrDefault(this IEnumerable<AttributeListSyntax
277308
/// <summary>
278309
/// Gets the value of the native name attribute from the given attribute list.
279310
/// </summary>
280-
public static bool TryGetNativeName(this IEnumerable<AttributeListSyntax> attributeLists, [NotNullWhen(true)] out string? nativeName)
311+
public static bool TryGetNativeName(
312+
this IEnumerable<AttributeListSyntax> attributeLists,
313+
[NotNullWhen(true)] out string? nativeName
314+
)
281315
{
282-
var nativeNameAttribute = attributeLists.SelectMany(list => list.Attributes).FirstOrDefault(attribute => attribute.IsAttribute("Silk.NET.Core.NativeName"));
316+
var nativeNameAttribute = attributeLists
317+
.SelectMany(list => list.Attributes)
318+
.FirstOrDefault(attribute => attribute.IsAttribute("Silk.NET.Core.NativeName"));
283319
if (nativeNameAttribute == null)
284320
{
285321
nativeName = null;
@@ -295,25 +331,43 @@ public static bool TryGetNativeName(this IEnumerable<AttributeListSyntax> attrib
295331
/// <summary>
296332
/// Sets or replaces the native name attribute in the given attribute list.
297333
/// </summary>
298-
public static SyntaxList<AttributeListSyntax> WithNativeName(this IEnumerable<AttributeListSyntax> attributeLists, string nativeName)
334+
public static SyntaxList<AttributeListSyntax> WithNativeName(
335+
this IEnumerable<AttributeListSyntax> attributeLists,
336+
string nativeName
337+
)
299338
{
300339
var nativeNameAttribute = AttributeList([
301340
Attribute(
302341
IdentifierName("NativeName"),
303342
AttributeArgumentList([
304-
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal($"\"{nativeName}\"", nativeName))),
305-
])),
343+
AttributeArgument(
344+
LiteralExpression(
345+
SyntaxKind.StringLiteralExpression,
346+
Literal($"\"{nativeName}\"", nativeName)
347+
)
348+
),
349+
])
350+
),
306351
]);
307352

308-
return List(attributeLists.Select(list => {
309-
var attributes = list.Attributes;
310-
attributes = [..attributes.Where(attribute => !attribute.IsAttribute("Silk.NET.Core.NativeName"))];
311-
312-
return attributes.Count == 0 ? null : list.WithAttributes(attributes);
313-
})
314-
.Where(list => list != null)
315-
.Cast<AttributeListSyntax>()
316-
.Prepend(nativeNameAttribute));
353+
return List(
354+
attributeLists
355+
.Select(list =>
356+
{
357+
var attributes = list.Attributes;
358+
attributes =
359+
[
360+
.. attributes.Where(attribute =>
361+
!attribute.IsAttribute("Silk.NET.Core.NativeName")
362+
),
363+
];
364+
365+
return attributes.Count == 0 ? null : list.WithAttributes(attributes);
366+
})
367+
.Where(list => list != null)
368+
.Cast<AttributeListSyntax>()
369+
.Prepend(nativeNameAttribute)
370+
);
317371
}
318372

319373
/// <summary>
@@ -368,7 +422,7 @@ out NativeTypeNameInfo info
368422
switch (nativeTypeName)
369423
{
370424
// Handle case: "#define NAME VALUE"
371-
case {} when nativeTypeName.StartsWith("#define "):
425+
case { } when nativeTypeName.StartsWith("#define "):
372426
{
373427
// Trim off the #define
374428
var nativeTypeSpan = nativeTypeName["#define ".Length..].Trim();
@@ -404,7 +458,7 @@ out NativeTypeNameInfo info
404458
}
405459

406460
// Handle cases: "const NAME **", "NAME **"
407-
case {}:
461+
case { }:
408462
{
409463
// Trim off the const
410464
var isConst = false;

sources/SilkTouch/SilkTouch/Mods/Common/ModCSharpSyntaxRewriter.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ public abstract class ModCSharpSyntaxRewriter(bool visitIntoStructuredTrivia = f
1616
: CSharpSyntaxRewriter(visitIntoStructuredTrivia),
1717
ITransformationContext
1818
{
19-
private ThreadLocal<Dictionary<string, UsingDirectiveSyntax>> _usingsToAdd =
20-
new(() => new Dictionary<string, UsingDirectiveSyntax>());
19+
private ThreadLocal<Dictionary<string, UsingDirectiveSyntax>> _usingsToAdd = new(() =>
20+
new Dictionary<string, UsingDirectiveSyntax>()
21+
);
2122

2223
/// <summary>
2324
/// <c>using</c>s to add to the appropriate place within the syntax tree.
@@ -37,7 +38,9 @@ public Dictionary<string, UsingDirectiveSyntax> UsingsToAdd
3738
return ret;
3839
}
3940

40-
foreach (var use in comp.Usings.Where(use => !use.GlobalKeyword.IsKind(SyntaxKind.GlobalKeyword)))
41+
foreach (
42+
var use in comp.Usings.Where(use => !use.GlobalKeyword.IsKind(SyntaxKind.GlobalKeyword))
43+
)
4144
{
4245
AddUsing(use);
4346
}
@@ -68,7 +71,9 @@ and not SyntaxKind.MultiLineCommentTrivia
6871
FileScopedNamespaceDeclarationSyntax node
6972
)
7073
{
71-
foreach (var use in node.Usings.Where(use => !use.GlobalKeyword.IsKind(SyntaxKind.GlobalKeyword)))
74+
foreach (
75+
var use in node.Usings.Where(use => !use.GlobalKeyword.IsKind(SyntaxKind.GlobalKeyword))
76+
)
7277
{
7378
AddUsing(use);
7479
}

0 commit comments

Comments
 (0)